fix: write emitted assets with an absolute path as-is#21223
Conversation
🦋 Changeset detectedLatest commit: a99b760 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 (6e5bd5d). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@6e5bd5d
yarn add -D webpack@https://pkg.pr.new/webpack@6e5bd5d
pnpm add -D webpack@https://pkg.pr.new/webpack@6e5bd5d |
14ec71a to
d556115
Compare
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (88.46%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #21223 +/- ##
==========================================
- Coverage 92.77% 92.76% -0.02%
==========================================
Files 591 591
Lines 64458 64467 +9
Branches 17908 17911 +3
==========================================
- Hits 59802 59801 -1
- Misses 4656 4666 +10
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:
|
d556115 to
1cda4bb
Compare
Merging this PR will degrade performance by 51.39%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "side-effects-reexport", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
128.4 KB | 859.1 KB | -85.05% |
| ❌ | Memory | benchmark "asset-modules-bytes", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
246 KB | 889.3 KB | -72.34% |
| ❌ | Memory | benchmark "wasm-modules-sync", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
251.9 KB | 358.9 KB | -29.83% |
| ❌ | Memory | benchmark "many-modules-esm", scenario '{"name":"mode-production","mode":"production"}' |
7.2 MB | 9.3 MB | -22.14% |
| ⚡ | Memory | benchmark "many-chunks-commonjs", scenario '{"name":"mode-production","mode":"production"}' |
9.1 MB | 7.6 MB | +20.15% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing claude/webpack-12759-tests-6spajo (a99b760) with main (5ba1265)
1cda4bb to
7250f2f
Compare
Joining an absolute targetFile onto output.path produced an invalid path on Windows (e.g. C:\out\D:\file) and threw EINVAL. Detect an absolute target file and write it to that location directly. Introduce a single cross-platform ABSOLUTE_PATH_REGEXP (POSIX /foo plus every Windows form: drive-letter C:\ and C:/, UNC, rooted), equal to path.posix.isAbsolute || path.win32.isAbsolute, and reuse it as the one absolute-path check across the codebase: Compiler, util/fs isAbsolute, extractSourceMap, NormalModule (also fixes the forward-slash gap from #20403), CleanPlugin and the sharing plugins. Closes #12759
7250f2f to
2dba99b
Compare
memfs and some platforms throw EISDIR (not EEXIST) when mkdir targets an existing directory such as the root "/", which made output.path "/" fail. Treat EISDIR like EEXIST in mkdirp/mkdirpSync (#10544).
dc2781b to
a99b760
Compare
Summary
Emitting an asset whose name is an absolute path threw
EINVALon Windows: the absolutetargetFilewas joined ontooutput.path, producing an invalid path such asC:\out\D:\file. Absolute target files are now written to their absolute location as-is.While here, the scattered "is this path absolute" checks — each a slightly different regex, several of which missed forward-slash Windows paths like
C:/dir— are consolidated onto a single cross-platformABSOLUTE_PATH_REGEXP(equal topath.posix.isAbsolute || path.win32.isAbsolute), reused inCompiler,util/fsisAbsolute,extractSourceMap,NormalModule,CleanPluginand the sharing plugins.Also fixes
output.pathset to the filesystem root:memfsand some platforms throwEISDIR(notEEXIST) whenmkdirtargets an existing directory such as/, whichmkdirp/mkdirpSyncnow treat as already-existing.Closes #12759
Closes #20403
Closes #12906
Closes #10544
What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Yes — a Windows-only configCase
test/configCases/emit-asset/absolute-paththat emits an asset to an absolute path, a configCasetest/configCases/emit-asset/mkdir-eisdirthat wraps the output file system somkdirreportsEISDIRfor existing dirs, and unit tests forABSOLUTE_PATH_REGEXPintest/identifier.unittest.js.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?
n/a
Use of AI
AI (Claude Code) was used to investigate the issues, implement the fixes, consolidate the absolute-path checks, and write the tests. All changes were reviewed by a human before submitting.
Generated by Claude Code