You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(TsconfigPathsPlugin): resolve inherited paths like tsc - #710
Two problems with configs loaded through extends in TsconfigPathsPlugin:
paths without baseUrl were resolved relative to the root tsconfig. tsc resolves them relative to the config file that declares them (docs), so paths from ./configs/base.json or from a package config pointed to the wrong place.
Now _loadTsconfig records the directory of the config that declares paths (pathsBasePath, the same name tsc uses internally). It travels with paths through mergeTsconfigs: a config that redefines paths also sets its own pathsBasePath. tsconfigPathsToResolveOptions uses it when there is no baseUrl. When there is a baseUrl (from any config), nothing changes: paths are still relative to baseUrl.
${configDir} in baseUrl was never substituted. In an extended config it was joined to that config's directory as a literal string. Now it is left as is when the extended config is loaded and substituted with the root config directory when the paths are built (the same as ${configDir} in paths).
I compared the result with ts.resolveModuleName (TypeScript 6.0.3, the version in devDependencies) on 12 setups: the 3 from the issue, root baseUrl + inherited paths, root paths overriding inherited paths, baseUrl + paths both in the base, a 2-level extends chain with paths in the middle config, ${configDir} in inherited paths, ${configDir} as an inherited baseUrl with relative paths, and an empty baseUrl ("") in the root config, in the base config, and in the base config next to paths. All 12 now match tsc. On main, 7 of them differ.
Empty baseUrl: "baseUrl": "" is treated as set (the directory of its config), as tsc does. An inherited "" is rebased to its own config directory like any other inherited baseUrl (on main it was left empty and so meant the root directory).
Tests: new fixtures in test/fixtures/tsconfig-paths/extends-paths-base/ and 6 tests. The 3 cases from the issue and the inherited empty baseUrl fail on main. The root baseUrl and root empty baseUrl tests are guards and pass on both. test/tsconfig-paths.test.js passes (65), and npm run lint (eslint, tsc, prettier, cspell) is clean. Added a patch changeset.
Note: in my local run of the whole suite, the 18 "should resolve itself" tests in test/simple.test.js fail, but they fail the same way on main. They resolve ./enhanced-resolve/lib/index from the parent directory, and my clone's folder has a different name.
Summary by CodeRabbit
Bug Fixes
Corrected inherited TypeScript path mapping resolution: mappings without a baseUrl resolve relative to the configuration that declares them.
Improved handling of ${configDir} and empty baseUrl values in extended configurations to align with TypeScript behavior.
Tests
Added coverage for inherited mappings and base URL resolution across extended configurations.
No actionable comments were generated in the recent review.
Walkthrough
The plugin now records the directory that declares inherited paths. When baseUrl is absent, it resolves path mappings from that directory. It also keeps ${configDir} templates until later substitution and treats empty baseUrl values as explicit values. The test suite adds synchronous regression coverage for extended configs, package configs, and empty or inherited baseUrl cases.
Severity of issue fixed: Medium
Merge Risk: Minimal · up to af9ab
This change makes inherited tsconfig paths and ${configDir} resolve the way tsc does. No actionable merge-blocking risk remains in the reviewed material.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the fixed component (TsconfigPathsPlugin) and the main behavior (resolving inherited paths like tsc). The changeset adds inherited-paths resolution relative to the declaring config, al…
Linked Issues check
[#705] Requirement 1: paths without baseUrl resolve relative to the config that declares them, including package configs. The summary of lib/TsconfigPathsPlugin.js shows that _loadTsconfig records pat…
Out of Scope Changes check
The pathsBasePath change, the deferred ${configDir} substitution in an extended baseUrl, and the tsconfigPathsToResolveOptions logic implement #705 directly. The fixtures and tests under test/fixtures…
Full details: Title check
Explanation
The title names the fixed component (TsconfigPathsPlugin) and the main behavior (resolving inherited paths like tsc). The changeset adds inherited-paths resolution relative to the declaring config, along with baseUrl handling, and the linked issue #705 matches this scope. The title is specific and matches the primary change.
Full details: Linked Issues check
Explanation
[#705] Requirement 1: paths without baseUrl resolve relative to the config that declares them, including package configs. The summary of lib/TsconfigPathsPlugin.js shows that _loadTsconfig records pathsBasePath for the declaring config, mergeTsconfigs carries it with paths, and tsconfigPathsToResolveOptions uses it when baseUrl is absent. The PR tests cover the file-relative case (test/fixtures/tsconfig-paths/extends-paths-base/relative). The package case uses the same extends path logic; its fixture under node_modules was excluded from review, so only the code path and the author's reported comparison support it. [#705] Requirement 2: ${configDir} in an inherited baseUrl is left unexpanded on load and substituted with the root config directory when options are built. Fixture config-dir-base-url covers this. [#705] Paths with a root baseUrl still resolve against that baseUrl, as tsc does. The incremental change since the previous review (empty baseUrl treated as set, with fixtures empty-base-url-root and empty-base-url-inherited) does not weaken either requirement. Limits: the whole-PR and incremental diffs could not be read in full. Test results (65 passing, lint clean) were reported by the author and were not re-run.
Full details: Out of Scope Changes check
Explanation
The pathsBasePath change, the deferred ${configDir} substitution in an extended baseUrl, and the tsconfigPathsToResolveOptions logic implement #705 directly. The fixtures and tests under test/fixtures/tsconfig-paths/extends-paths-base/ and test/tsconfig-paths.test.js support those behaviors. The empty baseUrl handling is not listed in #705, but the current PR description now documents it as item 3, with the tsc comparison. It uses the same baseUrl versus pathsBasePath decision that #705 requires, so it is a closely connected change and not unrelated work. The changeset is a patch note for the same behavior. The excluded node_modules package fixture was not inspected. The whole-PR diff was not fully readable, so the complete file set was checked only through the summary.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
ESLint
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
ESLint install timed out. The project may have too many dependencies for the sandbox.
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 05c15260-0164-43e4-a7d4-41e371170291
Commits
Reviewing files that changed from the base of the PR and between 9c66bd0 and af9abbd.
Files ignored due to path filters: 2
test/fixtures/tsconfig-paths/extends-paths-base/package/node_modules/shared-config/base.json is excluded by !**/node_modules/**
test/fixtures/tsconfig-paths/extends-paths-base/package/node_modules/shared-config/package.json is excluded by !**/node_modules/**
Files selected for processing: 2
lib/TsconfigPathsPlugin.js
test/tsconfig-paths.test.js
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
paths declared in an extended config with no baseUrl were resolved
relative to the root tsconfig, so they missed when the extended config
lives in another directory or in a package. tsc resolves them relative
to the config that declares them, so remember that directory
(pathsBasePath, as tsc calls it) and use it when there is no baseUrl.
Also substitute ${configDir} in baseUrl. In an extended config it was
joined to the extended config's directory as a literal string.
Fixes#705
An empty baseUrl is the directory of the config that declares it, not
"no baseUrl". Keep using it in the root config (paths inherited from a
base config were resolved from the base config directory), and rebase
an inherited empty baseUrl to its own config directory.
Rebased on main after #709 landed. The only conflict was both PRs adding a describe block at the end of test/tsconfig-paths.test.js, so I kept both. Tests and lint pass locally (same 18 "should resolve itself" failures as on main, because my clone folder isn't named enhanced-resolve).
#711)
**Summary**
Fixes#705.
#709 fixed `extends` lookup (#706), but configs loaded through `extends`
still resolve `paths` and `baseUrl` differently from tsc. This PR builds
on #710 by @bardrop. It applies its two commits onto current `main`,
since #710 now conflicts with #709 in `test/tsconfig-paths.test.js`. It
also adds two fixes:
- **#710 (commits `f70894d`, `5520785`)**: `paths` without `baseUrl`
resolve relative to the config that declares them (`pathsBasePath`).
`${configDir}` in an inherited `baseUrl` becomes the root config
directory. An inherited empty `baseUrl` becomes the directory of the
config that declares it.
- **Empty root `baseUrl` (`99da949`)**: `"baseUrl": ""` was used for
`paths` but never added to `modules`, so bare requests did not resolve
from it. This bug also exists on `main`.
```diff
- if (baseUrl && absoluteBaseUrl && !modules.includes(absoluteBaseUrl))
{
+ if (baseUrl !== undefined && !modules.includes(absoluteBaseUrl)) {
```
- **Generated types (`9ee297e`)**: regenerates
`types/TsconfigPathsPlugin.d.ts` for the new `pathsBasePath` JSDoc
property. Without it, CI's `build:types` check fails.
I compared enhanced-resolve with `ts.resolveModuleName` (TypeScript
6.0.3, `moduleResolution: bundler`) on 34 setups. They cover the #705
and #706 repros, multi-level and array `extends`, packages (`exports`,
the `tsconfig` field, scoped), `${configDir}`, empty `baseUrl`,
backslashes, and project references.
| Code | Setups that differ from tsc |
| ---------------------- | --------------------------- |
| `main` | 16 / 34 |
| `main` + #710 | 1 / 34 (empty root `baseUrl`) |
| this PR | 0 / 34 |
The #705 repro, before and after:
```text
before: one @/foo -> Can't resolve '@/foo' two @/foo -> Can't resolve '@/foo' three foo -> Can't resolve 'foo'
after: one @/foo -> src/foo.ts two @/foo -> src/foo.ts three foo -> src/foo.ts
```
**What kind of change does this PR introduce?**
fix
**Did you add tests for your changes?**
Yes. #710 adds 6 tests with fixtures in
`test/fixtures/tsconfig-paths/extends-paths-base/`. I added one test
that resolves `src/foo` through an empty root `baseUrl`; it fails
without `99da949` and passes with it. `npm run lint` is clean and `npm
run test:only` passes (1664 tests).
**Does this PR introduce a breaking change?**
No.
**If relevant, what needs to be documented once your changes are merged
or what have you already documented?**
n/a. The changeset from #710 is included.
**Use of AI**
Yes. I used Claude Code to apply #710 onto `main`, write a differential
script against tsc, find and fix the remaining empty-`baseUrl` case, add
its test, and regenerate the types. Lint and the full test suite were
run locally.
---
_Generated by [Claude
Code](https://claude.ai/code/session_013FhutR7wqtULZXURwFF5ER)_
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Bug Fixes**
* Corrected resolution of inherited TypeScript path aliases when
`baseUrl` is missing or empty.
* Improved handling of `${configDir}` in inherited `baseUrl` settings
and path resolution across extended configurations.
* Prevented one extended configuration from affecting subsequent loads
that share a filesystem cache.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Mradul Singh <msingh@dealmeridian.com>
Co-authored-by: Claude <noreply@anthropic.com>
Thanks for the PR, fixed in the main with more tests and small fixes, let’s close, feel free to feedback (better to open a new issue if you will find more bugs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #705.
Two problems with configs loaded through
extendsinTsconfigPathsPlugin:pathswithoutbaseUrlwere resolved relative to the root tsconfig. tsc resolves them relative to the config file that declares them (docs), sopathsfrom./configs/base.jsonor from a package config pointed to the wrong place.Now
_loadTsconfigrecords the directory of the config that declarespaths(pathsBasePath, the same name tsc uses internally). It travels withpathsthroughmergeTsconfigs: a config that redefinespathsalso sets its ownpathsBasePath.tsconfigPathsToResolveOptionsuses it when there is nobaseUrl. When there is abaseUrl(from any config), nothing changes:pathsare still relative tobaseUrl.${configDir}inbaseUrlwas never substituted. In an extended config it was joined to that config's directory as a literal string. Now it is left as is when the extended config is loaded and substituted with the root config directory when the paths are built (the same as${configDir}inpaths).I compared the result with
ts.resolveModuleName(TypeScript 6.0.3, the version in devDependencies) on 12 setups: the 3 from the issue, rootbaseUrl+ inheritedpaths, rootpathsoverriding inheritedpaths,baseUrl+pathsboth in the base, a 2-levelextendschain withpathsin the middle config,${configDir}in inheritedpaths,${configDir}as an inheritedbaseUrlwith relativepaths, and an emptybaseUrl("") in the root config, in the base config, and in the base config next topaths. All 12 now match tsc. Onmain, 7 of them differ.baseUrl:"baseUrl": ""is treated as set (the directory of its config), as tsc does. An inherited""is rebased to its own config directory like any other inheritedbaseUrl(onmainit was left empty and so meant the root directory).Tests: new fixtures in
test/fixtures/tsconfig-paths/extends-paths-base/and 6 tests. The 3 cases from the issue and the inherited emptybaseUrlfail onmain. The rootbaseUrland root emptybaseUrltests are guards and pass on both.test/tsconfig-paths.test.jspasses (65), andnpm run lint(eslint, tsc, prettier, cspell) is clean. Added a patch changeset.Note: in my local run of the whole suite, the 18 "should resolve itself" tests in
test/simple.test.jsfail, but they fail the same way onmain. They resolve./enhanced-resolve/lib/indexfrom the parent directory, and my clone's folder has a different name.Summary by CodeRabbit
baseUrlresolve relative to the configuration that declares them.${configDir}and emptybaseUrlvalues in extended configurations to align with TypeScript behavior.