-
-
Notifications
You must be signed in to change notification settings - Fork 32
feat: add ESM file:// protocol support with comprehensive tests #746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add comprehensive tests for ESM file:// protocol URL resolution in the NAPI bindings. Tests cover: - Absolute file:// URLs - Query strings and fragments - Unicode paths - Percent-encoded characters - Directory paths - Invalid/malformed URLs - Both sync and async resolution All tests assert consistent behavior across platforms. Platform-specific failures will be addressed in follow-up work. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
How to use the Graphite Merge QueueAdd the label merge to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
CodSpeed Performance ReportMerging #746 will not alter performanceComparing Summary
Footnotes
|
Enable ESM file:// protocol URL resolution on macOS and Linux, not just Windows. Changes: - Move `url` crate dependency from Windows-only to all platforms in Cargo.toml - Remove `#[cfg(target_os = "windows")]` from `resolve_file_protocol` function - Remove platform-specific `cfg_if` wrapper at call site - Preserve URL query strings and fragments when converting file:// URLs to paths All file-protocol tests now pass on macOS/Linux. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #746 +/- ##
==========================================
- Coverage 95.62% 95.09% -0.54%
==========================================
Files 16 16
Lines 2951 2974 +23
==========================================
+ Hits 2822 2828 +6
- Misses 129 146 +17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add conditional compilation to support wasm32 targets where `to_file_path()` is not available. On wasm32, the file:// protocol resolver is a no-op that returns the specifier unchanged, since WebAssembly has no filesystem access. This fixes the build error: ``` error[E0599]: no method named `to_file_path` found for struct `Url` ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Refactor to use cfg_if::cfg_if! macro at the call site instead of having two separate function definitions. This matches the original pattern and is more consistent with the rest of the codebase. Changes: - Wrap resolve_file_protocol call in cfg_if block - Only compile/call on non-wasm32 targets - Remove wasm32 stub function (no longer needed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Fix clippy warnings: - Remove unnecessary reference in url::Url::parse call - Use () instead of _ for explicit unit type in map_err 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Skip all file:// protocol tests when running with WASI_TEST=1 since the file:// protocol code is excluded on wasm32 targets (no filesystem access). Uses vitest's `test.skipIf(process.env.WASI_TEST)` to conditionally skip all 9 tests in the file when running on WASI. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Refactor file:// protocol tests to use a single `describe.skipIf` block instead of repeating `test.skipIf` on each individual test. This is cleaner and groups all file:// protocol tests together. Changes: - Import `describe` from vitest - Wrap all tests in `describe.skipIf(process.env.WASI_TEST)` block - Simplify test names (remove "file:// protocol" prefix) - Proper indentation for nested tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
// ESM allows file:// protocol URLs for module specifiers | ||
// See: https://nodejs.org/api/esm.html#urls | ||
|
||
describe.skipIf(process.env.WASI_TEST)('file:// protocol', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the tests are skipped for WASI?
closes #744
Summary
Add full ESM
file://
protocol URL resolution support across all platforms (macOS, Linux, Windows) with comprehensive test coverage.Changes
Implementation
url
crate dependency from Windows-only to all platformsfile://
URLs to pathscfg_if
to exclude file:// protocol handling on wasm32 targets (no filesystem access)Testing
Add comprehensive test suite in
napi/tests/file-protocol.test.mjs
:file://
URLs usingpathToFileURL()
?query=value
)#fragment
)Technical Details
Previously:
file://
protocol was only supported on Windows (#[cfg(target_os = "windows")]
)Now: Supported on all platforms with filesystems using conditional compilation:
The
url
crate'sto_file_path()
method works on all non-wasm platforms, so we removed the Windows-only restriction.Test Plan
All tests pass on macOS/Linux/Windows:
just test
Verify wasm32 build:
Verify no clippy warnings:
Related
Implements ESM file:// protocol as specified in: https://nodejs.org/api/esm.html#urls
🤖 Generated with Claude Code