Making WordPress.org

Changeset 10085

Timestamp:
07/20/2020 08:40:31 AM (4 years ago)
Author:
tellyworth
Message:

Plugin directory: better asset detection in block checker.

This should make the block checker use identical guesswork to the importer when looking for block assets.

See #5303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-block-plugin-checker.php

    r10071 r10085  
    3737    protected $asset_php_files = null;
    3838    protected $block_json_validation = array();
     39
     40
    3941
    4042    /**
     
    233235
    234236        $this->asset_php_files = $this->find_asset_php_files( $this->path_to_plugin );
     237
     238
     239
    235240    }
    236241
     
    274279    }
    275280
    276     public function find_block_scripts() {
     281    public function find_block_assets( $base_dir ) {
     282        $assets = Import::find_possible_block_assets( $base_dir );
     283        $assets = array_map( array( $this, 'relative_filename' ), $assets );
     284
     285        $block_assets = array(
     286            'js' => array(),
     287            'css' => array(),
     288        );
     289
     290        foreach ( $assets as $file ) {
     291            $ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
     292            if ( array_key_exists( $ext, $block_assets ) ) {
     293                $block_assets[ $ext ][] = $file;
     294            }
     295        }
     296
     297        return $block_assets;
     298    }
     299
     300    public function find_block_scripts( $base_dir ) {
     301
    277302        $block_scripts = \array_map(
    278303            function( $block ) {
     
    283308                    if ( isset( $block->$prop ) ) {
    284309                        $assets[ $prop ] = $block->$prop;
     310
     311
     312
     313
     314
     315
     316
     317
     318
     319
     320
     321
    285322                    }
    286323                }
     
    570607    function check_for_block_script_files() {
    571608        $seen_scripts = array();
    572         foreach ( $this->find_block_scripts() as $block_name => $scripts ) {
     609        foreach ( $this-> as $block_name => $scripts ) {
    573610            foreach ( $scripts as $kind => $script ) {
    574611                // No need to warn multiple times for the same value.
Note: See TracChangeset for help on using the changeset viewer.