Skip to content

feat: add file: protocol path support#151

Merged
JounQin merged 1 commit intomainfrom
feat/file_protocol
Jun 11, 2025
Merged

feat: add file: protocol path support#151
JounQin merged 1 commit intomainfrom
feat/file_protocol

Conversation

@JounQin
Copy link
Member

@JounQin JounQin commented Jun 11, 2025

close #127


Important

Add support for file:// protocol in path resolution and improve error handling for unsupported cases.

  • Behavior:
    • Add support for file:// protocol in require() in lib.rs, allowing file URL resolution.
    • Improve error handling for unsupported file:// URLs with relative paths in lib.rs.
  • Dependencies:
    • Add url crate to Cargo.toml for URL parsing.
    • Update Cargo.lock with new dependencies: url, form_urlencoded, idna, percent-encoding.
  • Tests:
    • Add test cases in resolve.rs for file:// URL resolution and error scenarios.

This description was created by Ellipsis for 0404b2a. You can customize this summary. It will automatically update as commits are pushed.


Summary by CodeRabbit

  • New Features

    • Added support for resolving specifiers that use the "file://" protocol, allowing direct handling of file URLs.
  • Bug Fixes

    • Improved error handling for unsupported "file://" URLs with relative paths, ensuring clear error messages.
  • Tests

    • Added and updated test cases to verify correct behavior for "file://" URL resolution and error scenarios.

@JounQin JounQin self-assigned this Jun 11, 2025
@JounQin JounQin added the enhancement New feature or request label Jun 11, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 11, 2025

"""

Walkthrough

This change adds support for resolving specifiers with the file:// protocol by parsing them as URLs and converting to local file paths. It introduces the url crate as a dependency and adds tests verifying correct resolution and error handling of file:// URLs.

Changes

File(s) Change Summary
Cargo.toml Added url = "2.5.4" dependency to [dependencies].
src/lib.rs Enhanced require_without_parse to parse and resolve file:// URLs to local file paths or error.
src/tests/resolve.rs Added tests for resolving absolute and relative file:// URLs; imported url::Url.
.github/workflows/ci.yml Updated Rust target from wasm32-unknown-unknown to wasm32-wasip1 in CI workflow.

Assessment against linked issues

Objective Addressed Explanation
Add file: protocol path support (#127)
Use url crate to parse and convert paths
Handle Windows-specific file: import use

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Changed Rust target in GitHub Actions workflow (.github/workflows/ci.yml) This change is unrelated to file: protocol support and pertains to CI environment configuration.

Suggested labels

internal

🐇 A file URL hops in with grace,
Turning paths to a local place.
With url crate by its side,
Resolving paths far and wide.
Tests now check each little clue,
To make sure the paths are true! 🐾✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d797656 and 0404b2a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • .github/workflows/ci.yml (1 hunks)
  • Cargo.toml (1 hunks)
  • src/lib.rs (2 hunks)
  • src/tests/resolve.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • Cargo.toml
  • .github/workflows/ci.yml
  • src/lib.rs
  • src/tests/resolve.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed everything up to 13af688 in 2 minutes and 14 seconds. Click for details.
  • Reviewed 448 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/tests/resolve.rs:16
  • Draft comment:
    Good test coverage for file protocol support. The test cases verify both successful resolution with absolute file URLs and correct error handling for invalid file URL paths.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_B95JuDzgoGY1xtj2

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@codecov
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.20%. Comparing base (e02a6bd) to head (0404b2a).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #151      +/-   ##
==========================================
+ Coverage   92.17%   92.20%   +0.03%     
==========================================
  Files          13       13              
  Lines        3053     3068      +15     
==========================================
+ Hits         2814     2829      +15     
  Misses        239      239              

☔ 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.

@codspeed-hq
Copy link

codspeed-hq bot commented Jun 11, 2025

CodSpeed Performance Report

Merging #151 will not alter performance

Comparing feat/file_protocol (0404b2a) with main (e02a6bd)

Summary

✅ 3 untouched benchmarks

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/lib.rs (1)

389-399: Minor: return early instead of labelled block

The labelled 'check_file_protocol block + break is hard to read.
After applying the leak fix you can simplify:

if let Some(local) = try_convert_file_url(specifier)? {
    return self.require_without_parse(cached_path, &local, ctx);
}

…or keep specifier mutable but drop the label.

src/tests/resolve.rs (1)

108-112: Duplicate test case – remove one instance

The tuple "file in module with query and fragment" appears twice.
It’s harmless but clutters the test array.

-        (
-            "file in module with query and fragment",
-            f.clone(),
-            "m1/a?#fragment",
-            f.join("node_modules/m1/a.js?#fragment"),
-        ),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c9efe8d and f3aeaf7.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • Cargo.toml (1 hunks)
  • src/lib.rs (2 hunks)
  • src/tests/resolve.rs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Benchmark
🔇 Additional comments (3)
Cargo.toml (1)

95-96: Consider disabling default features for url crate

url pulls in a noticeable dependency tree (idna, percent-encoding, etc.).
If you only need Url::parse + Url::to_file_path, the default features (especially serde & rustls) are not required.

-url = "2.5.4"
+url = { version = "2.5.4", default-features = false }

Trims compile time and binary size while keeping the new functionality intact.

Check with cargo tree -e features before/after to quantify the win.

src/lib.rs (1)

84-85: 👍 Import looks good

Adding the url crate is the right call for robust file:// parsing.

src/tests/resolve.rs (1)

177-179: Nice negative test

The explicit PathNotSupported assertion documents the new behaviour well.

@JounQin JounQin force-pushed the feat/file_protocol branch from f3aeaf7 to 5679bcb Compare June 11, 2025 16:05
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed 5679bcb in 2 minutes and 27 seconds. Click for details.
  • Reviewed 453 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/tests/resolve.rs:72
  • Draft comment:
    The tests for file protocol resolution look solid. Consider adding tests for variations such as uppercase 'FILE://' and cases with query/fragment parameters in file URLs to ensure comprehensive coverage.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None
2. src/lib.rs:389
  • Draft comment:
    The error mapping for file:// URLs returns a generic 'PathNotSupported'. Consider refining the error message to distinguish between URL parse failures and unsupported (e.g. relative) file URLs.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None

Workflow ID: wflow_tbSEQj26pNmBQNOM

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@JounQin JounQin force-pushed the feat/file_protocol branch 2 times, most recently from 93b7f1d to d797656 Compare June 11, 2025 16:44
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed f2d2711 in 2 minutes and 3 seconds. Click for details.
  • Reviewed 473 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/lib.rs:385
  • Draft comment:
    In the block handling file:// protocol (lines ~385–400), the URL is parsed and converted into a local file path. This implementation correctly separates absolute paths from relative ones and intentionally rejects relative file:// URLs. Consider adding a comment to document the platform‐specific behavior (e.g. on non‑Windows, relative URLs yield a 'PathNotSupported' error).
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. src/lib.rs:386
  • Draft comment:
    The check uses specifier.starts_with("file://") which is case-sensitive. Since URL schemes are case-insensitive, consider normalizing the scheme (e.g. to lowercase) if supporting variants like "FILE://" is desired.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
3. src/tests/resolve.rs:71
  • Draft comment:
    The test for file protocol resolution (lines 71–79) correctly distinguishes platform-specific errors (using NotFound on Windows and PathNotSupported elsewhere). This confirms the intended behavior; ensure such platform differences are documented in the API docs.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
4. .github/workflows/ci.yml:80
  • Draft comment:
    Typographical error: The target name "wasm32-wasip1" looks suspicious. Did you mean "wasm32-wasi"?
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% wasip1 appears to be a legitimate target, not a typo. It's used consistently in the file and appears alongside wasip1-threads variant. WASI Preview 1 (wasip1) is a real WebAssembly target that succeeded wasm32-wasi. The comment appears to be incorrect in suggesting this is a typo. I could be wrong about the legitimacy of wasip1 if it's a very new or experimental target. Maybe there's a reason to stick with wasm32-wasi. wasip1 is actually the newer, standardized name for the WASI target, and its consistent use in the file along with wasip1-threads variant strongly suggests this is intentional and correct. The comment should be deleted as it incorrectly flags a legitimate target name as a typo.
5. .github/workflows/ci.yml:81
  • Draft comment:
    Typographical error: The target name "wasm32-wasip1" looks like it might be a typo and perhaps should be "wasm32-wasi".
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% 1. wasm32-wasip1 appears to be intentionally used throughout the file. 2. The fact it's used in multiple places suggests this is not a typo. 3. wasip1 appears to be a legitimate WASM target - it's the WASI Preview 1 target. 4. The change from wasm32-unknown-unknown to wasm32-wasip1 seems deliberate and coordinated with other parts of the build. I could be wrong about wasip1 being a legitimate target - maybe it really is a typo that was made consistently throughout the file. A quick verification shows that wasm32-wasip1 is indeed a valid Rust target - it's the WASI Preview 1 target that replaced wasm32-wasi in newer versions. The comment should be deleted as wasm32-wasip1 is not a typo but rather a legitimate and intentionally used WASM target.

Workflow ID: wflow_YixyxOvikfewPbLv

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed d797656 in 1 minute and 59 seconds. Click for details.
  • Reviewed 470 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/lib.rs:386
  • Draft comment:
    Consider extracting the file:// protocol conversion into a helper for clarity.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 30% vs. threshold = 50% The code block is moderately complex with error handling and string manipulation. A helper function could improve readability. However, this is a relatively self-contained piece of functionality that only appears once in the codebase. The current implementation is not particularly hard to understand. The suggestion is subjective - reasonable developers could disagree on whether this refactoring would meaningfully improve the code. The current implementation is already fairly clear. While the refactoring could help slightly, the benefit seems minimal given this appears to be a one-off piece of code. The current implementation is adequately clear and self-contained. The comment should be deleted as the suggested refactoring would provide minimal benefit and the current code is sufficiently clear.
2. src/tests/resolve.rs:44
  • Draft comment:
    Duplicate test case for 'file in module with query and fragment'; consider removing one.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
3. .github/workflows/ci.yml:80
  • Draft comment:
    Typo alert: The target string 'wasm32-wasip1' on line 80 might be a typo. It is likely intended to be 'wasm32-wasi' (consistent with the 'wasi' target) unless this naming is deliberate. Please double-check.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% 1. The comment assumes wasm32-wasip1 is a typo, but this appears to be incorrect. 2. wasip1 is actually a valid and newer WASI preview 1 target. 3. The consistent use of wasip1 in multiple places in the file suggests this is intentional. 4. The comment is speculative and asks for verification, which violates our rules. Could there be some technical reason why wasm32-wasi would be preferred over wasm32-wasip1 that I'm not aware of? Even if there were technical tradeoffs, the consistent use of wasip1 throughout the file and the existence of wasip1-threads strongly indicates this is a deliberate choice, not a typo. Delete the comment. It incorrectly assumes a valid target name is a typo, and it violates our rules by being speculative and asking for verification.

Workflow ID: wflow_Cr1FORvQEqRdk5w3

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@JounQin JounQin force-pushed the feat/file_protocol branch from d797656 to ec417eb Compare June 11, 2025 16:54
@JounQin JounQin force-pushed the feat/file_protocol branch from ec417eb to 0404b2a Compare June 11, 2025 16:54
@sonarqubecloud
Copy link

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed 0404b2a in 2 minutes and 36 seconds. Click for details.
  • Reviewed 470 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/lib.rs:388
  • Draft comment:
    In the file:// branch, the URL is parsed and converted to a file path. Consider adding documentation explaining that only absolute file URLs are supported and that on Windows, a relative file URL (e.g. "file://./main.js") results in a PathNotSupported error, which must match platform expectations.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% The comment points out a potential platform-specific behavior that could be surprising to users. However, the behavior is determined by the url::Url crate's implementation, not by this code directly. The code simply delegates to url::Url for parsing and doesn't make any guarantees about relative vs absolute URLs. Adding documentation about platform-specific behaviors that we don't control could be misleading if the underlying library changes. I could be wrong about whether this is a limitation we should document - if this is a known limitation of url::Url that won't change, documenting it could help users avoid issues. Even if it's a stable limitation of url::Url, documenting external library behaviors in our code is risky. Users should refer to url::Url docs for its limitations. Our code simply delegates to that library. The comment should be deleted. While it points out a potentially useful detail, it asks us to document behavior that is controlled by an external dependency rather than our own code.
2. src/tests/resolve.rs:71
  • Draft comment:
    The tests for file:// resolution are comprehensive; ensure that the expected error (NotFound on Windows vs PathNotSupported on others) is consistent with the implementation.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
3. .github/workflows/ci.yml:80
  • Draft comment:
    It appears that the target name "wasm32-wasip1" may be a typographical error. If the intention was to support WASI, it might be meant to be "wasm32-wasi". Please confirm if "wasip1" is correct.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The comment suggests a possible typo, but the consistent use of 'wasip1' in multiple places in the file strongly suggests this is intentional. WASIP1 appears to be a real target - it's the WASI Preview 1 target. The comment is questioning something that appears to be correct and intentional. I might be missing some context about whether wasip1 is a valid Rust target. Maybe there's some specific version requirement or compatibility issue. The consistent usage in the file and the existence of related targets like wasm32-wasip1-threads strongly suggests this is a valid target. Even if there were version requirements, that would be caught by the build system. The comment should be deleted as it's questioning something that appears to be correct and intentional, and any actual issues would be caught by the build.

Workflow ID: wflow_qqAyWGDcQSCvPKw1

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@JounQin JounQin merged commit e3e93eb into main Jun 11, 2025
25 checks passed
@JounQin JounQin deleted the feat/file_protocol branch June 11, 2025 17:09
@JounQin JounQin mentioned this pull request Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add file: protocol path support

1 participant