Skip to content

Commit

Permalink
Make path props configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Jul 16, 2024
1 parent 9c48c06 commit 5fca20b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
29 changes: 24 additions & 5 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 );
} );
}
}
Expand Down Expand Up @@ -324,7 +343,7 @@ const scriptConfig = {
cleanStaleWebpackAssets: false,
} ),

new PhpFilePathsPlugin(),
new PhpFilePathsPlugin( { props: [ 'render', 'variations' ] } ),
new CopyWebpackPlugin( {
patterns: [
{
Expand Down
1 change: 1 addition & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5fca20b

Please sign in to comment.