Skip to content

feat: make the resolver runtime-agnostic (browser/deno/bun) - #606

Merged
alexander-akait merged 1 commit into
mainfrom
claude/platform-agnostic-package-6Ceqr
Jun 9, 2026
Merged

feat: make the resolver runtime-agnostic (browser/deno/bun)#606
alexander-akait merged 1 commit into
mainfrom
claude/platform-agnostic-package-6Ceqr

Conversation

@alexander-akait

Copy link
Copy Markdown
Member

Decouple the core resolver from Node-only assumptions so it runs on
browsers, Deno and Bun in addition to Node, and verify it on each runtime.

Library changes:

  • Decode file contents without assuming a Node Buffer: add a shared
    decodeText helper (util/fs) and use it in both readJson and
    DescriptionFileUtils, so a file system returning Uint8Array resolves
    correctly (the package.json path previously did content.toString()).
  • Fix readJson throwing "Invalid value used as weak map key" when a file
    system returns a string with stripComments: only use the strip-comments
    WeakMap cache when the contents are an object.
  • Replace the Node url builtin with a runtime-agnostic fileURLToPath built
    on the global URL (used by util/path toPath and util/identifier).
  • Add a browser shim for the Node path builtin (posix/win32 normalize and
    dirname, plus basename) wired through the package browser field; Node,
    Deno and Bun keep native path.

Testing and CI:

  • Run the real test suite on bun (bun test) and deno (jest via deno node
    compatibility); align the snapshot format (printBasicPrototype:false, the
    jest default) so node/deno/bun agree, and broaden one JSON-error assertion
    for JavaScriptCore.
  • Add a browser job that bundles the core with webpack as an ES module
    (experiments.outputModule) and runs it in a sandbox exposing only web
    globals, proving no Node builtin leaks; the in-memory FS is async.
  • Add parity tests (fuzzed against node:path and node:url) for the path shim
    and fileURLToPath, decodeText tests, and a Uint8Array file-system
    regression test. Document the path shim's DOS-device-path scope and the
    fileURLToPath punycode-UNC-host deviation.

https://claude.ai/code/session_01Q4F8fLwQSvaErLUDxdJ5cg

@changeset-bot

changeset-bot Bot commented Jun 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bdca505

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
enhanced-resolve Patch

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

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 6, 2026

Copy link
Copy Markdown

CLA Not Signed

@codecov

codecov Bot commented Jun 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.34219% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.64%. Comparing base (f3b08dd) to head (bdca505).

Files with missing lines Patch % Lines
lib/util/graceful-fs-browser.js 0.00% 4 Missing ⚠️
lib/util/path-browser.js 98.71% 3 Missing ⚠️
lib/util/url-browser.js 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #606      +/-   ##
==========================================
+ Coverage   96.58%   96.64%   +0.05%     
==========================================
  Files          50       54       +4     
  Lines        3077     3367     +290     
  Branches      997     1126     +129     
==========================================
+ Hits         2972     3254     +282     
- Misses         89       97       +8     
  Partials       16       16              
Flag Coverage Δ
integration 96.64% <97.34%> (+0.05%) ⬆️

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.

@codspeed-hq

codspeed-hq Bot commented Jun 6, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 26.7%

⚡ 1 improved benchmark
✅ 137 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory realistic-midsize: mixed batch (warm cache) 5.8 KB 4.6 KB +26.7%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing claude/platform-agnostic-package-6Ceqr (bdca505) with main (f3b08dd)

Open in CodSpeed

@alexander-akait
alexander-akait force-pushed the claude/platform-agnostic-package-6Ceqr branch 8 times, most recently from b993742 to 382e6a0 Compare June 9, 2026 13:51
Decouple the core resolver from Node-only assumptions so it runs on
browsers, Deno and Bun in addition to Node, and verify it on each runtime.

Library changes:
- Decode file contents without assuming a Node Buffer: add a shared
  decodeText helper (util/fs) and use it in both readJson and
  DescriptionFileUtils, so a file system returning Uint8Array resolves
  correctly (the package.json path previously did content.toString()).
- Fix readJson throwing "Invalid value used as weak map key" when a file
  system returns a string with stripComments: only use the strip-comments
  WeakMap cache when the contents are an object.
- Replace the Node url builtin with a runtime-agnostic fileURLToPath built
  on the global URL (used by util/path toPath and util/identifier).
- Add a browser shim for the Node path builtin (posix/win32 normalize and
  dirname, plus basename) wired through the package browser field; Node,
  Deno and Bun keep native path.

Testing and CI:
- Run the real test suite on bun (bun test) and deno (jest via deno node
  compatibility), and add a browser job that bundles the core with webpack
  as an ES module (experiments.outputModule) and runs it in a sandbox
  exposing only web globals, proving no Node builtin leaks. The in-memory
  browser FS is async.
- Keep the suite passing on the full Node matrix: a jest setup file
  polyfills TextEncoder/TextDecoder from util on Node 10 (globals are
  Node 11+), and the five snapshot assertions are skipped under bun, whose
  serializer can't emit jest's `Array [` format.
- Add parity tests (fuzzed against node:path and node:url) for the path
  shim and fileURLToPath, decodeText tests, and a Uint8Array file-system
  regression test. Document the path shim's DOS-device-path scope and the
  fileURLToPath punycode-UNC-host deviation.

https://claude.ai/code/session_01Q4F8fLwQSvaErLUDxdJ5cg
@alexander-akait
alexander-akait force-pushed the claude/platform-agnostic-package-6Ceqr branch from 382e6a0 to bdca505 Compare June 9, 2026 14:09
@alexander-akait
alexander-akait merged commit ac7d7c5 into main Jun 9, 2026
64 of 66 checks passed
@alexander-akait
alexander-akait deleted the claude/platform-agnostic-package-6Ceqr branch June 9, 2026 15:04
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.

2 participants