Skip to content

Conversation

@JounQin
Copy link
Member

@JounQin JounQin commented May 28, 2025

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


Important

Custom condition_names now take precedence over default in module resolution, with new tests and fixtures added.

  • Behavior:
    • Custom condition_names now take precedence over default in src/lib.rs.
    • Adds default as a fallback condition if not present.
  • Fixtures:
    • Adds dual-condition-names/package.json with dependency zod.
    • Updates pnpm-workspace.yaml to include fixtures/dual-condition-names.
  • Tests:
    • Adds dual_condition_names() test in resolve_test.rs to verify module resolution with multiple condition names.
    • Modifies test cases in exports_field.rs and imports_field.rs to reflect new condition name precedence.

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


Summary by CodeRabbit

  • New Features
    • Added a new fixture for dual condition names with its own package configuration.
    • Workspace now includes the new dual-condition-names fixture for easier management.
  • Tests
    • Introduced a new test to verify correct module resolution when multiple condition names are used.
    • Updated test cases to reflect changes in condition name order and resolved paths for improved accuracy.

@JounQin JounQin requested a review from Copilot May 28, 2025 01:59
@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

A new fixture named dual-condition-names was introduced, including a package.json with a dependency on zod. The workspace configuration was updated to recognize this fixture. The resolver's method for handling package target resolution was modified to always include "default" as a fallback condition. Additionally, a new test was added to verify module resolution with multiple condition names using the resolver. Some existing tests were updated to reflect changes in condition order and expected resolved paths.

Changes

File(s) Change Summary
fixtures/dual-condition-names/package.json Added package.json for the new fixture, specifying the zod dependency.
pnpm-workspace.yaml Included fixtures/dual-condition-names in the workspace package list.
src/lib.rs Modified package_target_resolve to always include "default" condition as fallback during resolution.
tests/resolve_test.rs Added a test function to verify resolution with dual condition names using the new fixture.
src/tests/exports_field.rs, src/tests/imports_field.rs Updated test cases to change expected resolved paths and swap order of condition names from ["browser", "webpack"] to ["webpack", "browser"].

Sequence Diagram(s)

sequenceDiagram
    participant Test as dual_condition_names() Test
    participant Resolver as Resolver
    participant FS as Filesystem

    Test->>Resolver: Create with conditions ["import", "require"]
    Test->>Resolver: resolve("zod", fixture_dir)
    Resolver->>Resolver: Add "default" to conditions if missing
    Resolver->>FS: Look up "zod" in fixture_dir with conditions
    FS-->>Resolver: Return resolved path to zod/index.mjs
    Resolver-->>Test: Return resolved path
    Test->>Test: Assert path matches expected
Loading

Suggested labels

dependencies

Poem

🐇 In code’s green meadow, new paths align,
With "zod" beside, conditions combine.
Default hops in when others may stray,
Tests bound along, ensuring the way.
Workspace expands, a joyous cheer,
Resolver’s logic, crystal clear! ✨🐇


📜 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 1956700 and 6e0f63a.

📒 Files selected for processing (3)
  • src/lib.rs (1 hunks)
  • src/tests/exports_field.rs (3 hunks)
  • src/tests/imports_field.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • 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
🔇 Additional comments (5)
src/tests/imports_field.rs (2)

520-520: LGTM! Test correctly reflects updated condition priority.

The expected result change from "./src/index.js" to "./index.js" correctly reflects the updated resolution logic where custom condition names (in this case "browser") take higher priority than the "default" condition. This aligns with the PR's objective to ensure custom condition_names have higher priority.


908-908: LGTM! Condition ordering change validates resolution priority.

The reordering from ["browser", "webpack"] to ["webpack", "browser"] correctly tests that condition resolution follows the specified order. Since the expected result resolves to the webpack target ("./wpk/index.mjs"), placing "webpack" first ensures the test validates that the first matching condition is used, which aligns with the updated resolution logic.

src/tests/exports_field.rs (3)

825-825: Test expectation updated to reflect proper condition priority.

The expectation change from "./src/index.js" to "./index.js" correctly reflects that when the browser condition is specified, it should take priority over the default condition. This aligns with the PR objective of ensuring custom condition_names have higher priority than the default target.


1347-1347: Condition order change reflects updated priority handling.

The reordering from ["browser", "webpack"] to ["webpack", "browser"] ensures that webpack condition is checked before browser. Given the exports field configuration where both conditions are available, this change ensures webpack takes precedence and the test resolves to "./wpk/index.mjs" as expected.


1365-1365: Consistent condition ordering for wildcard variant.

This change maintains consistency with the non-wildcard test case above (line 1347) by applying the same condition order ["webpack", "browser"]. This ensures both test variants behave identically and validate the same resolution logic.

✨ 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

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 fixes an issue where custom condition names were not resolved correctly by adding a dedicated test, updating the pnpm workspace configuration, and providing a corresponding package fixture.

  • Added a new test (dual_condition_names) in resolve_test.rs to verify resolution with dual condition names.
  • Updated pnpm-workspace.yaml to include the new fixture.
  • Created a package.json fixture for dual condition names.

Reviewed Changes

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

File Description
tests/resolve_test.rs Added test dual_condition_names to verify resolution behavior
pnpm-workspace.yaml Included the dual-condition-names fixture in the workspace list
fixtures/dual-condition-names/package.json Added package.json file for the new fixture
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

@socket-security
Copy link

socket-security bot commented May 28, 2025

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

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedzod@​3.24.410010010096100

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 everything up to a203a53 in 31 seconds. Click for details.
  • Reviewed 46 lines of code in 3 files
  • Skipped 1 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. fixtures/dual-condition-names/package.json:1
  • Draft comment:
    Fixture looks good; ensure the zod version (~3.24.4) matches expected resolution.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. pnpm-workspace.yaml:4
  • Draft comment:
    Added the dual-condition-names fixture to the workspace; YAML structure is correct.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
3. tests/resolve_test.rs:251
  • Draft comment:
    New test 'dual_condition_names' correctly verifies resolution using custom condition_names.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_6BoES77MkFeEm1gG

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/condition-names branch from a203a53 to 9db41ed Compare May 28, 2025 02:01
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 9db41ed in 50 seconds. Click for details.
  • Reviewed 46 lines of code in 3 files
  • Skipped 1 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. fixtures/dual-condition-names/package.json:1
  • Draft comment:
    New test fixture with dependency on 'zod'; the JSON is correctly structured.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. pnpm-workspace.yaml:4
  • Draft comment:
    Added new fixture 'fixtures/dual-condition-names' to the workspace; configuration looks proper.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
3. tests/resolve_test.rs:251
  • Draft comment:
    Test 'dual_condition_names' correctly verifies resolution with custom condition_names; expected resolution to index.mjs is clear.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_plgRDDu0GZiRVdtn

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

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4b5f796 and 9db41ed.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • fixtures/dual-condition-names/package.json (1 hunks)
  • pnpm-workspace.yaml (1 hunks)
  • tests/resolve_test.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
pnpm-workspace.yaml (1)
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.
🪛 GitHub Actions: CI
tests/resolve_test.rs

[error] 259-259: Test 'dual_condition_names' failed due to assertion failure: expected Ok(".../index.mjs") but got Ok(".../index.js").

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (2)
fixtures/dual-condition-names/package.json (1)

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

The fixture package configuration is clean and appropriate for testing dual condition name resolution with the zod dependency.

pnpm-workspace.yaml (1)

4-4: LGTM! Correctly integrates the new fixture into the workspace.

The addition follows the existing pattern and properly includes the dual-condition-names fixture in the pnpm workspace.

@JounQin JounQin changed the title fix: incorrect resolution with custom condition_names specified fix: custom condition_names should take higher priority than target in package.json May 28, 2025
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 1956700 in 1 minute and 51 seconds. Click for details.
  • Reviewed 26 lines of code in 1 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/lib.rs:1769
  • Draft comment:
    Bug: The iterator over condition_names is consumed by the .any() call. If "default" is present, the iterator is already exhausted and the subsequent for loop won’t iterate over any conditions.
  • 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% The comment is correct that .any() consumes the iterator. However, the code explicitly creates a new iterator on line 1774 with conditions_vec.iter() after modifying the vector. This is intentional - the iterator is meant to be consumed by .any() and then recreated. The code is actually handling this case correctly. Could I be missing some subtle case where recreating the iterator doesn't work? Or some performance implication? No - the code explicitly creates a new iterator after the .any() call, so there is no bug. While using .contains() might be slightly more idiomatic, the current code is correct. The comment should be deleted because it incorrectly identifies a bug - the code is actually handling the iterator consumption and recreation correctly.

Workflow ID: wflow_nEFaD2bwNHdH2CL3

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

@codspeed-hq
Copy link

codspeed-hq bot commented May 28, 2025

CodSpeed Performance Report

Merging #115 will not alter performance

Comparing fix/condition-names (6e0f63a) with main (4b5f796)

Summary

✅ 3 untouched benchmarks

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9db41ed and 1956700.

📒 Files selected for processing (1)
  • src/lib.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Benchmark
🔇 Additional comments (1)
src/lib.rs (1)

1780-1780: 🛠️ Refactor suggestion

Update condition comparison for borrowed string.

Since we're now iterating over &String instead of String, the comparison needs to be adjusted.

Apply this diff:

-                if let Some((_, target_value)) = target.iter().find(|(key, _)| condition == key) {
+                if let Some((_, target_value)) = target.iter().find(|(key, _)| condition == key) {

Actually, this line should work as-is since string comparison handles the reference automatically. However, for clarity, you might want to make it explicit:

-                if let Some((_, target_value)) = target.iter().find(|(key, _)| condition == key) {
+                if let Some((_, target_value)) = target.iter().find(|(key, _)| condition.as_str() == key) {

Likely an incorrect or invalid review comment.

@JounQin JounQin force-pushed the fix/condition-names branch from 1956700 to 6e0f63a Compare May 28, 2025 05:21
@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.

Important

Looks good to me! 👍

Reviewed 6e0f63a in 43 seconds. Click for details.
  • Reviewed 77 lines of code in 3 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/tests/imports_field.rs:1
  • Draft comment:
    The test file covers many edge cases for imports field resolution. Consider splitting the very long list of test cases into smaller, grouped modules or a table‐driven test harness to improve readability and maintainability.
  • 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/imports_field.rs:108
  • Draft comment:
    The helper function imports_field uses Box::leak to extend lifetimes. This is acceptable in tests but document that this is only for testing purposes.
  • 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/imports_field.rs:121
  • Draft comment:
    Several test cases use duplicated names (e.g. multiple 'sample #1'). Unique test case identifiers would aid in diagnosing failures.
  • 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.
4. src/tests/imports_field.rs:60
  • Draft comment:
    In tests like 'test_simple()' and 'shared_resolvers()', comparisons using assert_eq! for resolution errors rely on PartialEq for error types. Verify that custom error types implement PartialEq consistently to avoid brittle test assertions.
  • 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.

Workflow ID: wflow_kwbqgvOqXdU41JTM

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

@codecov
Copy link

codecov bot commented May 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.41%. Comparing base (4b5f796) to head (6e0f63a).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #115      +/-   ##
==========================================
+ Coverage   93.40%   93.41%   +0.01%     
==========================================
  Files          13       13              
  Lines        2865     2870       +5     
==========================================
+ Hits         2676     2681       +5     
  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.

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