fix: tsconfig extends supporting same extensions (inc .jsonc) for relative and package imports (bug #43121)
#62092
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 #43121
This PR adds support for
.jsoncfile extensions when resolving tsconfigextendspaths through Node.js module resolution. Previously, TypeScript only supported.jsoncfiles for relative paths (e.g.,"extends": "./config.jsonc") but failed when trying to resolve package-based extends (e.g.,"extends": "pkg/config.jsonc").Problem
When using
"extends": "pkg/foo.jsonc"in a tsconfig.json, TypeScript would attempt to resolvenode_modules/pkg/foo.jsonc.jsonand fail, even though the same.jsoncfile could be successfully loaded using relative paths like"extends": "./foo.jsonc".This inconsistency forced developers to either:
.jsonextensions and deal with linter warnings about commentstsconfig*.jsonfiles.jsoncfilesChanges
Core Resolution Changes
src/compiler/moduleNameResolver.ts:nodeNextJsonConfigResolvertonodeNextTsconfigResolverExtensions.Anyinstead ofExtensions.Json. I was thinking about adding aJsoncExtensions value, but decided against this so the behaviour of relative tsconfig and package tsconfig imports would be the same (any extensions are valid for relative imports)src/compiler/commandLineParser.ts:Testing
Added test cases before starting, to ensure test went from failing to passing:
tests/cases/compiler/tsconfigExtendsJsoncPackage.ts: Tests package-based.jsoncextendstests/cases/compiler/tsconfigExtendsJsoncRelative.ts: Ensures relative.jsoncextends still work (regression test)Both test cases verify that:
.jsoncconfig files are properly resolved and loadedinlineSourceMap: trueis setBackward Compatibility
This change is fully backward compatible:
.jsonconfig files continue to work exactly as before.jsoncpaths that already worked remain unchanged