fix: prefer index over current file for . and ./#121
Conversation
WalkthroughThe changes update comments and logic in the resolver to explicitly handle specifiers Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Resolver
participant Filesystem
Caller->>Resolver: require(".") or require("./")
Resolver->>Resolver: Check if specifier is "." or "./"
alt Specifier is "." or "./"
Resolver->>Resolver: Normalize path to parent/index.js
Resolver->>Filesystem: Attempt to load parent/index.js
Filesystem-->>Resolver: Return file or alias
else
Resolver->>Filesystem: Proceed with standard file loading logic
end
Resolver-->>Caller: Return resolved file path or error
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (3)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 88b7372 in 1 minute and 52 seconds. Click for details.
- Reviewed
68lines of code in4files - Skipped
0files when reviewing. - Skipped posting
4draft 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:625
- Draft comment:
Add a clarifying comment explaining why specifiers '.' and './' are normalized with '../index.js'. This helps future maintainers understand that the resolution intentionally prefers an index file over the current file, aligning with Node.js behavior. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 0% vs. threshold = 50% This appears to be a non-obvious behavior that could confuse future maintainers. The comment points out that this is intentionally aligning with Node.js behavior, which is important context. However, the comment is purely informational and doesn't request a specific code change - it's just asking for documentation. Per the rules, we should not make purely informative comments. The behavior does seem unusual and documentation could be genuinely helpful. Maybe this is an exception to the "no informational comments" rule since it helps prevent confusion? While documentation would be nice, the rules are clear that we should not make purely informational comments. The code works correctly as is, and if documentation is needed it should be requested through other channels. Delete this comment since it is purely informational and doesn't request a specific code change, even though the documentation would be helpful.
2. src/tests/resolve.rs:39
- Draft comment:
Duplicate test case detected for 'file in module with query and fragment'. Consider removing one of the duplicate entries 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.
3. src/tests/resolve.rs:136
- Draft comment:
Ensure the test for resolving '.' and './' clearly documents that the intended behavior is to resolve to the index file. A brief comment in the test explaining this Node.js–aligned behavior would add clarity. - 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 asks for documentation but doesn't point out a bug or necessary code change. It's asking for explanation/clarification, which violates our rules. The test cases themselves are clear about what they're testing through their descriptive names and assertions. The file already has a reference to the original webpack/enhanced-resolve tests at the top. Perhaps having explicit documentation would help future maintainers understand the Node.js compatibility aspect better. The test names alone might not fully convey the reasoning. While documentation can be helpful, our rules explicitly state not to make purely informative comments or ask for explanations. The test is already clear and linked to the original implementation it's based on. Delete the comment as it only requests additional documentation without suggesting any necessary code changes, which violates our review rules.
4. src/lib.rs:625
- Draft comment:
Consider updating the function's documentation to mention that when a module specifier is '.' or './', the resolver intentionally prefers the index file over the current file. This will help align the internal behavior with external documentation. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%<= threshold50%The comment suggests updating documentation, which is not allowed as it falls under asking the author to update the PR description or similar. It doesn't provide a specific code suggestion or point out a potential issue in the code itself.
Workflow ID: wflow_dTsArui0pSccsKrx
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for resolving . and ./ requests to the index.js in the containing directory rather than the current file.
- Updated comment blocks to mention the
.request case. - Enhanced
require_relativelogic to detect.and./and normalize to../index.js. - Added a new unit test (
resolve_dot) to verify././resolution.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/tests/resolve.rs | Added resolve_dot test covering . and ./ resolution to index |
| src/lib.rs | Updated comments and enhanced require_relative to handle ././ |
Comments suppressed due to low confidence (2)
src/tests/resolve.rs:136
- Add test cases for resolving
.and./when the base path is a directory (not a file) to ensure consistent behavior in that scenario.
fn resolve_dot() {
src/tests/resolve.rs:136
- [nitpick] Consider renaming the test function from
resolve_dottoresolve_dot_and_dot_slashfor clearer coverage of both cases.
fn resolve_dot() {
88b7372 to
68386b7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #121 +/- ##
==========================================
- Coverage 93.43% 93.42% -0.01%
==========================================
Files 13 13
Lines 2879 2891 +12
==========================================
+ Hits 2690 2701 +11
- Misses 189 190 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CodSpeed Performance ReportMerging #121 will degrade performances by 13.57%Comparing Summary
Benchmarks breakdown
|
68386b7 to
efb77b5
Compare
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed efb77b5 in 42 seconds. Click for details.
- Reviewed
70lines of code in2files - Skipped
0files when reviewing. - Skipped posting
1draft 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:136
- Draft comment:
The new 'resolve_dot' test clearly verifies that '.' and './' resolve to the directory's index file. This aligns with the intended fix. Consider adding an edge-case test for when an index file is missing (if applicable) to ensure proper fallback behavior. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
Workflow ID: wflow_ajGEGicZKjTKGIus
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
efb77b5 to
869fe1a
Compare
|
There was a problem hiding this comment.
Caution
Changes requested ❌
Reviewed 869fe1a in 1 minute and 41 seconds. Click for details.
- Reviewed
74lines of code in2files - Skipped
0files when reviewing. - Skipped posting
1draft 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:136
- Draft comment:
The new test 'resolve_dot' validates that '.' and './' resolve to the index file, which is exactly the expected behavior. This is a good addition to cover the intended fix. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
Workflow ID: wflow_ZZXTfCvY2eGlSO52
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.



Important
Fix module resolution for
.and./to preferindex.jsin the parent directory.require_relativeinsrc/lib.rsto resolve.and./toindex.jsin the parent directory.resolve_dottest insrc/tests/resolve.rsto verify.and./resolve toindex.js.This description was created by
for 869fe1a. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit
Bug Fixes
"."and"./"specifiers to load the parent directory'sindex.jsfile correctly.Tests
"."and"./"resolve to the correctindex.jsfile.