Skip to content

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented May 1, 2025

Summary by CodeRabbit

  • New Features
    • Added the ability to detect if a path is a "node_modules" directory or located inside one.
  • Refactor
    • Improved internal logic to use new detection methods for "node_modules" directories, enhancing reliability when searching for package files.

@coderabbitai
Copy link

coderabbitai bot commented May 1, 2025

Walkthrough

The changes introduce two new methods, is_node_modules and inside_node_modules, to the CachedPath trait. Implementation support for these methods is added in the file system cache layer by storing and exposing two corresponding boolean flags within the CachedPathImpl struct. The resolver logic in the library is refactored to use these new methods instead of performing direct string checks on directory names, improving encapsulation and clarity. No changes are made to the overall control flow or error handling.

Changes

File(s) Change Summary
src/cache.rs Added is_node_modules and inside_node_modules method signatures to the CachedPath trait.
src/fs_cache.rs Added is_node_modules and inside_node_modules boolean fields to CachedPathImpl; updated constructor and CachedPath implementation for FsCachedPath to support and expose these fields.
src/lib.rs Refactored resolver logic to use new inside_node_modules() and is_node_modules() methods instead of string-based path checks.

Sequence Diagram(s)

sequenceDiagram
    participant Resolver
    participant CachedPath
    participant FsCachedPath

    Resolver->>CachedPath: inside_node_modules()
    CachedPath->>FsCachedPath: inside_node_modules()
    FsCachedPath-->>CachedPath: returns bool

    Resolver->>CachedPath: is_node_modules()
    CachedPath->>FsCachedPath: is_node_modules()
    FsCachedPath-->>CachedPath: returns bool
Loading

Poem

In the warren of code, new tunnels appear,
To find node_modules, the path is now clear.
No more string peeking, just methods so neat,
With booleans guiding our little rabbit feet.
Hop, hop, encapsulation’s delight—
The cache knows its burrows, and all is just right!
🐇✨


📜 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 6684a64 and 00daa1e.

📒 Files selected for processing (3)
  • src/cache.rs (1 hunks)
  • src/fs_cache.rs (3 hunks)
  • src/lib.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/cache.rs (1)
src/fs_cache.rs (2)
  • is_node_modules (321-323)
  • inside_node_modules (325-327)
src/lib.rs (1)
src/fs_cache.rs (1)
  • inside_node_modules (325-327)
src/fs_cache.rs (1)
src/cache.rs (4)
  • is_node_modules (65-65)
  • path (59-59)
  • inside_node_modules (67-67)
  • parent (63-63)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Benchmark
🔇 Additional comments (9)
src/cache.rs (1)

65-68: Solid addition for performance optimization.

The addition of these two new methods to the CachedPath trait provides a clean abstraction for checking whether a path is a node_modules directory or is inside one. This change enables caching of this information rather than repeatedly performing string comparisons, which should improve performance.

src/fs_cache.rs (6)

70-72: LGTM: Efficient computation of node_modules status.

The implementation correctly identifies:

  1. If the current path is a node_modules directory by checking its file name
  2. If the current path is inside a node_modules directory by checking either the current path or recursively checking its parent

This computation happens only once during path value creation, avoiding repeated string comparisons.


76-77: Well structured: Adding the new flags to CachedPathImpl.

These flags are appropriately passed to the CachedPathImpl constructor.


270-271: Good: Adding storage for node_modules flags.

Adding these boolean fields to the struct provides an efficient way to store this information that was previously computed repeatedly.


279-285: LGTM: Updated constructor signature.

The constructor has been appropriately updated to accept the new boolean parameters.


290-291: Properly stored flag values.

The constructor properly stores the flag values in the struct fields.


321-327: Clean implementation of trait methods.

These implementations simply return the cached boolean values, making the check O(1) instead of potentially O(n) for string operations or recursive parent checks.

src/lib.rs (2)

290-291: Improved: Replaced string check with cached method call.

Using the cached inside_node_modules() method instead of manually checking the path is more efficient and makes the code more readable.


294-296: Better encapsulation: Using trait method instead of direct string check.

Using the is_node_modules() method provides a clearer abstraction than checking the path directly, centralizing the logic for identifying node_modules directories.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

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
Member Author

Boshen commented May 1, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov
Copy link

codecov bot commented May 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.85%. Comparing base (6684a64) to head (00daa1e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #490      +/-   ##
==========================================
+ Coverage   93.81%   93.85%   +0.03%     
==========================================
  Files          13       13              
  Lines        2780     2797      +17     
==========================================
+ Hits         2608     2625      +17     
  Misses        172      172              

☔ 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 May 1, 2025

CodSpeed Performance Report

Merging #490 will improve performances by 18.79%

Comparing 05-01-perf_cache_whether_a_path_is_node_modules_or_inside_node_modules_ (00daa1e) with main (6684a64)

Summary

⚡ 3 improvements

Benchmarks breakdown

Benchmark BASE HEAD Change
resolver[multi-thread] 558.5 µs 470.1 µs +18.79%
resolver[resolve from symlinks] 85.4 ms 58.7 ms +45.51%
resolver[single-thread] 558.3 µs 461 µs +21.1%

@Boshen Boshen merged commit 80adaf3 into main May 1, 2025
20 checks passed
@Boshen Boshen deleted the 05-01-perf_cache_whether_a_path_is_node_modules_or_inside_node_modules_ branch May 1, 2025 03:43
@oxc-bot oxc-bot mentioned this pull request May 1, 2025
Boshen pushed a commit that referenced this pull request May 1, 2025
## 🤖 New release

* `oxc_resolver`: 7.0.1 -> 8.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:
  ResolveOptions::with_module, previously in file /tmp/.tmpCfZ3uE/oxc_resolver/src/options.rs:342

--- failure struct_pub_field_missing: pub struct's pub field removed or renamed ---

Description:
A publicly-visible struct has at least one public field that 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/struct_pub_field_missing.ron

Failed in:
  field description_files of struct ResolveOptions, previously in file /tmp/.tmpCfZ3uE/oxc_resolver/src/options.rs:47
  field modules of struct ResolveOptions, previously in file /tmp/.tmpCfZ3uE/oxc_resolver/src/options.rs:119

--- failure trait_method_added: pub trait method added ---

Description:
A non-sealed public trait added a new method without a default implementation, which breaks downstream implementations of the trait
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/trait_method_added.ron

Failed in:
  trait method oxc_resolver::CachedPath::is_node_modules in file /tmp/.tmpoUaDz8/oxc-resolver/src/cache.rs:65
  trait method oxc_resolver::CachedPath::inside_node_modules in file /tmp/.tmpoUaDz8/oxc-resolver/src/cache.rs:67

--- failure trait_method_missing: pub trait method removed or renamed ---

Description:
A trait method is no longer callable, and may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#major-any-change-to-trait-item-signatures
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/trait_method_missing.ron

Failed in:
  method node_modules of trait CachedPath, previously in file /tmp/.tmpCfZ3uE/oxc_resolver/src/cache.rs:65
  method module_directory of trait CachedPath, previously in file /tmp/.tmpCfZ3uE/oxc_resolver/src/cache.rs:67
  method cached_node_modules of trait CachedPath, previously in file /tmp/.tmpCfZ3uE/oxc_resolver/src/cache.rs:74
```

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

<blockquote>

##
[8.0.0](oxc_resolver-v7.0.1...oxc_resolver-v8.0.0)
- 2025-05-01

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

- fix incorrect return of package.json when a workspace module has
`node_modules`
([#482](#482))

### <!-- 2 -->Performance

- cache whether a path is `node_modules` or inside `node_modules`
([#490](#490))
- remove a useless `load_as_directory` call
([#487](#487))

### <!-- 4 -->Refactor

- [**breaking**] remove `description_files` option
([#488](#488))
- [**breaking**] remove `modules` options
([#484](#484))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Documentation**
- Added a new changelog entry for version 8.0.0, highlighting a bug fix,
performance improvements, and breaking changes.
- **Chores**
  - Updated the package version to 8.0.0 in project files.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

2 participants