8000 feat: merge from upstream `oxc-project/oxc-resolver` - 5th by JounQin · Pull Request #94 · unrs/unrs-resolver · GitHub
[go: up one dir, main page]

Skip to content

feat: merge from upstream oxc-project/oxc-resolver - 5th #94

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

Merged
merged 3 commits into from
Apr 23, 2025
Merged

Conversation

JounQin
Copy link
Member
@JounQin JounQin commented Apr 23, 2025

Important

This PR adds support for handling BOM in package.json and tsconfig.json by stripping it during parsing and updates tests to verify this behavior.

  • Behavior:
    • Handle BOM in package.json and tsconfig.json by stripping it during parsing in src/package_json_serde.rs and src/tsconfig_serde.rs.
    • Update load_node_modules() in src/lib.rs to accept package_name and subpath parameters.
  • Tests:
    • Add with_bom() test in src/tests/tsconfig_paths.rs to verify BOM handling in tsconfig.json.
    • Add package_json_with_bom() test in tests/resolve_test.rs to verify BOM handling in package.json.
  • Misc:
    • Update README.md to include reference to the new upstream merge #94.

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

Summary by CodeRabbit

  • New Features
    • Improved support for JSON files containing a Byte Order Mark (BOM), including package.json and tsconfig.json.
  • Bug Fixes
    • Resolvers now correctly handle and parse JSON files with a BOM at the beginning.
  • Tests
    • Added tests to verify correct resolution of modules and paths when BOM is present in configuration files.
  • Documentation
    • Updated documentation to reflect recent synchronized changes.

sapphi-red and others added 2 commits April 23, 2025 17:32
Node supports `package.json` with UTF-8 BOM and TypeScript supports
`tsconfig.json` with UTF-8 BOM.

An error was happening for these cases.
@JounQin JounQin requested a review from Copilot April 23, 2025 15:42
Copy link
coderabbitai bot commented Apr 23, 2025

Walkthrough

This update introduces support for handling files with a Byte Order Mark (BOM) in both package.json and tsconfig.json files. Internal parsing logic is updated to strip the BOM before deserialization. New test fixtures and test cases are added to verify correct resolution behavior when BOMs are present. Additionally, the resolver's internal control flow is optimized by passing parsed package specifier components directly to relevant methods, reducing redundant parsing. The README is updated to reference an additional synchronized pull request.

Changes

Files/Paths Change Summary
README.md Updated documentation to include PR #94 in the list of synchronized changes.
fixtures/misc/package-json-with-bom/package.json,
fixtures/tsconfig/cases/with-bom/tsconfig.json
Added new test fixture files for package.json and tsconfig.json, both containing a BOM at the start.
src/lib.rs Refactored resolver logic to pass package name and subpath directly, optimizing control flow and reducing redundant parsing. Method signatures updated accordingly.
src/package_json_serde.rs,
src/tsconfig_serde.rs
Modified parsers to strip a UTF-8 BOM from the start of JSON strings before deserialization.
src/tests/tsconfig_paths.rs,
tests/resolve_test.rs
Added new test cases to verify correct handling of BOMs in tsconfig.json and package.json files.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant Resolver
    participant Parser

    Test->>Resolver: resolve(specifier, base_dir)
    Resolver->>Parser: parse(package.json or tsconfig.json string)
    Parser->>Parser: strip BOM if present
    Parser->>Resolver: return deserialized config
    Resolver->>Test: return resolved path
Loading

Suggested labels

documentation

Poem

In files where BOMs sneak in unseen,
The parser now wipes their slates clean.
With fixtures and tests,
Our code truly bests—
Resolving with grace, neat and keen!

(ʕ•ᴥ•ʔ)✨


📜 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 0995fea and b6d70f6.

📒 Files selected for processing (8)
  • README.md (1 hunks)
  • fixtures/misc/package-json-with-bom/package.json (1 hunks)
  • fixtures/tsconfig/cases/with-bom/tsconfig.json (1 hunks)
  • src/lib.rs (3 hunks)
  • src/package_json_serde.rs (1 hunks)
  • src/tests/tsconfig_paths.rs (1 hunks)
  • src/tsconfig_serde.rs (1 hunks)
  • tests/resolve_test.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/tsconfig_serde.rs (2)
src/tsconfig.rs (4)
  • tsconfig (373-373)
  • root (28-28)
  • path (34-34)
  • path (369-369)
tests/integration_test.rs (1)
  • tsconfig (48-53)
🪛 LanguageTool
README.md

[uncategorized] ~21-~21: Loose punctuation mark.
Context: ...the latest changes: > > - oxc-resolver: [#15](https://github.com/unrs/unrs-reso...

(UNLIKELY_OPENING_PUNCTUATION)

🪛 GitHub Check: Codacy Static Code Analysis
fixtures/misc/package-json-with-bom/package.json

[warning] 1-1: fixtures/misc/package-json-with-bom/package.json#L1
It's possible to embed malicious secret instructions to AI rules files using unicode characters that are invisible to human reviewers.This can lead to future AI-generated code that has security vulnerabilities or other weaknesses baked in which may not be noticed.

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (10)
fixtures/tsconfig/cases/with-bom/tsconfig.json (1)

1-7: Appropriate test fixture for BOM handling

This new fixture correctly includes a Byte Order Mark (BOM) character at the beginning of the file, which is represented as \uFEFF but appears invisible. The content provides a basic TypeScript configuration with paths mapping, suitable for testing BOM handling in tsconfig.json files.

fixtures/misc/package-json-with-bom/package.json (1)

1-7: Well-structured test fixture with BOM

This test fixture correctly includes a Byte Order Mark (BOM) character at the beginning of the file (represented as \uFEFF). The package configuration is appropriate for testing BOM handling in package.json files.

Note: The static analysis warning about invisible Unicode characters is expected and can be safely ignored in this context, as the BOM character is intentionally included for testing purposes.

🧰 Tools
🪛 GitHub Check: Codacy Static Code Analysis

[warning] 1-1: fixtures/misc/package-json-with-bom/package.json#L1
It's possible to embed malicious secret instructions to AI rules files using unicode characters that are invisible to human reviewers.This can lead to future AI-generated code that has security vulnerabilities or other weaknesses baked in which may not be noticed.

src/package_json_serde.rs (1)

137-137: Good implementation of BOM stripping

The added line correctly uses trim_start_matches("\u{feff}") to remove the Byte Order Mark from the beginning of JSON strings before parsing. The comment "strip bom" clearly indicates the purpose of this change.

src/tsconfig_serde.rs (2)

272-272: Correct BOM handling implementation

The code correctly implements BOM stripping for TypeScript configuration files by using a custom function to remove the Byte Order Mark (\u{feff}) if present, before comment stripping and JSON parsing.


281-288: Well-implemented utility function for BOM removal

The trim_start_matches_mut helper function is correctly implemented to work with mutable string slices. It efficiently checks if the string starts with the specified character and returns the appropriate slice.

Note that the approach differs slightly from the immutable trim_start_matches used in package_json_serde.rs, but both approaches are functionally correct for their respective contexts.

README.md (1)

21-21: Documentation updated with PR reference!

The README has been properly updated to include this PR (#94) in the list of synchronized changes from the oxc-resolver repository, maintaining consistency with the documentation style.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~21-~21: Loose punctuation mark.
Context: ...the latest changes: > > - oxc-resolver: [#15](https://github.com/unrs/unrs-reso...

(UNLIKELY_OPENING_PUNCTUATION)

tests/resolve_test.rs (1)

238-249: Good test for the new BOM handling feature!

This test effectively verifies that the resolver can correctly handle package.json files containing a Byte Order Mark (BOM). The test structure follows the established pattern of other tests in this file and directly targets the functionality being added in this PR.

src/tests/tsconfig_paths.rs (1)

96-110: Well-structured test for tsconfig BOM handling!

This test complements the package.json BOM test by verifying that the resolver correctly handles Byte Ord 8000 er Marks in tsconfig.json files. The test follows the consistent pattern of other tsconfig tests and properly validates the functionality added in this PR.

src/lib.rs (2)

516-517: Good optimization to extract package components once!

Extracting the package name and subpath in the calling function avoids redundant parsing operations later in the code.


525-527: Improved function signature for better control flow!

The updated function signature now accepts pre-parsed components (package_name and subpath) rather than re-parsing the specifier internally, which is more efficient and clearer.

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces BOM (Byte Order Mark) support by stripping BOMs from JSON strings during configuration parsing, and it enhances package resolution by adjusting package specifier parsing. Key changes include:

  • Adding tests for BOM handling in package.json and tsconfig paths.
  • Implementing BOM stripping in tsconfig_serde.rs using a custom helper.
  • Modifying the package specifier parsing in src/lib.rs to pass package name and subpath separately.

Reviewed Changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/resolve_test.rs Added a test for BOM handling in package-json resolution.
src/tsconfig_serde.rs Introduced a custom BOM stripping function and integrated its call in parsing.
src/tests/tsconfig_paths.rs Added a test case for BOM presence in tsconfig paths.
src/package_json_serde.rs Updated BOM removal to use the standard library function.
src/lib.rs Adjusted package specifier parsing and updated the node modules resolution call.
Files not reviewed (2)
  • fixtures/misc/package-json-with-bom/package.json: Language not supported
  • fixtures/tsconfig/cases/with-bom/tsconfig.json: Language not supported
Comments suppressed due to low confidence (2)

src/tsconfig_serde.rs:272

  • [nitpick] Consider using the standard library's trim_start_matches (as done in package_json_serde.rs) for BOM removal to maintain consistency across modules.
let json = trim_start_matches_mut(json, '\u{feff}'); // strip bom

src/tsconfig_serde.rs:281

  • [nitpick] The function name 'trim_start_matches_mut' may be misleading since it does not modify the original string in place but rather returns a trimmed slice; consider renaming it to better reflect its behavior, for example 'trim_bom'.
fn trim_start_matches_mut(s: &mut str, pat: char) -> &mut str {

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 everything up to 8faa583 in 1 minute and 48 seconds. Click for details.
  • Reviewed 144 lines of code in 8 files
  • Skipped 1 files when reviewing.
  • Skipped posting 7 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. tests/resolve_test.rs:240
  • Draft comment:
    Good test for BOM; it correctly checks that package.json with BOM is trimmed and resolved properly.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. tests/resolve_test.rs:3
  • Draft comment:
    Ensure module alias consistency: unrs_resolver and oxc_resolver are both referenced; consider using consistent naming.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
3. src/tsconfig_serde.rs:272
  • Draft comment:
    The result of json_strip_comments::strip(json) is discarded. It likely returns a new, comment‑free string that should be used for parsing. Consider assigning its result (e.g. let json = json_strip_comments::strip(json);) so that comments are removed before deserialization.
  • Reason this comment was not posted:
    Comment was on unchanged code.
4. tests/resolve_test.rs:240
  • Draft comment:
    There is a mix of resolver result mappings using both unrs_resolver::Resolution and oxc_resolver::Resolution. Confirm that this is intentional and that the proper resolution type is used consistently in tests.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
5. fixtures/misc/package-json-with-bom/package.json:1
  • Draft comment:
    The file begins with a Byte Order Mark (BOM) before the '{'. While BOMs are sometimes used, they can introduce subtle issues in JSON files. Please ensure that this is intentional; if not, consider removing the BOM to keep the file clean.
  • 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% This appears to be a test fixture specifically created to test handling of package.json files with BOMs. The file name and location strongly suggest the BOM is intentional. Making a comment to remove an intentional test case feature would be counterproductive. I could be wrong about the intention - maybe this is just a poorly named file that accidentally got a BOM. The combination of the explicit filename 'package-json-with-bom' and its location in a 'fixtures' directory (commonly used for test cases) makes it extremely unlikely the BOM is accidental. The comment should be deleted as it suggests removing a BOM that appears to be an intentional part of a test fixture.
6. src/package_json_serde.rs:3
  • Draft comment:
    Typo: The comment on line 3 says 'Code related to export field are copied...' which should probably be 'Code related to export fields are copied...' for correct pluralization.
  • 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.
7. src/package_json_serde.rs:192
  • Draft comment:
    Typo: The documentation comment starting on line 192 says 'large fields that useless for pragmatic use are removed.' Consider revising to 'large fields that are useless for pragmatic use are removed.'
  • 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.

Workflow ID: wflow_o4wjAon1alPMT2Rk

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

Copy link
codspeed-hq bot commented Apr 23, 2025

CodSpeed Performance Report

Merging #94 will not alter performance

Comparing merge/oxc (b6d70f6) with main (610d9f3)

Summary

✅ 3 untouched benchmarks

Copy link

Copy link
codecov bot commented Apr 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.40%. Comparing base (610d9f3) to head (b6d70f6).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #94      +/-   ##
==========================================
+ Coverage   93.38%   93.40%   +0.02%     
==========================================
  Files          13       13              
  Lines        2856     2865       +9     
==========================================
+ Hits         2667     2676       +9     
  Misses        189      189              

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

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 b6d70f6 in 1 minute and 36 seconds. Click for details.
  • Reviewed 151 lines of code in 7 files
  • Skipped 1 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/tsconfig_serde.rs:272
  • Draft comment:
    The call to json_strip_comments::strip(json) discards its result. If the intent is to remove comments, consider reassigning the result (e.g. let json = json_strip_comments::strip(json);) so that the cleaned JSON is parsed.
  • Reason this comment was not posted:
    Comment was on unchanged code.
2. src/tsconfig_serde.rs:272
  • Draft comment:
    The call to json_strip_comments::strip(json) discards its result—this means comments aren’t actually removed. Consider assigning its return value (e.g. let stripped = json_strip_comments::strip(json)) and then parsing from the stripped string.
  • Reason this comment was not posted:
    Comment was on unchanged code.
3. README.md:13
  • Draft comment:
    Typographical Issue: 'Raspberry PI 4 aarch64' should be 'Raspberry Pi 4 aarch64' to reflect the correct product naming.
  • 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.

Workflow ID: wflow_TnPTbgZgJndiKTkB

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

@JounQin
Copy link
Member Author
JounQin commented Apr 23, 2025

@coderabbitai review

Copy link
coderabbitai bot commented Apr 23, 2025
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@JounQin JounQin merged commit b6d70f6 into main Apr 23, 2025
22 checks passed
@JounQin JounQin deleted the merge/oxc branch April 23, 2025 23:52
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.

3 participants
0