10000 fix: prefer file over package dir in `node_modules` by JounQin · Pull Request #116 · unrs/unrs-resolver · GitHub
[go: up one dir, main page]

Skip to content

fix: prefer file over package dir in node_modules #116

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 1 commit into from
May 28, 2025

Conversation

JounQin
Copy link
Member
@JounQin JounQin commented May 28, 2025

related un-ts/eslint-plugin-import-x#272 (comment)


Important

Modify ResolverGeneric to prefer files over directories in node_modules and add test for this behavior.

  • Behavior:
    • Modify ResolverGeneric in src/lib.rs to prefer files over directories in node_modules when specifier lacks a slash.
    • Add test prefer_file_over_pkg in resolve.rs to verify file preference over package directory.
  • Fixtures:
    • Add prefer-file-over-pkg fixture with node_modules/bar.js and node_modules/bar/index.js to test file preference.

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

Summary by CodeRabbit

  • New Features
    • Improved module resolution to prioritize loading files over package directories when a simple package name is used.
  • Tests
    • Added a new test to verify that file resolution is preferred over package directory resolution in specific scenarios.
    • Simplified resolver instantiation in existing tests for improved readability.
  • Chores
    • Added new fixture files to support enhanced testing scenarios.

@JounQin JounQin requested a review from Copilot May 28, 2025 09:59
@JounQin JounQin self-assigned this May 28, 2025
@JounQin JounQin added the bug Something isn't working label May 28, 2025
Copy link
coderabbitai bot commented May 28, 2025

Walkthrough

A new .gitignore and package.json were added to a fixture directory. The module resolution logic in load_node_modules was enhanced to prefer resolving a simple specifier as a file before falling back to directory resolution. A new test verifies this behavior, and existing tests were simplified.

Changes

File(s) Change Summary
fixtures/prefer-file-over-pkg/.gitignore Added .gitignore with negation pattern to include node_modules.
fixtures/prefer-file-over-pkg/package.json Added minimal package.json with "name": "prefer-file-over-pkg".
src/lib.rs Modified load_node_modules to prefer resolving specifiers without slashes as files before directories.
src/tests/resolve.rs Simplified resolver instantiation in tests; added prefer_file_over_pkg test to check file preference.

Possibly related PRs

Poem

🐇 In code's green meadow, a file takes the lead,
When names are simple, it's the file we heed.
No slashes to wander, just a clear, bright way,
The resolver hops swiftly, no delay.
Fixtures align, tests cheer with delight,
A rabbit’s small dance in the soft coding light! 🌿✨

✨ 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

Copy link
codecov bot commented May 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.42%. Comparing base (b782e89) to head (3ca7379).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #116      +/-   ##
==========================================
+ Coverage   93.41%   93.42%   +0.01%     
==========================================
  Files          13       13              
  Lines        2870     2876       +6     
==========================================
+ Hits         2681     2687       +6     
  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 everything up to 3ca7379 in 1 minute and 35 seconds. Click for details.
  • Reviewed 84 lines of code in 7 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/tests/resolve.rs:39
  • Draft comment:
    Duplicate test case: Two entries with description 'file in module with query and fragment' using the same input "m1/a?#fragment". Consider removing or differentiating one to avoid redundancy.
  • 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.
2. src/tests/resolve.rs:121
  • Draft comment:
    Good addition: the 'prefer_file_over_pkg' test validates that a file is preferred over a package directory. Consider adding additional variations (e.g. with slashes) to further strengthen coverage.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None
3. src/lib.rs:784
  • Draft comment:
    Typographical error: The comment using "doesn't contains" should be corrected to "doesn't contain".
  • 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% While the comment is technically correct about the grammar, comments about typos in documentation/comments are generally not important enough to warrant a PR comment. The meaning is still clear despite the minor grammatical error. This kind of nitpick creates noise without adding significant value. The grammar error could potentially confuse non-native English speakers. Documentation quality is important for project maintainability. While documentation quality matters, this particular error is minor enough that it doesn't significantly impact readability or understanding. The development process shouldn't be slowed down for such minor text issues. Delete this comment as it addresses a trivial grammatical issue that doesn't impact code functionality or documentation clarity.

Workflow ID: wflow_ioS5nwKxlC8KyVQU

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 May 28, 2025

CodSpeed Performance Report

Merging #116 will not alter performance

Comparing fix/prefer_file_over_pkg (3ca7379) with main (b782e89)

Summary

✅ 3 untouched benchmarks

@JounQin
Copy link
Member Author
JounQin commented May 28, 2025

@coderabbitai full review

Copy link
coderabbitai bot commented May 28, 2025
✅ Actions performed

Full review triggered.

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 (1)
src/lib.rs (1)

784-790: Fix grammar in comment.

The implementation logic is correct and properly implements the file-over-package preference for simple specifiers. However, there's a minor grammar issue in the comment.

-                    // file is preferred over directory when specifier doesn't contains a slash which indicates a dir
+                    // file is preferred over directory when specifier doesn't contain a slash which indicates a dir
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b782e89 and 3ca7379.

⛔ Files ignored due to path filters (3)
  • fixtures/prefer-file-over-pkg/node_modules/bar.js is excluded by !**/node_modules/**
  • fixtures/prefer-file-over-pkg/node_modules/bar/index.js is excluded by !**/node_modules/**
  • fixtures/prefer-file-over-pkg/node_modules/bar/package.json is excluded by !**/node_modules/**
📒 Files selected for processing (4)
  • fixtures/prefer-file-over-pkg/.gitignore (1 hunks)
  • fixtures/prefer-file-over-pkg/package.json (1 hunks)
  • src/lib.rs (1 hunks)
  • src/tests/resolve.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (5)
fixtures/prefer-file-over-pkg/package.json (1)

1-3: LGTM! Well-structured test fixture.

This minimal package.json serves its purpose perfectly for testing the new file-over-package preference behavior.

fixtures/prefer-file-over-pkg/.gitignore (1)

1-1: LGTM! Correct .gitignore pattern for test fixtures.

The !node_modules pattern appropriately ensures that the test fixture's node_modules directory is included in version control, which is necessary for the test to function properly.

src/tests/resolve.rs (3)

116-116: LGTM! Good simplification.

Using Resolver::default() is cleaner than Resolver::new(ResolveOptions::default()).


121-128: LGTM! Excellent test coverage for the new feature.

This test properly validates that the resolver now prefers resolving simple specifiers as files over package directories. The test setup and assertions correctly verify the intended behavior.


139-139: LGTM! Consistent simplification.

Good to see the same simplification applied consistently across tests.

@JounQin JounQin merged commit ff4799e into main May 28, 2025
22 checks passed
@JounQin JounQin deleted the fix/prefer_file_over_pkg branch May 28, 2025 10:07
Sign up for free to join this conversation on GitH 7593 ub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0