fix: interpolate [fullhash:N] / [hash:N] in output.publicPath at runtime#21004
Conversation
The detection regex in RuntimePlugin only matched [fullhash] / [hash] without a length suffix, so PublicPathRuntimeModule was not flagged as a full-hash module and __webpack_require__.p kept the placeholder "XXXX" instead of the real hash truncated to the requested length. Also adds test coverage for output.publicPath placeholders and for Rule.generator.publicPath with every supported placeholder ([file], [name], [ext], [base], [path], [id], [hash], [modulehash], [contenthash], [runtime], function form, plain and empty strings).
…ders Expand output-publicPath-placeholders into a multi-entry test using entry-level publicPath so a single build exercises every supported form: - plain string - string with [fullhash] - string with [fullhash:N] (regression for the length-suffix fix) - string with multiple [fullhash]/[fullhash:N] - function returning a plain string - function reading data.hash directly - function returning a string containing [fullhash:N]
🦋 Changeset detectedLatest commit: 607dc8c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (9edcb3d). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@9edcb3d
yarn add -D webpack@https://pkg.pr.new/webpack@9edcb3d
pnpm add -D webpack@https://pkg.pr.new/webpack@9edcb3d |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21004 +/- ##
=======================================
Coverage 90.94% 90.94%
=======================================
Files 573 573
Lines 58986 58986
Branches 15898 15898
=======================================
Hits 53644 53644
Misses 5342 5342
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes runtime interpolation of [fullhash:N] / [hash:N] in publicPath strings by ensuring PublicPathRuntimeModule is treated as a full-hash-dependent runtime module when a length suffix is present, and adds config-case coverage for output.publicPath and Rule.generator.publicPath placeholder interpolation.
Changes:
- Update
RuntimePluginhash-placeholder detection to also match[fullhash:N]/[hash:N]. - Add config-case tests for
output.publicPathplaceholder interpolation (plain,[fullhash],[fullhash:N], combined, and function forms). - Add config-case tests for
Rule.generator.publicPathcovering plain/empty values and supported placeholders across asset types.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
lib/RuntimePlugin.js |
Expands publicPath placeholder detection to include :N length suffix. |
.changeset/public-path-fullhash-length-suffix.md |
Adds a patch changeset documenting the fix and impact. |
test/configCases/asset-modules/output-publicPath-placeholders/webpack.config.js |
New config case exercising entry publicPath with [fullhash] and [fullhash:N] plus function forms. |
test/configCases/asset-modules/output-publicPath-placeholders/test.config.js |
Runs all entry bundles for the new output publicPath placeholder case. |
test/configCases/asset-modules/output-publicPath-placeholders/plain.js |
Asserts plain string publicPath behavior for asset URLs. |
test/configCases/asset-modules/output-publicPath-placeholders/fullhash.js |
Asserts [fullhash] interpolation in publicPath. |
test/configCases/asset-modules/output-publicPath-placeholders/fullhashLen.js |
Asserts [fullhash:N] interpolation in publicPath. |
test/configCases/asset-modules/output-publicPath-placeholders/combined.js |
Asserts multiple [fullhash] occurrences, including a truncated variant. |
test/configCases/asset-modules/output-publicPath-placeholders/fnString.js |
Asserts function-form publicPath returning a plain string. |
test/configCases/asset-modules/output-publicPath-placeholders/fnHash.js |
Asserts function-form publicPath consuming data.hash. |
test/configCases/asset-modules/output-publicPath-placeholders/fnPlaceholder.js |
Asserts function-form publicPath returning a string containing [fullhash:N]. |
test/configCases/asset-modules/rule-generator-publicPath-placeholders/webpack.config.js |
New config case covering Rule.generator.publicPath placeholders and value forms. |
test/configCases/asset-modules/rule-generator-publicPath-placeholders/index.js |
Assertions for each supported placeholder/value form in Rule.generator.publicPath. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ( | ||
| typeof publicPath !== "string" || | ||
| /\[(?:full)?hash\]/.test(publicPath) | ||
| /\[(?:full)?hash(?::\d+)?\]/.test(publicPath) |
Types CoverageCoverage after merging claude/test-public-path-placeholders-d0tye into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The detection regex in RuntimePlugin only matched [fullhash] / [hash]
without a length suffix, so PublicPathRuntimeModule was not flagged as a
full-hash module and webpack_require.p kept the placeholder "XXXX"
instead of the real hash truncated to the requested length.
Also adds test coverage for output.publicPath placeholders and for
Rule.generator.publicPath with every supported placeholder
([file], [name], [ext], [base], [path], [id], [hash], [modulehash],
[contenthash], [runtime], function form, plain and empty strings).