-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If a Core block's `block.json` contains a `render` and/or `variations` field that points to a PHP file name, copy those files to the build directory. Co-authored-by: ockham <bernhard-reiter@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org>
- Loading branch information
1 parent
aca9273
commit cc133bf
Showing
5 changed files
with
103 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const { validate } = require( 'schema-utils' ); | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const { getPhpFilePaths } = require( './config' ); | ||
|
||
const phpFilePathsPluginSchema = { | ||
type: 'object', | ||
properties: { | ||
context: { | ||
type: 'string', | ||
}, | ||
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 | ||
* changes in `block.json` files are picked up in watch mode. | ||
*/ | ||
class PhpFilePathsPlugin { | ||
/** | ||
* PHP file paths from `render` and `variations` props found in `block.json` files. | ||
* | ||
* @type {string[]} | ||
*/ | ||
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( | ||
this.options.context, | ||
this.options.props | ||
); | ||
} ); | ||
} | ||
} | ||
|
||
module.exports = { PhpFilePathsPlugin }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters