Repository navigation
feat: resolve import.meta.resolve() to the emitted asset URL - #21415
Conversation
🦋 Changeset detectedLatest commit: cc2db96 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 (8a0f1ed). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@8a0f1ed
yarn add -D webpack@https://pkg.pr.new/webpack@8a0f1ed
pnpm add -D webpack@https://pkg.pr.new/webpack@8a0f1ed |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21415 +/- ##
=======================================
Coverage 93.18% 93.18%
=======================================
Files 609 610 +1
Lines 70722 70785 +63
Branches 20118 20135 +17
=======================================
+ Hits 65899 65959 +60
- Misses 4823 4826 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will improve performance by 77.1%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "future-defaults", scenario '{"name":"mode-production","mode":"production"}' |
7.5 MB | 9.6 MB | -21.87% |
| ⚡ | Memory | benchmark "asset-modules-resource", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1,479.3 KB | 180.7 KB | ×8.2 |
| ⚡ | Memory | benchmark "concatenate-modules", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
395.2 KB | 157 KB | ×2.5 |
| ⚡ | Memory | benchmark "import-meta-glob", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
947 KB | 733.4 KB | +29.13% |
| ⚡ | Memory | benchmark "many-modules-esm", scenario '{"name":"mode-production","mode":"production"}' |
8.9 MB | 7.2 MB | +23.64% |
| ⚡ | Memory | benchmark "lodash", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
348 KB | 289.7 KB | +20.12% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing claude/import-meta-resolve-bundlers-tpc3kp (cc2db96) with main (bc5412a)
Footnotes
-
21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
26cdef5 to
cba69bc
Compare
cba69bc to
9702129
Compare
9702129 to
b51e0bf
Compare
Treat a statically-known import.meta.resolve(specifier) like the string form of new URL(specifier, import.meta.url): emit the referenced asset and render the resolved URL string, tree-shaking unused results. Handled in the existing ImportMetaPlugin and controlled by the importMeta.resolve parser option (enabled by default, like the other import.meta fields).
b51e0bf to
cc2db96
Compare
Types CoverageCoverage after merging claude/import-meta-resolve-bundlers-tpc3kp into main will be
Coverage Report |
Summary
Adds support for
import.meta.resolve(specifier)in the JavaScript parser. A statically known specifier is treated like the string form ofnew URL(specifier, import.meta.url): the referenced module/asset is emitted and the call is replaced with the resolved URL string (unused results are tree-shaken viaparser.hooks.isPure). This mirrors how Vite and other bundlers recognize the argument as part of the module graph. Handled in the existingImportMetaPluginand controlled by theimportMeta.resolveparser option (enabled by default, like the otherimport.metafields; setmodule.parser.javascript.importMeta.resolvetofalseto opt out). Non-static forms (dynamic, spread, multiple args) are left untouched for the runtime.Closes #16693. Refs #20568 (an earlier PR proposing the same feature).
What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes, config cases under
test/configCases/parsing/import-meta-resolve*: static/computed/template-literal resolution,url: "relative", tree-shaking of an unused result, the disabled option (importMeta.resolve: false), non-static bail forms, and Vite/Turbopack-inspired cases (sibling module, nested path, bare package specifier, package subpath, andfileURLToPath(import.meta.resolve(...))).Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
The new
module.parser.javascript.importMeta.resolveoption (enable/disable resolvingimport.meta.resolveto the emitted asset URL) should be added to the parser options documentation.Use of AI
AI (Claude) was used to research the behavior of other bundlers (Vite, Turbopack/esbuild), implement the parser handling and dependency, and write the tests. All changes were reviewed and verified locally with targeted Jest config cases,
tsc, ESLint, and Prettier.