Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Work on centralized script module registration
  • Loading branch information
sirreal committed Sep 20, 2024
commit bdd512320390ad1b9a93511bd5bb33c30accbad9
1 change: 1 addition & 0 deletions src/wp-includes/assets/script-modules-packages.min.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('interactivity/index.min.js' => array('dependencies' => array(), 'version' => '3e74d9d0860b282f2c76', 'type' => 'module'), 'interactivity/debug.min.js' => array('dependencies' => array(), 'version' => '75090a5bf4a74c69c96c', 'type' => 'module'), 'interactivity-router/index.min.js' => array('dependencies' => array('@wordpress/interactivity'), 'version' => '64645ef3cd2d32860d7d', 'type' => 'module'), 'a11y/index.min.js' => array('dependencies' => array(), 'version' => 'b7d06936b8bc23cff2ad', 'type' => 'module'));
35 changes: 31 additions & 4 deletions src/wp-includes/script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,39 @@ function wp_default_script_modules() {
$assets = include ABSPATH . WPINC . "/assets/script-modules-packages{$suffix}.php";

foreach ( $assets as $file_name => $script_module_data ) {
if ( basename( $file_name ) !== "index{$suffix}.js" ) {
continue;
$package_name = dirname( $file_name );
$package_sub_name = basename( $file_name, "{$suffix}.js" );

switch ( $package_name ) {
/*
* Interactivity exposes two entrypoints, `/index` and `/debug`.
* They're the production and development versions of the package.
*/
case 'interactivity':
if ( SCRIPT_DEBUG ) {
if ( 'index' === $package_sub_name ) {
continue 2;
}
} else {
if ( 'debug' === $package_sub_name ) {
continue 2;
}
}
$script_module_id = '@wordpress/interactivity';
break;

/*
* @wordpress/block-library block view script modules
*/
case 'interactivity':

default:
$script_module_id = 'index' === $package_sub_name ?
"@wordpress/{$package_name}" :
"@wordpress/{$package_name}/{$package_sub_name}";
}
$script_module_id = '@wordpress/' . dirname( $file_name );
$path = "/wp-includes/js/dist/script-modules/{$file_name}";

$path = "/wp-includes/js/dist/script-modules/{$file_name}";
wp_register_script_module( $script_module_id, $path, $script_module_data['dependencies'], $script_module_data['version'] );
}
}
2 changes: 2 additions & 0 deletions tools/webpack/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ const MODULES = [
'@wordpress/interactivity-router',
];
const SCRIPT_AND_MODULE_DUAL_PACKAGES = [
'@wordpress/a11y',
'@wordpress/block-library',
];
const WORDPRESS_NAMESPACE = '@wordpress/';

Expand Down