fix(tsconfig): resolve extends-inherited include/exclude/files relative to the declaring config#1204
Open
webpro wants to merge 1 commit into
Open
Conversation
…ve to the declaring config
`include` / `exclude` / `files` inherited via `extends` were normalized relative
to the extending config's directory instead of the config that declared them
(`rootDirs` is already normalized at parse time relative to its declaring config).
So an inherited relative `include` such as `../src/**` resolved against the wrong
directory, `claims_ownership_of` returned false, and `tsconfig:'auto'` fell through
to an ancestor `tsconfig.json` — silently dropping the inherited `paths` and
`rootDirs`. This broke SvelteKit in a monorepo (app `extends
./.svelte-kit/tsconfig.json`, mapping `./$types` via `rootDirs`, with a monorepo
root `tsconfig.json` as the ancestor), which `tsc`/`tsgo` resolve.
Normalize `include`/`exclude`/`files` at parse time relative to the declaring
config, mirroring `rootDirs`. `build()` now only resolves the `{configDir}`
template.
4408329 to
42ed0d3
Compare
Member
|
@shulaoda can you help with review |
Contributor
Got it, leave it to me. I’ll take a look. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
include/exclude/filesinherited viaextendsare resolved relative to the extending config's directory instead of the config that declared them.rootDirsis already normalized at parse time relative to its declaring config (src/tsconfig.rs), butinclude/exclude/fileswere normalized later inbuild()relative to the root config.TypeScript resolves these relative to the file they originate in:
— https://www.typescriptlang.org/tsconfig/#extends
Why it matters
An inherited relative
includesuch as../src/**is resolved against the wrong directory, soclaims_ownership_ofreturnsfalseandtsconfig: 'auto'walks up to an ancestortsconfig.json— silently dropping the inheritedpathsandrootDirs.This is SvelteKit in a monorepo: the app's
tsconfig.jsonhas"extends": "./.svelte-kit/tsconfig.json"(which maps./$typesviarootDirsand$libviapaths), and the monorepo roottsconfig.jsonis the ancestor.tsc/typescript-goresolve it;oxc-resolverdid not.Reproduction (added as a fixture)
tsgo --noEmit -p pkg/tsconfig.jsonresolves./data(noTS2307).resolve_file("pkg/src/consumer.ts", "./data")withtsconfig: 'auto'returnedNotFoundbefore this change — because the inherited../src/**was resolved relative topkg/instead ofpkg/gen/, sopkg/tsconfig.jsonfailed to claimpkg/src/consumer.tsand discovery fell through to the ancestor.Fix
Normalize
include/exclude/filesat parse time relative to the config that declared them — mirroring howrootDirsis already handled.build()now only resolves the{configDir}template (plain relative paths are already absolute).Test
extends_root_dirs_with_ancestor_tsconfig— fails before, passes after. The fulltsconfigsuite stays green.Distinct from #1185 (unresolvable
extends→TsconfigNotFound).