From 4ae9dee2e5802800f0d37ed4e477bced5a92164a Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Tue, 23 Jul 2024 21:27:42 +0200 Subject: [PATCH] Monorepo: rework deps patching in admin plugin for better Webpack performance. (#49703) * Monorepo: rework deps patching in admin plugin. * Monorepo: changelog entry. --- .../bin/modified-editsite-lock-unlock.js | 5 +++++ plugins/woocommerce-admin/package.json | 2 ++ plugins/woocommerce-admin/webpack.config.js | 10 ---------- .../changelog/dev-webpack-resources-copy-tweaks | 4 ++++ 4 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 plugins/woocommerce/changelog/dev-webpack-resources-copy-tweaks diff --git a/plugins/woocommerce-admin/bin/modified-editsite-lock-unlock.js b/plugins/woocommerce-admin/bin/modified-editsite-lock-unlock.js index 140c67f8930..e9e10980bfd 100644 --- a/plugins/woocommerce-admin/bin/modified-editsite-lock-unlock.js +++ b/plugins/woocommerce-admin/bin/modified-editsite-lock-unlock.js @@ -3,6 +3,11 @@ */ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; +// Workaround for Gutenberg private API consent string differences between WP 6.3 and 6.4+ +// The modified version checks for the WP version and replaces the consent string with the correct one. +// This can be removed once we drop support for WP 6.3 in the "Customize Your Store" task. +// See this PR for details: https://github.com/woocommerce/woocommerce/pull/40884 + const wordPressConsentString = { 6.4: 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', 6.5: 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', diff --git a/plugins/woocommerce-admin/package.json b/plugins/woocommerce-admin/package.json index dbceeeb74d5..6b4cc1fb7f2 100644 --- a/plugins/woocommerce-admin/package.json +++ b/plugins/woocommerce-admin/package.json @@ -16,6 +16,7 @@ "build": "pnpm --if-present --workspace-concurrency=Infinity --stream --filter=\"$npm_package_name...\" '/^build:project:.*$/'", "build:project": "pnpm --if-present '/^build:project:.*$/'", "build:project:bundle": "wireit", + "build:project:patch-dependecies": "cp ./bin/modified-editsite-lock-unlock.js ./node_modules/@wordpress/edit-site/build-module/lock-unlock.js", "build:project:feature-config": "php ../woocommerce/bin/generate-feature-config.php", "changelog": "XDEBUG_MODE=off composer install --quiet && composer exec -- changelogger", "example": "webpack --config docs/examples/extensions/examples.config.js", @@ -29,6 +30,7 @@ "watch:build": "pnpm --if-present --workspace-concurrency=Infinity --filter=\"$npm_package_name...\" --parallel '/^watch:build:project:.*$/'", "watch:build:project": "pnpm --if-present run '/^watch:build:project:.*$/'", "watch:build:project:bundle": "wireit", + "watch:build:project:patch-dependecies": "cp ./bin/modified-editsite-lock-unlock.js ./node_modules/@wordpress/edit-site/build-module/lock-unlock.js", "watch:build:project:feature-config": "WC_ADMIN_PHASE=development php ../woocommerce/bin/generate-feature-config.php", "postinstall": "node ./bin/xstate5-react-script.js" }, diff --git a/plugins/woocommerce-admin/webpack.config.js b/plugins/woocommerce-admin/webpack.config.js index a82c5f86b60..d259661f391 100644 --- a/plugins/woocommerce-admin/webpack.config.js +++ b/plugins/woocommerce-admin/webpack.config.js @@ -10,8 +10,6 @@ const BundleAnalyzerPlugin = const MomentTimezoneDataPlugin = require( 'moment-timezone-data-webpack-plugin' ); const ForkTsCheckerWebpackPlugin = require( 'fork-ts-checker-webpack-plugin' ); const ReactRefreshWebpackPlugin = require( '@pmmmwh/react-refresh-webpack-plugin' ); -const NormalModuleReplacementPlugin = - require( 'webpack' ).NormalModuleReplacementPlugin; /** * Internal dependencies @@ -184,14 +182,6 @@ const webpackConfig = { }, }, plugins: [ - // Workaround for Gutenberg private API consent string differences between WP 6.3 and 6.4+ - // The modified version checks for the WP version and replaces the consent string with the correct one. - // This can be removed once we drop support for WP 6.3 in the "Customize Your Store" task. - // See this PR for details: https://github.com/woocommerce/woocommerce/pull/40884 - new NormalModuleReplacementPlugin( - /@wordpress\/edit-site\/build-module\/lock-unlock\.js/, - path.resolve( __dirname, 'bin/modified-editsite-lock-unlock.js' ) - ), ...styleConfig.plugins, // Runs TypeScript type checker on a separate process. ! process.env.STORYBOOK && new ForkTsCheckerWebpackPlugin(), diff --git a/plugins/woocommerce/changelog/dev-webpack-resources-copy-tweaks b/plugins/woocommerce/changelog/dev-webpack-resources-copy-tweaks new file mode 100644 index 00000000000..1263513684c --- /dev/null +++ b/plugins/woocommerce/changelog/dev-webpack-resources-copy-tweaks @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Monorepo: tweak patching dependencies for better Webpack perfromance.