WIP: Attempt to remove the need for PHP asset files.#76712
WIP: Attempt to remove the need for PHP asset files.#76712
Conversation
d6a8092 to
81394ba
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the wp-build pipeline to stop relying on generated *.asset.php files for scripts/modules by capturing dependency/version metadata during bundling and embedding it into the generated scripts/registry.php and modules/registry.php.
Changes:
- Capture dependency + version metadata in-memory during esbuild bundling (instead of emitting/reading
.asset.php). - Extend generated script/module registries to include
dependencies,module_dependencies, andversion, and update PHP registration templates to read from those registries. - Update block editor settings REST processing to read boot dependencies from the modules registry instead of
index.min.asset.php.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/wp-build/templates/script-registration.php.template | Reads script dependencies/version from scripts/registry.php instead of per-script asset files. |
| packages/wp-build/templates/module-registration.php.template | Reads module dependencies/version from modules/registry.php instead of per-module asset files. |
| packages/wp-build/lib/wordpress-externals-plugin.mjs | Adds optional result container to return deps/module deps/version without writing .asset.php. |
| packages/wp-build/lib/build.mjs | Plumbs captured metadata into registries and removes parsing of .asset.php for style inference. |
| lib/experimental/class-wp-rest-block-editor-settings-controller.php | Switches boot dependency lookup from module asset file to modules registry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $boot_asset_file = include __DIR__ . '/../../build/modules/boot/index.min.asset.php'; | ||
| $boot_dependencies = $boot_asset_file['dependencies'] ?? array(); | ||
| // Get boot module dependencies from the modules registry. | ||
| $modules_registry = require __DIR__ . '/../../build/modules/registry.php'; |
There was a problem hiding this comment.
require on build/modules/registry.php will fatally error if the build artifacts aren’t present (e.g., development checkout without npm run build). Previously this used include for an asset file, which failed more gracefully. Please guard with file_exists() and fall back to an empty registry (or keep using include and validate the return value) before iterating.
| $modules_registry = require __DIR__ . '/../../build/modules/registry.php'; | |
| $modules_registry_file = __DIR__ . '/../../build/modules/registry.php'; | |
| $modules_registry = array(); | |
| if ( file_exists( $modules_registry_file ) ) { | |
| $maybe_registry = include $modules_registry_file; | |
| if ( is_array( $maybe_registry ) ) { | |
| $modules_registry = $maybe_registry; | |
| } | |
| } |
|
|
||
| $asset_path = $modules_dir . '/' . $module['asset']; | ||
| $asset = file_exists( $asset_path ) ? require $asset_path : array(); | ||
| $version = SCRIPT_DEBUG ? false : ( $module['version'] ?? false ); |
There was a problem hiding this comment.
$module['version'] may be present but empty (the registry generator currently emits an empty string when version is missing). Passing an empty string to wp_register_script_module results in a ver= query arg rather than behaving like false. Consider treating empty string as false (e.g., use ! empty( $module['version'] ) ? $module['version'] : false).
| $version = SCRIPT_DEBUG ? false : ( $module['version'] ?? false ); | |
| $version = SCRIPT_DEBUG ? false : ( ! empty( $module['version'] ) ? $module['version'] : false ); |
| $dependencies = $asset['dependencies'] ?? array(); | ||
| $version = $asset['version'] ?? $default_version; | ||
| $dependencies = $script_data['dependencies'] ?? array(); | ||
| $version = SCRIPT_DEBUG ? $default_version : ( $script_data['version'] ?? $default_version ); |
There was a problem hiding this comment.
Similar to modules: $script_data['version'] ?? $default_version will use an empty-string version from the registry (if present), which produces a ver= query arg and disables cache busting. Consider falling back to $default_version when the registry version is empty (e.g., check ! empty( $script_data['version'] )).
| $version = SCRIPT_DEBUG ? $default_version : ( $script_data['version'] ?? $default_version ); | |
| $version = SCRIPT_DEBUG ? $default_version : ( ! empty( $script_data['version'] ) ? $script_data['version'] : $default_version ); |
| `\t\t'module_dependencies' => array(${ moduleDepsPhp }),\n` + | ||
| `\t\t'version' => '${ module.version ?? '' }',\n`; |
There was a problem hiding this comment.
The registry generator always emits a 'version' => '...' key, defaulting to an empty string when module.version is undefined. This makes downstream consumers treat the version as a real (but empty) value instead of “no version”/false, leading to ver= query args. Consider omitting the version key entirely when module.version is missing, or emitting false/null consistently with previous .asset.php semantics.
| `\t\t'module_dependencies' => array(${ moduleDepsPhp }),\n` + | |
| `\t\t'version' => '${ module.version ?? '' }',\n`; | |
| `\t\t'module_dependencies' => array(${ moduleDepsPhp }),\n`; | |
| if ( module.version === undefined || module.version === null ) { | |
| entry += `\t\t'version' => false,\n`; | |
| } else { | |
| entry += `\t\t'version' => '${ module.version }',\n`; | |
| } |
| if ( moduleDepsPhp ) { | ||
| entry += `\t\t'module_dependencies' => array(${ moduleDepsPhp }),\n`; | ||
| } | ||
| entry += `\t\t'version' => '${ script.version ?? '' }',\n` + `\t),`; |
There was a problem hiding this comment.
Same issue for scripts: the registry generator forces a 'version' key and writes an empty string when script.version is undefined. This can result in scripts being registered with ver= instead of falling back to the build constants version. Consider only writing the version key when a non-empty version is available, or writing $default_version into the registry explicitly.
| entry += `\t\t'version' => '${ script.version ?? '' }',\n` + `\t),`; | |
| if ( script.version ) { | |
| entry += `\t\t'version' => '${ script.version }',\n`; | |
| } | |
| entry += `\t),`; |
DO NOT MERGE
What?
This aims to remove the need for any
.min.asset.phpfiles for script modules. The contents of these files are PHP arrays containing a list of dependencies at thedependencieskey, and a version string keyed atversion.Why?
While this information is important, it would be nice to skip having to generate these files entirely by including this information in the
registry.phpfile instead.The
registry.phprelated to styles is not bundled with aversionkey, but thedependenciesare included in that file.The
wordpress-developbuild script has a function dedicated to parsing all of these.phpfiles in order to include thedependenciesandversiondetails in a built file. Including these details in one registry file by default eliminates the need for that.How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
Use of AI Tools