Skip to content

WIP: Attempt to remove the need for PHP asset files.#76712

Draft
desrosj wants to merge 2 commits intotrunkfrom
try/remove-need-for-index.min.asset.php-files
Draft

WIP: Attempt to remove the need for PHP asset files.#76712
desrosj wants to merge 2 commits intotrunkfrom
try/remove-need-for-index.min.asset.php-files

Conversation

@desrosj
Copy link
Member

@desrosj desrosj commented Mar 20, 2026

DO NOT MERGE

What?

This aims to remove the need for any .min.asset.php files for script modules. The contents of these files are PHP arrays containing a list of dependencies at the dependencies key, and a version string keyed at version.

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.php file instead.

The registry.php related to styles is not bundled with a version key, but the dependencies are included in that file.

The wordpress-develop build script has a function dedicated to parsing all of these .php files in order to include the dependencies and version details 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

Before After

Use of AI Tools

@desrosj desrosj changed the title Attempt to remove the need for PHP asset files. WIP: Attempt to remove the need for PHP asset files. Mar 20, 2026
@desrosj desrosj force-pushed the try/remove-need-for-index.min.asset.php-files branch from d6a8092 to 81394ba Compare March 20, 2026 04:44
@desrosj desrosj self-assigned this Mar 20, 2026
@desrosj desrosj added [Type] Build Tooling Issues or PRs related to build tooling [Package] wp-build /packages/wp-build [Type] Bug An existing feature does not function as intended and removed [Type] Bug An existing feature does not function as intended labels Mar 20, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and version, 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';
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
$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;
}
}

Copilot uses AI. Check for mistakes.

$asset_path = $modules_dir . '/' . $module['asset'];
$asset = file_exists( $asset_path ) ? require $asset_path : array();
$version = SCRIPT_DEBUG ? false : ( $module['version'] ?? false );
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$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).

Suggested change
$version = SCRIPT_DEBUG ? false : ( $module['version'] ?? false );
$version = SCRIPT_DEBUG ? false : ( ! empty( $module['version'] ) ? $module['version'] : false );

Copilot uses AI. Check for mistakes.
$dependencies = $asset['dependencies'] ?? array();
$version = $asset['version'] ?? $default_version;
$dependencies = $script_data['dependencies'] ?? array();
$version = SCRIPT_DEBUG ? $default_version : ( $script_data['version'] ?? $default_version );
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'] )).

Suggested change
$version = SCRIPT_DEBUG ? $default_version : ( $script_data['version'] ?? $default_version );
$version = SCRIPT_DEBUG ? $default_version : ( ! empty( $script_data['version'] ) ? $script_data['version'] : $default_version );

Copilot uses AI. Check for mistakes.
Comment on lines +942 to +943
`\t\t'module_dependencies' => array(${ moduleDepsPhp }),\n` +
`\t\t'version' => '${ module.version ?? '' }',\n`;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
`\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`;
}

Copilot uses AI. Check for mistakes.
if ( moduleDepsPhp ) {
entry += `\t\t'module_dependencies' => array(${ moduleDepsPhp }),\n`;
}
entry += `\t\t'version' => '${ script.version ?? '' }',\n` + `\t),`;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
entry += `\t\t'version' => '${ script.version ?? '' }',\n` + `\t),`;
if ( script.version ) {
entry += `\t\t'version' => '${ script.version }',\n`;
}
entry += `\t),`;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] wp-build /packages/wp-build [Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants