From 77c70429d8038c5058eaa07c8d038376ede916f2 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Tue, 28 Mar 2023 14:05:23 +0000 Subject: [PATCH] Cherry-pick PR #53443 into release-5.0 Component commits: 6885ed39a6 Support wildcard exports in tsconfig lookup --- src/compiler/moduleNameResolver.ts | 2 +- ...tendsPackageJsonExportsWildcard.errors.txt | 30 +++++++++++++++++++ ...configExtendsPackageJsonExportsWildcard.ts | 27 +++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/tsconfigExtendsPackageJsonExportsWildcard.errors.txt create mode 100644 tests/cases/compiler/tsconfigExtendsPackageJsonExportsWildcard.ts diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index e24f647c99c2f..a673672119cf3 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -1679,7 +1679,7 @@ export function nodeModuleNameResolver(moduleName: string, containingFile: strin /** @internal */ export function nodeNextJsonConfigResolver(moduleName: string, containingFile: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { - return nodeModuleNameResolverWorker(NodeResolutionFeatures.Exports, moduleName, getDirectoryPath(containingFile), { moduleResolution: ModuleResolutionKind.NodeNext }, host, /*cache*/ undefined, Extensions.Json, /*isConfigLookup*/ true, /*redirectedReference*/ undefined); + return nodeModuleNameResolverWorker(NodeResolutionFeatures.NodeNextDefault, moduleName, getDirectoryPath(containingFile), { moduleResolution: ModuleResolutionKind.NodeNext }, host, /*cache*/ undefined, Extensions.Json, /*isConfigLookup*/ true, /*redirectedReference*/ undefined); } function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleName: string, containingDirectory: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache: ModuleResolutionCache | undefined, extensions: Extensions, isConfigLookup: boolean, redirectedReference: ResolvedProjectReference | undefined): ResolvedModuleWithFailedLookupLocations { diff --git a/tests/baselines/reference/tsconfigExtendsPackageJsonExportsWildcard.errors.txt b/tests/baselines/reference/tsconfigExtendsPackageJsonExportsWildcard.errors.txt new file mode 100644 index 0000000000000..1cc129214b666 --- /dev/null +++ b/tests/baselines/reference/tsconfigExtendsPackageJsonExportsWildcard.errors.txt @@ -0,0 +1,30 @@ +/index.ts(2,1): error TS2454: Variable 'x' is used before being assigned. + + +==== /tsconfig.json (0 errors) ==== + { + "extends": "foo/strict.json" + } + +==== /node_modules/foo/package.json (0 errors) ==== + { + "name": "foo", + "version": "1.0.0", + "exports": { + "./*.json": "./configs/*.json" + } + } + +==== /node_modules/foo/configs/strict.json (0 errors) ==== + { + "compilerOptions": { + "strict": true + } + } + +==== /index.ts (1 errors) ==== + let x: string; + x.toLowerCase(); + ~ +!!! error TS2454: Variable 'x' is used before being assigned. + \ No newline at end of file diff --git a/tests/cases/compiler/tsconfigExtendsPackageJsonExportsWildcard.ts b/tests/cases/compiler/tsconfigExtendsPackageJsonExportsWildcard.ts new file mode 100644 index 0000000000000..1caadbb1260b1 --- /dev/null +++ b/tests/cases/compiler/tsconfigExtendsPackageJsonExportsWildcard.ts @@ -0,0 +1,27 @@ +// @noTypesAndSymbols: true +// @noEmit: true + +// @Filename: /node_modules/foo/package.json +{ + "name": "foo", + "version": "1.0.0", + "exports": { + "./*.json": "./configs/*.json" + } +} + +// @Filename: /node_modules/foo/configs/strict.json +{ + "compilerOptions": { + "strict": true + } +} + +// @Filename: /tsconfig.json +{ + "extends": "foo/strict.json" +} + +// @Filename: /index.ts +let x: string; +x.toLowerCase();