Skip to content

Commit 5a41278

Browse files
fix: read a file: URL the way Node does (#22089)
The prefix wanted exactly two slashes, but Node's URL parser normalizes any number of them and `import("file:/abs/x.js")` loads - so that spelling was kept as a literal path. It needs one slash after the scheme now, which leaves `file:x.js` the relative-looking request it reads as. The `absolutePath` schema keyword had the same assumption, so a value of that shape was rejected before it ever reached the conversion; bumping `schema-utils` and `tooling` regenerates the pre-compiled validators to match. `enhanced-resolve` goes to 5.25.0 for the file URLs it now takes in `resolve` options.
1 parent 919ef10 commit 5a41278

23 files changed

Lines changed: 74 additions & 34 deletions

‎.changeset/007-file-url-paths.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": minor
33
---
44

5-
Accept file URLs where an option or plugin option takes an absolute path.
5+
Accept a file URL in any spelling Node reads where an absolute path is taken.

‎lib/util/identifier.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const SEGMENTS_SPLIT_REGEXP = /([|!])/;
1717
const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
1818
const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i;
1919
// A file URL, the form `import.meta.resolve()` returns a local module in.
20-
const FILE_URL_REGEXP = /^file:\/\//i;
20+
// One slash after the scheme is enough, as Node's own URL parser needs.
21+
const FILE_URL_REGEXP = /^file:\//i;
2122
// What `import()` resolves as a place rather than as a package name: relative,
2223
// rooted, or carrying a scheme.
2324
const RESOLVABLE_SPECIFIER_REGEXP = /^(?:\.{0,2}\/|[a-zA-Z][\w+.-]*:)/;

‎package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@
116116
"acorn": "^8.16.0",
117117
"browserslist": "^4.28.1",
118118
"chrome-trace-event": "^1.0.2",
119-
"enhanced-resolve": "^5.24.4",
119+
"enhanced-resolve": "^5.25.0",
120120
"es-module-lexer": "^2.1.0",
121121
"events": "^3.2.0",
122122
"graceful-fs": "^4.2.11",
123123
"mime-db": "^1.54.0",
124124
"minimizer-webpack-plugin": "^5.7.0",
125-
"schema-utils": "^4.4.0",
125+
"schema-utils": "^4.5.0",
126126
"tapable": "^2.3.0",
127127
"watchpack": "^2.5.2",
128128
"webpack-sources": "^3.5.1"
@@ -213,7 +213,7 @@
213213
"three": "^0.185.1",
214214
"tinybench": "^6.0.1",
215215
"toml": "^5.0.0",
216-
"tooling": "webpack/tooling#v1.28.2",
216+
"tooling": "webpack/tooling#v1.28.3",
217217
"ts-loader": "^9.6.0",
218218
"typescript": "^6.0.3",
219219
"unified": "^11.0.5",

‎schemas/WebpackOptions.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎schemas/plugins/LoaderOptionsPlugin.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎schemas/plugins/ManifestPlugin.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎schemas/plugins/SourceMapDevToolPlugin.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎schemas/plugins/asset/AssetGeneratorOptions.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎schemas/plugins/asset/AssetResourceGeneratorOptions.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)