From 5fca20b257e320493b65e8ad3c5e5bbdbe09ec96 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 16 Jul 2024 10:58:32 +0200 Subject: [PATCH] Make path props configurable --- packages/scripts/config/webpack.config.js | 29 +++++++++++++++++++---- packages/scripts/package.json | 1 + 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/scripts/config/webpack.config.js b/packages/scripts/config/webpack.config.js index b3b8af22b5812..508d4d262942d 100644 --- a/packages/scripts/config/webpack.config.js +++ b/packages/scripts/config/webpack.config.js @@ -13,6 +13,7 @@ const RtlCssPlugin = require( 'rtlcss-webpack-plugin' ); const TerserPlugin = require( 'terser-webpack-plugin' ); const { realpathSync } = require( 'fs' ); const { sync: glob } = require( 'fast-glob' ); +const { validate } = require( 'schema-utils' ); /** * WordPress dependencies @@ -49,6 +50,18 @@ const hasExperimentalModulesFlag = getAsBooleanFromENV( 'WP_EXPERIMENTAL_MODULES' ); +const phpFilePathsPluginSchema = { + type: 'object', + properties: { + props: { + type: 'array', + items: { + type: 'string', + }, + }, + }, +}; + /** * The plugin recomputes PHP file paths once on each compilation. It is necessary to avoid repeating processing * when filtering every discovered PHP file in the source folder. This is the most performant way to ensure that @@ -62,14 +75,20 @@ class PhpFilePathsPlugin { */ static paths; + constructor( options = {} ) { + validate( phpFilePathsPluginSchema, options, { + name: 'PHP File Paths Plugin', + baseDataPath: 'options', + } ); + + this.options = options; + } + apply( compiler ) { const pluginName = this.constructor.name; compiler.hooks.thisCompilation.tap( pluginName, () => { - this.constructor.paths = getPhpFilePaths( [ - 'render', - 'variations', - ] ); + this.constructor.paths = getPhpFilePaths( this.options.props ); } ); } } @@ -324,7 +343,7 @@ const scriptConfig = { cleanStaleWebpackAssets: false, } ), - new PhpFilePathsPlugin(), + new PhpFilePathsPlugin( { props: [ 'render', 'variations' ] } ), new CopyWebpackPlugin( { patterns: [ { diff --git a/packages/scripts/package.json b/packages/scripts/package.json index 6d735745977da..6f5218f7978f0 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -82,6 +82,7 @@ "rtlcss-webpack-plugin": "^4.0.7", "sass": "^1.35.2", "sass-loader": "^12.1.0", + "schema-utils": "^4.2.0", "source-map-loader": "^3.0.0", "stylelint": "^14.2.0", "terser-webpack-plugin": "^5.3.9",