Skip to content

Commit

Permalink
Fix asset path handling to align with WP core handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Jun 25, 2021
1 parent 6057b94 commit 446b786
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,14 @@ function gutenberg_register_packages_scripts( $scripts ) {
// When in production, use the plugin's version as the default asset version;
// else (for development or test) default to use the current time.
$default_version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time();
$suffix = '.min.js';

foreach ( glob( gutenberg_dir_path() . "build/*/index$suffix" ) as $path ) {
foreach ( glob( gutenberg_dir_path() . 'build/*/index.min.js' ) as $path ) {
// Prefix `wp-` to package directory to get script handle.
// For example, `…/build/a11y/index.min.js` becomes `wp-a11y`.
$handle = 'wp-' . basename( dirname( $path ) );

// Replace suffix and extension with `.asset.php` to find the generated dependencies file.
$asset_file = substr( $path, 0, -( strlen( $suffix ) ) ) . '.asset.php';
$asset_file = substr( $path, 0, -( strlen( '.js' ) ) ) . '.asset.php';
$asset = file_exists( $asset_file )
? require( $asset_file )
: null;
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-5.8/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function gutenberg_block_type_metadata_view_script( $settings, $metadata ) {
wp_deregister_script( $view_script_handle );

// Replace suffix and extension with `.asset.php` to find the generated dependencies file.
$view_asset_file = substr( $view_script_path, 0, -( strlen( '.min.js' ) ) ) . '.asset.php';
$view_asset_file = substr( $view_script_path, 0, -( strlen( '.js' ) ) ) . '.asset.php';
$view_asset = file_exists( $view_asset_file ) ? require( $view_asset_file ) : null;
$view_script_dependencies = isset( $view_asset['dependencies'] ) ? $view_asset['dependencies'] : array();
$view_script_version = isset( $view_asset['version'] ) ? $view_asset['version'] : false;
Expand Down
2 changes: 1 addition & 1 deletion packages/dependency-extraction-webpack-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class DependencyExtractionWebpackPlugin {
}

const assetFilename = buildFilename.replace(
/(\.min)?\.js$/i,
/\.js$/i,
'.asset.' + ( outputFormat === 'php' ? 'php' : 'json' )
);

Expand Down

0 comments on commit 446b786

Please sign in to comment.