feat: read a file: URL the way Node does in absolutePath - #226
Merged
Conversation
The prefix wanted exactly two slashes and a lower-case scheme, but Node's
URL parser normalizes any number of them and treats the scheme
case-insensitively - `import("file:/abs/x.js")` loads. The optional group
now takes the scheme with a lookahead, leaving the first slash to the path
itself, so a scheme with nothing after it still names no absolute path.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #226 +/- ##
=======================================
Coverage 96.72% 96.72%
=======================================
Files 10 10
Lines 1009 1009
Branches 415 414 -1
=======================================
Hits 976 976
Misses 31 31
Partials 2 2
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:
|
This was referenced Sep 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#222 taught the
absolutePathkeyword to accept afile://prefix, but it wants exactly two slashes and a lower-case scheme. Node is looser on both counts: its URL parser normalizesfile:/abs/x.jstofile:///abs/x.jsand reads the scheme case-insensitively, soimport("file:/abs/x.js")really does load the module. Values of that shape are rejected by validation today.The optional prefix becomes
(?:file:(?=\/))?with aniflag — the lookahead leaves the first slash to the path part, so any number of slashes works whilefile:directory(a scheme with nothing absolute after it) is still rejected, as isfile:C:/directory.This is the first of three steps to make the behaviour reachable from webpack:
tooling'sprecompile-schemashoists its own copy of this regexp, andwebpack'sfileUrlToPathhas the same two-slash assumption. webpack/enhanced-resolve#670 is the equivalent change on the resolver side, where/^file:\/\//ibecomes/^file:\//i— the same accept/reject set as here.What kind of change does this PR introduce?
feat.
Did you add tests for your changes?
Yes —
test/index.test.jsgainsabsolutePath #8–#10(single-slash POSIX, single-slash Windows drive, upper-case scheme) and failing casesabsolute path #5/#6forfile:directoryandfile:C:/directory. The webpack-schema loop that proves every absolute-path option takes afile://URL now runs a second pass with the single-slash spelling, so all 24 options are covered in both forms. Full suite: 542/542,lintclean.Does this PR introduce a breaking change?
No — every value accepted before is still accepted; only rejected ones become valid. Options that take a relative path reject the new spellings the same way they already reject
file://.If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a — the
absolutePathprefix is not spelled out in the README beyond the keyword itself.Use of AI
Written with Claude Code. It found the mismatch while aligning the same regexp in enhanced-resolve, checked each form against Node (
new URL,fileURLToPathon both branches, and a realimport()), made the change and the tests, and ran the full suite andlintlocally; every claim above was verified by running it.🤖 Generated with Claude Code
https://claude.ai/code/session_01TmnzpSwSysywhmNw9p3uT5
Generated by Claude Code