feat: make the resolver runtime-agnostic (browser/deno/bun) - #606
Conversation
🦋 Changeset detectedLatest commit: bdca505 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
Codecov Report❌ Patch coverage is
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
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:
|
Merging this PR will improve performance by 26.7%
Performance Changes
Tip Curious why this is faster? Comment Comparing |
b993742 to
382e6a0
Compare
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
382e6a0 to
bdca505
Compare
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:
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()).
system returns a string with stripComments: only use the strip-comments
WeakMap cache when the contents are an object.
on the global URL (used by util/path toPath and util/identifier).
dirname, plus basename) wired through the package browser field; Node,
Deno and Bun keep native path.
Testing and CI:
compatibility); align the snapshot format (printBasicPrototype:false, the
jest default) so node/deno/bun agree, and broaden one JSON-error assertion
for JavaScriptCore.
(experiments.outputModule) and runs it in a sandbox exposing only web
globals, proving no Node builtin leaks; the in-memory FS is async.
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