diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index e330825fa3f..b28f03e5902 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -484,6 +484,13 @@ function getOriginalAndResolvedFileName(fileName: string, host: ModuleResolution }; } +function getCandidateFromTypeRoot(typeRoot: string, typeReferenceDirectiveName: string, moduleResolutionState: ModuleResolutionState) { + const nameForLookup = endsWith(typeRoot, "/node_modules/@types") || endsWith(typeRoot, "/node_modules/@types/") ? + mangleScopedPackageNameWithTrace(typeReferenceDirectiveName, moduleResolutionState) : + typeReferenceDirectiveName; + return combinePaths(typeRoot, nameForLookup); +} + /** * @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown. * This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups @@ -619,7 +626,7 @@ export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", ")); } return firstDefined(typeRoots, typeRoot => { - const candidate = combinePaths(typeRoot, typeReferenceDirectiveName); + const candidate = getCandidateFromTypeRoot(typeRoot, typeReferenceDirectiveName, moduleResolutionState); const directoryExists = directoryProbablyExists(typeRoot, host); if (!directoryExists && traceEnabled) { trace(host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, typeRoot); @@ -3084,7 +3091,7 @@ export function classicNameResolver(moduleName: string, containingFile: string, function resolveFromTypeRoot(moduleName: string, state: ModuleResolutionState) { if (!state.compilerOptions.typeRoots) return; for (const typeRoot of state.compilerOptions.typeRoots) { - const candidate = combinePaths(typeRoot, moduleName); + const candidate = getCandidateFromTypeRoot(typeRoot, moduleName, state); const directoryExists = directoryProbablyExists(typeRoot, state.host); if (!directoryExists && state.traceEnabled) { trace(state.host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, typeRoot); diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.errors.txt b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.errors.txt new file mode 100644 index 00000000000..b265c25f913 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.errors.txt @@ -0,0 +1,41 @@ +/a.ts(2,30): error TS2307: Cannot find module '@mangled/typescache' or its corresponding type declarations. +/a.ts(4,36): error TS2307: Cannot find module '@mangled/nodemodulescache' or its corresponding type declarations. +/a.ts(5,30): error TS2307: Cannot find module '@scoped/attypescache' or its corresponding type declarations. + + +==== /a.ts (3 errors) ==== + import { typesCache } from "@scoped/typescache"; + import { mangledTypes } from "@mangled/typescache"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module '@mangled/typescache' or its corresponding type declarations. + import { nodeModulesCache } from "@scoped/nodemodulescache"; + import { mangledNodeModules } from "@mangled/nodemodulescache"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module '@mangled/nodemodulescache' or its corresponding type declarations. + import { atTypesCache } from "@scoped/attypescache"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module '@scoped/attypescache' or its corresponding type declarations. + import { mangledAtTypesCache } from "@mangled/attypescache"; + +==== /a/types/dummy/index.d.ts (0 errors) ==== + export const dummy: number; + +==== /a/types/@scoped/typescache/index.d.ts (0 errors) ==== + export const typesCache: number; + +==== /a/types/mangled__typescache/index.d.ts (0 errors) ==== + export const mangledTypes: number; + +==== /a/node_modules/@scoped/nodemodulescache/index.d.ts (0 errors) ==== + export const nodeModulesCache: number; + +==== /a/node_modules/mangled__nodemodulescache/index.d.ts (0 errors) ==== + export const mangledNodeModules: number; + +==== /a/node_modules/@types/@scoped/attypescache/index.d.ts (0 errors) ==== + export const atTypesCache: number; + +==== /a/node_modules/@types/mangled__attypescache/index.d.ts (0 errors) ==== + export const mangledAtTypesCache: number; + + \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.js b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.js new file mode 100644 index 00000000000..e4bd6a6ba86 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.js @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveScoped.ts] //// + +//// [index.d.ts] +export const dummy: number; + +//// [index.d.ts] +export const typesCache: number; + +//// [index.d.ts] +export const mangledTypes: number; + +//// [index.d.ts] +export const nodeModulesCache: number; + +//// [index.d.ts] +export const mangledNodeModules: number; + +//// [index.d.ts] +export const atTypesCache: number; + +//// [index.d.ts] +export const mangledAtTypesCache: number; + + +//// [a.ts] +import { typesCache } from "@scoped/typescache"; +import { mangledTypes } from "@mangled/typescache"; +import { nodeModulesCache } from "@scoped/nodemodulescache"; +import { mangledNodeModules } from "@mangled/nodemodulescache"; +import { atTypesCache } from "@scoped/attypescache"; +import { mangledAtTypesCache } from "@mangled/attypescache"; + + +//// [a.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.symbols b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.symbols new file mode 100644 index 00000000000..04ffef7cbf7 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.symbols @@ -0,0 +1,36 @@ +=== /a.ts === +import { typesCache } from "@scoped/typescache"; +>typesCache : Symbol(typesCache, Decl(a.ts, 0, 8)) + +import { mangledTypes } from "@mangled/typescache"; +>mangledTypes : Symbol(mangledTypes, Decl(a.ts, 1, 8)) + +import { nodeModulesCache } from "@scoped/nodemodulescache"; +>nodeModulesCache : Symbol(nodeModulesCache, Decl(a.ts, 2, 8)) + +import { mangledNodeModules } from "@mangled/nodemodulescache"; +>mangledNodeModules : Symbol(mangledNodeModules, Decl(a.ts, 3, 8)) + +import { atTypesCache } from "@scoped/attypescache"; +>atTypesCache : Symbol(atTypesCache, Decl(a.ts, 4, 8)) + +import { mangledAtTypesCache } from "@mangled/attypescache"; +>mangledAtTypesCache : Symbol(mangledAtTypesCache, Decl(a.ts, 5, 8)) + +=== /a/types/dummy/index.d.ts === +export const dummy: number; +>dummy : Symbol(dummy, Decl(index.d.ts, 0, 12)) + +=== /a/types/@scoped/typescache/index.d.ts === +export const typesCache: number; +>typesCache : Symbol(typesCache, Decl(index.d.ts, 0, 12)) + +=== /a/node_modules/@scoped/nodemodulescache/index.d.ts === +export const nodeModulesCache: number; +>nodeModulesCache : Symbol(nodeModulesCache, Decl(index.d.ts, 0, 12)) + +=== /a/node_modules/@types/mangled__attypescache/index.d.ts === +export const mangledAtTypesCache: number; +>mangledAtTypesCache : Symbol(mangledAtTypesCache, Decl(index.d.ts, 0, 12)) + + diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.trace.json b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.trace.json new file mode 100644 index 00000000000..ad1029e415b --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.trace.json @@ -0,0 +1,73 @@ +[ + "======== Resolving module '@scoped/typescache' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'Node10'.", + "Loading module '@scoped/typescache' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "Scoped package detected, looking in 'scoped__typescache'", + "File '/a/types/@scoped/typescache.d.ts' does not exist.", + "File '/a/types/@scoped/typescache/package.json' does not exist.", + "File '/a/types/@scoped/typescache/index.d.ts' exists - use it as a name resolution result.", + "Resolving real path for '/a/types/@scoped/typescache/index.d.ts', result '/a/types/@scoped/typescache/index.d.ts'.", + "======== Module name '@scoped/typescache' was successfully resolved to '/a/types/@scoped/typescache/index.d.ts'. ========", + "======== Resolving module '@mangled/typescache' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'Node10'.", + "Loading module '@mangled/typescache' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "Scoped package detected, looking in 'mangled__typescache'", + "Scoped package detected, looking in 'mangled__typescache'", + "File '/a/node_modules/@types/mangled__typescache.d.ts' does not exist.", + "Loading module '@mangled/typescache' from 'node_modules' folder, target file types: JavaScript.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "======== Module name '@mangled/typescache' was not resolved. ========", + "======== Resolving module '@scoped/nodemodulescache' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'Node10'.", + "Loading module '@scoped/nodemodulescache' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "Scoped package detected, looking in 'scoped__nodemodulescache'", + "File '/a/types/@scoped/nodemodulescache.d.ts' does not exist.", + "File '/a/node_modules/@scoped/nodemodulescache.d.ts' does not exist.", + "File '/a/node_modules/@scoped/nodemodulescache/package.json' does not exist.", + "File '/a/node_modules/@scoped/nodemodulescache/index.d.ts' exists - use it as a name resolution result.", + "Resolving real path for '/a/node_modules/@scoped/nodemodulescache/index.d.ts', result '/a/node_modules/@scoped/nodemodulescache/index.d.ts'.", + "======== Module name '@scoped/nodemodulescache' was successfully resolved to '/a/node_modules/@scoped/nodemodulescache/index.d.ts'. ========", + "======== Resolving module '@mangled/nodemodulescache' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'Node10'.", + "Loading module '@mangled/nodemodulescache' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "Scoped package detected, looking in 'mangled__nodemodulescache'", + "Scoped package detected, looking in 'mangled__nodemodulescache'", + "File '/a/node_modules/@types/mangled__nodemodulescache.d.ts' does not exist.", + "Loading module '@mangled/nodemodulescache' from 'node_modules' folder, target file types: JavaScript.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "======== Module name '@mangled/nodemodulescache' was not resolved. ========", + "======== Resolving module '@scoped/attypescache' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'Node10'.", + "Loading module '@scoped/attypescache' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "Scoped package detected, looking in 'scoped__attypescache'", + "File '/a/types/@scoped/attypescache.d.ts' does not exist.", + "File '/a/node_modules/@scoped/attypescache.d.ts' does not exist.", + "Scoped package detected, looking in 'scoped__attypescache'", + "File '/a/node_modules/@types/scoped__attypescache.d.ts' does not exist.", + "Loading module '@scoped/attypescache' from 'node_modules' folder, target file types: JavaScript.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "======== Module name '@scoped/attypescache' was not resolved. ========", + "======== Resolving module '@mangled/attypescache' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'Node10'.", + "Loading module '@mangled/attypescache' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "Scoped package detected, looking in 'mangled__attypescache'", + "Scoped package detected, looking in 'mangled__attypescache'", + "File '/a/node_modules/@types/mangled__attypescache.d.ts' does not exist.", + "File '/a/node_modules/@types/mangled__attypescache/package.json' does not exist.", + "File '/a/node_modules/@types/mangled__attypescache/index.d.ts' exists - use it as a name resolution result.", + "Resolving real path for '/a/node_modules/@types/mangled__attypescache/index.d.ts', result '/a/node_modules/@types/mangled__attypescache/index.d.ts'.", + "======== Module name '@mangled/attypescache' was successfully resolved to '/a/node_modules/@types/mangled__attypescache/index.d.ts'. ========", + "======== Resolving type reference directive 'dummy', containing file '/__inferred type names__.ts', root directory '/a/types,/a/node_modules,/a/node_modules/@types'. ========", + "Resolving with primary search path '/a/types, /a/node_modules, /a/node_modules/@types'.", + "File '/a/types/dummy.d.ts' does not exist.", + "File '/a/types/dummy/package.json' does not exist.", + "File '/a/types/dummy/index.d.ts' exists - use it as a name resolution result.", + "Resolving real path for '/a/types/dummy/index.d.ts', result '/a/types/dummy/index.d.ts'.", + "======== Type reference directive 'dummy' was successfully resolved to '/a/types/dummy/index.d.ts', primary: true. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.types b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.types new file mode 100644 index 00000000000..7847df0f06e --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveScoped.types @@ -0,0 +1,36 @@ +=== /a.ts === +import { typesCache } from "@scoped/typescache"; +>typesCache : number + +import { mangledTypes } from "@mangled/typescache"; +>mangledTypes : any + +import { nodeModulesCache } from "@scoped/nodemodulescache"; +>nodeModulesCache : number + +import { mangledNodeModules } from "@mangled/nodemodulescache"; +>mangledNodeModules : any + +import { atTypesCache } from "@scoped/attypescache"; +>atTypesCache : any + +import { mangledAtTypesCache } from "@mangled/attypescache"; +>mangledAtTypesCache : number + +=== /a/types/dummy/index.d.ts === +export const dummy: number; +>dummy : number + +=== /a/types/@scoped/typescache/index.d.ts === +export const typesCache: number; +>typesCache : number + +=== /a/node_modules/@scoped/nodemodulescache/index.d.ts === +export const nodeModulesCache: number; +>nodeModulesCache : number + +=== /a/node_modules/@types/mangled__attypescache/index.d.ts === +export const mangledAtTypesCache: number; +>mangledAtTypesCache : number + + diff --git a/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.errors.txt b/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.errors.txt new file mode 100644 index 00000000000..477a9831661 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.errors.txt @@ -0,0 +1,52 @@ +error TS2688: Cannot find type definition file for '@mangled/nodemodulescache'. + The file is in the program because: + Entry point of type library '@mangled/nodemodulescache' specified in compilerOptions +error TS2688: Cannot find type definition file for '@mangled/typescache'. + The file is in the program because: + Entry point of type library '@mangled/typescache' specified in compilerOptions +error TS2688: Cannot find type definition file for '@scoped/attypescache'. + The file is in the program because: + Entry point of type library '@scoped/attypescache' specified in compilerOptions +/a.ts(4,1): error TS2304: Cannot find name 'mangledNodeModules'. +/a.ts(5,1): error TS2552: Cannot find name 'atTypesCache'. Did you mean 'typesCache'? + + +!!! error TS2688: Cannot find type definition file for '@mangled/nodemodulescache'. +!!! error TS2688: The file is in the program because: +!!! error TS2688: Entry point of type library '@mangled/nodemodulescache' specified in compilerOptions +!!! error TS2688: Cannot find type definition file for '@mangled/typescache'. +!!! error TS2688: The file is in the program because: +!!! error TS2688: Entry point of type library '@mangled/typescache' specified in compilerOptions +!!! error TS2688: Cannot find type definition file for '@scoped/attypescache'. +!!! error TS2688: The file is in the program because: +!!! error TS2688: Entry point of type library '@scoped/attypescache' specified in compilerOptions +==== /a.ts (2 errors) ==== + typesCache; + mangledAtTypesCache; + nodeModulesCache; + mangledNodeModules; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'mangledNodeModules'. + atTypesCache; + ~~~~~~~~~~~~ +!!! error TS2552: Cannot find name 'atTypesCache'. Did you mean 'typesCache'? +!!! related TS2728 /types/@scoped/typescache/index.d.ts:1:15: 'typesCache' is declared here. + mangledAtTypesCache; +==== /types/@scoped/typescache/index.d.ts (0 errors) ==== + declare const typesCache: number; + +==== /types/mangled__typescache/index.d.ts (0 errors) ==== + declare const mangledTypes: number; + +==== /node_modules/@scoped/nodemodulescache/index.d.ts (0 errors) ==== + declare const nodeModulesCache: number; + +==== /node_modules/mangled__nodemodulescache/index.d.ts (0 errors) ==== + declare const mangledNodeModules: number; + +==== /node_modules/@types/@scoped/attypescache/index.d.ts (0 errors) ==== + declare const atTypesCache: number; + +==== /node_modules/@types/mangled__attypescache/index.d.ts (0 errors) ==== + declare const mangledAtTypesCache: number; + \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.js b/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.js new file mode 100644 index 00000000000..3b86fc58b00 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/typeReferenceDirectiveScopedPackageCustomTypeRoot.ts] //// + +//// [index.d.ts] +declare const typesCache: number; + +//// [index.d.ts] +declare const mangledTypes: number; + +//// [index.d.ts] +declare const nodeModulesCache: number; + +//// [index.d.ts] +declare const mangledNodeModules: number; + +//// [index.d.ts] +declare const atTypesCache: number; + +//// [index.d.ts] +declare const mangledAtTypesCache: number; + +//// [a.ts] +typesCache; +mangledAtTypesCache; +nodeModulesCache; +mangledNodeModules; +atTypesCache; +mangledAtTypesCache; + +//// [a.js] +typesCache; +mangledAtTypesCache; +nodeModulesCache; +mangledNodeModules; +atTypesCache; +mangledAtTypesCache; diff --git a/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.symbols b/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.symbols new file mode 100644 index 00000000000..052eb6fa7ac --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.symbols @@ -0,0 +1,27 @@ +=== /a.ts === +typesCache; +>typesCache : Symbol(typesCache, Decl(index.d.ts, 0, 13)) + +mangledAtTypesCache; +>mangledAtTypesCache : Symbol(mangledAtTypesCache, Decl(index.d.ts, 0, 13)) + +nodeModulesCache; +>nodeModulesCache : Symbol(nodeModulesCache, Decl(index.d.ts, 0, 13)) + +mangledNodeModules; +atTypesCache; +mangledAtTypesCache; +>mangledAtTypesCache : Symbol(mangledAtTypesCache, Decl(index.d.ts, 0, 13)) + +=== /types/@scoped/typescache/index.d.ts === +declare const typesCache: number; +>typesCache : Symbol(typesCache, Decl(index.d.ts, 0, 13)) + +=== /node_modules/@scoped/nodemodulescache/index.d.ts === +declare const nodeModulesCache: number; +>nodeModulesCache : Symbol(nodeModulesCache, Decl(index.d.ts, 0, 13)) + +=== /node_modules/@types/mangled__attypescache/index.d.ts === +declare const mangledAtTypesCache: number; +>mangledAtTypesCache : Symbol(mangledAtTypesCache, Decl(index.d.ts, 0, 13)) + diff --git a/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.trace.json b/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.trace.json new file mode 100644 index 00000000000..2066af0b43c --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.trace.json @@ -0,0 +1,45 @@ +[ + "======== Resolving type reference directive '@scoped/typescache', containing file '/__inferred type names__.ts', root directory '/types,/node_modules,/node_modules/@types'. ========", + "Resolving with primary search path '/types, /node_modules, /node_modules/@types'.", + "File '/types/@scoped/typescache.d.ts' does not exist.", + "File '/types/@scoped/typescache/package.json' does not exist.", + "File '/types/@scoped/typescache/index.d.ts' exists - use it as a name resolution result.", + "Resolving real path for '/types/@scoped/typescache/index.d.ts', result '/types/@scoped/typescache/index.d.ts'.", + "======== Type reference directive '@scoped/typescache' was successfully resolved to '/types/@scoped/typescache/index.d.ts', primary: true. ========", + "======== Resolving type reference directive '@scoped/nodemodulescache', containing file '/__inferred type names__.ts', root directory '/types,/node_modules,/node_modules/@types'. ========", + "Resolving with primary search path '/types, /node_modules, /node_modules/@types'.", + "File '/types/@scoped/nodemodulescache.d.ts' does not exist.", + "File '/node_modules/@scoped/nodemodulescache.d.ts' does not exist.", + "File '/node_modules/@scoped/nodemodulescache/package.json' does not exist.", + "File '/node_modules/@scoped/nodemodulescache/index.d.ts' exists - use it as a name resolution result.", + "Resolving real path for '/node_modules/@scoped/nodemodulescache/index.d.ts', result '/node_modules/@scoped/nodemodulescache/index.d.ts'.", + "======== Type reference directive '@scoped/nodemodulescache' was successfully resolved to '/node_modules/@scoped/nodemodulescache/index.d.ts', primary: true. ========", + "======== Resolving type reference directive '@scoped/attypescache', containing file '/__inferred type names__.ts', root directory '/types,/node_modules,/node_modules/@types'. ========", + "Resolving with primary search path '/types, /node_modules, /node_modules/@types'.", + "File '/types/@scoped/attypescache.d.ts' does not exist.", + "File '/node_modules/@scoped/attypescache.d.ts' does not exist.", + "Scoped package detected, looking in 'scoped__attypescache'", + "File '/node_modules/@types/scoped__attypescache.d.ts' does not exist.", + "Resolving type reference directive for program that specifies custom typeRoots, skipping lookup in 'node_modules' folder.", + "======== Type reference directive '@scoped/attypescache' was not resolved. ========", + "======== Resolving type reference directive '@mangled/typescache', containing file '/__inferred type names__.ts', root directory '/types,/node_modules,/node_modules/@types'. ========", + "Resolving with primary search path '/types, /node_modules, /node_modules/@types'.", + "Scoped package detected, looking in 'mangled__typescache'", + "File '/node_modules/@types/mangled__typescache.d.ts' does not exist.", + "Resolving type reference directive for program that specifies custom typeRoots, skipping lookup in 'node_modules' folder.", + "======== Type reference directive '@mangled/typescache' was not resolved. ========", + "======== Resolving type reference directive '@mangled/nodemodulescache', containing file '/__inferred type names__.ts', root directory '/types,/node_modules,/node_modules/@types'. ========", + "Resolving with primary search path '/types, /node_modules, /node_modules/@types'.", + "Scoped package detected, looking in 'mangled__nodemodulescache'", + "File '/node_modules/@types/mangled__nodemodulescache.d.ts' does not exist.", + "Resolving type reference directive for program that specifies custom typeRoots, skipping lookup in 'node_modules' folder.", + "======== Type reference directive '@mangled/nodemodulescache' was not resolved. ========", + "======== Resolving type reference directive '@mangled/attypescache', containing file '/__inferred type names__.ts', root directory '/types,/node_modules,/node_modules/@types'. ========", + "Resolving with primary search path '/types, /node_modules, /node_modules/@types'.", + "Scoped package detected, looking in 'mangled__attypescache'", + "File '/node_modules/@types/mangled__attypescache.d.ts' does not exist.", + "File '/node_modules/@types/mangled__attypescache/package.json' does not exist.", + "File '/node_modules/@types/mangled__attypescache/index.d.ts' exists - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/mangled__attypescache/index.d.ts', result '/node_modules/@types/mangled__attypescache/index.d.ts'.", + "======== Type reference directive '@mangled/attypescache' was successfully resolved to '/node_modules/@types/mangled__attypescache/index.d.ts', primary: true. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.types b/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.types new file mode 100644 index 00000000000..7134ba8e167 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveScopedPackageCustomTypeRoot.types @@ -0,0 +1,31 @@ +=== /a.ts === +typesCache; +>typesCache : number + +mangledAtTypesCache; +>mangledAtTypesCache : number + +nodeModulesCache; +>nodeModulesCache : number + +mangledNodeModules; +>mangledNodeModules : any + +atTypesCache; +>atTypesCache : any + +mangledAtTypesCache; +>mangledAtTypesCache : number + +=== /types/@scoped/typescache/index.d.ts === +declare const typesCache: number; +>typesCache : number + +=== /node_modules/@scoped/nodemodulescache/index.d.ts === +declare const nodeModulesCache: number; +>nodeModulesCache : number + +=== /node_modules/@types/mangled__attypescache/index.d.ts === +declare const mangledAtTypesCache: number; +>mangledAtTypesCache : number + diff --git a/tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveScoped.ts b/tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveScoped.ts new file mode 100644 index 00000000000..f286645efe3 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveScoped.ts @@ -0,0 +1,35 @@ +// @noImplicitReferences: true +// @typeRoots: /a/types,/a/node_modules,/a/node_modules/@types +// @types: dummy +// @traceResolution: true +// @currentDirectory: / + +// @Filename: /a/types/dummy/index.d.ts +export const dummy: number; + +// @Filename: /a/types/@scoped/typescache/index.d.ts +export const typesCache: number; + +// @Filename: /a/types/mangled__typescache/index.d.ts +export const mangledTypes: number; + +// @Filename: /a/node_modules/@scoped/nodemodulescache/index.d.ts +export const nodeModulesCache: number; + +// @Filename: /a/node_modules/mangled__nodemodulescache/index.d.ts +export const mangledNodeModules: number; + +// @Filename: /a/node_modules/@types/@scoped/attypescache/index.d.ts +export const atTypesCache: number; + +// @Filename: /a/node_modules/@types/mangled__attypescache/index.d.ts +export const mangledAtTypesCache: number; + + +// @Filename: /a.ts +import { typesCache } from "@scoped/typescache"; +import { mangledTypes } from "@mangled/typescache"; +import { nodeModulesCache } from "@scoped/nodemodulescache"; +import { mangledNodeModules } from "@mangled/nodemodulescache"; +import { atTypesCache } from "@scoped/attypescache"; +import { mangledAtTypesCache } from "@mangled/attypescache"; diff --git a/tests/cases/compiler/typeReferenceDirectiveScopedPackageCustomTypeRoot.ts b/tests/cases/compiler/typeReferenceDirectiveScopedPackageCustomTypeRoot.ts new file mode 100644 index 00000000000..26d2f1ce9b8 --- /dev/null +++ b/tests/cases/compiler/typeReferenceDirectiveScopedPackageCustomTypeRoot.ts @@ -0,0 +1,31 @@ +// @noImplicitReferences: true +// @typeRoots: /types,/node_modules,/node_modules/@types +// @types: @scoped/typescache,@scoped/nodemodulescache,@scoped/attypescache,@mangled/typescache,@mangled/nodemodulescache,@mangled/attypescache +// @traceResolution: true +// @currentDirectory: / + +// @Filename: /types/@scoped/typescache/index.d.ts +declare const typesCache: number; + +// @Filename: /types/mangled__typescache/index.d.ts +declare const mangledTypes: number; + +// @Filename: /node_modules/@scoped/nodemodulescache/index.d.ts +declare const nodeModulesCache: number; + +// @Filename: /node_modules/mangled__nodemodulescache/index.d.ts +declare const mangledNodeModules: number; + +// @Filename: /node_modules/@types/@scoped/attypescache/index.d.ts +declare const atTypesCache: number; + +// @Filename: /node_modules/@types/mangled__attypescache/index.d.ts +declare const mangledAtTypesCache: number; + +// @Filename: /a.ts +typesCache; +mangledAtTypesCache; +nodeModulesCache; +mangledNodeModules; +atTypesCache; +mangledAtTypesCache; \ No newline at end of file