Skip to content

refactor(assets): align dist filenames with webpack manifest#488

Open
firestar300 wants to merge 4 commits intomasterfrom
refactor/assets-name
Open

refactor(assets): align dist filenames with webpack manifest#488
firestar300 wants to merge 4 commits intomasterfrom
refactor/assets-name

Conversation

@firestar300
Copy link
Copy Markdown
Contributor

@firestar300 firestar300 commented Apr 24, 2026

  • Use stable output names in production (app.js, [name].css) and same MiniCssExtract + WebpackManifestPlugin in all modes.
  • Register theme JS/CSS from assets.json only; remove is_minified() and SCRIPT_DEBUG-based branching.
  • Fix get_asset_data() static cache to key by the requested filename.
  • Update PHPDoc and inline comments to match the new flow.

Note

Medium Risk
Asset build output naming and WordPress theme asset resolution logic are changed to rely on assets.json, which could break script/style loading if the manifest or built files are missing or mismatched.

Overview
Switches webpack to stable production filenames ([name].js, [name].css) and always emits assets.json/extracts CSS via WebpackManifestPlugin + MiniCssExtractPlugin in all modes (bundle analysis remains production-only).

Refactors PHP asset registration to always resolve JS/CSS/editor/login assets via dist/assets.json (removing SCRIPT_DEBUG/is_minified() branching), adds file-existence fallbacks for theme and login stylesheets, and fixes get_asset_data()’s static cache to key by the requested filename.

Reviewed by Cursor Bugbot for commit d2775dc. Bugbot is set up for automated code reviews on this repo. Configure here.

- Use stable output names in production (app.js, [name].css) and same
  MiniCssExtract + WebpackManifestPlugin in all modes.
- Register theme JS/CSS from assets.json only; remove is_minified() and
  SCRIPT_DEBUG-based branching.
- Fix get_asset_data() static cache to key by the requested filename.
- Update PHPDoc and inline comments to match the new flow.
Comment thread inc/Services/Assets.php
Comment thread inc/Services/Editor.php
Comment thread inc/Services/Assets.php
Add empty-file check, dist/login.css fallback, and pass through filter
default to avoid invalid dist/ URL when get_min_file returns empty.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d2775dc. Configure here.

Comment thread inc/Services/Assets.php
$theme = wp_get_theme();

// Js
$file = $this->is_minified() ? $this->get_min_file( 'js' ) : 'app.js';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

JS registration lacks empty-file guard unlike CSS paths

Medium Severity

get_min_file('js') returns an empty string when assets.json is absent or lacks the app.js key. In that case register_script is called with path 'dist/', registering a broken script URL pointing to a directory. The CSS equivalents (stylesheet_uri and login_stylesheet_uri) both have proper fallback chains (check for empty, try a hardcoded dist/app.css, then fall back to the original URI), but the JS registration has no guard or fallback at all. The old ternary guaranteed a non-empty 'app.js' fallback in dev mode; removing it without adding an equivalent guard leaves the JS path unprotected.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d2775dc. Configure here.

Comment thread inc/Services/Editor.php
*/
public function admin_editor_script(): void {
$file = $this->assets->is_minified() ? $this->assets->get_min_file( 'editor.js' ) : 'editor.js';
$file = $this->assets->get_min_file( 'editor.js' );
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Editor script guard bypassed when file is empty

Medium Severity

When get_min_file('editor.js') returns an empty string, $filepath becomes 'dist/'. The guard on line 83 uses file_exists(), which returns true for directories, so the check is bypassed and a broken script is registered at 'dist/'. The sibling style() method correctly uses is_file() for its guard, which returns false for directories. Previously the hardcoded 'editor.js' fallback in dev mode prevented $file from ever being empty; removing that fallback makes this guard ineffective.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d2775dc. Configure here.

@francoistibo
Copy link
Copy Markdown
Contributor

TODO :
Actions maj la doc pour supprimer le SCRIPT_DEBUG (modèle de wiki + wiki projets)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants