Skip to content

refactor: replace url crate with percent-encoding#1065

Merged
Boshen merged 7 commits into
mainfrom
refactor/remove-url-crate
Mar 15, 2026
Merged

refactor: replace url crate with percent-encoding#1065
Boshen merged 7 commits into
mainfrom
refactor/remove-url-crate

Conversation

@Boshen

@Boshen Boshen commented Mar 15, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace the url crate with percent-encoding + manual file:// URL parsing, removing url, idna, icu_*, and ~15 other transitive dependencies (~267 lines from Cargo.lock)
  • Extract resolve_file_protocol into its own src/file_url.rs module following the Node.js getPathFromURLPosix / getPathFromURLWin32 spec
  • Use strict UTF-8 decoding (error on invalid bytes instead of silent replacement), single-pass encoded separator validation, and pre-allocated string building

🤖 Generated with Claude Code

…/ parsing

The `url` crate pulls in `idna` + `icu` (unicode normalization), adding
~66K to the NAPI binary. Replace it with `percent-encoding` and manual
parsing following the Node.js `getPathFromURLPosix` / `getPathFromURLWin32`
spec.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Mar 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.24771% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.35%. Comparing base (28badfe) to head (dfd2eb0).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/file_url.rs 97.22% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1065      +/-   ##
==========================================
+ Coverage   91.83%   92.35%   +0.51%     
==========================================
  Files          20       21       +1     
  Lines        3992     4079      +87     
==========================================
+ Hits         3666     3767     +101     
+ Misses        326      312      -14     

☔ View full report in Codecov by Sentry.
📢 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9559cf6b17

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/file_url.rs
WHATWG URL spec canonicalizes `file://localhost/...` to `file:///...`.
The previous `url::Url` implementation handled this, so normalize
localhost to empty host to avoid regression.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codspeed-hq

codspeed-hq Bot commented Mar 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 13 untouched benchmarks
⏩ 5 skipped benchmarks1


Comparing refactor/remove-url-crate (dfd2eb0) with main (e73b6a4)

Open in CodSpeed

Footnotes

  1. 5 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.

Boshen and others added 2 commits March 15, 2026 12:43
Cover passthrough, basic parsing, percent-decoding, query/fragment
preservation, localhost normalization, hostname rejection, encoded
slash rejection, invalid UTF-8 rejection, and has_encoded_separators.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests using POSIX paths fail on Windows (no drive letter). Add
cfg(not(windows)) guards and corresponding Windows-specific test
variants covering drive letters, UNC paths, encoded backslash
rejection, and missing drive letter rejection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc147118f8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/file_url.rs Outdated
Boshen and others added 2 commits March 15, 2026 12:53
Percent-decode the hostname before comparing to "localhost" so that
`file://local%68ost/...` is correctly normalized to an empty host,
matching WHATWG URL spec and the previous `url::Url` behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d681a59b3a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/file_url.rs
`file://C:/repo/main.js` was misclassified as hostname="C:" instead
of a local drive-letter path. Detect Windows drive letters (e.g. `C:`)
in the authority position and treat them as pathname with no hostname,
matching WHATWG URL spec normalization.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dfd2eb0790

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/file_url.rs
@Boshen Boshen merged commit d01241c into main Mar 15, 2026
15 checks passed
@Boshen Boshen deleted the refactor/remove-url-crate branch March 15, 2026 05:17
@Boshen Boshen mentioned this pull request Mar 15, 2026
Boshen added a commit that referenced this pull request May 25, 2026
## 🤖 New release

* `oxc_resolver`: 11.19.1 -> 11.19.2
* `oxc_resolver_napi`: 11.19.1 -> 11.19.2

<details><summary><i><b>Changelog</b></i></summary><p>

## `oxc_resolver`

<blockquote>

##
[11.19.2](v11.19.1...v11.19.2)
- 2026-05-25

### <!-- 1 -->🐛 Bug Fixes

- *(tsconfig)* apply later-wins semantics for extends array
([#1156](#1156)) (by
@Boshen)
- *(tsconfig)* walk past a tsconfig that doesn't claim the file
([#1154](#1154)) (by
@Boshen)
- *(tsconfig)* let project references take priority over their parent
([#1151](#1151)) (by
@Boshen)
- *(tsconfig)* resolve `rootDirs` against the config that declared them
([#1150](#1150)) (by
@Boshen)
- *(tsconfig)* resolve `baseUrl` / `paths` against the canonical
tsconfig path
([#1148](#1148)) (by
@Boshen)
- strip query fragments when calling `find_tsconfig`
([#1147](#1147)) (by
@Boshen)
- avoid panic in resolve_file for parentless paths
([#1053](#1053)) (by
@Boshen)
- *(dts)* strip ./ prefix from package entry when matching typesVersions
([#1051](#1051)) (by
@Boshen)
- *(dts)* expand Declaration to TypeScript|Declaration for package entry
resolution
([#1050](#1050)) (by
@Boshen)
- *(dts)* prefer declaration extensions over JS in exports-resolved
paths ([#1047](#1047))
(by @Boshen)
- avoid wasm/wasi dead-code lint in NodePath
([#1043](#1043)) (by
@Boshen)
- *(napi)* replace panics with error returns to prevent WASM traps
([#1055](#1055)) (by
@Boshen)

### <!-- 2 -->🚜 Refactor

- remove clear_cache test that dynamically creates fixtures (by @Boshen)
- move resolve and misc fixtures into fixtures/integration (by @Boshen)
- replace ignored doctest with link to example (by @Boshen)
- consolidate fixture directories for better test file mapping (by
@Boshen)
- replace `url` crate with `percent-encoding`
([#1065](#1065)) (by
@Boshen)

### <!-- 4 -->⚡ Performance

- *(cache)* pack CachedPathImpl::meta into a CachedMeta byte
([#1144](#1144)) (by
@Boshen)
- *(cache)* store canonical path as Box<Path> instead of PathBuf
([#1143](#1143)) (by
@Boshen)
- *(alias)* fast-reject alias entries by cached first byte
([#1142](#1142)) (by
@Boshen)

### <!-- 6 -->🧪 Testing

- *(tsconfig)* port lookup scenarios from typescript-go
([#1155](#1155)) (by
@Boshen)
- add 28 tests to improve coverage (92% → 93%)
([#1082](#1082)) (by
@Boshen)

### Contributors

* @Boshen
* @renovate[bot]
</blockquote>



</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: oxc-guard[bot] <276638029+oxc-guard[bot]@users.noreply.github.com>
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