Skip to content

fix: prefer index over current file for . and ./#121

Merged
JounQin merged 1 commit intomainfrom
fix/prefer_index_over_current_file
May 28, 2025
Merged

fix: prefer index over current file for . and ./#121
JounQin merged 1 commit intomainfrom
fix/prefer_index_over_current_file

Conversation

@JounQin
Copy link
Member

@JounQin JounQin commented May 28, 2025

Important

Fix module resolution for . and ./ to prefer index.js in the parent directory.

  • Bug Fixes:
    • Update require_relative in src/lib.rs to resolve . and ./ to index.js in the parent directory.
  • Tests:
    • Add resolve_dot test in src/tests/resolve.rs to verify . and ./ resolve to index.js.

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


Summary by CodeRabbit

  • Bug Fixes

    • Improved resolution for "." and "./" specifiers to load the parent directory's index.js file correctly.
  • Tests

    • Added tests verifying that "." and "./" resolve to the correct index.js file.

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

coderabbitai bot commented May 28, 2025

Walkthrough

The changes update comments and logic in the resolver to explicitly handle specifiers "." and "./" as relative paths, ensuring they resolve to the parent directory's index.js. A new test verifies that both "." and "./" correctly resolve to the expected file.

Changes

File(s) Change Summary
src/lib.rs Updated comments to clarify handling of "." as a relative path. Added special case in require_relative for "." and "./" to resolve to ../index.js. Replaced require_relative(".") with direct load_as_file_or_directory(".") call in load_tsconfig_paths.
src/tests/resolve.rs Added resolve_dot test to verify that "." and "./" specifiers resolve to the correct index.js file.

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
Loading

Poem

A dot and a slash, so simple, so neat,
Now find their way to an index seat.
The resolver hops with newfound glee,
Knowing "." means more than it used to be.
Tests now confirm what rabbits adore—
That every path leads to the right door! 🐇


📜 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 efb77b5 and 869fe1a.

📒 Files selected for processing (2)
  • src/lib.rs (4 hunks)
  • src/tests/resolve.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/tests/resolve.rs
  • src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Benchmark
✨ 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

@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 88b7372 in 1 minute and 52 seconds. Click for details.
  • Reviewed 68 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 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/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% <= threshold 50% 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 Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link

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 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_relative logic 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_dot to resolve_dot_and_dot_slash for clearer coverage of both cases.
fn resolve_dot() {

@JounQin JounQin force-pushed the fix/prefer_index_over_current_file branch from 88b7372 to 68386b7 Compare May 28, 2025 16:31
@codecov
Copy link

codecov bot commented May 28, 2025

Codecov Report

Attention: Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.42%. Comparing base (7f57c6e) to head (869fe1a).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/lib.rs 90.90% 1 Missing ⚠️
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.
📢 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 28, 2025

CodSpeed Performance Report

Merging #121 will degrade performances by 13.57%

Comparing fix/prefer_index_over_current_file (869fe1a) with main (7f57c6e)

Summary

❌ 2 regressions
✅ 1 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
resolver[multi-thread] 497.2 µs 575.3 µs -13.57%
resolver[single-thread] 499.2 µs 556.2 µs -10.25%

@JounQin JounQin force-pushed the fix/prefer_index_over_current_file branch from 68386b7 to efb77b5 Compare May 28, 2025 16:35
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 efb77b5 in 42 seconds. Click for details.
  • Reviewed 70 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 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: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% <= threshold 50% None

Workflow ID: wflow_ajGEGicZKjTKGIus

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

@JounQin JounQin force-pushed the fix/prefer_index_over_current_file branch from efb77b5 to 869fe1a Compare May 28, 2025 17:17
@sonarqubecloud
Copy link

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 869fe1a in 1 minute and 41 seconds. Click for details.
  • Reviewed 74 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 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: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% <= threshold 50% None

Workflow ID: wflow_ZZXTfCvY2eGlSO52

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

@JounQin JounQin merged commit f582cf1 into main May 28, 2025
21 of 22 checks passed
@JounQin JounQin deleted the fix/prefer_index_over_current_file branch May 28, 2025 17:23
@JounQin JounQin mentioned this pull request May 28, 2025
Sign up for free to join this conversation on GitHub. 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.

2 participants