From f033eb3fd18f8a1f5169c653150d50a064e1926c Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 21 May 2024 17:03:03 +0200 Subject: [PATCH 1/2] Add globalThis DefinePlugin config to webpack This updates the build to account for the following PR: https://github.com/WordPress/gutenberg/pull/61486 --- tools/webpack/shared.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/webpack/shared.js b/tools/webpack/shared.js index 6c1397db40f09..7871259074ad6 100644 --- a/tools/webpack/shared.js +++ b/tools/webpack/shared.js @@ -41,6 +41,26 @@ const getBaseConfig = ( env ) => { watch: env.watch, plugins: [ new DefinePlugin( { + /* + * These variables are part of https://github.com/WordPress/gutenberg/pull/61486 + * They're expected to be released in an upcoming version of Gutenberg. + * + * Defining this before the packages are released is harmless. + * + * @todo Remove the non-globalThis defines here when packages have been upgraded to the globalThis versions. + */ + + // Inject the `IS_GUTENBERG_PLUGIN` global, used for feature flagging. + 'globalThis.IS_GUTENBERG_PLUGIN': JSON.stringify( + Boolean( process.env.npm_package_config_IS_GUTENBERG_PLUGIN ) + ), + // Inject the `IS_WORDPRESS_CORE` global, used for feature flagging. + 'globalThis.IS_WORDPRESS_CORE': JSON.stringify( + Boolean( process.env.npm_package_config_IS_WORDPRESS_CORE ) + ), + // Inject the `SCRIPT_DEBUG` global, used for dev versions of JavaScript. + 'globalThis.SCRIPT_DEBUG': JSON.stringify( mode === 'development' ), + // Inject the `IS_GUTENBERG_PLUGIN` global, used for feature flagging. 'process.env.IS_GUTENBERG_PLUGIN': false, // Inject the `IS_WORDPRESS_CORE` global, used for feature flagging. From c825a2931c7eafde17f2d7975894e720147b4bd4 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 23 May 2024 14:11:27 +0200 Subject: [PATCH 2/2] fix config variables --- tools/webpack/shared.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/webpack/shared.js b/tools/webpack/shared.js index 7871259074ad6..ec12959351151 100644 --- a/tools/webpack/shared.js +++ b/tools/webpack/shared.js @@ -51,22 +51,20 @@ const getBaseConfig = ( env ) => { */ // Inject the `IS_GUTENBERG_PLUGIN` global, used for feature flagging. - 'globalThis.IS_GUTENBERG_PLUGIN': JSON.stringify( - Boolean( process.env.npm_package_config_IS_GUTENBERG_PLUGIN ) - ), + 'globalThis.IS_GUTENBERG_PLUGIN': JSON.stringify( false ), // Inject the `IS_WORDPRESS_CORE` global, used for feature flagging. - 'globalThis.IS_WORDPRESS_CORE': JSON.stringify( - Boolean( process.env.npm_package_config_IS_WORDPRESS_CORE ) - ), + 'globalThis.IS_WORDPRESS_CORE': JSON.stringify( true ), // Inject the `SCRIPT_DEBUG` global, used for dev versions of JavaScript. - 'globalThis.SCRIPT_DEBUG': JSON.stringify( mode === 'development' ), + 'globalThis.SCRIPT_DEBUG': JSON.stringify( + mode === 'development' + ), // Inject the `IS_GUTENBERG_PLUGIN` global, used for feature flagging. - 'process.env.IS_GUTENBERG_PLUGIN': false, + 'process.env.IS_GUTENBERG_PLUGIN': JSON.stringify( false ), // Inject the `IS_WORDPRESS_CORE` global, used for feature flagging. - 'process.env.IS_WORDPRESS_CORE': true, + 'process.env.IS_WORDPRESS_CORE': JSON.stringify( true ), // Inject the `SCRIPT_DEBUG` global, used for dev versions of JavaScript. - SCRIPT_DEBUG: mode === 'development', + SCRIPT_DEBUG: JSON.stringify( mode === 'development' ), } ), ], };