Skip to content

Conversation

@JounQin
Copy link
Member

@JounQin JounQin commented Jul 2, 2025

close jestjs/jest#15712


Important

Adds support for resolving abnormal relative paths in module requests by introducing normalize_relative() and updating resolver logic.

  • Behavior:
    • Adds support for resolving abnormal relative paths like jest-runner-../../.. in lib.rs.
    • Introduces normalize_relative() in path.rs to handle non-absolute path normalization.
  • Tests:
    • Adds abnormal_relative() test in resolve.rs to verify handling of abnormal relative paths.
    • New test fixtures abnormal-relative-with-node_modules and abnormal-relative-without-node_modules added.
  • Dependencies:
    • Updates enhanced-resolve version in pnpm-workspace/package.json.

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


Summary by CodeRabbit

  • New Features
    • Improved handling of abnormal relative module specifiers, enabling resolution of certain legacy-style paths in specific scenarios.
  • Bug Fixes
    • Enhanced compatibility for resolving module paths that combine unusual relative segments with module name prefixes, addressing legacy behaviors.
  • Tests
    • Added new tests to verify resolver behavior with abnormal relative module paths, covering both success and error cases.
  • Chores
    • Updated a dependency version in the workspace configuration.

@JounQin JounQin requested a review from Copilot July 2, 2025 03:20
@JounQin JounQin self-assigned this Jul 2, 2025
@JounQin JounQin added the bug Something isn't working label Jul 2, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 2, 2025

Walkthrough

The changes introduce handling for abnormal relative module specifiers (e.g., jest-runner-../../..) in the resolver logic. A new normalization method is added for relative paths, and the resolver now attempts to resolve such specifiers in a legacy-compatible way. Extensive tests and fixtures are added to verify the new behavior in various scenarios.

Changes

File(s) Change Summary
src/lib.rs Added logic in load_package_self_or_node_modules to detect and handle abnormal relative specifiers using new normalization method.
src/path.rs Added normalize_relative method to PathUtil trait and its implementation for Path; added tests for this method.
src/tests/resolve.rs Added new test function abnormal_relative to verify resolver behavior with abnormal relative module specifiers.
fixtures/abnormal-relative-with-node_modules/, fixtures/abnormal-relative-without-node_modules/ Added test fixtures: package.json, test files using abnormal relative module specifiers, both with and without node_modules.
fixtures/pnpm-workspace/package.json Updated dependency version of "enhanced-resolve" from "^5.18.1" to "^5.18.2".

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Resolver
    participant PathUtil

    Caller->>Resolver: load_package_self_or_node_modules(specifier)
    alt Specifier contains abnormal relative segments
        Resolver->>PathUtil: normalize_relative(specifier)
        PathUtil-->>Resolver: normalized_specifier
        Resolver->>Resolver: parse_package_name(normalized_specifier)
        alt package_name == ".."
            Resolver->>Resolver: load_node_modules(normalized_specifier)
            alt Success
                Resolver-->>Caller: Resolved path
            else Failure
                Resolver-->>Caller: NotFound error
            end
        else
            Resolver-->>Caller: NotFound error
        end
    else
        Resolver->>Resolver: (existing resolution logic)
        Resolver-->>Caller: (existing result)
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Correctly resolve abnormal/nested relative module specifiers (e.g., jest-runner-../../..) in resolver (#15712)
Add tests to verify resolver behavior with abnormal relative specifiers (#15712)
Add fixtures to simulate environments with and without node_modules for abnormal relative resolution (#15712)

Poem

In tunnels deep, a rabbit found
Paths that looped and spun around.
With clever code, the way was cleared,
Abnormal routes no longer feared!
Now modules hop from place to place—
🐇 The resolver wins the race!

✨ 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 cce1f34 in 44 seconds. Click for details.
  • Reviewed 49 lines of code in 5 files
  • Skipped 1 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. fixtures/abnormal-relative/foo/bar/baz/test.js:1
  • Draft comment:
    Remove unused import of 'node:path' if not needed.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. fixtures/abnormal-relative/foo/bar/baz/test.js:3
  • Draft comment:
    Clarify the purpose of using the abnormal relative request 'jest-runner-../../../'.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. fixtures/abnormal-relative/runner.js:1
  • Draft comment:
    If the empty runner.js is intentional, add a comment indicating its role.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
4. src/tests/resolve.rs:197
  • Draft comment:
    Add inline documentation in the 'abnormal_relative' test to explain why resolving 'jest-runner-../../../' should yield runner.js.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_lUWYqPv6YsisO8hZ

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

This comment was marked as outdated.

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)
fixtures/abnormal-relative/foo/bar/baz/test.js (1)

1-1: Remove unused import.

The path module is imported but never used in this test file.

-const path = require('node:path')
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 93cedab and cce1f34.

⛔ Files ignored due to path filters (2)
  • fixtures/abnormal-relative/node_modules/.gitkeep is excluded by !**/node_modules/**
  • fixtures/abnormal-relative/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • fixtures/abnormal-relative/foo/bar/baz/test.js (1 hunks)
  • fixtures/abnormal-relative/package.json (1 hunks)
  • src/tests/resolve.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T08:17:34.175Z
Learning: Test cases in unrs-resolver that intentionally document failing behavior should make the intent clear by either: 1) asserting on the expected error condition rather than the desired behavior, 2) using #[should_panic] for tests expected to panic, or 3) using #[ignore] with a reason to skip known failing tests in CI.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T08:13:59.358Z
Learning: In the unrs-resolver project, tests that intentionally document failing behavior (regression tests) should either use #[should_panic], assert on the expected error, or include clear documentation indicating they are intentional failing test cases.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:4-6
Timestamp: 2025-04-20T16:00:16.106Z
Learning: The configuration with `".": ["."]` in the paths setting in fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json is an intentional test case for testing the TypeScript dot alias resolution behavior, specifically related to issue #437 in the eslint-import-resolver-typescript repository.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T09:52:45.840Z
Learning: In Yarn PnP environments, some packages use nested package.json files for subpaths instead of the exports field. The resolver should check for these nested package.json files when resolving subpaths like `@atlaskit/pragmatic-drag-and-drop/combine` to correctly handle packages with this structure.
Learnt from: JounQin
PR: unrs/unrs-resolver#40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:0-0
Timestamp: 2025-04-21T06:11:46.964Z
Learning: JounQin's fix for the dot alias issue in PR #72 addresses the problem by correctly normalizing paths in the `extend_tsconfig` method, ensuring that base URLs are properly resolved as absolute paths when extending tsconfigs, rather than adding special case handling for dot aliases in the resolver.
Learnt from: JounQin
PR: unrs/unrs-resolver#115
File: tests/resolve_test.rs:251-263
Timestamp: 2025-05-28T02:21:41.547Z
Learning: In pnpm workspaces, `pnpm install` must be run first to initialize dependencies and create the proper node_modules/.pnpm structure before tests can pass. Tests that rely on resolving packages will fail if dependencies haven't been installed yet.
Learnt from: JounQin
PR: unrs/unrs-resolver#144
File: napi/patch.mjs:5-5
Timestamp: 2025-06-10T13:53:02.983Z
Learning: Build-time scripts in napi/patch.mjs and similar build pipeline contexts don't require error handling for reading expected files like index.js, as these files are guaranteed to be present during the build process.
fixtures/abnormal-relative/foo/bar/baz/test.js (8)
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:4-6
Timestamp: 2025-04-20T16:00:16.106Z
Learning: The configuration with `".": ["."]` in the paths setting in fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json is an intentional test case for testing the TypeScript dot alias resolution behavior, specifically related to issue #437 in the eslint-import-resolver-typescript repository.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:0-0
Timestamp: 2025-04-21T06:11:46.964Z
Learning: JounQin's fix for the dot alias issue in PR #72 addresses the problem by correctly normalizing paths in the `extend_tsconfig` method, ensuring that base URLs are properly resolved as absolute paths when extending tsconfigs, rather than adding special case handling for dot aliases in the resolver.
Learnt from: JounQin
PR: unrs/unrs-resolver#144
File: napi/patch.mjs:5-5
Timestamp: 2025-06-10T13:53:02.983Z
Learning: Build-time scripts in napi/patch.mjs and similar build pipeline contexts don't require error handling for reading expected files like index.js, as these files are guaranteed to be present during the build process.
Learnt from: JounQin
PR: unrs/unrs-resolver#40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T09:52:45.840Z
Learning: In Yarn PnP environments, some packages use nested package.json files for subpaths instead of the exports field. The resolver should check for these nested package.json files when resolving subpaths like `@atlaskit/pragmatic-drag-and-drop/combine` to correctly handle packages with this structure.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: fixtures/pnp/package.json:11-14
Timestamp: 2025-04-21T08:11:41.469Z
Learning: The project uses a justfile with an `install` task that includes running yarn in the fixtures/pnp directory to install dependencies with the command: `cd fixtures/pnp && yarn`.
fixtures/abnormal-relative/package.json (7)
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T09:52:45.840Z
Learning: In Yarn PnP environments, some packages use nested package.json files for subpaths instead of the exports field. The resolver should check for these nested package.json files when resolving subpaths like `@atlaskit/pragmatic-drag-and-drop/combine` to correctly handle packages with this structure.
Learnt from: JounQin
PR: unrs/unrs-resolver#40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: fixtures/pnp/package.json:11-14
Timestamp: 2025-04-21T08:11:41.469Z
Learning: The project uses a justfile with an `install` task that includes running yarn in the fixtures/pnp directory to install dependencies with the command: `cd fixtures/pnp && yarn`.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:4-6
Timestamp: 2025-04-20T16:00:16.106Z
Learning: The configuration with `".": ["."]` in the paths setting in fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json is an intentional test case for testing the TypeScript dot alias resolution behavior, specifically related to issue #437 in the eslint-import-resolver-typescript repository.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:0-0
Timestamp: 2025-04-21T06:11:46.964Z
Learning: JounQin's fix for the dot alias issue in PR #72 addresses the problem by correctly normalizing paths in the `extend_tsconfig` method, ensuring that base URLs are properly resolved as absolute paths when extending tsconfigs, rather than adding special case handling for dot aliases in the resolver.
src/tests/resolve.rs (9)
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:4-6
Timestamp: 2025-04-20T16:00:16.106Z
Learning: The configuration with `".": ["."]` in the paths setting in fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json is an intentional test case for testing the TypeScript dot alias resolution behavior, specifically related to issue #437 in the eslint-import-resolver-typescript repository.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T08:13:59.358Z
Learning: In the unrs-resolver project, tests that intentionally document failing behavior (regression tests) should either use #[should_panic], assert on the expected error, or include clear documentation indicating they are intentional failing test cases.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T08:17:34.175Z
Learning: Test cases in unrs-resolver that intentionally document failing behavior should make the intent clear by either: 1) asserting on the expected error condition rather than the desired behavior, 2) using #[should_panic] for tests expected to panic, or 3) using #[ignore] with a reason to skip known failing tests in CI.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:0-0
Timestamp: 2025-04-21T06:11:46.964Z
Learning: JounQin's fix for the dot alias issue in PR #72 addresses the problem by correctly normalizing paths in the `extend_tsconfig` method, ensuring that base URLs are properly resolved as absolute paths when extending tsconfigs, rather than adding special case handling for dot aliases in the resolver.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T09:52:45.840Z
Learning: In Yarn PnP environments, some packages use nested package.json files for subpaths instead of the exports field. The resolver should check for these nested package.json files when resolving subpaths like `@atlaskit/pragmatic-drag-and-drop/combine` to correctly handle packages with this structure.
Learnt from: JounQin
PR: unrs/unrs-resolver#40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.
Learnt from: JounQin
PR: unrs/unrs-resolver#129
File: src/tests/pnp.rs:6-6
Timestamp: 2025-06-02T15:57:50.888Z
Learning: In the unrs-resolver project, std::env is acceptable for test cases even when deprecated, as the user prefers simpler approaches in test code compared to production code standards.
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test (macos-14)
  • GitHub Check: Test wasi target
  • GitHub Check: Test (ubuntu-latest)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Lint
  • GitHub Check: Code Coverage
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (actions)
🔇 Additional comments (3)
fixtures/abnormal-relative/package.json (1)

1-6: LGTM! Test fixture package.json is well-structured.

The minimal package.json configuration is appropriate for the test fixture, with the main field correctly pointing to "runner.js" as expected by the resolver test.

fixtures/abnormal-relative/foo/bar/baz/test.js (1)

3-3: LGTM! Core test logic is correct.

The require.resolve call effectively tests the runtime resolution behavior for the abnormal relative path, complementing the resolver unit test.

src/tests/resolve.rs (1)

196-205: Clarify test intent: failing vs. passing test case.

The PR title indicates this is a "failing test case," but the test asserts on successful resolution without any failing test markers. Based on the project's patterns for documenting failing behavior, consider:

  1. If this test should fail: Use #[should_panic], #[ignore], or assert on the expected error condition
  2. If this test should pass: The current implementation is correct

The core test logic for abnormal relative path resolution looks sound.

Could you clarify whether this test is expected to pass or fail? If it's meant to document failing behavior, it should follow the established patterns for failing tests in this codebase.

@JounQin JounQin changed the title test: add the failing test case fix: support abnormal relative paths Jul 2, 2025
@JounQin JounQin force-pushed the fix/abnormal_relative branch from 72beea0 to 8b40466 Compare July 2, 2025 03:32
@socket-security
Copy link

socket-security bot commented Jul 2, 2025

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

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedenhanced-resolve@​5.18.1 ⏵ 5.18.210010010088100

View full report

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 8b40466 in 37 seconds. Click for details.
  • Reviewed 58 lines of code in 4 files
  • Skipped 2 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. fixtures/abnormal-relative/foo/bar/baz/test.js:1
  • Draft comment:
    Consider using an assertion instead of console.log to automatically verify the resolution outcome.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. fixtures/abnormal-relative/package.json:4
  • Draft comment:
    The 'main' file 'runner.js' is referenced but not shown in the diff; please confirm that it exists as expected.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. fixtures/pnpm-workspace/package.json:10
  • Draft comment:
    The dependency 'enhanced-resolve' has been bumped to ^5.18.2; ensure that corresponding lockfile updates are applied if needed.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
4. src/tests/resolve.rs:196
  • Draft comment:
    The new 'abnormal_relative' test effectively validates abnormal relative path resolution. Consider adding more edge cases if similar patterns exist.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_zjCVewTk3Z9fQngM

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

@JounQin JounQin changed the title fix: support abnormal relative paths fix: support resolving abnormal relative paths with node_modules Jul 2, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 2, 2025

@JounQin JounQin changed the title fix: support resolving abnormal relative paths with node_modules fix: support resolving abnormal relative paths with node_modules Jul 2, 2025
@JounQin JounQin requested a review from Copilot July 2, 2025 10:21
@codecov
Copy link

codecov bot commented Jul 2, 2025

Codecov Report

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

Project coverage is 92.30%. Comparing base (93cedab) to head (5144e04).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/path.rs 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #171      +/-   ##
==========================================
+ Coverage   92.22%   92.30%   +0.08%     
==========================================
  Files          13       13              
  Lines        3060     3106      +46     
==========================================
+ Hits         2822     2867      +45     
- Misses        238      239       +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.

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)

597-626: Well-implemented legacy compatibility for abnormal relative specifiers.

The implementation correctly handles the edge case described in Jest issue #15712:

Strengths:

  • Properly detects abnormal relative patterns ("/../.." and "../../")
  • Uses the new normalize_relative method appropriately
  • Preserves trailing slash semantics
  • Only attempts legacy resolution when package_name == ".."
  • Includes clear documentation and references

Design considerations:

  • The TODO comment suggests adding a configuration option for this legacy behavior, which would be beneficial for users who want to opt out
  • The implementation correctly limits this to require contexts (not ESM) as indicated by the comments

The logic flow is sound and maintains backward compatibility while being clearly scoped to specific abnormal cases.

Consider adding the configuration option mentioned in the TODO comment:

// TODO: add a new option for this legacy behavior?
+ if !self.options.enable_legacy_abnormal_relative {
+     return Err(ResolveError::NotFound(specifier.to_string()));
+ }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 72beea0 and 5144e04.

⛔ Files ignored due to path filters (2)
  • fixtures/abnormal-relative-with-node_modules/node_modules/.gitkeep is excluded by !**/node_modules/**
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • fixtures/abnormal-relative-with-node_modules/foo/bar/baz/test.js (1 hunks)
  • fixtures/abnormal-relative-with-node_modules/foo/bar/baz/test.mjs (1 hunks)
  • fixtures/abnormal-relative-with-node_modules/package.json (1 hunks)
  • fixtures/abnormal-relative-without-node_modules/foo/bar/baz/test.js (1 hunks)
  • fixtures/abnormal-relative-without-node_modules/foo/bar/baz/test.mjs (1 hunks)
  • fixtures/abnormal-relative-without-node_modules/package.json (1 hunks)
  • fixtures/pnpm-workspace/package.json (1 hunks)
  • src/lib.rs (1 hunks)
  • src/path.rs (3 hunks)
  • src/tests/resolve.rs (1 hunks)
✅ Files skipped from review due to trivial changes (5)
  • fixtures/abnormal-relative-with-node_modules/package.json
  • fixtures/pnpm-workspace/package.json
  • fixtures/abnormal-relative-without-node_modules/package.json
  • fixtures/abnormal-relative-without-node_modules/foo/bar/baz/test.js
  • fixtures/abnormal-relative-with-node_modules/foo/bar/baz/test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tests/resolve.rs
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:0-0
Timestamp: 2025-04-21T06:11:46.964Z
Learning: JounQin's fix for the dot alias issue in PR #72 addresses the problem by correctly normalizing paths in the `extend_tsconfig` method, ensuring that base URLs are properly resolved as absolute paths when extending tsconfigs, rather than adding special case handling for dot aliases in the resolver.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T09:52:45.840Z
Learning: In Yarn PnP environments, some packages use nested package.json files for subpaths instead of the exports field. The resolver should check for these nested package.json files when resolving subpaths like `@atlaskit/pragmatic-drag-and-drop/combine` to correctly handle packages with this structure.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:4-6
Timestamp: 2025-04-20T16:00:16.106Z
Learning: The configuration with `".": ["."]` in the paths setting in fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json is an intentional test case for testing the TypeScript dot alias resolution behavior, specifically related to issue #437 in the eslint-import-resolver-typescript repository.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.
Learnt from: JounQin
PR: unrs/unrs-resolver#144
File: napi/patch.mjs:5-5
Timestamp: 2025-06-10T13:53:02.983Z
Learning: Build-time scripts in napi/patch.mjs and similar build pipeline contexts don't require error handling for reading expected files like index.js, as these files are guaranteed to be present during the build process.
fixtures/abnormal-relative-without-node_modules/foo/bar/baz/test.mjs (8)
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:4-6
Timestamp: 2025-04-20T16:00:16.106Z
Learning: The configuration with `".": ["."]` in the paths setting in fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json is an intentional test case for testing the TypeScript dot alias resolution behavior, specifically related to issue #437 in the eslint-import-resolver-typescript repository.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#144
File: napi/patch.mjs:5-5
Timestamp: 2025-06-10T13:53:02.983Z
Learning: Build-time scripts in napi/patch.mjs and similar build pipeline contexts don't require error handling for reading expected files like index.js, as these files are guaranteed to be present during the build process.
Learnt from: JounQin
PR: unrs/unrs-resolver#40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:0-0
Timestamp: 2025-04-21T06:11:46.964Z
Learning: JounQin's fix for the dot alias issue in PR #72 addresses the problem by correctly normalizing paths in the `extend_tsconfig` method, ensuring that base URLs are properly resolved as absolute paths when extending tsconfigs, rather than adding special case handling for dot aliases in the resolver.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T09:52:45.840Z
Learning: In Yarn PnP environments, some packages use nested package.json files for subpaths instead of the exports field. The resolver should check for these nested package.json files when resolving subpaths like `@atlaskit/pragmatic-drag-and-drop/combine` to correctly handle packages with this structure.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: fixtures/pnp/package.json:11-14
Timestamp: 2025-04-21T08:11:41.469Z
Learning: The project uses a justfile with an `install` task that includes running yarn in the fixtures/pnp directory to install dependencies with the command: `cd fixtures/pnp && yarn`.
fixtures/abnormal-relative-with-node_modules/foo/bar/baz/test.mjs (8)
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:4-6
Timestamp: 2025-04-20T16:00:16.106Z
Learning: The configuration with `".": ["."]` in the paths setting in fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json is an intentional test case for testing the TypeScript dot alias resolution behavior, specifically related to issue #437 in the eslint-import-resolver-typescript repository.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#144
File: napi/patch.mjs:5-5
Timestamp: 2025-06-10T13:53:02.983Z
Learning: Build-time scripts in napi/patch.mjs and similar build pipeline contexts don't require error handling for reading expected files like index.js, as these files are guaranteed to be present during the build process.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:0-0
Timestamp: 2025-04-21T06:11:46.964Z
Learning: JounQin's fix for the dot alias issue in PR #72 addresses the problem by correctly normalizing paths in the `extend_tsconfig` method, ensuring that base URLs are properly resolved as absolute paths when extending tsconfigs, rather than adding special case handling for dot aliases in the resolver.
Learnt from: JounQin
PR: unrs/unrs-resolver#40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T09:52:45.840Z
Learning: In Yarn PnP environments, some packages use nested package.json files for subpaths instead of the exports field. The resolver should check for these nested package.json files when resolving subpaths like `@atlaskit/pragmatic-drag-and-drop/combine` to correctly handle packages with this structure.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: fixtures/pnp/package.json:11-14
Timestamp: 2025-04-21T08:11:41.469Z
Learning: The project uses a justfile with an `install` task that includes running yarn in the fixtures/pnp directory to install dependencies with the command: `cd fixtures/pnp && yarn`.
src/lib.rs (6)
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T09:52:45.840Z
Learning: In Yarn PnP environments, some packages use nested package.json files for subpaths instead of the exports field. The resolver should check for these nested package.json files when resolving subpaths like `@atlaskit/pragmatic-drag-and-drop/combine` to correctly handle packages with this structure.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:0-0
Timestamp: 2025-04-21T06:11:46.964Z
Learning: JounQin's fix for the dot alias issue in PR #72 addresses the problem by correctly normalizing paths in the `extend_tsconfig` method, ensuring that base URLs are properly resolved as absolute paths when extending tsconfigs, rather than adding special case handling for dot aliases in the resolver.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T08:17:34.175Z
Learning: Test cases in unrs-resolver that intentionally document failing behavior should make the intent clear by either: 1) asserting on the expected error condition rather than the desired behavior, 2) using #[should_panic] for tests expected to panic, or 3) using #[ignore] with a reason to skip known failing tests in CI.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:4-6
Timestamp: 2025-04-20T16:00:16.106Z
Learning: The configuration with `".": ["."]` in the paths setting in fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json is an intentional test case for testing the TypeScript dot alias resolution behavior, specifically related to issue #437 in the eslint-import-resolver-typescript repository.
🧬 Code Graph Analysis (1)
src/path.rs (1)
src/tests/missing.rs (1)
  • test (8-70)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test (macos-14)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Benchmark
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
src/path.rs (3)

19-20: LGTM! Clear documentation for the new method.

The method signature and documentation clearly distinguish this from the existing normalize method by explicitly stating it doesn't require absolute paths.


65-79: LGTM! Correct implementation of relative path normalization.

The implementation correctly handles the different path components:

  • ParentDir: Attempts to pop, or adds .. if no components to pop
  • CurDir: Properly ignored for normalization
  • Other components: Preserved as-is

This is the appropriate behavior for relative path normalization without absolute path requirements.


153-159: Comprehensive test coverage for the new functionality.

The test cases effectively cover:

  • Multiple parent directory traversals (foo/../../foo/../foo)
  • Mixed current/parent directories (foo/.././foo/foo)
  • Edge cases like jest-runner-../../ → empty string
  • Various path component combinations

The test cases align well with the intended use case for abnormal relative specifiers.

fixtures/abnormal-relative-with-node_modules/foo/bar/baz/test.mjs (1)

1-1: Appropriate test fixture for ESM abnormal relative resolution.

This fixture correctly tests the ESM behavior where import.meta.resolve with abnormal relative specifiers should fail, consistent with the implementation that only provides legacy support for require contexts.

fixtures/abnormal-relative-without-node_modules/foo/bar/baz/test.mjs (1)

1-1: Consistent test fixture for environments without node_modules.

This fixture appropriately tests the same ESM abnormal relative resolution behavior in an environment without node_modules, ensuring consistent error handling across different package layouts.

@codspeed-hq
Copy link

codspeed-hq bot commented Jul 2, 2025

CodSpeed Performance Report

Merging #171 will not alter performance

Comparing fix/abnormal_relative (5144e04) with main (93cedab)

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 5144e04 in 2 minutes and 22 seconds. Click for details.
  • Reviewed 237 lines of code in 11 files
  • Skipped 1 files when reviewing.
  • Skipped posting 5 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:600
  • Draft comment:
    The new branch for handling abnormal relative specifiers uses a broad check (contains '/../..' || '../../'). Consider tightening this matching (e.g. via a regex) to avoid unintended matches, and ensure it only applies to CommonJS require calls, not to ESM imports.
  • 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% The current string-based check is actually quite clear and matches the documented intent - it's looking for parent directory traversal patterns. The regex suggestion would make the code more complex without clear benefits. The comment also misunderstands that this is intentionally handling a legacy edge case, not a bug that needs to be fixed. The current implementation is sufficient for the documented use case. I could be wrong about the regex being more complex - a well-crafted regex might actually be more precise and catch edge cases I haven't considered. The comment does raise a valid point about being more precise with the matching. While regexes can be more precise, in this case the simple string contains() check is adequate since we're just looking for specific substrings. The code comment explicitly states this is handling a legacy edge case, so being overly precise isn't necessary. The comment should be deleted. The current string-based check is clear and sufficient for the documented legacy behavior it's handling. Making it more complex with regex would not provide meaningful benefits.
2. src/path.rs:65
  • Draft comment:
    The implementation of normalize_relative is clear. A minor suggestion: add a brief inline comment explaining that leading ParentDir components are preserved when no preceding segment exists, to aid future maintainers.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None
3. src/tests/resolve.rs:197
  • Draft comment:
    Tests for abnormal relative paths are thorough. It might be beneficial to add explicit tests verifying that abnormal relative specifiers do not resolve in ESM contexts (e.g. via import.meta.resolve) as indicated by the comments in the fix.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
4. fixtures/abnormal-relative-with-node_modules/foo/bar/baz/test.js:3
  • Draft comment:
    It appears that the string 'jest-runner-/../..' in the second console.log might contain an extra dash after jest-runner. Please confirm if this is intentional or if it should be corrected to match the other patterns (perhaps 'jest-runner-../..' or another intended format).
  • 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% This appears to be a test file specifically testing different path patterns with require.resolve. The varying patterns, including the one with the extra dash, seem intentional as they're testing different cases. The comment at line 5 marking one as "error" suggests these are deliberate test cases. The dash is likely part of the test coverage. I could be wrong about the intention - maybe this is not a test file and these are actual module imports that need to work correctly. The file is in a "fixtures" directory and has a systematic variation of patterns, strongly suggesting these are intentional test cases rather than actual imports. The comment should be deleted as it's questioning what appears to be an intentional test case pattern, and we shouldn't question the author's intention in test fixtures.
5. src/path.rs:157
  • Draft comment:
    Typo alert: The string "foo../../.." may be missing a slash after "foo". Did you intend to use "foo/../../.." for consistency with the other test cases?
  • 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 normalize_relative() function works by iterating through path components. The Rust Path implementation can handle paths with inconsistent slashes. The test case is valid and produces the expected "../" result, showing that the function correctly handles parent directory references even with unusual formatting. Adding a slash wouldn't change the behavior or improve test coverage. The comment author might be right that consistency in test case formatting could make the code more readable. The unusual formatting might confuse future readers. While consistent formatting is nice, the current test case is valid and actually provides value by testing edge case path parsing. The unusual format helps ensure the function works with imperfect input. Delete the comment. The test case is valid as-is and tests important edge case behavior. The suggested change wouldn't improve functionality.

Workflow ID: wflow_nN6dDdhQVdG1VvZi

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

Adds support for resolving abnormal relative paths through a new normalize_relative helper and updated resolver logic, with accompanying tests and fixture updates.

  • Introduces normalize_relative() in path.rs and adds tests for it
  • Updates resolver in lib.rs to handle legacy abnormal relative specifiers
  • Adds abnormal_relative tests in resolve.rs and bumps enhanced-resolve dependency

Reviewed Changes

Copilot reviewed 4 out of 14 changed files in this pull request and generated 3 comments.

File Description
src/path.rs Added normalize_relative method and its unit tests
src/lib.rs Enhanced resolver logic to support abnormal relative paths
src/tests/resolve.rs New abnormal_relative test covering both fixture cases
fixtures/pnpm-workspace/package.json Bumped enhanced-resolve from ^5.18.1 to ^5.18.2
Files not reviewed (7)
  • fixtures/abnormal-relative-with-node_modules/foo/bar/baz/test.js: Language not supported
  • fixtures/abnormal-relative-with-node_modules/foo/bar/baz/test.mjs: Language not supported
  • fixtures/abnormal-relative-with-node_modules/package.json: Language not supported
  • fixtures/abnormal-relative-without-node_modules/foo/bar/baz/test.js: Language not supported
  • fixtures/abnormal-relative-without-node_modules/foo/bar/baz/test.mjs: Language not supported
  • fixtures/abnormal-relative-without-node_modules/package.json: Language not supported
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (3)

src/lib.rs:604

  • [nitpick] The variable name owned is generic. Consider renaming it to something like normalized_string or normalized_specifier for clarity.
            let mut owned = path.to_string_lossy().into_owned();

src/path.rs:157

  • The test input lacks a slash before the parent‐directory segments, so components() won’t split them correctly. Change to Path::new("foo/../../..").normalize_relative() to match the expected behavior.
    assert_eq!(Path::new("foo../../..").normalize_relative(), Path::new(".."));

src/path.rs:158

  • The path literal should include a slash before the .. so it’s treated as a separate ParentDir component. For example use Path::new("jest-runner-/../../").normalize_relative().
    assert_eq!(Path::new("jest-runner-../../").normalize_relative(), Path::new(""));

@JounQin JounQin merged commit 824844d into main Jul 2, 2025
22 checks passed
@JounQin JounQin deleted the fix/abnormal_relative branch July 2, 2025 13:30
@JounQin JounQin mentioned this pull request Jul 2, 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.

[Bug]: "Runner is not a constructor" when using nested relative path and Yarn

3 participants