From a301d56e0fce5c2d013a0f3c195d3aec1110f84b Mon Sep 17 00:00:00 2001 From: David Arenas Date: Wed, 8 May 2024 16:52:02 +0200 Subject: [PATCH 1/4] Add an entry point for the runtime's debug version --- tools/webpack/modules.js | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/tools/webpack/modules.js b/tools/webpack/modules.js index cfb19aedbb3a1..c3c977f6b6321 100644 --- a/tools/webpack/modules.js +++ b/tools/webpack/modules.js @@ -14,6 +14,10 @@ const { WORDPRESS_NAMESPACE, } = require( './shared' ); +const SUBMODULES = [ + { name: 'interactivity-debug', path: 'interactivity/build-module/debug' }, +]; + module.exports = function ( env = { environment: 'production', watch: false, buildTarget: false } ) { @@ -29,18 +33,30 @@ module.exports = function ( const baseConfig = getBaseConfig( env ); const config = { ...baseConfig, - entry: MODULES.map( ( packageName ) => - packageName.replace( WORDPRESS_NAMESPACE, '' ) - ).reduce( ( memo, packageName ) => { - memo[ packageName ] = { - import: normalizeJoin( - baseDir, - `node_modules/@wordpress/${ packageName }` - ), - }; + entry: { + ...MODULES.map( ( packageName ) => + packageName.replace( WORDPRESS_NAMESPACE, '' ) + ).reduce( ( memo, packageName ) => { + memo[ packageName ] = { + import: normalizeJoin( + baseDir, + `node_modules/@wordpress/${ packageName }` + ), + }; + + return memo; + }, {} ), + ...SUBMODULES.reduce( ( memo, { name, path } ) => { + memo[ name ] = { + import: normalizeJoin( + baseDir, + `node_modules/@wordpress/${ path }` + ), + }; - return memo; - }, {} ), + return memo; + }, {} ), + }, experiments: { outputModule: true, }, From d03d5f54af2b83bfe9886f4091a1cfae17161c37 Mon Sep 17 00:00:00 2001 From: David Arenas Date: Wed, 8 May 2024 16:52:37 +0200 Subject: [PATCH 2/4] Register the runtime's debug version when appropriate --- .../interactivity-api/class-wp-interactivity-api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php index ac9a48982a5c5..e2a17bac17432 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -219,9 +219,12 @@ public function print_client_interactivity_data() { public function register_script_modules() { $suffix = wp_scripts_get_suffix(); + // Use a debug version of the runtime when SCRIPT_DEBUG is enabled. + $runtime_module = SCRIPT_DEBUG ? 'interactivity-debug' : 'interactivity'; + wp_register_script_module( '@wordpress/interactivity', - includes_url( "js/dist/interactivity$suffix.js" ) + includes_url( "js/dist/$runtime_module$suffix.js" ) ); wp_register_script_module( From b1ce722727b018ad5c608ce3fc1fdb68d196de21 Mon Sep 17 00:00:00 2001 From: David Arenas Date: Thu, 23 May 2024 18:50:28 +0200 Subject: [PATCH 3/4] Change the entry point depending on the mode --- tools/webpack/modules.js | 42 ++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/tools/webpack/modules.js b/tools/webpack/modules.js index c3c977f6b6321..e365942b85c24 100644 --- a/tools/webpack/modules.js +++ b/tools/webpack/modules.js @@ -14,10 +14,6 @@ const { WORDPRESS_NAMESPACE, } = require( './shared' ); -const SUBMODULES = [ - { name: 'interactivity-debug', path: 'interactivity/build-module/debug' }, -]; - module.exports = function ( env = { environment: 'production', watch: false, buildTarget: false } ) { @@ -33,30 +29,22 @@ module.exports = function ( const baseConfig = getBaseConfig( env ); const config = { ...baseConfig, - entry: { - ...MODULES.map( ( packageName ) => - packageName.replace( WORDPRESS_NAMESPACE, '' ) - ).reduce( ( memo, packageName ) => { - memo[ packageName ] = { - import: normalizeJoin( - baseDir, - `node_modules/@wordpress/${ packageName }` - ), - }; - - return memo; - }, {} ), - ...SUBMODULES.reduce( ( memo, { name, path } ) => { - memo[ name ] = { - import: normalizeJoin( - baseDir, - `node_modules/@wordpress/${ path }` - ), - }; + entry: MODULES.map( ( packageName ) => + packageName.replace( WORDPRESS_NAMESPACE, '' ) + ).reduce( ( memo, packageName ) => { + const path = + 'development' === mode && 'interactivity' === packageName + ? 'interactivity/build-module/debug' + : packageName; + memo[ packageName ] = { + import: normalizeJoin( + baseDir, + `node_modules/@wordpress/${ path }` + ), + }; - return memo; - }, {} ), - }, + return memo; + }, {} ), experiments: { outputModule: true, }, From 9fbcb9b26052386210eab0daeeae10e129771399 Mon Sep 17 00:00:00 2001 From: David Arenas Date: Thu, 23 May 2024 18:51:25 +0200 Subject: [PATCH 4/4] Revert "Register the runtime's debug version when appropriate" This reverts commit 6088342c9604e1f19c340db714f784c8d066fd81. --- .../interactivity-api/class-wp-interactivity-api.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php index e2a17bac17432..ac9a48982a5c5 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -219,12 +219,9 @@ public function print_client_interactivity_data() { public function register_script_modules() { $suffix = wp_scripts_get_suffix(); - // Use a debug version of the runtime when SCRIPT_DEBUG is enabled. - $runtime_module = SCRIPT_DEBUG ? 'interactivity-debug' : 'interactivity'; - wp_register_script_module( '@wordpress/interactivity', - includes_url( "js/dist/$runtime_module$suffix.js" ) + includes_url( "js/dist/interactivity$suffix.js" ) ); wp_register_script_module(