Skip to content

feat: read a file: URL the way Node does in absolutePath - #226

Merged
alexander-akait merged 1 commit into
mainfrom
feat/absolute-path-file-url-slashes
Sep 13, 2026
Merged

feat: read a file: URL the way Node does in absolutePath#226
alexander-akait merged 1 commit into
mainfrom
feat/absolute-path-file-url-slashes

Conversation

@alexander-akait

Copy link
Copy Markdown
Member

Summary

#222 taught the absolutePath keyword to accept a file:// prefix, but it wants exactly two slashes and a lower-case scheme. Node is looser on both counts: its URL parser normalizes file:/abs/x.js to file:///abs/x.js and reads the scheme case-insensitively, so import("file:/abs/x.js") really does load the module. Values of that shape are rejected by validation today.

The optional prefix becomes (?:file:(?=\/))? with an i flag — the lookahead leaves the first slash to the path part, so any number of slashes works while file:directory (a scheme with nothing absolute after it) is still rejected, as is file:C:/directory.

This is the first of three steps to make the behaviour reachable from webpack: tooling's precompile-schemas hoists its own copy of this regexp, and webpack's fileUrlToPath has the same two-slash assumption. webpack/enhanced-resolve#670 is the equivalent change on the resolver side, where /^file:\/\//i becomes /^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.js gains absolutePath #8#10 (single-slash POSIX, single-slash Windows drive, upper-case scheme) and failing cases absolute path #5/#6 for file:directory and file:C:/directory. The webpack-schema loop that proves every absolute-path option takes a file:// URL now runs a second pass with the single-slash spelling, so all 24 options are covered in both forms. Full suite: 542/542, lint clean.

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 absolutePath prefix 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, fileURLToPath on both branches, and a real import()), made the change and the tests, and ran the full suite and lint locally; every claim above was verified by running it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TmnzpSwSysywhmNw9p3uT5


Generated by Claude Code

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

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.72%. Comparing base (b4fd660) to head (6737c92).

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           
Flag Coverage Δ
integration 96.72% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexander-akait
alexander-akait merged commit 9578e1a into main Sep 13, 2026
33 checks passed
@alexander-akait
alexander-akait deleted the feat/absolute-path-file-url-slashes branch September 13, 2026 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant