Skip to content

Conversation

@mauriceackel
Copy link
Contributor

@mauriceackel mauriceackel commented Jun 9, 2025

This PR enables extension of referenced configs as explained in this issue: import-js/eslint-import-resolver-typescript#400

For reference, to for tsconfigs in the references field have not been post-processed (i.e. no resolution of "extends" keyword). This PR introduces the default load_config function for all referenced configs, which also ensures that extended configs will be loaded properly.

⚠️ I am not a RUST developer and the changes have been untested @JounQin, can you please take a look at this! The PR is allowed to be updated by maintainers.


Important

Enhances load_tsconfig in src/lib.rs to extend referenced TypeScript configs by resolving extends keyword.

  • Behavior:
    • load_tsconfig in src/lib.rs now extends referenced TypeScript configs using extend_tsconfig and load_tsconfig_references.
    • Ensures extends keyword in tsconfigs is resolved.
  • Functions:
    • New extend_tsconfig function to handle extending tsconfigs.
    • New load_tsconfig_references function to load references in tsconfigs.

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

Summary by CodeRabbit

  • Refactor
    • Improved internal structure for loading configuration files, resulting in clearer and more maintainable logic. No changes to user-facing functionality.

@coderabbitai
Copy link

coderabbitai bot commented Jun 9, 2025

Walkthrough

The logic within the load_tsconfig method of ResolverGeneric has been refactored by extracting the processes for handling "extends" and "references" into two new private methods: extend_tsconfig and load_tsconfig_references. The main method now calls these helpers in sequence, maintaining the original functionality.

Changes

File(s) Change Summary
src/lib.rs Refactored load_tsconfig by extracting "extends" logic into extend_tsconfig and "references" logic into load_tsconfig_references. Added both as private methods to the ResolverGeneric implementation.

Poem

In the warren of code, two paths did appear,
"Extends" and "references"—now crystal clear!
With helpers to guide, the logic’s refined,
Tsconfig’s a puzzle, no longer entwined.
Modular and neat, the burrow’s well swept—
This rabbit’s refactor is perfectly kept! 🐇✨


📜 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 3acfa56 and f8a9f08.

📒 Files selected for processing (1)
  • src/lib.rs (1 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 (1)
  • GitHub Check: Codacy Static Code Analysis
✨ 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

@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)

1351-1372: Excellent implementation that addresses the core issue.

This method enables the extension of referenced tsconfigs by ensuring they go through the full load_tsconfig process, which includes extend_tsconfig. Key improvements:

  • Self-reference check prevents direct cycles
  • Referenced tsconfigs now have their "extends" processed (the main PR objective)
  • Proper error handling and path normalization

Note: This prevents direct self-references but not indirect circular references (A→B→A). Consider if additional cycle detection is needed.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 395df2a and 690aa39.

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

1319-1329: LGTM! Clean refactoring that improves modularity.

The method maintains the original functionality while delegating to focused helper methods. The sequential order (extend first, then references) is correct.


1331-1349: Well-implemented extends processing.

The method correctly processes the extends chain by:

  • Loading each extended tsconfig with references disabled (preventing recursion)
  • Allowing extended configs to have their own extends processed
  • Proper error propagation throughout the chain

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 690aa39 in 2 minutes and 5 seconds. Click for details.
  • Reviewed 94 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/lib.rs:1320
  • Draft comment:
    Good extraction: the inline block for extending tsconfigs & loading references was nicely refactored into extend_tsconfig and load_tsconfig_references, improving readability and reducing duplication.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. src/lib.rs:1348
  • Draft comment:
    Ensure that the use of the root flag is correct: the original inline code used root: true when loading referenced tsconfigs, but the new load_tsconfig_references uses root: false. Confirm that this change in behavior is intentional.
  • 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% Looking at the code: 1. The change from root:true to root:false does appear to be a real change in behavior 2. However, this appears to be an intentional change, not an oversight: - The code was carefully refactored into a separate function - The root:false parameter is consistently used for all referenced tsconfigs - The original code may have had a bug by using root:true 3. The comment is asking for confirmation/explanation rather than pointing out a clear issue 4. Per the rules, we should not ask authors to confirm their intentions or explain changes The behavior change could potentially cause issues if root:true was actually needed for some reason. I may be missing some important context about why root:true was used originally. While the change could theoretically cause issues, there's no clear evidence that this is a bug rather than an intentional improvement. The rules state we should not ask authors to confirm their intentions. Delete the comment. It violates the rule against asking authors to confirm their intentions, and there's no clear evidence that the change is incorrect.
3. src/lib.rs:1348
  • Draft comment:
    Consider adding doc comments to the new helper functions (extend_tsconfig and load_tsconfig_references) to clarify their purpose and usage.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_bYOg1c0UqyzZs1Yo

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

@JounQin
Copy link
Member

JounQin commented Jun 9, 2025

@mauriceackel Thanks for this! Could you do better by adding a new test fixture under https://github.com/unrs/unrs-resolver/tree/main/fixtures/tsconfig and a new test case after the following?

If you are not familiar with Rust, that's also OK, I'll do it myself later.

@codspeed-hq
Copy link

codspeed-hq bot commented Jun 9, 2025

CodSpeed Performance Report

Merging #138 will not alter performance

Comparing mauriceackel:fix/extend-referenced-configs (f8a9f08) with main (6f3d3d4)

Summary

✅ 3 untouched benchmarks

@mauriceackel
Copy link
Contributor Author

@mauriceackel Thanks for this! Could you do better by adding a new test fixture under https://github.com/unrs/unrs-resolver/tree/main/fixtures/tsconfig and a new test case after the following?

If you are not familiar with Rust, that's also OK, I'll do it myself later.

Unfortunately, I'm not 🙈 This was just a crude approach of implementing what I assume we need to fix this issue. If you could take it over from here, this would be highly appreciated @JounQin 💯

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 9, 2025

@JounQin
Copy link
Member

JounQin commented Jun 9, 2025

A fix should start from a failing test case.

cf6de51 (#142)

@JounQin
Copy link
Member

JounQin commented Jun 10, 2025

Thanks for inspiring me to work on a fix for that issue, and it spent me a whole night for me to find out the key: https://github.com/unrs/unrs-resolver/pull/142/files#diff-b1a35a68f14e696205874893c07fd24fdb88882b47c23cc0e0c80a30c7d53759R1348-R1351.

@JounQin JounQin closed this in #142 Jun 10, 2025
JounQin pushed a commit that referenced this pull request Jun 10, 2025
## 🤖 New release

* `oxc_resolver`: 8.0.0 -> 9.0.0 (⚠ API breaking changes)
* `oxc_napi_resolver`: 8.0.0

### ⚠ `oxc_resolver` breaking changes

```text
--- failure constructible_struct_adds_field: externally-constructible struct adds field ---

Description:
A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field ResolveOptions.modules in /tmp/.tmpTBvVad/oxc-resolver/src/options.rs:114

--- failure trait_method_added: pub trait method added ---

Description:
A non-sealed public trait added a new method without a default implementation, which breaks downstream implementations of the trait
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/trait_method_added.ron

Failed in:
  trait method oxc_resolver::CachedPath::module_directory in file /tmp/.tmpTBvVad/oxc-resolver/src/cache.rs:69
  trait method oxc_resolver::CachedPath::cached_node_modules in file /tmp/.tmpTBvVad/oxc-resolver/src/cache.rs:76
```

<details><summary><i><b>Changelog</b></i></summary><p>

## `oxc_resolver`

<blockquote>

##
[9.0.0](oxc-project/oxc-resolver@oxc_resolver-v8.0.0...oxc_resolver-v9.0.0)
- 2025-05-09

### <!-- 1 -->Bug Fixes

- hash import does not need to load from node_modules
([#501](oxc-project/oxc-resolver#501))

### <!-- 7 -->Chore

- add `--tsconfig` to example
([#505](oxc-project/oxc-resolver#505))
- publish `oxc_napi_resolver`
([#496](oxc-project/oxc-resolver#496))
</blockquote>

## `oxc_napi_resolver`

<blockquote>

##
[8.0.0](https://github.com/oxc-project/oxc-resolver/releases/tag/oxc_napi_resolver-v8.0.0)
- 2025-05-09

### <!-- 0 -->Features

- *(napi)* add mimalloc
([#423](oxc-project/oxc-resolver#423))
- [**breaking**] Rust Edition 2024
([#402](oxc-project/oxc-resolver#402))
- expose `package_json_path`
([#376](oxc-project/oxc-resolver#376))
- *(napi)* expose module type info in ResolveResult
([#223](oxc-project/oxc-resolver#223))
- *(napi)* add tracing via `OXC_LOG:DEBUG`
([#202](oxc-project/oxc-resolver#202))
- *(napi)* add async API
([#191](oxc-project/oxc-resolver#191))
- add `imports_fields` option
([#138](oxc-project/oxc-resolver#138))
- add more builder functions for options
([#110](oxc-project/oxc-resolver#110))
- *(napi)* support wasi target
([#31](oxc-project/oxc-resolver#31))
- add file_dependencies and missing_dependencies API
([#50](oxc-project/oxc-resolver#50))
- *(napi)* expose cloneWithOptions and clearCache methods
([#40](oxc-project/oxc-resolver#40))
- *(napi)* update the doc and type for tsconfig references
([#24](oxc-project/oxc-resolver#24))
- *(napi)* add options
([#19](oxc-project/oxc-resolver#19))
- *(resolver)* add tracing-subscriber feature
([#904](https://github.com/oxc-project/oxc-resolver/pull/904))
- *(resolver)* tsconfig project references
([#862](https://github.com/oxc-project/oxc-resolver/pull/862))
- *(resolver)* add thiserror
([#847](https://github.com/oxc-project/oxc-resolver/pull/847))
- *(resolver)* implement nested alias field
([#795](oxc-project/oxc-resolver#795))
- *(resolver)* implement tsconfig-paths
([#750](oxc-project/oxc-resolver#750))
- *(resolver)* implement configurable `exports_fields` option
([#733](oxc-project/oxc-resolver#733))
- *(resolver)* implement `main_fields`
- *(resolver)* implement resolveToContext
([#694](oxc-project/oxc-resolver#694))
- *(resolver)* implement restrictions (path only)
([#693](oxc-project/oxc-resolver#693))
- *(resolver)* implement fully specified
([#687](oxc-project/oxc-resolver#687))
- *(resolver)* imports field
([#681](oxc-project/oxc-resolver#681))
- *(resolver)* finish most of exports field
([#674](oxc-project/oxc-resolver#674))
- *(resolver)* port the rest of the exports field tests
([#659](oxc-project/oxc-resolver#659))
- *(resolver)* implement symlinks
([#582](oxc-project/oxc-resolver#582))
- *(resolver)* complete query and fragment parsing
([#579](oxc-project/oxc-resolver#579))
- *(resolver)* add preferRelative and preferAbsolute
([#577](oxc-project/oxc-resolver#577))
- *(resolver)* implement roots
([#576](oxc-project/oxc-resolver#576))
- *(resolver)* implement fallback
([#572](oxc-project/oxc-resolver#572))
- *(resolver)* implement enforceExtension
([#566](oxc-project/oxc-resolver#566))
- *(resolver)* implement descriptionFiles option
([#565](oxc-project/oxc-resolver#565))
- *(resolver)* implement the basics of path alias
([#564](oxc-project/oxc-resolver#564))
- *(resolver)* accept different file system implementations
([#562](oxc-project/oxc-resolver#562))
- *(resolver)* implement browser field
([#561](oxc-project/oxc-resolver#561))
- *(resolver)* implement scoped packages
([#558](oxc-project/oxc-resolver#558))
- *(resolver)* port incorrect description file test
([#557](oxc-project/oxc-resolver#557))
- *(resolver)* implement extension_alias
([#556](oxc-project/oxc-resolver#556))
- *(resolver)* port resolve tests
([#555](oxc-project/oxc-resolver#555))
- *(resolver)* resolve extensions
([#549](oxc-project/oxc-resolver#549))
- *(resolver)* add resolver test fixtures
([#542](oxc-project/oxc-resolver#542))

### <!-- 1 -->Bug Fixes

- hash import does not need to load from node_modules
([#501](oxc-project/oxc-resolver#501))
- *(napi)* `new ResolverFactory()` options should be optional
([#256](oxc-project/oxc-resolver#256))
- *(napi)* update buggy NAPI-RS versions
([#225](oxc-project/oxc-resolver#225))
- canonicalize is not supported on wasi target
([#124](oxc-project/oxc-resolver#124))
- resolve "browser" field when "exports" is present
([#59](oxc-project/oxc-resolver#59))

### <!-- 4 -->Refactor

- [**breaking**] remove `description_files` option
([#488](oxc-project/oxc-resolver#488))
- [**breaking**] remove `modules` options
([#484](oxc-project/oxc-resolver#484))
- vitest ([#380](oxc-project/oxc-resolver#380))
- apply latest `cargo +nightly fmt`
([#281](oxc-project/oxc-resolver#281))
- selectively parse package_json fields instead of parsing everything
([#103](oxc-project/oxc-resolver#103))
- *(resolver)* clean up some code and tests
- *(resolver)* change internal funcs to non-pub by moving to unit tests
([#682](oxc-project/oxc-resolver#682))

### <!-- 7 -->Chore

- publish `oxc_napi_resolver`
([#496](oxc-project/oxc-resolver#496))
- *(napi)* make mimalloc optional to build
([#495](oxc-project/oxc-resolver#495))
- *(README)* add wasm usage example
- *(README)* crates.io badge use recent downloads
- *(napi)* auto download wasm binding on webcontainer
([#471](oxc-project/oxc-resolver#471))
- use root package.json for napi build
([#469](oxc-project/oxc-resolver#469))
- *(deps)* update github-actions
([#444](oxc-project/oxc-resolver#444))
- *(deps)* lock file maintenance npm packages
([#436](oxc-project/oxc-resolver#436))
- bump napi
([#404](oxc-project/oxc-resolver#404))
- *(deps)* lock file maintenance npm packages
([#391](oxc-project/oxc-resolver#391))
- *(deps)* lock file maintenance rust crates
([#390](oxc-project/oxc-resolver#390))
- *(README)* clarify Rust and node.js usages
- add dprint
([#326](oxc-project/oxc-resolver#326))
- *(deps)* update napi-rs to 3.0.0-alpha
- `cargo upgrade` && `pnpm upgrade`
- *(deps)* update napi-rs to 3.0.0-alpha
- update napi changes
- *(deps)* update rust crate napi-derive to 3.0.0-alpha
- *(deps)* update rust crate napi to 3.0.0-alpha
- *(deps)* update napi-rs to 2.16.8
- *(napi)* make napi binary smaller with minimal tracing features
([#213](oxc-project/oxc-resolver#213))
- *(napi)* remove tokio
([#212](oxc-project/oxc-resolver#212))
- document directory is an absolute path for `resolve(directory,
specifier)`
([#206](oxc-project/oxc-resolver#206))
- re-enable the wasi build
([#193](oxc-project/oxc-resolver#193))
- use pnpm workspace
([#182](oxc-project/oxc-resolver#182))
- *(deps)* update rust crates
([#176](oxc-project/oxc-resolver#176))
- *(napi)* update NAPI-RS cli version and binding template
([#111](oxc-project/oxc-resolver#111))
- update project github url
- *(deps)* update pnpm to v8.14.1
([#52](oxc-project/oxc-resolver#52))
- *(deps)* update pnpm to v8.14.0
([#48](oxc-project/oxc-resolver#48))
- *(deps)* update pnpm to v8.13.1
([#42](oxc-project/oxc-resolver#42))
- remove FIXME comments
- *(napi)* align `*Fields` user options with enhanced-resolve
([#35](oxc-project/oxc-resolver#35))
- *(deps)* update pnpm to v8.12.1
([#21](oxc-project/oxc-resolver#21))
- add some doc for napi TsconfigOptions
([#20](oxc-project/oxc-resolver#20))
- *(deps)* update pnpm to v8.12.0
([#18](oxc-project/oxc-resolver#18))
- *(README)* adding debugging command from Rspack
- *(deps)* update pnpm to v8.11.0
([#9](oxc-project/oxc-resolver#9))
- *(resolver)* remove tracing_subscriber
([#1362](https://github.com/oxc-project/oxc-resolver/pull/1362))
- *(resolver)* improve documentation
([#591](oxc-project/oxc-resolver#591))

### <!-- 8 -->CI

- check for napi .d.index changes
([#491](oxc-project/oxc-resolver#491))
- *(release-napi)* support `riscv64gc-unknown-linux-gnu` and
`s390x-unknown-linux-gnu`
([#451](oxc-project/oxc-resolver#451))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants