Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: merge from upstream oxc-project/oxc-resolver - 4th #86

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 6 commits into from
Apr 22, 2025
Merged

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented Apr 22, 2025

Important

Enhance Windows path handling, update dependencies, and adjust tests for long path support.

  • Behavior:
    • Properly handle DOS device paths in try_strip_windows_prefix() in src/windows.rs.
    • Update ResolveError in src/error.rs to include PathNotSupported for unsupported paths.
  • Dependencies:
    • Update react to ^19.1.0 in fixtures/pnpm-workspace/packages/lib/package.json.
    • Update napi-postinstall to ^0.1.5 in npm/package.json.
    • Update vitest to ^3.1.2 in package.json.
  • Testing:
    • Add tests for try_strip_windows_prefix() in src/windows.rs.
    • Modify windows_symlinked_longfilename test in tests/resolve_test.rs to handle long paths on Windows.

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

Summary by CodeRabbit

  • Bug Fixes
    • Corrected handling of DOS device paths on Windows to ensure proper path resolution and compatibility.
  • New Features
    • Improved error reporting for unsupported Windows path constructs.
  • Chores
    • Updated dependencies: "react" to 19.1.0, "napi-postinstall" to 0.1.5, and "vitest" to 3.1.2.
    • Added a configuration option to control virtual store directory length for workspace projects.
  • Documentation
    • Updated changelog to reflect bug fixes related to Windows path handling.
  • Tests
    • Enhanced and updated tests for Windows long path and symlink scenarios.

renovate bot and others added 6 commits April 21, 2025 09:38
Fixes #454 

This PR changed the name and return type of `strip_windows_prefix` to
`try_strip_windows_prefix`, allowing it to return `None` to indicate
unsupported [DOS device
paths](https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths).

Most significantly, symlinks referring to a drive without drive letter,
usually accessed via a mount point (Mounted Volume), should not be
resolved at all, as nodejs `import`/`require` does not support such
properly, as of Node 22.

This PR also rectified the [UNC
path](https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#unc-paths)
resolution to prepend the `"\\"` portion to the path.

---------

Co-authored-by: Boshen <[email protected]>
## 🤖 New release

* `oxc_resolver`: 5.3.0 -> 6.0.0 (⚠ API breaking changes)

### ⚠ `oxc_resolver` breaking changes

```text
--- failure inherent_method_missing: pub method removed or renamed ---

Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/inherent_method_missing.ron

Failed in:
  FileSystemOs::strip_windows_prefix, previously in file /tmp/.tmpZFrfKd/oxc_resolver/src/file_system.rs:168
```

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[6.0.0](oxc-project/oxc-resolver@oxc_resolver-v5.3.0...oxc_resolver-v6.0.0)
- 2025-04-22

### <!-- 1 -->Bug Fixes

- properly handle DOS device paths in strip_windows_prefix
([#455](oxc-project/oxc-resolver#455))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
@JounQin JounQin requested a review from Copilot April 22, 2025 12:51
Copy link

coderabbitai bot commented Apr 22, 2025

Walkthrough

The changes introduce updates across configuration files, dependency versions, and core logic for handling Windows-specific path normalization. A new function, try_strip_windows_prefix, is added to process DOS device paths and convert them to standard paths, with error handling for unsupported formats. Related code in the file system and cache modules is updated to use this new function, and a new error variant is introduced for unsupported paths. Test cases are revised to reflect updated path expectations, particularly for long Windows paths. Several package dependencies and configuration options are also updated.

Changes

Files/Paths Change Summary
CHANGELOG.md Added a bug fix entry for handling DOS device paths in strip_windows_prefix.
fixtures/pnpm-workspace/packages/lib/package.json Updated "react" dependency from ^19.0.0 to ^19.1.0.
npm/package.json Updated "napi-postinstall" dependency from ^0.1.1 to ^0.1.5.
package.json Updated "vitest" devDependency from ^3.1.1 to ^3.1.2.
pnpm-workspace.yaml Added virtualStoreDirMaxLength: 1024 for Windows long path testing.
src/error.rs Added PathNotSupported(PathBuf) variant to ResolveError enum.
src/file_system.rs, src/fs_cache.rs Refactored to use try_strip_windows_prefix for Windows path normalization; removed old strip_windows_prefix method.
src/lib.rs Added conditional import for new Windows-specific module.
src/windows.rs Added new try_strip_windows_prefix function for normalizing DOS device paths; includes error handling for unsupported formats.
tests/resolve_test.rs Updated imports and test expectations for module resolution; revised Windows long path test and removed ignore attributes.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant FileSystem
    participant WindowsModule
    participant Error

    Caller->>FileSystem: read_link(path)
    FileSystem->>WindowsModule: try_strip_windows_prefix(path)
    WindowsModule-->>FileSystem: PathBuf or ResolveError::PathNotSupported
    FileSystem-->>Caller: PathBuf or Error
Loading

Poem

A bunny hopped through Windows’ maze,
Stripping prefixes in clever ways.
With GUIDs blocked and paths made neat,
Now every file resolve’s a treat!
Tests run long, dependencies bloom—
This patch brings order to the room.
🐇✨

✨ 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 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 merges upstream changes from oxc-project/oxc-resolver and updates Windows path handling. The key changes include:

  • Updating tests to reflect changes in the Resolution API and module path construction.
  • Introducing a new Windows-specific module to safely handle DOS device paths.
  • Adjusting file system functions to leverage the new Windows prefix stripping logic.

Reviewed Changes

Copilot reviewed 8 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/resolve_test.rs Updated imports and test expectations for module resolution with new API.
src/windows.rs New module to convert DOS device paths to standard paths using unsafe blocks.
src/lib.rs Added conditional compilation for the Windows module.
src/fs_cache.rs Modified Windows path handling to call the new try_strip_windows_prefix.
src/file_system.rs Updated Windows branch to use try_strip_windows_prefix with pattern matching.
src/error.rs Added a new error variant for unsupported Windows paths.
pnpm-workspace.yaml Configured virtualStoreDirMaxLength to support long Windows paths.
CHANGELOG.md Documented the bug fix for DOS device path handling.
Files not reviewed (4)
  • fixtures/pnpm-workspace/packages/lib/package.json: Language not supported
  • npm/package.json: Language not supported
  • package.json: Language not supported
  • pnpm-lock.yaml: Language not supported

Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedvitest@​3.1.1 ⏵ 3.1.2981007799100
Updatednapi-postinstall@​0.1.1 ⏵ 0.1.584 +13100100 +191 +2100

View full report

Copy link

codecov bot commented Apr 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.67%. Comparing base (e172e11) to head (ed82ebd).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   93.24%   93.67%   +0.42%     
==========================================
  Files          13       13              
  Lines        2858     2844      -14     
==========================================
- Hits         2665     2664       -1     
+ Misses        193      180      -13     

☔ 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

codspeed-hq bot commented Apr 22, 2025

CodSpeed Performance Report

Merging #86 will not alter performance

Comparing merge/oxc (ed82ebd) with main (e172e11)

Summary

✅ 3 untouched benchmarks

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 ed82ebd in 2 minutes and 28 seconds. Click for details.
  • Reviewed 313 lines of code in 11 files
  • Skipped 1 files when reviewing.
  • Skipped posting 11 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:49
  • Draft comment:
    Ensure consistency in mapping resolutions. Some tests use Resolution::into_path_buf directly and others via unrs_resolver::Resolution::into_path_buf. This is fine if intentional, but consider unifying for clarity.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None
2. tests/resolve_test.rs:217
  • Draft comment:
    The Windows symlinked long filename test asserts that the resolved path is super long (>260 characters). This is good for Windows-specific behavior, but adding comments on why the test is needed could aid future maintainers.
  • Reason this comment was not posted:
    Confidence changes required: 20% <= threshold 50% None
3. src/windows.rs:23
  • Draft comment:
    Risky index access: the code assumes that p has at least 2 bytes when checking p[1] != b':'. Consider adding a length check on p before indexing to avoid potential panic.
  • 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 is handling Windows paths, specifically after stripping "\?" or "\." prefixes. For a valid DOS path, there must be a drive letter followed by a colon (e.g., "C:"). The strip_prefix() operation guarantees that p only matches if the prefix exists. Given the strict Windows path format requirements, it's extremely unlikely that a valid Windows path would ever be shorter than 2 characters after these prefixes. I could be wrong about the guarantees of Windows path formats - there might be edge cases I'm not considering. The suggestion to add a length check is defensive programming and wouldn't hurt. While defensive programming is good practice, in this case we're dealing with a very specific Windows path format where the structure is well-defined. The test cases cover the main scenarios. While the comment suggests a valid defensive programming practice, the risk is extremely low given the well-defined Windows path format requirements. The current code is reasonable.
4. src/windows.rs:12
  • Draft comment:
    The usage of unsafe conversions via from_encoded_bytes_unchecked requires strong guarantees that the OS string bytes are valid. Consider adding or referencing tests/documentation verifying these preconditions.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
5. pnpm-workspace.yaml:10
  • Draft comment:
    The addition of virtualStoreDirMaxLength: 1024 is clear, but ensure that this value fits all environments and document its purpose if not already.
  • Reason this comment was not posted:
    Confidence changes required: 20% <= threshold 50% None
6. tests/resolve_test.rs:217
  • Draft comment:
    The Windows long filename test uses a path length assertion. Confirm that this test runs only on Windows (or is conditionally skipped) to avoid false failures on other OSes.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None
7. CHANGELOG.md:62
  • Draft comment:
    Typographical error: In the [1.4.0] release section, 'pacakge.json' is misspelled. Please correct it to 'package.json'.
  • 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.
8. src/error.rs:29
  • Draft comment:
    Typo: The comment on the MatchedAliasNotFound variant reads "Matched alias value not found" with two spaces between 'value' and 'not'. Could you remove the extra space for consistency?
  • 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.
9. src/error.rs:37
  • Draft comment:
    Typo: In the comment for TsconfigSelfReference, "points to it self" should be written as "points to itself".
  • 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.
10. src/error.rs:76
  • Draft comment:
    Typo/Error: In the error message for the Restriction variant, the formatting string is "Path "{0}" restricted by {0}". Given that the variant takes two PathBuf arguments, it seems the second placeholder should be {1} instead of repeating {0}.
  • 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.
11. tests/resolve_test.rs:49
  • Draft comment:
    The test uses an inconsistent reference to Resolution: in some places it is referred to directly (e.g. Resolution::into_path_buf), while in others it is prefixed with unrs_resolver:: (e.g. unrs_resolver::Resolution::into_path_buf). Since Resolution is already imported at the top of the file, it would be clearer to use it consistently. Consider updating the occurrences of unrs_resolver::Resolution::into_path_buf to simply Resolution::into_path_buf.
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_i25T5Q36L3GNtk88

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

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: 0

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

196-196: Consider better handling of "unreachable" error cases.

Using unreachable!() assumes that no other error types besides PathNotSupported will ever be returned. This could cause a panic if the assumption is violated in the future.

Consider handling all possible error cases explicitly or propagating the error instead:

- match crate::windows::try_strip_windows_prefix(path) {
-     // We won't follow the link if we cannot represent its target properly.
-     Ok(p) | Err(crate::ResolveError::PathNotSupported(p)) => Ok(p),
-     _ => unreachable!(),
- }
+ match crate::windows::try_strip_windows_prefix(path) {
+     // We won't follow the link if we cannot represent its target properly.
+     Ok(p) | Err(crate::ResolveError::PathNotSupported(p)) => Ok(p),
+     Err(e) => {
+         tracing::warn!("Unexpected error stripping Windows path prefix: {:?}", e);
+         // Fall back to the original path
+         Ok(path)
+     }
+ }
src/windows.rs (1)

8-39: Well-structured implementation for Windows path normalization.

This function correctly handles various Windows DOS device path formats and converts them to standard paths that can be consumed by Node.js import/require syntax. The error handling for unsupported path formats is appropriate.

Consider adding a check to ensure p has at least 2 bytes before accessing p[1] on line 24, although it's unlikely to be an issue given the context:

 // Assuming traditional DOS path "\\?\C:\"
-if p[1] != b':' {
+if p.len() < 2 || p[1] != b':' {
     // E.g.,
     // \\?\Volume{b75e2c83-0000-0000-0000-602f00000000}
     // \\?\BootPartition\
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e172e11 and ed82ebd.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • CHANGELOG.md (1 hunks)
  • fixtures/pnpm-workspace/packages/lib/package.json (1 hunks)
  • npm/package.json (1 hunks)
  • package.json (1 hunks)
  • pnpm-workspace.yaml (1 hunks)
  • src/error.rs (1 hunks)
  • src/file_system.rs (1 hunks)
  • src/fs_cache.rs (1 hunks)
  • src/lib.rs (1 hunks)
  • src/windows.rs (1 hunks)
  • tests/resolve_test.rs (4 hunks)
🔇 Additional comments (15)
npm/package.json (1)

51-51: Dependency version update looks good.

Upgrading napi-postinstall from ^0.1.1 to ^0.1.5 aligns with the broader improvements in handling Windows path prefixes in this PR.

src/error.rs (1)

44-46: Well-structured error handling for unsupported paths.

The new error variant with descriptive documentation and error message provides proper handling for unsupported path constructs like Windows UNC paths with Volume GUIDs. This complements the Windows path handling improvements introduced in this PR.

pnpm-workspace.yaml (1)

10-11: Good configuration for long path testing.

The addition of virtualStoreDirMaxLength with a clear explanatory comment is helpful for supporting the Windows symlinked long filename tests. The value of 1024 provides sufficient length for these test cases.

fixtures/pnpm-workspace/packages/lib/package.json (1)

7-7: React dependency update looks good.

Simple version update from ^19.0.0 to ^19.1.0 as part of general maintenance across the workspace.

package.json (1)

24-24: LGTM! Clean dependency update to latest vitest version.

This minor version update to vitest from 3.1.1 to 3.1.2 will help support the Windows path handling changes introduced in this PR.

CHANGELOG.md (1)

9-11: Well-documented changelog entry.

The changelog entry appropriately documents the bug fix for DOS device path handling and includes a reference to the upstream PR.

src/lib.rs (1)

68-69: Good use of conditional compilation for platform-specific code.

Adding a dedicated Windows module that's only compiled on Windows targets is a clean way to organize platform-specific functionality. This centralizes the Windows path handling logic in one place, improving maintainability.

src/file_system.rs (1)

192-197: Improved Windows path handling with better error management.

The updated code now uses the centralized try_strip_windows_prefix function from the Windows module, which returns a proper Result type, allowing for better error handling of unsupported path formats.

src/fs_cache.rs (1)

82-86: The Windows path handling improvement looks solid.

The change from #[cfg(windows)] to #[cfg(target_os = "windows")] is more precise, specifically targeting Windows OS rather than the Windows platform family. The new approach using try_strip_windows_prefix handles errors properly by returning a Result<PathBuf, ResolveError> instead of transforming the path directly.

src/windows.rs (1)

41-64: Good test coverage for Windows path prefix handling.

The test cases cover both successful path transformations and error handling for unsupported paths, which is excellent for ensuring reliability.

tests/resolve_test.rs (5)

3-3: Import statement cleanup is a nice improvement.

Importing Resolution directly instead of using fully qualified names makes the code more readable.


24-30: Updated module path structure for styled-components.

The path update reflects the current package version and structure, using chained .join() calls for better readability.


38-38: Improved path construction for CJS resolution.

Using .join() method chain instead of string concatenation improves readability and cross-platform compatibility.


50-50: Improved path construction for ESM resolution.

Using .join() method chain instead of string concatenation improves readability and cross-platform compatibility.


214-236: Well-handled Windows long path test case with enhanced validation.

The revised test properly checks long path handling with:

  1. Detailed comments about pnpm configuration for reproducibility
  2. An explicit assertion that the path exceeds Windows' 260-character limit
  3. Cleaner resolution mapping with extracted specifier variable

This test is now expected to pass on Windows thanks to the new path handling implementation.

@JounQin JounQin merged commit ed82ebd into main Apr 22, 2025
21 checks passed
@JounQin JounQin deleted the merge/oxc branch April 22, 2025 13:00
@coderabbitai coderabbitai bot mentioned this pull request Apr 22, 2025
This was referenced Apr 23, 2025
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.

4 participants