From 7f58b1805fd77a85d4747da17f5ef836ad0100d0 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 22 Nov 2022 14:55:12 -0800 Subject: [PATCH 1/6] Test case --- ...eReferenceDirectiveWithTypeAsFile.errors.txt | 17 +++++++++++++++++ .../typeReferenceDirectiveWithTypeAsFile.js | 11 +++++++++++ ...typeReferenceDirectiveWithTypeAsFile.symbols | 4 ++++ ...eReferenceDirectiveWithTypeAsFile.trace.json | 10 ++++++++++ .../typeReferenceDirectiveWithTypeAsFile.types | 4 ++++ .../typeReferenceDirectiveWithTypeAsFile.ts | 11 +++++++++++ 6 files changed, 57 insertions(+) create mode 100644 tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.errors.txt create mode 100644 tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.js create mode 100644 tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.symbols create mode 100644 tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.trace.json create mode 100644 tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.types create mode 100644 tests/cases/compiler/typeReferenceDirectiveWithTypeAsFile.ts diff --git a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.errors.txt b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.errors.txt new file mode 100644 index 0000000000000..0e34e0fcb8190 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.errors.txt @@ -0,0 +1,17 @@ +error TS2688: Cannot find type definition file for 'phaser'. + The file is in the program because: + Entry point of type library 'phaser' specified in compilerOptions +/a.ts(1,1): error TS2304: Cannot find name 'a'. + + +!!! error TS2688: Cannot find type definition file for 'phaser'. +!!! error TS2688: The file is in the program because: +!!! error TS2688: Entry point of type library 'phaser' specified in compilerOptions +==== /a.ts (1 errors) ==== + a; + ~ +!!! error TS2304: Cannot find name 'a'. + +==== /node_modules/phaser/types/phaser.d.ts (0 errors) ==== + declare const a: number; + \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.js b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.js new file mode 100644 index 0000000000000..58a1fb047d8b2 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.js @@ -0,0 +1,11 @@ +//// [tests/cases/compiler/typeReferenceDirectiveWithTypeAsFile.ts] //// + +//// [phaser.d.ts] +declare const a: number; + +//// [a.ts] +a; + + +//// [a.js] +a; diff --git a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.symbols b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.symbols new file mode 100644 index 0000000000000..e803f8614d33e --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.symbols @@ -0,0 +1,4 @@ +=== /a.ts === + +a; + diff --git a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.trace.json b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.trace.json new file mode 100644 index 0000000000000..e3c356a07350d --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.trace.json @@ -0,0 +1,10 @@ +[ + "======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/node_modules/phaser/types'. ========", + "Resolving with primary search path '/node_modules/phaser/types'.", + "Looking up in 'node_modules' folder, initial location '/'.", + "File '/node_modules/phaser/package.json' does not exist.", + "File '/node_modules/phaser.d.ts' does not exist.", + "File '/node_modules/phaser/index.d.ts' does not exist.", + "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", + "======== Type reference directive 'phaser' was not resolved. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.types b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.types new file mode 100644 index 0000000000000..2ec6ffcf1be41 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.types @@ -0,0 +1,4 @@ +=== /a.ts === +a; +>a : any + diff --git a/tests/cases/compiler/typeReferenceDirectiveWithTypeAsFile.ts b/tests/cases/compiler/typeReferenceDirectiveWithTypeAsFile.ts new file mode 100644 index 0000000000000..e730d31001759 --- /dev/null +++ b/tests/cases/compiler/typeReferenceDirectiveWithTypeAsFile.ts @@ -0,0 +1,11 @@ +// @noImplicitReferences: true +// @typeRoots: /node_modules/phaser/types +// @types: phaser +// @traceResolution: true +// @currentDirectory: / + +// @Filename: /node_modules/phaser/types/phaser.d.ts +declare const a: number; + +// @Filename: /a.ts +a; From 1c2318d92e2e93c99b8ed87419470ddfd7719796 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 22 Nov 2022 14:58:42 -0800 Subject: [PATCH 2/6] Resolve typeReferenceDirective as fileOrDirectory instead of just directory when its not default typeRoots Fixes #37708 Bug 2 part of the issue --- src/compiler/moduleNameResolver.ts | 14 +++++++++++--- .../reference/library-reference-1.trace.json | 1 + .../reference/library-reference-10.trace.json | 1 + .../reference/library-reference-13.trace.json | 1 + .../reference/library-reference-14.trace.json | 1 + .../reference/library-reference-15.trace.json | 1 + .../reference/library-reference-2.trace.json | 2 ++ .../reference/library-reference-4.trace.json | 4 ++++ .../reference/library-reference-8.trace.json | 4 ++++ ...library-reference-scoped-packages.trace.json | 2 +- .../type-reference-from-primary-location.js | 9 ++++++++- .../type-reference-from-secondary-location.js | 5 +++++ ...pe-reference-overrides-secondary-location.js | 1 + ...ent-resolution-options-referenced-project.js | 2 ++ ...eReferenceDirectiveWithTypeAsFile.errors.txt | 17 ----------------- ...typeReferenceDirectiveWithTypeAsFile.symbols | 6 +++++- ...eReferenceDirectiveWithTypeAsFile.trace.json | 8 +++----- .../typeReferenceDirectiveWithTypeAsFile.types | 6 +++++- .../typeReferenceDirectives1.trace.json | 1 + .../typeReferenceDirectives10.trace.json | 1 + .../typeReferenceDirectives11.trace.json | 1 + .../typeReferenceDirectives12.trace.json | 1 + .../typeReferenceDirectives13.trace.json | 1 + .../typeReferenceDirectives2.trace.json | 1 + .../typeReferenceDirectives3.trace.json | 1 + .../typeReferenceDirectives4.trace.json | 1 + .../typeReferenceDirectives5.trace.json | 1 + .../typeReferenceDirectives6.trace.json | 1 + .../typeReferenceDirectives7.trace.json | 1 + .../typeReferenceDirectives8.trace.json | 1 + .../typeReferenceDirectives9.trace.json | 1 + 31 files changed, 69 insertions(+), 29 deletions(-) delete mode 100644 tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.errors.txt diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index b400bc23ba1df..f187609b249b2 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -549,10 +549,18 @@ export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string } return firstDefined(typeRoots, typeRoot => { const candidate = combinePaths(typeRoot, typeReferenceDirectiveName); - const candidateDirectory = getDirectoryPath(candidate); - const directoryExists = directoryProbablyExists(candidateDirectory, host); + const directoryExists = directoryProbablyExists(typeRoot, host); if (!directoryExists && traceEnabled) { - trace(host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, candidateDirectory); + trace(host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, typeRoot); + } + if (options.typeRoots) { + // Custom typeRoots resolve as file or directory just like we do modules + const resolvedFromFile = loadModuleFromFile(Extensions.Declaration, candidate, !directoryExists, moduleResolutionState); + if (resolvedFromFile) { + const packageDirectory = parseNodeModuleFromPath(resolvedFromFile.path); + const packageInfo = packageDirectory ? getPackageJsonInfo(packageDirectory, /*onlyRecordFailures*/ false, moduleResolutionState) : undefined; + return resolvedTypeScriptOnly(withPackageId(packageInfo, resolvedFromFile)); + } } return resolvedTypeScriptOnly( loadNodeModuleFromDirectory(Extensions.Declaration, candidate, diff --git a/tests/baselines/reference/library-reference-1.trace.json b/tests/baselines/reference/library-reference-1.trace.json index 03dea210c7155..77993cd1539ae 100644 --- a/tests/baselines/reference/library-reference-1.trace.json +++ b/tests/baselines/reference/library-reference-1.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory 'types'. ========", "Resolving with primary search path 'types'.", + "File 'types/jquery.d.ts' does not exist.", "File 'types/jquery/package.json' does not exist.", "File 'types/jquery/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'types/jquery/index.d.ts', result '/src/types/jquery/index.d.ts'.", diff --git a/tests/baselines/reference/library-reference-10.trace.json b/tests/baselines/reference/library-reference-10.trace.json index ac5bacd893326..42b70d0519540 100644 --- a/tests/baselines/reference/library-reference-10.trace.json +++ b/tests/baselines/reference/library-reference-10.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'jquery', containing file '/foo/consumer.ts', root directory './types'. ========", "Resolving with primary search path './types'.", + "File './types/jquery.d.ts' does not exist.", "Found 'package.json' at './types/jquery/package.json'.", "'package.json' does not have a 'typesVersions' field.", "'package.json' has 'typings' field 'jquery.d.ts' that references 'types/jquery/jquery.d.ts'.", diff --git a/tests/baselines/reference/library-reference-13.trace.json b/tests/baselines/reference/library-reference-13.trace.json index 70ebb87589937..c432daf6b44bd 100644 --- a/tests/baselines/reference/library-reference-13.trace.json +++ b/tests/baselines/reference/library-reference-13.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'jquery', containing file '/a/__inferred type names__.ts', root directory '/a/types'. ========", "Resolving with primary search path '/a/types'.", + "File '/a/types/jquery.d.ts' does not exist.", "File '/a/types/jquery/package.json' does not exist.", "File '/a/types/jquery/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/a/types/jquery/index.d.ts', result '/a/types/jquery/index.d.ts'.", diff --git a/tests/baselines/reference/library-reference-14.trace.json b/tests/baselines/reference/library-reference-14.trace.json index 70ebb87589937..c432daf6b44bd 100644 --- a/tests/baselines/reference/library-reference-14.trace.json +++ b/tests/baselines/reference/library-reference-14.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'jquery', containing file '/a/__inferred type names__.ts', root directory '/a/types'. ========", "Resolving with primary search path '/a/types'.", + "File '/a/types/jquery.d.ts' does not exist.", "File '/a/types/jquery/package.json' does not exist.", "File '/a/types/jquery/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/a/types/jquery/index.d.ts', result '/a/types/jquery/index.d.ts'.", diff --git a/tests/baselines/reference/library-reference-15.trace.json b/tests/baselines/reference/library-reference-15.trace.json index 0f76cf52984c7..6fbe14fc2211a 100644 --- a/tests/baselines/reference/library-reference-15.trace.json +++ b/tests/baselines/reference/library-reference-15.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'jquery', containing file '/a/__inferred type names__.ts', root directory 'types'. ========", "Resolving with primary search path 'types'.", + "File 'types/jquery.d.ts' does not exist.", "File 'types/jquery/package.json' does not exist.", "File 'types/jquery/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'types/jquery/index.d.ts', result '/a/types/jquery/index.d.ts'.", diff --git a/tests/baselines/reference/library-reference-2.trace.json b/tests/baselines/reference/library-reference-2.trace.json index da8ad8d4e5577..c3e4c231894f4 100644 --- a/tests/baselines/reference/library-reference-2.trace.json +++ b/tests/baselines/reference/library-reference-2.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/jquery.d.ts' does not exist.", "Found 'package.json' at '/types/jquery/package.json'.", "'package.json' does not have a 'typesVersions' field.", "'package.json' does not have a 'typings' field.", @@ -10,6 +11,7 @@ "======== Type reference directive 'jquery' was successfully resolved to '/types/jquery/jquery.d.ts', primary: true. ========", "======== Resolving type reference directive 'jquery', containing file '/test/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/jquery.d.ts' does not exist.", "File '/types/jquery/package.json' exists according to earlier cached lookups.", "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", diff --git a/tests/baselines/reference/library-reference-4.trace.json b/tests/baselines/reference/library-reference-4.trace.json index ceeb754bb0bdd..80f4da9461e7c 100644 --- a/tests/baselines/reference/library-reference-4.trace.json +++ b/tests/baselines/reference/library-reference-4.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'foo', containing file '/src/root.ts', root directory '/src'. ========", "Resolving with primary search path '/src'.", + "File '/src/foo.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/src'.", "Directory '/src/node_modules' does not exist, skipping all lookups in it.", "File '/node_modules/foo/package.json' does not exist.", @@ -10,6 +11,7 @@ "======== Type reference directive 'foo' was successfully resolved to '/node_modules/foo/index.d.ts', primary: false. ========", "======== Resolving type reference directive 'bar', containing file '/src/root.ts', root directory '/src'. ========", "Resolving with primary search path '/src'.", + "File '/src/bar.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/src'.", "Directory '/src/node_modules' does not exist, skipping all lookups in it.", "File '/node_modules/bar/package.json' does not exist.", @@ -19,6 +21,7 @@ "======== Type reference directive 'bar' was successfully resolved to '/node_modules/bar/index.d.ts', primary: false. ========", "======== Resolving type reference directive 'alpha', containing file '/node_modules/foo/index.d.ts', root directory '/src'. ========", "Resolving with primary search path '/src'.", + "File '/src/alpha.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/node_modules/foo'.", "File '/node_modules/foo/node_modules/alpha/package.json' does not exist.", "File '/node_modules/foo/node_modules/alpha.d.ts' does not exist.", @@ -27,6 +30,7 @@ "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/foo/node_modules/alpha/index.d.ts', primary: false. ========", "======== Resolving type reference directive 'alpha', containing file '/node_modules/bar/index.d.ts', root directory '/src'. ========", "Resolving with primary search path '/src'.", + "File '/src/alpha.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/node_modules/bar'.", "File '/node_modules/bar/node_modules/alpha/package.json' does not exist.", "File '/node_modules/bar/node_modules/alpha.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-8.trace.json b/tests/baselines/reference/library-reference-8.trace.json index 4d5f694c93495..25f8a6a4a7fe3 100644 --- a/tests/baselines/reference/library-reference-8.trace.json +++ b/tests/baselines/reference/library-reference-8.trace.json @@ -1,24 +1,28 @@ [ "======== Resolving type reference directive 'alpha', containing file '/test/foo.ts', root directory '/test/types'. ========", "Resolving with primary search path '/test/types'.", + "File '/test/types/alpha.d.ts' does not exist.", "File '/test/types/alpha/package.json' does not exist.", "File '/test/types/alpha/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/test/types/alpha/index.d.ts', result '/test/types/alpha/index.d.ts'.", "======== Type reference directive 'alpha' was successfully resolved to '/test/types/alpha/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'beta', containing file '/test/foo.ts', root directory '/test/types'. ========", "Resolving with primary search path '/test/types'.", + "File '/test/types/beta.d.ts' does not exist.", "File '/test/types/beta/package.json' does not exist.", "File '/test/types/beta/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/test/types/beta/index.d.ts', result '/test/types/beta/index.d.ts'.", "======== Type reference directive 'beta' was successfully resolved to '/test/types/beta/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'beta', containing file '/test/types/alpha/index.d.ts', root directory '/test/types'. ========", "Resolving with primary search path '/test/types'.", + "File '/test/types/beta.d.ts' does not exist.", "File '/test/types/beta/package.json' does not exist according to earlier cached lookups.", "File '/test/types/beta/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/test/types/beta/index.d.ts', result '/test/types/beta/index.d.ts'.", "======== Type reference directive 'beta' was successfully resolved to '/test/types/beta/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'alpha', containing file '/test/types/beta/index.d.ts', root directory '/test/types'. ========", "Resolving with primary search path '/test/types'.", + "File '/test/types/alpha.d.ts' does not exist.", "File '/test/types/alpha/package.json' does not exist according to earlier cached lookups.", "File '/test/types/alpha/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/test/types/alpha/index.d.ts', result '/test/types/alpha/index.d.ts'.", diff --git a/tests/baselines/reference/library-reference-scoped-packages.trace.json b/tests/baselines/reference/library-reference-scoped-packages.trace.json index cfc8819820182..f9ee441141008 100644 --- a/tests/baselines/reference/library-reference-scoped-packages.trace.json +++ b/tests/baselines/reference/library-reference-scoped-packages.trace.json @@ -1,7 +1,7 @@ [ "======== Resolving type reference directive '@beep/boop', containing file '/a.ts', root directory 'types'. ========", "Resolving with primary search path 'types'.", - "Directory 'types/@beep' does not exist, skipping all lookups in it.", + "Directory 'types' does not exist, skipping all lookups in it.", "Looking up in 'node_modules' folder, initial location '/'.", "Scoped package detected, looking in 'beep__boop'", "File '/node_modules/@types/beep__boop/package.json' does not exist.", diff --git a/tests/baselines/reference/moduleResolution/type-reference-from-primary-location.js b/tests/baselines/reference/moduleResolution/type-reference-from-primary-location.js index b00b634abd1fa..f244e93ac5d46 100644 --- a/tests/baselines/reference/moduleResolution/type-reference-from-primary-location.js +++ b/tests/baselines/reference/moduleResolution/type-reference-from-primary-location.js @@ -12,6 +12,7 @@ Resolution:: { "isExternalLibraryImport": false }, "failedLookupLocations": [ + "/root/src/types/lib.d.ts", "/root/src/types/lib/package.json" ], "affectingLocations": [], @@ -34,7 +35,9 @@ Resolution:: { "resolvedFileName": "/root/src/types/lib/typings/lib.d.ts", "isExternalLibraryImport": false }, - "failedLookupLocations": [], + "failedLookupLocations": [ + "/root/src/types/lib.d.ts" + ], "affectingLocations": [ "/root/src/types/lib/package.json" ], @@ -55,6 +58,7 @@ Resolution:: { "isExternalLibraryImport": true }, "failedLookupLocations": [ + "/root/src/types/lib.d.ts", "/root/src/types/lib/package.json", "/root/src/types/lib/index.d.ts", "/root/src/node_modules/lib/package.json", @@ -81,6 +85,7 @@ Resolution:: { "isExternalLibraryImport": true }, "failedLookupLocations": [ + "/root/src/types/lib.d.ts", "/root/src/types/lib/package.json", "/root/src/types/lib/index.d.ts", "/root/src/node_modules/lib.d.ts" @@ -105,6 +110,7 @@ Resolution:: { "isExternalLibraryImport": true }, "failedLookupLocations": [ + "/root/src/types/lib.d.ts", "/root/src/types/lib/package.json", "/root/src/types/lib/index.d.ts", "/root/src/node_modules/lib/package.json", @@ -134,6 +140,7 @@ Resolution:: { "isExternalLibraryImport": true }, "failedLookupLocations": [ + "/root/src/types/lib.d.ts", "/root/src/types/lib/package.json", "/root/src/types/lib/index.d.ts", "/root/src/node_modules/lib/package.json", diff --git a/tests/baselines/reference/moduleResolution/type-reference-from-secondary-location.js b/tests/baselines/reference/moduleResolution/type-reference-from-secondary-location.js index 04c64b7a7d7a8..72cd01d10585d 100644 --- a/tests/baselines/reference/moduleResolution/type-reference-from-secondary-location.js +++ b/tests/baselines/reference/moduleResolution/type-reference-from-secondary-location.js @@ -12,6 +12,7 @@ Resolution:: { "isExternalLibraryImport": true }, "failedLookupLocations": [ + "/root/src/types/lib.d.ts", "/root/src/types/lib/package.json", "/root/src/types/lib/index.d.ts", "/root/src/node_modules/lib/package.json", @@ -40,6 +41,7 @@ Resolution:: { "isExternalLibraryImport": true }, "failedLookupLocations": [ + "/root/src/types/lib.d.ts", "/root/src/types/lib/package.json", "/root/src/types/lib/index.d.ts", "/root/src/node_modules/lib/package.json", @@ -72,6 +74,7 @@ Resolution:: { "isExternalLibraryImport": true }, "failedLookupLocations": [ + "/root/src/types/lib.d.ts", "/root/src/types/lib/package.json", "/root/src/types/lib/index.d.ts", "/root/src/node_modules/lib/package.json", @@ -102,6 +105,7 @@ Resolution:: { "isExternalLibraryImport": true }, "failedLookupLocations": [ + "/root/src/types/lib.d.ts", "/root/src/types/lib/package.json", "/root/src/types/lib/index.d.ts", "/root/src/node_modules/lib/package.json", @@ -137,6 +141,7 @@ Resolution:: { "isExternalLibraryImport": true }, "failedLookupLocations": [ + "/root/src/types/lib.d.ts", "/root/src/types/lib/package.json", "/root/src/types/lib/index.d.ts", "/root/src/node_modules/lib/package.json", diff --git a/tests/baselines/reference/moduleResolution/type-reference-overrides-secondary-location.js b/tests/baselines/reference/moduleResolution/type-reference-overrides-secondary-location.js index 2ada305086654..0dc6cdbb194b9 100644 --- a/tests/baselines/reference/moduleResolution/type-reference-overrides-secondary-location.js +++ b/tests/baselines/reference/moduleResolution/type-reference-overrides-secondary-location.js @@ -15,6 +15,7 @@ Resolution:: { "isExternalLibraryImport": false }, "failedLookupLocations": [ + "/root/src/types/lib.d.ts", "/root/src/types/lib/package.json" ], "affectingLocations": [], diff --git a/tests/baselines/reference/tsbuild/moduleResolution/type-reference-resolution-uses-correct-options-for-different-resolution-options-referenced-project.js b/tests/baselines/reference/tsbuild/moduleResolution/type-reference-resolution-uses-correct-options-for-different-resolution-options-referenced-project.js index be7128c25e2e8..b8ae1da9608b4 100644 --- a/tests/baselines/reference/tsbuild/moduleResolution/type-reference-resolution-uses-correct-options-for-different-resolution-options-referenced-project.js +++ b/tests/baselines/reference/tsbuild/moduleResolution/type-reference-resolution-uses-correct-options-for-different-resolution-options-referenced-project.js @@ -46,6 +46,7 @@ Output:: ======== Resolving type reference directive 'sometype', containing file '/src/packages/__inferred type names__.ts', root directory '/src/packages/typeroot1'. ======== Resolving with primary search path '/src/packages/typeroot1'. +File '/src/packages/typeroot1/sometype.d.ts' does not exist. File '/src/packages/typeroot1/sometype/package.json' does not exist. File '/src/packages/typeroot1/sometype/index.d.ts' exist - use it as a name resolution result. Resolving real path for '/src/packages/typeroot1/sometype/index.d.ts', result '/src/packages/typeroot1/sometype/index.d.ts'. @@ -56,6 +57,7 @@ Resolving real path for '/src/packages/typeroot1/sometype/index.d.ts', result '/ ======== Resolving type reference directive 'sometype', containing file '/src/packages/__inferred type names__.ts', root directory '/src/packages/typeroot2'. ======== Resolving with primary search path '/src/packages/typeroot2'. +File '/src/packages/typeroot2/sometype.d.ts' does not exist. File '/src/packages/typeroot2/sometype/package.json' does not exist. File '/src/packages/typeroot2/sometype/index.d.ts' exist - use it as a name resolution result. Resolving real path for '/src/packages/typeroot2/sometype/index.d.ts', result '/src/packages/typeroot2/sometype/index.d.ts'. diff --git a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.errors.txt b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.errors.txt deleted file mode 100644 index 0e34e0fcb8190..0000000000000 --- a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -error TS2688: Cannot find type definition file for 'phaser'. - The file is in the program because: - Entry point of type library 'phaser' specified in compilerOptions -/a.ts(1,1): error TS2304: Cannot find name 'a'. - - -!!! error TS2688: Cannot find type definition file for 'phaser'. -!!! error TS2688: The file is in the program because: -!!! error TS2688: Entry point of type library 'phaser' specified in compilerOptions -==== /a.ts (1 errors) ==== - a; - ~ -!!! error TS2304: Cannot find name 'a'. - -==== /node_modules/phaser/types/phaser.d.ts (0 errors) ==== - declare const a: number; - \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.symbols b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.symbols index e803f8614d33e..f29a1bafe2741 100644 --- a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.symbols +++ b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.symbols @@ -1,4 +1,8 @@ === /a.ts === - a; +>a : Symbol(a, Decl(phaser.d.ts, 0, 13)) + +=== /node_modules/phaser/types/phaser.d.ts === +declare const a: number; +>a : Symbol(a, Decl(phaser.d.ts, 0, 13)) diff --git a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.trace.json b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.trace.json index e3c356a07350d..7bd67878a222f 100644 --- a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.trace.json +++ b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.trace.json @@ -1,10 +1,8 @@ [ "======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/node_modules/phaser/types'. ========", "Resolving with primary search path '/node_modules/phaser/types'.", - "Looking up in 'node_modules' folder, initial location '/'.", + "File '/node_modules/phaser/types/phaser.d.ts' exist - use it as a name resolution result.", "File '/node_modules/phaser/package.json' does not exist.", - "File '/node_modules/phaser.d.ts' does not exist.", - "File '/node_modules/phaser/index.d.ts' does not exist.", - "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", - "======== Type reference directive 'phaser' was not resolved. ========" + "Resolving real path for '/node_modules/phaser/types/phaser.d.ts', result '/node_modules/phaser/types/phaser.d.ts'.", + "======== Type reference directive 'phaser' was successfully resolved to '/node_modules/phaser/types/phaser.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.types b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.types index 2ec6ffcf1be41..20416fc921d6d 100644 --- a/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.types +++ b/tests/baselines/reference/typeReferenceDirectiveWithTypeAsFile.types @@ -1,4 +1,8 @@ === /a.ts === a; ->a : any +>a : number + +=== /node_modules/phaser/types/phaser.d.ts === +declare const a: number; +>a : number diff --git a/tests/baselines/reference/typeReferenceDirectives1.trace.json b/tests/baselines/reference/typeReferenceDirectives1.trace.json index 8be3b668a2bd8..66ae0a4816bd9 100644 --- a/tests/baselines/reference/typeReferenceDirectives1.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives1.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives10.trace.json b/tests/baselines/reference/typeReferenceDirectives10.trace.json index 7d52d66a6b411..bd94becc638fc 100644 --- a/tests/baselines/reference/typeReferenceDirectives10.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives10.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives11.trace.json b/tests/baselines/reference/typeReferenceDirectives11.trace.json index 38aa6ed8a53b2..12a5a19486c37 100644 --- a/tests/baselines/reference/typeReferenceDirectives11.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives11.trace.json @@ -6,6 +6,7 @@ "======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives12.trace.json b/tests/baselines/reference/typeReferenceDirectives12.trace.json index cd97596ba13b8..253ad31734b65 100644 --- a/tests/baselines/reference/typeReferenceDirectives12.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives12.trace.json @@ -11,6 +11,7 @@ "======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/mod1.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives13.trace.json b/tests/baselines/reference/typeReferenceDirectives13.trace.json index 7d52d66a6b411..bd94becc638fc 100644 --- a/tests/baselines/reference/typeReferenceDirectives13.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives13.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives2.trace.json b/tests/baselines/reference/typeReferenceDirectives2.trace.json index 47ae2761584fe..9d997c946407c 100644 --- a/tests/baselines/reference/typeReferenceDirectives2.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives2.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives3.trace.json b/tests/baselines/reference/typeReferenceDirectives3.trace.json index 8be3b668a2bd8..66ae0a4816bd9 100644 --- a/tests/baselines/reference/typeReferenceDirectives3.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives3.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives4.trace.json b/tests/baselines/reference/typeReferenceDirectives4.trace.json index 8be3b668a2bd8..66ae0a4816bd9 100644 --- a/tests/baselines/reference/typeReferenceDirectives4.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives4.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives5.trace.json b/tests/baselines/reference/typeReferenceDirectives5.trace.json index 7d52d66a6b411..bd94becc638fc 100644 --- a/tests/baselines/reference/typeReferenceDirectives5.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives5.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives6.trace.json b/tests/baselines/reference/typeReferenceDirectives6.trace.json index 8be3b668a2bd8..66ae0a4816bd9 100644 --- a/tests/baselines/reference/typeReferenceDirectives6.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives6.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives7.trace.json b/tests/baselines/reference/typeReferenceDirectives7.trace.json index 8be3b668a2bd8..66ae0a4816bd9 100644 --- a/tests/baselines/reference/typeReferenceDirectives7.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives7.trace.json @@ -1,6 +1,7 @@ [ "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives8.trace.json b/tests/baselines/reference/typeReferenceDirectives8.trace.json index 38aa6ed8a53b2..12a5a19486c37 100644 --- a/tests/baselines/reference/typeReferenceDirectives8.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives8.trace.json @@ -6,6 +6,7 @@ "======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", diff --git a/tests/baselines/reference/typeReferenceDirectives9.trace.json b/tests/baselines/reference/typeReferenceDirectives9.trace.json index cd97596ba13b8..253ad31734b65 100644 --- a/tests/baselines/reference/typeReferenceDirectives9.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives9.trace.json @@ -11,6 +11,7 @@ "======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/mod1.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", + "File '/types/lib.d.ts' does not exist.", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'.", From 4ea628e90723738b9d13e4048ff1febc6e86cf22 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 22 Nov 2022 21:25:39 -0800 Subject: [PATCH 3/6] Test to show even when typeRoots are specified, resolution falls back to node_modules in nearest directory --- ...eReferenceDirectiveWithFailedFromTypeRoot.js | 16 ++++++++++++++++ ...renceDirectiveWithFailedFromTypeRoot.symbols | 8 ++++++++ ...ceDirectiveWithFailedFromTypeRoot.trace.json | 14 ++++++++++++++ ...ferenceDirectiveWithFailedFromTypeRoot.types | 8 ++++++++ ...eReferenceDirectiveWithFailedFromTypeRoot.ts | 17 +++++++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.js create mode 100644 tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.symbols create mode 100644 tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.trace.json create mode 100644 tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.types create mode 100644 tests/cases/compiler/typeReferenceDirectiveWithFailedFromTypeRoot.ts diff --git a/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.js b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.js new file mode 100644 index 0000000000000..ca6fb691a224b --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/typeReferenceDirectiveWithFailedFromTypeRoot.ts] //// + +//// [dummy.d.ts] +declare const a2: number; + +//// [phaser.d.ts] +declare const a: number; + +//// [package.json] +{ "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" } + +//// [a.ts] +a; + +//// [a.js] +a; diff --git a/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.symbols b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.symbols new file mode 100644 index 0000000000000..f29a1bafe2741 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.symbols @@ -0,0 +1,8 @@ +=== /a.ts === +a; +>a : Symbol(a, Decl(phaser.d.ts, 0, 13)) + +=== /node_modules/phaser/types/phaser.d.ts === +declare const a: number; +>a : Symbol(a, Decl(phaser.d.ts, 0, 13)) + diff --git a/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.trace.json b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.trace.json new file mode 100644 index 0000000000000..3374d83d78e5b --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.trace.json @@ -0,0 +1,14 @@ +[ + "======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/typings'. ========", + "Resolving with primary search path '/typings'.", + "File '/typings/phaser.d.ts' does not exist.", + "Looking up in 'node_modules' folder, initial location '/'.", + "Found 'package.json' at '/node_modules/phaser/package.json'.", + "'package.json' does not have a 'typesVersions' field.", + "File '/node_modules/phaser.d.ts' does not exist.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'types/phaser.d.ts' that references '/node_modules/phaser/types/phaser.d.ts'.", + "File '/node_modules/phaser/types/phaser.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/phaser/types/phaser.d.ts', result '/node_modules/phaser/types/phaser.d.ts'.", + "======== Type reference directive 'phaser' was successfully resolved to '/node_modules/phaser/types/phaser.d.ts' with Package ID 'phaser/types/phaser.d.ts@1.2.3', primary: false. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.types b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.types new file mode 100644 index 0000000000000..20416fc921d6d --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.types @@ -0,0 +1,8 @@ +=== /a.ts === +a; +>a : number + +=== /node_modules/phaser/types/phaser.d.ts === +declare const a: number; +>a : number + diff --git a/tests/cases/compiler/typeReferenceDirectiveWithFailedFromTypeRoot.ts b/tests/cases/compiler/typeReferenceDirectiveWithFailedFromTypeRoot.ts new file mode 100644 index 0000000000000..eec8f38a6dd8f --- /dev/null +++ b/tests/cases/compiler/typeReferenceDirectiveWithFailedFromTypeRoot.ts @@ -0,0 +1,17 @@ +// @noImplicitReferences: true +// @typeRoots: /typings +// @types: phaser +// @traceResolution: true +// @currentDirectory: / + +// @Filename: /typings/dummy.d.ts +declare const a2: number; + +// @Filename: /node_modules/phaser/types/phaser.d.ts +declare const a: number; + +// @Filename: /node_modules/phaser/package.json +{ "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" } + +// @Filename: /a.ts +a; \ No newline at end of file From 40bb75c8f5273d5cd379c97cb683f08a04947b58 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 22 Nov 2022 21:50:28 -0800 Subject: [PATCH 4/6] Auto type reference directive shouldnt lookup in node_modules Fixes #37708 Bug 1 part of the issue --- src/compiler/diagnosticMessages.json | 4 + src/compiler/moduleNameResolver.ts | 41 +++--- src/compiler/resolutionCache.ts | 53 ++++---- src/compiler/types.ts | 1 - src/server/project.ts | 2 +- .../unittests/tscWatch/programUpdates.ts | 54 ++++---- .../unittests/tsserver/resolutionCache.ts | 47 ++++--- .../reference/api/tsserverlibrary.d.ts | 1 - tests/baselines/reference/api/typescript.d.ts | 1 - .../reference/library-reference-11.trace.json | 5 +- .../reference/library-reference-12.trace.json | 5 +- .../reference/library-reference-3.trace.json | 6 +- .../reference/library-reference-7.trace.json | 5 +- ...onWithSymlinks_preserveSymlinks.trace.json | 6 +- .../nodeModulesAtTypesPriority.trace.json | 10 +- ...iffers-between-projects-for-shared-file.js | 10 +- .../with-nodeNext-resolution.js | 4 +- .../type-reference-resolutions-reuse.js | 28 ++-- ...-from-config-file-path-if-config-exists.js | 4 +- ...exists-but-does-not-specifies-typeRoots.js | 75 ++++++++++ .../reusing-type-ref-resolution.js | 21 ++- ...-file-with-case-insensitive-file-system.js | 128 +++++++++--------- ...ig-file-with-case-sensitive-file-system.js | 128 +++++++++--------- ...-from-config-file-path-if-config-exists.js | 61 +++++++++ ...exists-but-does-not-specifies-typeRoots.js | 55 ++++++++ ...DirectiveWithFailedFromTypeRoot.errors.txt | 22 +++ ...nceDirectiveWithFailedFromTypeRoot.symbols | 7 +- ...DirectiveWithFailedFromTypeRoot.trace.json | 11 +- ...renceDirectiveWithFailedFromTypeRoot.types | 6 +- ...mMultipleNodeModulesDirectories.trace.json | 15 +- ...romNodeModulesInParentDirectory.trace.json | 5 +- 31 files changed, 527 insertions(+), 294 deletions(-) create mode 100644 tests/baselines/reference/tscWatch/programUpdates/types-should-not-load-from-config-file-path-if-config-exists-but-does-not-specifies-typeRoots.js create mode 100644 tests/baselines/reference/tsserver/resolutionCache/types-should-load-from-config-file-path-if-config-exists.js create mode 100644 tests/baselines/reference/tsserver/resolutionCache/types-should-not-load-from-config-file-path-if-config-exists-but-does-not-specifies-typeRoots.js create mode 100644 tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.errors.txt diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e146cce88c8cb..33f81cc7940c9 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5154,6 +5154,10 @@ "category": "Message", "code": 6261 }, + "Resolving type reference directive for program that specifies custom typeRoots, skipping lookup in 'node_modules' folder.": { + "category": "Message", + "code": 6262 + }, "Directory '{0}' has no containing package.json scope. Imports will not resolve.": { "category": "Message", diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index f187609b249b2..a2d184c9b59a9 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -54,6 +54,7 @@ import { hasProperty, hasTrailingDirectorySeparator, hostGetCanonicalFileName, + inferredTypesContainingFile, isArray, isExternalModuleNameRelative, isRootedDiskPath, @@ -396,7 +397,7 @@ export function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffecti } if (currentDirectory !== undefined) { - return getDefaultTypeRoots(currentDirectory, host); + return getDefaultTypeRoots(currentDirectory); } } @@ -404,19 +405,11 @@ export function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffecti * Returns the path to every node_modules/@types directory from some ancestor directory. * Returns undefined if there are none. */ -function getDefaultTypeRoots(currentDirectory: string, host: { directoryExists?: (directoryName: string) => boolean }): string[] | undefined { - if (!host.directoryExists) { - return [combinePaths(currentDirectory, nodeModulesAtTypes)]; - // And if it doesn't exist, tough. - } - +function getDefaultTypeRoots(currentDirectory: string): string[] | undefined { let typeRoots: string[] | undefined; forEachAncestorDirectory(normalizePath(currentDirectory), directory => { const atTypes = combinePaths(directory, nodeModulesAtTypes); - if (host.directoryExists!(atTypes)) { - (typeRoots || (typeRoots = [])).push(atTypes); - } - return undefined; + (typeRoots ??= []).push(atTypes); }); return typeRoots; } @@ -576,20 +569,24 @@ export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string function secondaryLookup(): PathAndPackageId | undefined { const initialLocationForSecondaryLookup = containingFile && getDirectoryPath(containingFile); - if (initialLocationForSecondaryLookup !== undefined) { - // check secondary locations - if (traceEnabled) { - trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup); - } let result: Resolved | undefined; - if (!isExternalModuleNameRelative(typeReferenceDirectiveName)) { - const searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.Declaration, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined); - result = searchResult && searchResult.value; + if (!options.typeRoots || !endsWith(containingFile!, inferredTypesContainingFile)) { + // check secondary locations + if (traceEnabled) { + trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup); + } + if (!isExternalModuleNameRelative(typeReferenceDirectiveName)) { + const searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.Declaration, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined); + result = searchResult && searchResult.value; + } + else { + const { path: candidate } = normalizePathForCJSResolution(initialLocationForSecondaryLookup, typeReferenceDirectiveName); + result = nodeLoadModuleByRelativeName(Extensions.Declaration, candidate, /*onlyRecordFailures*/ false, moduleResolutionState, /*considerPackageJson*/ true); + } } - else { - const { path: candidate } = normalizePathForCJSResolution(initialLocationForSecondaryLookup, typeReferenceDirectiveName); - result = nodeLoadModuleByRelativeName(Extensions.Declaration, candidate, /*onlyRecordFailures*/ false, moduleResolutionState, /*considerPackageJson*/ true); + else if (traceEnabled) { + trace(host, Diagnostics.Resolving_type_reference_directive_for_program_that_specifies_custom_typeRoots_skipping_lookup_in_node_modules_folder); } return resolvedTypeScriptOnly(result); } diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index 90c45fc4ecf41..bc86cf2cdf446 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -1157,26 +1157,28 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD function createTypeRootsWatch(typeRootPath: Path, typeRoot: string): FileWatcher { // Create new watch and recursive info - return resolutionHost.watchTypeRootsDirectory(typeRoot, fileOrDirectory => { - const fileOrDirectoryPath = resolutionHost.toPath(fileOrDirectory); - if (cachedDirectoryStructureHost) { - // Since the file existence changed, update the sourceFiles cache - cachedDirectoryStructureHost.addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath); - } - - // For now just recompile - // We could potentially store more data here about whether it was/would be really be used or not - // and with that determine to trigger compilation but for now this is enough - hasChangedAutomaticTypeDirectiveNames = true; - resolutionHost.onChangedAutomaticTypeDirectiveNames(); + return canWatchTypeRootPath(typeRootPath) ? + resolutionHost.watchTypeRootsDirectory(typeRoot, fileOrDirectory => { + const fileOrDirectoryPath = resolutionHost.toPath(fileOrDirectory); + if (cachedDirectoryStructureHost) { + // Since the file existence changed, update the sourceFiles cache + cachedDirectoryStructureHost.addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath); + } - // Since directory watchers invoked are flaky, the failed lookup location events might not be triggered - // So handle to failed lookup locations here as well to ensure we are invalidating resolutions - const dirPath = getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath); - if (dirPath) { - scheduleInvalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath); - } - }, WatchDirectoryFlags.Recursive); + // For now just recompile + // We could potentially store more data here about whether it was/would be really be used or not + // and with that determine to trigger compilation but for now this is enough + hasChangedAutomaticTypeDirectiveNames = true; + resolutionHost.onChangedAutomaticTypeDirectiveNames(); + + // Since directory watchers invoked are flaky, the failed lookup location events might not be triggered + // So handle to failed lookup locations here as well to ensure we are invalidating resolutions + const dirPath = getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath); + if (dirPath) { + scheduleInvalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath); + } + }, WatchDirectoryFlags.Recursive) : + noopFileWatcher; } /** @@ -1194,7 +1196,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD // we need to assume the directories exist to ensure that we can get all the type root directories that get included // But filter directories that are at root level to say directory doesnt exist, so that we arent watching them - const typeRoots = getEffectiveTypeRoots(options, { directoryExists: directoryExistsForTypeRootWatch, getCurrentDirectory }); + const typeRoots = getEffectiveTypeRoots(options, { getCurrentDirectory }); if (typeRoots) { mutateMap( typeRootsWatches, @@ -1210,12 +1212,11 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD } } - /** - * Use this function to return if directory exists to get type roots to watch - * If we return directory exists then only the paths will be added to type roots - * Hence return true for all directories except root directories which are filtered from watching - */ - function directoryExistsForTypeRootWatch(nodeTypesDirectory: string) { + function canWatchTypeRootPath(nodeTypesDirectory: string) { + // If type roots is specified, watch that path + if (resolutionHost.getCompilationSettings().typeRoots) return true; + + // Otherwise can watch directory only if we can watch the parent directory of node_modules/@types const dir = getDirectoryPath(getDirectoryPath(nodeTypesDirectory)); const dirPath = resolutionHost.toPath(dir); return dirPath === rootPath || canWatchDirectoryOrFile(dirPath); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7ce54d3dd6c02..d8da069b73824 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -9049,7 +9049,6 @@ export interface EmitTextWriter extends SymbolWriter { } export interface GetEffectiveTypeRootsHost { - directoryExists?(directoryName: string): boolean; getCurrentDirectory?(): string; } diff --git a/src/server/project.ts b/src/server/project.ts index dcce4777002b2..c1e1e4cb2490c 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -2825,7 +2825,7 @@ export class ConfiguredProject extends Project { } getEffectiveTypeRoots() { - return getEffectiveTypeRoots(this.getCompilationSettings(), this.directoryStructureHost) || []; + return getEffectiveTypeRoots(this.getCompilationSettings(), this) || []; } /** @internal */ diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index ff58abc4c85ce..633a33935068b 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -937,29 +937,37 @@ declare const eval: any` ] }); - verifyTscWatch({ - scenario, - subScenario: "types should load from config file path if config exists", - commandLineArgs: ["-w", "-p", configFilePath], - sys: () => { - const f1 = { - path: "/a/b/app.ts", - content: "let x = 1" - }; - const config = { - path: configFilePath, - content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: [] } }) - }; - const node = { - path: "/a/b/node_modules/@types/node/index.d.ts", - content: "declare var process: any" - }; - const cwd = { - path: "/a/c" - }; - return createWatchedSystem([f1, config, node, cwd, libFile], { currentDirectory: cwd.path }); - }, - changes: ts.emptyArray + describe("types from config file", () => { + function verifyTypesLoad(includeTypeRoots: boolean) { + verifyTscWatch({ + scenario, + subScenario: includeTypeRoots ? + "types should not load from config file path if config exists but does not specifies typeRoots" : + "types should load from config file path if config exists", + commandLineArgs: ["-w", "-p", configFilePath], + sys: () => { + const f1 = { + path: "/a/b/app.ts", + content: "let x = 1" + }; + const config = { + path: configFilePath, + content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: includeTypeRoots ? [] : undefined } }) + }; + const node = { + path: "/a/b/node_modules/@types/node/index.d.ts", + content: "declare var process: any" + }; + const cwd = { + path: "/a/c" + }; + return createWatchedSystem([f1, config, node, cwd, libFile], { currentDirectory: cwd.path }); + }, + changes: ts.emptyArray + }); + } + verifyTypesLoad(/*includeTypeRoots*/ false); + verifyTypesLoad(/*includeTypeRoots*/ true); }); verifyTscWatch({ diff --git a/src/testRunner/unittests/tsserver/resolutionCache.ts b/src/testRunner/unittests/tsserver/resolutionCache.ts index 29e9f7b33339a..3558f19aac898 100644 --- a/src/testRunner/unittests/tsserver/resolutionCache.ts +++ b/src/testRunner/unittests/tsserver/resolutionCache.ts @@ -345,27 +345,32 @@ describe("unittests:: tsserver:: resolutionCache:: tsserverProjectSystem rename projectService.checkNumberOfProjects({ configuredProjects: 1 }); }); - it("types should load from config file path if config exists", () => { - const f1 = { - path: "/a/b/app.ts", - content: "let x = 1" - }; - const config = { - path: "/a/b/tsconfig.json", - content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: [] } }) - }; - const node = { - path: "/a/b/node_modules/@types/node/index.d.ts", - content: "declare var process: any" - }; - const cwd = { - path: "/a/c" - }; - const host = createServerHost([f1, config, node, cwd], { currentDirectory: cwd.path }); - const projectService = createProjectService(host); - projectService.openClientFile(f1.path); - projectService.checkNumberOfProjects({ configuredProjects: 1 }); - checkProjectActualFiles(configuredProjectAt(projectService, 0), [f1.path, node.path, config.path]); + describe("types from config file", () => { + function verifyTypesLoad(subScenario: string, includeTypeRoots: boolean) { + it(subScenario, () => { + const f1 = { + path: "/a/b/app.ts", + content: "let x = 1" + }; + const config = { + path: "/a/b/tsconfig.json", + content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: includeTypeRoots ? [] : undefined } }) + }; + const node = { + path: "/a/b/node_modules/@types/node/index.d.ts", + content: "declare var process: any" + }; + const cwd = { + path: "/a/c" + }; + const host = createServerHost([f1, config, node, cwd], { currentDirectory: cwd.path }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); + projectService.openClientFile(f1.path); + baselineTsserverLogs("resolutionCache", subScenario, projectService); + }); + } + verifyTypesLoad("types should load from config file path if config exists", /*includeTypeRoots*/ false); + verifyTypesLoad("types should not load from config file path if config exists but does not specifies typeRoots", /*includeTypeRoots*/ true); }); }); diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index e3e8466ccd1e7..c1b613727b0bb 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -8258,7 +8258,6 @@ declare namespace ts { noEmitHelpers?: boolean; } interface GetEffectiveTypeRootsHost { - directoryExists?(directoryName: string): boolean; getCurrentDirectory?(): string; } interface TextSpan { diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 7bc06c330da8a..048facf320bcf 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4322,7 +4322,6 @@ declare namespace ts { noEmitHelpers?: boolean; } interface GetEffectiveTypeRootsHost { - directoryExists?(directoryName: string): boolean; getCurrentDirectory?(): string; } interface TextSpan { diff --git a/tests/baselines/reference/library-reference-11.trace.json b/tests/baselines/reference/library-reference-11.trace.json index b2121f15d5de8..7ff9d88916379 100644 --- a/tests/baselines/reference/library-reference-11.trace.json +++ b/tests/baselines/reference/library-reference-11.trace.json @@ -1,6 +1,7 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory not set. ========", - "Root directory cannot be determined, skipping primary search paths.", + "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'.", + "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Looking up in 'node_modules' folder, initial location '/a/b'.", "Directory '/a/b/node_modules' does not exist, skipping all lookups in it.", "Found 'package.json' at '/a/node_modules/jquery/package.json'.", diff --git a/tests/baselines/reference/library-reference-12.trace.json b/tests/baselines/reference/library-reference-12.trace.json index 0ff14204c620b..96d9b82fce124 100644 --- a/tests/baselines/reference/library-reference-12.trace.json +++ b/tests/baselines/reference/library-reference-12.trace.json @@ -1,6 +1,7 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory not set. ========", - "Root directory cannot be determined, skipping primary search paths.", + "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'.", + "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Looking up in 'node_modules' folder, initial location '/a/b'.", "Directory '/a/b/node_modules' does not exist, skipping all lookups in it.", "Found 'package.json' at '/a/node_modules/jquery/package.json'.", diff --git a/tests/baselines/reference/library-reference-3.trace.json b/tests/baselines/reference/library-reference-3.trace.json index 5b084f1373841..a848ff635c233 100644 --- a/tests/baselines/reference/library-reference-3.trace.json +++ b/tests/baselines/reference/library-reference-3.trace.json @@ -1,6 +1,8 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory not set. ========", - "Root directory cannot be determined, skipping primary search paths.", + "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory '/src/node_modules/@types,/node_modules/@types'. ========", + "Resolving with primary search path '/src/node_modules/@types, /node_modules/@types'.", + "Directory '/src/node_modules/@types' does not exist, skipping all lookups in it.", + "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Looking up in 'node_modules' folder, initial location '/src'.", "File '/src/node_modules/jquery/package.json' does not exist.", "File '/src/node_modules/jquery.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-7.trace.json b/tests/baselines/reference/library-reference-7.trace.json index 5b084f1373841..ccf7fbd91943a 100644 --- a/tests/baselines/reference/library-reference-7.trace.json +++ b/tests/baselines/reference/library-reference-7.trace.json @@ -1,6 +1,7 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory not set. ========", - "Root directory cannot be determined, skipping primary search paths.", + "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'.", + "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Looking up in 'node_modules' folder, initial location '/src'.", "File '/src/node_modules/jquery/package.json' does not exist.", "File '/src/node_modules/jquery.d.ts' does not exist.", diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_preserveSymlinks.trace.json b/tests/baselines/reference/moduleResolutionWithSymlinks_preserveSymlinks.trace.json index f45e3ce16dc27..bed2470cb0189 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks_preserveSymlinks.trace.json +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_preserveSymlinks.trace.json @@ -1,6 +1,8 @@ [ - "======== Resolving type reference directive 'linked', containing file '/app/app.ts', root directory not set. ========", - "Root directory cannot be determined, skipping primary search paths.", + "======== Resolving type reference directive 'linked', containing file '/app/app.ts', root directory 'node_modules/@types,/node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types, /node_modules/@types'.", + "Directory 'node_modules/@types' does not exist, skipping all lookups in it.", + "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Looking up in 'node_modules' folder, initial location '/app'.", "File '/app/node_modules/linked/package.json' does not exist.", "File '/app/node_modules/linked.d.ts' does not exist.", diff --git a/tests/baselines/reference/nodeModulesAtTypesPriority.trace.json b/tests/baselines/reference/nodeModulesAtTypesPriority.trace.json index 99f4fb69909e1..181007b461424 100644 --- a/tests/baselines/reference/nodeModulesAtTypesPriority.trace.json +++ b/tests/baselines/reference/nodeModulesAtTypesPriority.trace.json @@ -55,14 +55,16 @@ "File '/packages/a/node_modules/redux/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/packages/a/node_modules/redux/index.d.ts', result '/packages/a/node_modules/redux/index.d.ts'.", "======== Module name 'redux' was successfully resolved to '/packages/a/node_modules/redux/index.d.ts'. ========", - "======== Resolving type reference directive 'react', containing file '__inferred type names__.ts', root directory '/node_modules/@types'. ========", - "Resolving with primary search path '/node_modules/@types'.", + "======== Resolving type reference directive 'react', containing file '__inferred type names__.ts', root directory 'node_modules/@types,/node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types, /node_modules/@types'.", + "Directory 'node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/@types/react/package.json' does not exist according to earlier cached lookups.", "File '/node_modules/@types/react/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/@types/react/index.d.ts', result '/node_modules/@types/react/index.d.ts'.", "======== Type reference directive 'react' was successfully resolved to '/node_modules/@types/react/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'redux', containing file '__inferred type names__.ts', root directory '/node_modules/@types'. ========", - "Resolving with primary search path '/node_modules/@types'.", + "======== Resolving type reference directive 'redux', containing file '__inferred type names__.ts', root directory 'node_modules/@types,/node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types, /node_modules/@types'.", + "Directory 'node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/@types/redux/package.json' does not exist according to earlier cached lookups.", "File '/node_modules/@types/redux/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/@types/redux/index.d.ts', result '/node_modules/@types/redux/index.d.ts'.", diff --git a/tests/baselines/reference/tsbuild/moduleResolution/impliedNodeFormat-differs-between-projects-for-shared-file.js b/tests/baselines/reference/tsbuild/moduleResolution/impliedNodeFormat-differs-between-projects-for-shared-file.js index 91ca1d745305c..7b9ce35b75ee6 100644 --- a/tests/baselines/reference/tsbuild/moduleResolution/impliedNodeFormat-differs-between-projects-for-shared-file.js +++ b/tests/baselines/reference/tsbuild/moduleResolution/impliedNodeFormat-differs-between-projects-for-shared-file.js @@ -62,8 +62,9 @@ Output:: [12:00:24 AM] Building project '/src/projects/a/tsconfig.json'... -======== Resolving type reference directive 'pg', containing file '/src/projects/a/__inferred type names__.ts', root directory '/src/projects/node_modules/@types'. ======== -Resolving with primary search path '/src/projects/node_modules/@types'. +======== Resolving type reference directive 'pg', containing file '/src/projects/a/__inferred type names__.ts', root directory '/src/projects/a/node_modules/@types,/src/projects/node_modules/@types,/src/node_modules/@types,/node_modules/@types'. ======== +Resolving with primary search path '/src/projects/a/node_modules/@types, /src/projects/node_modules/@types, /src/node_modules/@types, /node_modules/@types'. +Directory '/src/projects/a/node_modules/@types' does not exist, skipping all lookups in it. Found 'package.json' at '/src/projects/node_modules/@types/pg/package.json'. 'package.json' does not have a 'typesVersions' field. 'package.json' does not have a 'typings' field. @@ -98,8 +99,9 @@ File '/src/projects/node_modules/@types/pg/index.d.ts' exist - use it as a name Resolving real path for '/src/projects/node_modules/@types/pg/index.d.ts', result '/src/projects/node_modules/@types/pg/index.d.ts'. ======== Module name 'pg' was successfully resolved to '/src/projects/node_modules/@types/pg/index.d.ts'. ======== File '/src/projects/node_modules/@types/pg/package.json' exists according to earlier cached lookups. -======== Resolving type reference directive 'pg', containing file '/src/projects/b/__inferred type names__.ts', root directory '/src/projects/node_modules/@types'. ======== -Resolving with primary search path '/src/projects/node_modules/@types'. +======== Resolving type reference directive 'pg', containing file '/src/projects/b/__inferred type names__.ts', root directory '/src/projects/b/node_modules/@types,/src/projects/node_modules/@types,/src/node_modules/@types,/node_modules/@types'. ======== +Resolving with primary search path '/src/projects/b/node_modules/@types, /src/projects/node_modules/@types, /src/node_modules/@types, /node_modules/@types'. +Directory '/src/projects/b/node_modules/@types' does not exist, skipping all lookups in it. File '/src/projects/node_modules/@types/pg/package.json' exists according to earlier cached lookups. 'package.json' does not have a 'typings' field. 'package.json' has 'types' field 'index.d.ts' that references '/src/projects/node_modules/@types/pg/index.d.ts'. diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js index 659af38551610..5c7f342816fea 100644 --- a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js @@ -62,8 +62,8 @@ File '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' exist - use Resolving real path for '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts', result '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts'. ======== Module name 'yargs' was successfully resolved to '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' with Package ID 'yargs/index.d.ts@17.0.12'. ======== File '/Users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. -======== Resolving type reference directive 'yargs', containing file '/Users/name/projects/web/__inferred type names__.ts', root directory '/Users/name/projects/web/node_modules/@types'. ======== -Resolving with primary search path '/Users/name/projects/web/node_modules/@types'. +======== Resolving type reference directive 'yargs', containing file '/Users/name/projects/web/__inferred type names__.ts', root directory '/Users/name/projects/web/node_modules/@types,/Users/name/projects/node_modules/@types,/Users/name/node_modules/@types,/Users/node_modules/@types,/node_modules/@types'. ======== +Resolving with primary search path '/Users/name/projects/web/node_modules/@types, /Users/name/projects/node_modules/@types, /Users/name/node_modules/@types, /Users/node_modules/@types, /node_modules/@types'. File '/Users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. 'package.json' does not have a 'typesVersions' field. 'package.json' does not have a 'typings' field. diff --git a/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js b/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js index cf940c33e9e8e..03a61f3598587 100644 --- a/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js +++ b/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js @@ -71,8 +71,12 @@ File '/user/username/projects/package.json' does not exist according to earlier File '/user/username/package.json' does not exist according to earlier cached lookups. File '/user/package.json' does not exist according to earlier cached lookups. File '/package.json' does not exist according to earlier cached lookups. -======== Resolving type reference directive 'pkg', containing file '/user/username/projects/myproject/index.ts', root directory '/user/username/projects/myproject/node_modules/@types'. ======== -Resolving with primary search path '/user/username/projects/myproject/node_modules/@types'. +======== Resolving type reference directive 'pkg', containing file '/user/username/projects/myproject/index.ts', root directory '/user/username/projects/myproject/node_modules/@types,/user/username/projects/node_modules/@types,/user/username/node_modules/@types,/user/node_modules/@types,/node_modules/@types'. ======== +Resolving with primary search path '/user/username/projects/myproject/node_modules/@types, /user/username/projects/node_modules/@types, /user/username/node_modules/@types, /user/node_modules/@types, /node_modules/@types'. +Directory '/user/username/projects/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/user/username/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/user/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/node_modules/@types' does not exist, skipping all lookups in it. Looking up in 'node_modules' folder, initial location '/user/username/projects/myproject'. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg/package.json'. Matched 'exports' condition 'import'. @@ -81,8 +85,12 @@ File name '/user/username/projects/myproject/node_modules/pkg/import.js' has a ' File '/user/username/projects/myproject/node_modules/pkg/import.d.ts' exist - use it as a name resolution result. Resolving real path for '/user/username/projects/myproject/node_modules/pkg/import.d.ts', result '/user/username/projects/myproject/node_modules/pkg/import.d.ts'. ======== Type reference directive 'pkg' was successfully resolved to '/user/username/projects/myproject/node_modules/pkg/import.d.ts' with Package ID 'pkg/import.d.ts@0.0.1', primary: false. ======== -======== Resolving type reference directive 'pkg1', containing file '/user/username/projects/myproject/index.ts', root directory '/user/username/projects/myproject/node_modules/@types'. ======== -Resolving with primary search path '/user/username/projects/myproject/node_modules/@types'. +======== Resolving type reference directive 'pkg1', containing file '/user/username/projects/myproject/index.ts', root directory '/user/username/projects/myproject/node_modules/@types,/user/username/projects/node_modules/@types,/user/username/node_modules/@types,/user/node_modules/@types,/node_modules/@types'. ======== +Resolving with primary search path '/user/username/projects/myproject/node_modules/@types, /user/username/projects/node_modules/@types, /user/username/node_modules/@types, /user/node_modules/@types, /node_modules/@types'. +Directory '/user/username/projects/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/user/username/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/user/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/node_modules/@types' does not exist, skipping all lookups in it. Looking up in 'node_modules' folder, initial location '/user/username/projects/myproject'. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg1/package.json'. Saw non-matching condition 'import'. @@ -97,8 +105,8 @@ Directory '/user/node_modules' does not exist, skipping all lookups in it. Directory '/node_modules' does not exist, skipping all lookups in it. ======== Type reference directive 'pkg1' was not resolved. ======== File '/user/username/projects/myproject/node_modules/pkg/package.json' exists according to earlier cached lookups. -======== Resolving type reference directive 'pkg2', containing file '/user/username/projects/myproject/__inferred type names__.ts', root directory '/user/username/projects/myproject/node_modules/@types'. ======== -Resolving with primary search path '/user/username/projects/myproject/node_modules/@types'. +======== Resolving type reference directive 'pkg2', containing file '/user/username/projects/myproject/__inferred type names__.ts', root directory '/user/username/projects/myproject/node_modules/@types,/user/username/projects/node_modules/@types,/user/username/node_modules/@types,/user/node_modules/@types,/node_modules/@types'. ======== +Resolving with primary search path '/user/username/projects/myproject/node_modules/@types, /user/username/projects/node_modules/@types, /user/username/node_modules/@types, /user/node_modules/@types, /node_modules/@types'. File '/user/username/projects/myproject/node_modules/@types/pkg2/package.json' does not exist. File '/user/username/projects/myproject/node_modules/@types/pkg2/index.d.ts' exist - use it as a name resolution result. Resolving real path for '/user/username/projects/myproject/node_modules/@types/pkg2/index.d.ts', result '/user/username/projects/myproject/node_modules/@types/pkg2/index.d.ts'. @@ -247,8 +255,12 @@ File '/user/username/projects/package.json' does not exist according to earlier File '/user/username/package.json' does not exist according to earlier cached lookups. File '/user/package.json' does not exist according to earlier cached lookups. File '/package.json' does not exist according to earlier cached lookups. -======== Resolving type reference directive 'pkg', containing file '/user/username/projects/myproject/a.ts', root directory '/user/username/projects/myproject/node_modules/@types'. ======== -Resolving with primary search path '/user/username/projects/myproject/node_modules/@types'. +======== Resolving type reference directive 'pkg', containing file '/user/username/projects/myproject/a.ts', root directory '/user/username/projects/myproject/node_modules/@types,/user/username/projects/node_modules/@types,/user/username/node_modules/@types,/user/node_modules/@types,/node_modules/@types'. ======== +Resolving with primary search path '/user/username/projects/myproject/node_modules/@types, /user/username/projects/node_modules/@types, /user/username/node_modules/@types, /user/node_modules/@types, /node_modules/@types'. +Directory '/user/username/projects/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/user/username/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/user/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/node_modules/@types' does not exist, skipping all lookups in it. Looking up in 'node_modules' folder, initial location '/user/username/projects/myproject'. File '/user/username/projects/myproject/node_modules/pkg/package.json' exists according to earlier cached lookups. Matched 'exports' condition 'import'. diff --git a/tests/baselines/reference/tscWatch/programUpdates/types-should-load-from-config-file-path-if-config-exists.js b/tests/baselines/reference/tscWatch/programUpdates/types-should-load-from-config-file-path-if-config-exists.js index 05d9c456981c7..f936e1d84722a 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/types-should-load-from-config-file-path-if-config-exists.js +++ b/tests/baselines/reference/tscWatch/programUpdates/types-should-load-from-config-file-path-if-config-exists.js @@ -3,7 +3,7 @@ Input:: let x = 1 //// [/a/b/tsconfig.json] -{"compilerOptions":{"types":["node"],"typeRoots":[]}} +{"compilerOptions":{"types":["node"]}} //// [/a/b/node_modules/@types/node/index.d.ts] declare var process: any @@ -32,7 +32,7 @@ Output:: Program root files: ["/a/b/app.ts"] -Program options: {"types":["node"],"typeRoots":[],"watch":true,"project":"/a/b/tsconfig.json","configFilePath":"/a/b/tsconfig.json"} +Program options: {"types":["node"],"watch":true,"project":"/a/b/tsconfig.json","configFilePath":"/a/b/tsconfig.json"} Program structureReused: Not Program files:: /a/lib/lib.d.ts diff --git a/tests/baselines/reference/tscWatch/programUpdates/types-should-not-load-from-config-file-path-if-config-exists-but-does-not-specifies-typeRoots.js b/tests/baselines/reference/tscWatch/programUpdates/types-should-not-load-from-config-file-path-if-config-exists-but-does-not-specifies-typeRoots.js new file mode 100644 index 0000000000000..fd38ef9c8cc28 --- /dev/null +++ b/tests/baselines/reference/tscWatch/programUpdates/types-should-not-load-from-config-file-path-if-config-exists-but-does-not-specifies-typeRoots.js @@ -0,0 +1,75 @@ +Input:: +//// [/a/b/app.ts] +let x = 1 + +//// [/a/b/tsconfig.json] +{"compilerOptions":{"types":["node"],"typeRoots":[]}} + +//// [/a/b/node_modules/@types/node/index.d.ts] +declare var process: any + +//// [/a/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + + +/a/lib/tsc.js -w -p /a/b/tsconfig.json +Output:: +>> Screen clear +[12:00:25 AM] Starting compilation in watch mode... + +error TS2688: Cannot find type definition file for 'node'. + The file is in the program because: + Entry point of type library 'node' specified in compilerOptions + + ../b/tsconfig.json:1:30 + 1 {"compilerOptions":{"types":["node"],"typeRoots":[]}} +    ~~~~~~ + File is entry point of type library specified here. + +[12:00:28 AM] Found 1 error. Watching for file changes. + + + +Program root files: ["/a/b/app.ts"] +Program options: {"types":["node"],"typeRoots":[],"watch":true,"project":"/a/b/tsconfig.json","configFilePath":"/a/b/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.d.ts +/a/b/app.ts + +No cached semantic diagnostics in the builder:: + +Shape signatures in builder refreshed for:: +/a/lib/lib.d.ts (used version) +/a/b/app.ts (used version) + +PolledWatches:: + +FsWatches:: +/a/b/tsconfig.json: + {} +/a/b/app.ts: + {} +/a/lib/lib.d.ts: + {} + +FsWatchesRecursive:: +/a/b: + {} + +exitCode:: ExitStatus.undefined + +//// [/a/b/app.js] +var x = 1; + + diff --git a/tests/baselines/reference/tscWatch/resolutionCache/reusing-type-ref-resolution.js b/tests/baselines/reference/tscWatch/resolutionCache/reusing-type-ref-resolution.js index 9d9b67ea03bb3..fd240c2c31756 100644 --- a/tests/baselines/reference/tscWatch/resolutionCache/reusing-type-ref-resolution.js +++ b/tests/baselines/reference/tscWatch/resolutionCache/reusing-type-ref-resolution.js @@ -74,16 +74,22 @@ Directory '/node_modules' does not exist, skipping all lookups in it. ======== Module name 'pkg1' was not resolved. ======== FileWatcher:: Added:: WatchInfo: /src/project/node_modules/pkg0/index.d.ts 250 undefined Source file FileWatcher:: Added:: WatchInfo: /src/project/fileWithTypeRefs.ts 250 undefined Source file -======== Resolving type reference directive 'pkg2', containing file '/src/project/fileWithTypeRefs.ts', root directory not set. ======== -Root directory cannot be determined, skipping primary search paths. +======== Resolving type reference directive 'pkg2', containing file '/src/project/fileWithTypeRefs.ts', root directory '/src/project/node_modules/@types,/src/node_modules/@types,/node_modules/@types'. ======== +Resolving with primary search path '/src/project/node_modules/@types, /src/node_modules/@types, /node_modules/@types'. +Directory '/src/project/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/src/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/node_modules/@types' does not exist, skipping all lookups in it. Looking up in 'node_modules' folder, initial location '/src/project'. File '/src/project/node_modules/pkg2/package.json' does not exist. File '/src/project/node_modules/pkg2.d.ts' does not exist. File '/src/project/node_modules/pkg2/index.d.ts' exist - use it as a name resolution result. Resolving real path for '/src/project/node_modules/pkg2/index.d.ts', result '/src/project/node_modules/pkg2/index.d.ts'. ======== Type reference directive 'pkg2' was successfully resolved to '/src/project/node_modules/pkg2/index.d.ts', primary: false. ======== -======== Resolving type reference directive 'pkg3', containing file '/src/project/fileWithTypeRefs.ts', root directory not set. ======== -Root directory cannot be determined, skipping primary search paths. +======== Resolving type reference directive 'pkg3', containing file '/src/project/fileWithTypeRefs.ts', root directory '/src/project/node_modules/@types,/src/node_modules/@types,/node_modules/@types'. ======== +Resolving with primary search path '/src/project/node_modules/@types, /src/node_modules/@types, /node_modules/@types'. +Directory '/src/project/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/src/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/node_modules/@types' does not exist, skipping all lookups in it. Looking up in 'node_modules' folder, initial location '/src/project'. File '/src/project/node_modules/pkg3.d.ts' does not exist. Directory '/src/project/node_modules/@types' does not exist, skipping all lookups in it. @@ -566,8 +572,11 @@ CreatingProgramWith:: Reusing resolution of module 'pkg0' from '/src/project/fileWithImports.ts' of old program, it was successfully resolved to '/src/project/node_modules/pkg0/index.d.ts'. Reusing resolution of module 'pkg1' from '/src/project/fileWithImports.ts' of old program, it was successfully resolved to '/src/project/node_modules/pkg1/index.d.ts'. Reusing resolution of type reference directive 'pkg2' from '/src/project/fileWithTypeRefs.ts' of old program, it was successfully resolved to '/src/project/node_modules/pkg2/index.d.ts'. -======== Resolving type reference directive 'pkg3', containing file '/src/project/fileWithTypeRefs.ts', root directory not set. ======== -Root directory cannot be determined, skipping primary search paths. +======== Resolving type reference directive 'pkg3', containing file '/src/project/fileWithTypeRefs.ts', root directory '/src/project/node_modules/@types,/src/node_modules/@types,/node_modules/@types'. ======== +Resolving with primary search path '/src/project/node_modules/@types, /src/node_modules/@types, /node_modules/@types'. +Directory '/src/project/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/src/node_modules/@types' does not exist, skipping all lookups in it. +Directory '/node_modules/@types' does not exist, skipping all lookups in it. Looking up in 'node_modules' folder, initial location '/src/project'. File '/src/project/node_modules/pkg3/package.json' does not exist. File '/src/project/node_modules/pkg3.d.ts' does not exist. diff --git a/tests/baselines/reference/tsserver/cachingFileSystemInformation/watchDirectories-for-config-file-with-case-insensitive-file-system.js b/tests/baselines/reference/tsserver/cachingFileSystemInformation/watchDirectories-for-config-file-with-case-insensitive-file-system.js index 802443c20a962..abcefca228573 100644 --- a/tests/baselines/reference/tsserver/cachingFileSystemInformation/watchDirectories-for-config-file-with-case-insensitive-file-system.js +++ b/tests/baselines/reference/tsserver/cachingFileSystemInformation/watchDirectories-for-config-file-with-case-insensitive-file-system.js @@ -77,11 +77,9 @@ Info 11 [00:00:44.000] DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/w Info 12 [00:00:45.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/frontend/types 1 undefined Project: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Failed Lookup Locations Info 13 [00:00:46.000] DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/frontend/node_modules 1 undefined Project: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Failed Lookup Locations Info 14 [00:00:47.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/frontend/node_modules 1 undefined Project: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Failed Lookup Locations -Info 15 [00:00:48.000] DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/node_modules 1 undefined Project: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Failed Lookup Locations -Info 16 [00:00:49.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/node_modules 1 undefined Project: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Failed Lookup Locations -Info 17 [00:00:50.000] Finishing updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms -Info 18 [00:00:51.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 19 [00:00:52.000] Files (3) +Info 15 [00:00:48.000] Finishing updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info 16 [00:00:49.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 17 [00:00:50.000] Files (3) /a/lib/lib.es2016.full.d.ts /Users/someuser/work/applications/frontend/src/app/redux/configureStore.ts /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts @@ -94,18 +92,18 @@ Info 19 [00:00:52.000] Files (3) src/app/utils/Analytic.ts Matched by include pattern 'src/**/*' in 'tsconfig.json' -Info 20 [00:00:53.000] ----------------------------------------------- -Info 21 [00:00:54.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 21 [00:00:55.000] Files (3) - -Info 21 [00:00:56.000] ----------------------------------------------- -Info 21 [00:00:57.000] Open files: -Info 21 [00:00:58.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined -Info 21 [00:00:59.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json -Info 21 [00:01:02.000] DirectoryWatcher:: Triggered with /users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: WatchInfo: /users/someuser/work/applications/frontend/src 1 undefined Config: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Wild card directory -Info 22 [00:01:03.000] Scheduled: /Users/someuser/work/applications/frontend/tsconfig.json -Info 23 [00:01:04.000] Scheduled: *ensureProjectForOpenFiles* -Info 24 [00:01:05.000] Elapsed:: *ms DirectoryWatcher:: Triggered with /users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: WatchInfo: /users/someuser/work/applications/frontend/src 1 undefined Config: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Wild card directory +Info 18 [00:00:51.000] ----------------------------------------------- +Info 19 [00:00:52.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 19 [00:00:53.000] Files (3) + +Info 19 [00:00:54.000] ----------------------------------------------- +Info 19 [00:00:55.000] Open files: +Info 19 [00:00:56.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined +Info 19 [00:00:57.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json +Info 19 [00:01:00.000] DirectoryWatcher:: Triggered with /users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: WatchInfo: /users/someuser/work/applications/frontend/src 1 undefined Config: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Wild card directory +Info 20 [00:01:01.000] Scheduled: /Users/someuser/work/applications/frontend/tsconfig.json +Info 21 [00:01:02.000] Scheduled: *ensureProjectForOpenFiles* +Info 22 [00:01:03.000] Elapsed:: *ms DirectoryWatcher:: Triggered with /users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: WatchInfo: /users/someuser/work/applications/frontend/src 1 undefined Config: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Wild card directory Before running timeout callbacks //// [/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts] export class Cookie { } @@ -116,8 +114,6 @@ PolledWatches:: {"pollingInterval":500} /users/someuser/work/applications/frontend/node_modules: {"pollingInterval":500} -/users/someuser/work/applications/node_modules: - {"pollingInterval":500} FsWatches:: /users/someuser/work/applications/frontend/tsconfig.json: @@ -131,12 +127,12 @@ FsWatchesRecursive:: /users/someuser/work/applications/frontend/src: {} -Info 25 [00:01:06.000] Running: /Users/someuser/work/applications/frontend/tsconfig.json -Info 26 [00:01:07.000] FileWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts 500 undefined WatchType: Closed Script info -Info 27 [00:01:08.000] Starting updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json -Info 28 [00:01:09.000] Finishing updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json Version: 2 structureChanged: true structureIsReused:: Not Elapsed:: *ms -Info 29 [00:01:10.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 30 [00:01:11.000] Files (4) +Info 23 [00:01:04.000] Running: /Users/someuser/work/applications/frontend/tsconfig.json +Info 24 [00:01:05.000] FileWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts 500 undefined WatchType: Closed Script info +Info 25 [00:01:06.000] Starting updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json +Info 26 [00:01:07.000] Finishing updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json Version: 2 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info 27 [00:01:08.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 28 [00:01:09.000] Files (4) /a/lib/lib.es2016.full.d.ts /Users/someuser/work/applications/frontend/src/app/redux/configureStore.ts /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts @@ -152,24 +148,24 @@ Info 30 [00:01:11.000] Files (4) src/app/utils/Cookie.ts Matched by include pattern 'src/**/*' in 'tsconfig.json' -Info 31 [00:01:12.000] ----------------------------------------------- -Info 32 [00:01:13.000] Running: *ensureProjectForOpenFiles* -Info 33 [00:01:14.000] Before ensureProjectForOpenFiles: -Info 34 [00:01:15.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 34 [00:01:16.000] Files (4) - -Info 34 [00:01:17.000] ----------------------------------------------- -Info 34 [00:01:18.000] Open files: -Info 34 [00:01:19.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined -Info 34 [00:01:20.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json -Info 34 [00:01:21.000] After ensureProjectForOpenFiles: -Info 35 [00:01:22.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 35 [00:01:23.000] Files (4) - -Info 35 [00:01:24.000] ----------------------------------------------- -Info 35 [00:01:25.000] Open files: -Info 35 [00:01:26.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined -Info 35 [00:01:27.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json +Info 29 [00:01:10.000] ----------------------------------------------- +Info 30 [00:01:11.000] Running: *ensureProjectForOpenFiles* +Info 31 [00:01:12.000] Before ensureProjectForOpenFiles: +Info 32 [00:01:13.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 32 [00:01:14.000] Files (4) + +Info 32 [00:01:15.000] ----------------------------------------------- +Info 32 [00:01:16.000] Open files: +Info 32 [00:01:17.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined +Info 32 [00:01:18.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json +Info 32 [00:01:19.000] After ensureProjectForOpenFiles: +Info 33 [00:01:20.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 33 [00:01:21.000] Files (4) + +Info 33 [00:01:22.000] ----------------------------------------------- +Info 33 [00:01:23.000] Open files: +Info 33 [00:01:24.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined +Info 33 [00:01:25.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json After running timeout callbacks PolledWatches:: @@ -177,8 +173,6 @@ PolledWatches:: {"pollingInterval":500} /users/someuser/work/applications/frontend/node_modules: {"pollingInterval":500} -/users/someuser/work/applications/node_modules: - {"pollingInterval":500} FsWatches:: /users/someuser/work/applications/frontend/tsconfig.json: @@ -194,25 +188,25 @@ FsWatchesRecursive:: /users/someuser/work/applications/frontend/src: {} -Info 35 [00:01:28.000] fileExists:: [{"key":"/users/someuser/work/applications/frontend/src/app/utils/cookie.ts","count":1},{"key":"/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts","count":1}] -Info 36 [00:01:29.000] directoryExists:: [{"key":"/users/someuser/work/applications/frontend/src/app/utils/cookie.ts","count":1}] -Info 37 [00:01:30.000] getDirectories:: [] -Info 38 [00:01:31.000] readFile:: [{"key":"/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts","count":1}] -Info 39 [00:01:32.000] readDirectory:: [] -Info 40 [00:01:33.000] FileWatcher:: Close:: WatchInfo: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts 500 undefined WatchType: Closed Script info -Info 41 [00:01:34.000] Search path: /Users/someuser/work/applications/frontend/src/app/utils -Info 42 [00:01:35.000] For info: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: Config file name: /Users/someuser/work/applications/frontend/tsconfig.json -Info 43 [00:01:36.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 43 [00:01:37.000] Files (4) - -Info 43 [00:01:38.000] ----------------------------------------------- -Info 43 [00:01:39.000] Open files: -Info 43 [00:01:40.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined -Info 43 [00:01:41.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json -Info 43 [00:01:42.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts ProjectRootPath: undefined -Info 43 [00:01:43.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json -Info 43 [00:01:44.000] fileExists:: [] -Info 44 [00:01:45.000] directoryExists:: [] -Info 45 [00:01:46.000] getDirectories:: [] -Info 46 [00:01:47.000] readFile:: [] -Info 47 [00:01:48.000] readDirectory:: [] \ No newline at end of file +Info 33 [00:01:26.000] fileExists:: [{"key":"/users/someuser/work/applications/frontend/src/app/utils/cookie.ts","count":1},{"key":"/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts","count":1}] +Info 34 [00:01:27.000] directoryExists:: [{"key":"/users/someuser/work/applications/frontend/src/app/utils/cookie.ts","count":1}] +Info 35 [00:01:28.000] getDirectories:: [] +Info 36 [00:01:29.000] readFile:: [{"key":"/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts","count":1}] +Info 37 [00:01:30.000] readDirectory:: [] +Info 38 [00:01:31.000] FileWatcher:: Close:: WatchInfo: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts 500 undefined WatchType: Closed Script info +Info 39 [00:01:32.000] Search path: /Users/someuser/work/applications/frontend/src/app/utils +Info 40 [00:01:33.000] For info: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: Config file name: /Users/someuser/work/applications/frontend/tsconfig.json +Info 41 [00:01:34.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 41 [00:01:35.000] Files (4) + +Info 41 [00:01:36.000] ----------------------------------------------- +Info 41 [00:01:37.000] Open files: +Info 41 [00:01:38.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined +Info 41 [00:01:39.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json +Info 41 [00:01:40.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts ProjectRootPath: undefined +Info 41 [00:01:41.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json +Info 41 [00:01:42.000] fileExists:: [] +Info 42 [00:01:43.000] directoryExists:: [] +Info 43 [00:01:44.000] getDirectories:: [] +Info 44 [00:01:45.000] readFile:: [] +Info 45 [00:01:46.000] readDirectory:: [] \ No newline at end of file diff --git a/tests/baselines/reference/tsserver/cachingFileSystemInformation/watchDirectories-for-config-file-with-case-sensitive-file-system.js b/tests/baselines/reference/tsserver/cachingFileSystemInformation/watchDirectories-for-config-file-with-case-sensitive-file-system.js index 60c410090a674..3c1a0230068dd 100644 --- a/tests/baselines/reference/tsserver/cachingFileSystemInformation/watchDirectories-for-config-file-with-case-sensitive-file-system.js +++ b/tests/baselines/reference/tsserver/cachingFileSystemInformation/watchDirectories-for-config-file-with-case-sensitive-file-system.js @@ -77,11 +77,9 @@ Info 11 [00:00:44.000] DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/w Info 12 [00:00:45.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/frontend/types 1 undefined Project: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Failed Lookup Locations Info 13 [00:00:46.000] DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/frontend/node_modules 1 undefined Project: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Failed Lookup Locations Info 14 [00:00:47.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/frontend/node_modules 1 undefined Project: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Failed Lookup Locations -Info 15 [00:00:48.000] DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/node_modules 1 undefined Project: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Failed Lookup Locations -Info 16 [00:00:49.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/node_modules 1 undefined Project: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Failed Lookup Locations -Info 17 [00:00:50.000] Finishing updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms -Info 18 [00:00:51.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 19 [00:00:52.000] Files (3) +Info 15 [00:00:48.000] Finishing updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info 16 [00:00:49.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 17 [00:00:50.000] Files (3) /a/lib/lib.es2016.full.d.ts /Users/someuser/work/applications/frontend/src/app/redux/configureStore.ts /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts @@ -94,18 +92,18 @@ Info 19 [00:00:52.000] Files (3) src/app/utils/Analytic.ts Matched by include pattern 'src/**/*' in 'tsconfig.json' -Info 20 [00:00:53.000] ----------------------------------------------- -Info 21 [00:00:54.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 21 [00:00:55.000] Files (3) - -Info 21 [00:00:56.000] ----------------------------------------------- -Info 21 [00:00:57.000] Open files: -Info 21 [00:00:58.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined -Info 21 [00:00:59.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json -Info 21 [00:01:02.000] DirectoryWatcher:: Triggered with /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: WatchInfo: /Users/someuser/work/applications/frontend/src 1 undefined Config: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Wild card directory -Info 22 [00:01:03.000] Scheduled: /Users/someuser/work/applications/frontend/tsconfig.json -Info 23 [00:01:04.000] Scheduled: *ensureProjectForOpenFiles* -Info 24 [00:01:05.000] Elapsed:: *ms DirectoryWatcher:: Triggered with /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: WatchInfo: /Users/someuser/work/applications/frontend/src 1 undefined Config: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Wild card directory +Info 18 [00:00:51.000] ----------------------------------------------- +Info 19 [00:00:52.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 19 [00:00:53.000] Files (3) + +Info 19 [00:00:54.000] ----------------------------------------------- +Info 19 [00:00:55.000] Open files: +Info 19 [00:00:56.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined +Info 19 [00:00:57.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json +Info 19 [00:01:00.000] DirectoryWatcher:: Triggered with /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: WatchInfo: /Users/someuser/work/applications/frontend/src 1 undefined Config: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Wild card directory +Info 20 [00:01:01.000] Scheduled: /Users/someuser/work/applications/frontend/tsconfig.json +Info 21 [00:01:02.000] Scheduled: *ensureProjectForOpenFiles* +Info 22 [00:01:03.000] Elapsed:: *ms DirectoryWatcher:: Triggered with /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: WatchInfo: /Users/someuser/work/applications/frontend/src 1 undefined Config: /Users/someuser/work/applications/frontend/tsconfig.json WatchType: Wild card directory Before running timeout callbacks //// [/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts] export class Cookie { } @@ -116,8 +114,6 @@ PolledWatches:: {"pollingInterval":500} /Users/someuser/work/applications/frontend/node_modules: {"pollingInterval":500} -/Users/someuser/work/applications/node_modules: - {"pollingInterval":500} FsWatches:: /Users/someuser/work/applications/frontend/tsconfig.json: @@ -131,12 +127,12 @@ FsWatchesRecursive:: /Users/someuser/work/applications/frontend/src: {} -Info 25 [00:01:06.000] Running: /Users/someuser/work/applications/frontend/tsconfig.json -Info 26 [00:01:07.000] FileWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts 500 undefined WatchType: Closed Script info -Info 27 [00:01:08.000] Starting updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json -Info 28 [00:01:09.000] Finishing updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json Version: 2 structureChanged: true structureIsReused:: Not Elapsed:: *ms -Info 29 [00:01:10.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 30 [00:01:11.000] Files (4) +Info 23 [00:01:04.000] Running: /Users/someuser/work/applications/frontend/tsconfig.json +Info 24 [00:01:05.000] FileWatcher:: Added:: WatchInfo: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts 500 undefined WatchType: Closed Script info +Info 25 [00:01:06.000] Starting updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json +Info 26 [00:01:07.000] Finishing updateGraphWorker: Project: /Users/someuser/work/applications/frontend/tsconfig.json Version: 2 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info 27 [00:01:08.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 28 [00:01:09.000] Files (4) /a/lib/lib.es2016.full.d.ts /Users/someuser/work/applications/frontend/src/app/redux/configureStore.ts /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts @@ -152,24 +148,24 @@ Info 30 [00:01:11.000] Files (4) src/app/utils/Cookie.ts Matched by include pattern 'src/**/*' in 'tsconfig.json' -Info 31 [00:01:12.000] ----------------------------------------------- -Info 32 [00:01:13.000] Running: *ensureProjectForOpenFiles* -Info 33 [00:01:14.000] Before ensureProjectForOpenFiles: -Info 34 [00:01:15.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 34 [00:01:16.000] Files (4) - -Info 34 [00:01:17.000] ----------------------------------------------- -Info 34 [00:01:18.000] Open files: -Info 34 [00:01:19.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined -Info 34 [00:01:20.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json -Info 34 [00:01:21.000] After ensureProjectForOpenFiles: -Info 35 [00:01:22.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 35 [00:01:23.000] Files (4) - -Info 35 [00:01:24.000] ----------------------------------------------- -Info 35 [00:01:25.000] Open files: -Info 35 [00:01:26.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined -Info 35 [00:01:27.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json +Info 29 [00:01:10.000] ----------------------------------------------- +Info 30 [00:01:11.000] Running: *ensureProjectForOpenFiles* +Info 31 [00:01:12.000] Before ensureProjectForOpenFiles: +Info 32 [00:01:13.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 32 [00:01:14.000] Files (4) + +Info 32 [00:01:15.000] ----------------------------------------------- +Info 32 [00:01:16.000] Open files: +Info 32 [00:01:17.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined +Info 32 [00:01:18.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json +Info 32 [00:01:19.000] After ensureProjectForOpenFiles: +Info 33 [00:01:20.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 33 [00:01:21.000] Files (4) + +Info 33 [00:01:22.000] ----------------------------------------------- +Info 33 [00:01:23.000] Open files: +Info 33 [00:01:24.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined +Info 33 [00:01:25.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json After running timeout callbacks PolledWatches:: @@ -177,8 +173,6 @@ PolledWatches:: {"pollingInterval":500} /Users/someuser/work/applications/frontend/node_modules: {"pollingInterval":500} -/Users/someuser/work/applications/node_modules: - {"pollingInterval":500} FsWatches:: /Users/someuser/work/applications/frontend/tsconfig.json: @@ -194,25 +188,25 @@ FsWatchesRecursive:: /Users/someuser/work/applications/frontend/src: {} -Info 35 [00:01:28.000] fileExists:: [{"key":"/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts","count":2}] -Info 36 [00:01:29.000] directoryExists:: [{"key":"/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts","count":1}] -Info 37 [00:01:30.000] getDirectories:: [] -Info 38 [00:01:31.000] readFile:: [{"key":"/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts","count":1}] -Info 39 [00:01:32.000] readDirectory:: [] -Info 40 [00:01:33.000] FileWatcher:: Close:: WatchInfo: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts 500 undefined WatchType: Closed Script info -Info 41 [00:01:34.000] Search path: /Users/someuser/work/applications/frontend/src/app/utils -Info 42 [00:01:35.000] For info: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: Config file name: /Users/someuser/work/applications/frontend/tsconfig.json -Info 43 [00:01:36.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) -Info 43 [00:01:37.000] Files (4) - -Info 43 [00:01:38.000] ----------------------------------------------- -Info 43 [00:01:39.000] Open files: -Info 43 [00:01:40.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined -Info 43 [00:01:41.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json -Info 43 [00:01:42.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts ProjectRootPath: undefined -Info 43 [00:01:43.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json -Info 43 [00:01:44.000] fileExists:: [] -Info 44 [00:01:45.000] directoryExists:: [] -Info 45 [00:01:46.000] getDirectories:: [] -Info 46 [00:01:47.000] readFile:: [] -Info 47 [00:01:48.000] readDirectory:: [] \ No newline at end of file +Info 33 [00:01:26.000] fileExists:: [{"key":"/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts","count":2}] +Info 34 [00:01:27.000] directoryExists:: [{"key":"/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts","count":1}] +Info 35 [00:01:28.000] getDirectories:: [] +Info 36 [00:01:29.000] readFile:: [{"key":"/Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts","count":1}] +Info 37 [00:01:30.000] readDirectory:: [] +Info 38 [00:01:31.000] FileWatcher:: Close:: WatchInfo: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts 500 undefined WatchType: Closed Script info +Info 39 [00:01:32.000] Search path: /Users/someuser/work/applications/frontend/src/app/utils +Info 40 [00:01:33.000] For info: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts :: Config file name: /Users/someuser/work/applications/frontend/tsconfig.json +Info 41 [00:01:34.000] Project '/Users/someuser/work/applications/frontend/tsconfig.json' (Configured) +Info 41 [00:01:35.000] Files (4) + +Info 41 [00:01:36.000] ----------------------------------------------- +Info 41 [00:01:37.000] Open files: +Info 41 [00:01:38.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Analytic.ts ProjectRootPath: undefined +Info 41 [00:01:39.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json +Info 41 [00:01:40.000] FileName: /Users/someuser/work/applications/frontend/src/app/utils/Cookie.ts ProjectRootPath: undefined +Info 41 [00:01:41.000] Projects: /Users/someuser/work/applications/frontend/tsconfig.json +Info 41 [00:01:42.000] fileExists:: [] +Info 42 [00:01:43.000] directoryExists:: [] +Info 43 [00:01:44.000] getDirectories:: [] +Info 44 [00:01:45.000] readFile:: [] +Info 45 [00:01:46.000] readDirectory:: [] \ No newline at end of file diff --git a/tests/baselines/reference/tsserver/resolutionCache/types-should-load-from-config-file-path-if-config-exists.js b/tests/baselines/reference/tsserver/resolutionCache/types-should-load-from-config-file-path-if-config-exists.js new file mode 100644 index 0000000000000..c5220185bcb33 --- /dev/null +++ b/tests/baselines/reference/tsserver/resolutionCache/types-should-load-from-config-file-path-if-config-exists.js @@ -0,0 +1,61 @@ +Info 0 [00:00:21.000] Provided types map file "/typesMap.json" doesn't exist +Creating project service +//// [/a/b/app.ts] +let x = 1 + +//// [/a/b/tsconfig.json] +{"compilerOptions":{"types":["node"]}} + +//// [/a/b/node_modules/@types/node/index.d.ts] +declare var process: any + + +PolledWatches:: + +FsWatches:: + +FsWatchesRecursive:: + +Info 1 [00:00:22.000] Search path: /a/b +Info 2 [00:00:23.000] For info: /a/b/app.ts :: Config file name: /a/b/tsconfig.json +Info 3 [00:00:24.000] Creating configuration project /a/b/tsconfig.json +Info 4 [00:00:25.000] FileWatcher:: Added:: WatchInfo: /a/b/tsconfig.json 2000 undefined Project: /a/b/tsconfig.json WatchType: Config file +Info 5 [00:00:26.000] Config: /a/b/tsconfig.json : { + "rootNames": [ + "/a/b/app.ts" + ], + "options": { + "types": [ + "node" + ], + "configFilePath": "/a/b/tsconfig.json" + } +} +Info 6 [00:00:27.000] DirectoryWatcher:: Added:: WatchInfo: /a/b 1 undefined Config: /a/b/tsconfig.json WatchType: Wild card directory +Info 7 [00:00:28.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /a/b 1 undefined Config: /a/b/tsconfig.json WatchType: Wild card directory +Info 8 [00:00:29.000] Starting updateGraphWorker: Project: /a/b/tsconfig.json +Info 9 [00:00:30.000] DirectoryWatcher:: Added:: WatchInfo: /a/b/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache +Info 10 [00:00:31.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /a/b/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache +Info 11 [00:00:32.000] DirectoryWatcher:: Added:: WatchInfo: /a/b/node_modules 1 undefined Project: /a/b/tsconfig.json WatchType: Failed Lookup Locations +Info 12 [00:00:33.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /a/b/node_modules 1 undefined Project: /a/b/tsconfig.json WatchType: Failed Lookup Locations +Info 13 [00:00:34.000] FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 500 undefined Project: /a/b/tsconfig.json WatchType: Missing file +Info 14 [00:00:35.000] Finishing updateGraphWorker: Project: /a/b/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info 15 [00:00:36.000] Project '/a/b/tsconfig.json' (Configured) +Info 16 [00:00:37.000] Files (2) + /a/b/app.ts + /a/b/node_modules/@types/node/index.d.ts + + + app.ts + Matched by default include pattern '**/*' + node_modules/@types/node/index.d.ts + Entry point of type library 'node' specified in compilerOptions + +Info 17 [00:00:38.000] ----------------------------------------------- +Info 18 [00:00:39.000] Project '/a/b/tsconfig.json' (Configured) +Info 18 [00:00:40.000] Files (2) + +Info 18 [00:00:41.000] ----------------------------------------------- +Info 18 [00:00:42.000] Open files: +Info 18 [00:00:43.000] FileName: /a/b/app.ts ProjectRootPath: undefined +Info 18 [00:00:44.000] Projects: /a/b/tsconfig.json \ No newline at end of file diff --git a/tests/baselines/reference/tsserver/resolutionCache/types-should-not-load-from-config-file-path-if-config-exists-but-does-not-specifies-typeRoots.js b/tests/baselines/reference/tsserver/resolutionCache/types-should-not-load-from-config-file-path-if-config-exists-but-does-not-specifies-typeRoots.js new file mode 100644 index 0000000000000..5dd964c41b967 --- /dev/null +++ b/tests/baselines/reference/tsserver/resolutionCache/types-should-not-load-from-config-file-path-if-config-exists-but-does-not-specifies-typeRoots.js @@ -0,0 +1,55 @@ +Info 0 [00:00:21.000] Provided types map file "/typesMap.json" doesn't exist +Creating project service +//// [/a/b/app.ts] +let x = 1 + +//// [/a/b/tsconfig.json] +{"compilerOptions":{"types":["node"],"typeRoots":[]}} + +//// [/a/b/node_modules/@types/node/index.d.ts] +declare var process: any + + +PolledWatches:: + +FsWatches:: + +FsWatchesRecursive:: + +Info 1 [00:00:22.000] Search path: /a/b +Info 2 [00:00:23.000] For info: /a/b/app.ts :: Config file name: /a/b/tsconfig.json +Info 3 [00:00:24.000] Creating configuration project /a/b/tsconfig.json +Info 4 [00:00:25.000] FileWatcher:: Added:: WatchInfo: /a/b/tsconfig.json 2000 undefined Project: /a/b/tsconfig.json WatchType: Config file +Info 5 [00:00:26.000] Config: /a/b/tsconfig.json : { + "rootNames": [ + "/a/b/app.ts" + ], + "options": { + "types": [ + "node" + ], + "typeRoots": [], + "configFilePath": "/a/b/tsconfig.json" + } +} +Info 6 [00:00:27.000] DirectoryWatcher:: Added:: WatchInfo: /a/b 1 undefined Config: /a/b/tsconfig.json WatchType: Wild card directory +Info 7 [00:00:28.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /a/b 1 undefined Config: /a/b/tsconfig.json WatchType: Wild card directory +Info 8 [00:00:29.000] Starting updateGraphWorker: Project: /a/b/tsconfig.json +Info 9 [00:00:30.000] FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 500 undefined Project: /a/b/tsconfig.json WatchType: Missing file +Info 10 [00:00:31.000] Finishing updateGraphWorker: Project: /a/b/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info 11 [00:00:32.000] Project '/a/b/tsconfig.json' (Configured) +Info 12 [00:00:33.000] Files (1) + /a/b/app.ts + + + app.ts + Matched by default include pattern '**/*' + +Info 13 [00:00:34.000] ----------------------------------------------- +Info 14 [00:00:35.000] Project '/a/b/tsconfig.json' (Configured) +Info 14 [00:00:36.000] Files (1) + +Info 14 [00:00:37.000] ----------------------------------------------- +Info 14 [00:00:38.000] Open files: +Info 14 [00:00:39.000] FileName: /a/b/app.ts ProjectRootPath: undefined +Info 14 [00:00:40.000] Projects: /a/b/tsconfig.json \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.errors.txt b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.errors.txt new file mode 100644 index 0000000000000..5e7672baa4b39 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.errors.txt @@ -0,0 +1,22 @@ +error TS2688: Cannot find type definition file for 'phaser'. + The file is in the program because: + Entry point of type library 'phaser' specified in compilerOptions +/a.ts(1,1): error TS2304: Cannot find name 'a'. + + +!!! error TS2688: Cannot find type definition file for 'phaser'. +!!! error TS2688: The file is in the program because: +!!! error TS2688: Entry point of type library 'phaser' specified in compilerOptions +==== /a.ts (1 errors) ==== + a; + ~ +!!! error TS2304: Cannot find name 'a'. +==== /typings/dummy.d.ts (0 errors) ==== + declare const a2: number; + +==== /node_modules/phaser/types/phaser.d.ts (0 errors) ==== + declare const a: number; + +==== /node_modules/phaser/package.json (0 errors) ==== + { "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" } + \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.symbols b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.symbols index f29a1bafe2741..4b42ab41dfba4 100644 --- a/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.symbols +++ b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.symbols @@ -1,8 +1,3 @@ === /a.ts === -a; ->a : Symbol(a, Decl(phaser.d.ts, 0, 13)) - -=== /node_modules/phaser/types/phaser.d.ts === -declare const a: number; ->a : Symbol(a, Decl(phaser.d.ts, 0, 13)) +a; diff --git a/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.trace.json b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.trace.json index 3374d83d78e5b..a3cd33c89fd1b 100644 --- a/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.trace.json +++ b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.trace.json @@ -2,13 +2,6 @@ "======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/typings'. ========", "Resolving with primary search path '/typings'.", "File '/typings/phaser.d.ts' does not exist.", - "Looking up in 'node_modules' folder, initial location '/'.", - "Found 'package.json' at '/node_modules/phaser/package.json'.", - "'package.json' does not have a 'typesVersions' field.", - "File '/node_modules/phaser.d.ts' does not exist.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'types/phaser.d.ts' that references '/node_modules/phaser/types/phaser.d.ts'.", - "File '/node_modules/phaser/types/phaser.d.ts' exist - use it as a name resolution result.", - "Resolving real path for '/node_modules/phaser/types/phaser.d.ts', result '/node_modules/phaser/types/phaser.d.ts'.", - "======== Type reference directive 'phaser' was successfully resolved to '/node_modules/phaser/types/phaser.d.ts' with Package ID 'phaser/types/phaser.d.ts@1.2.3', primary: false. ========" + "Resolving type reference directive for program that specifies custom typeRoots, skipping lookup in 'node_modules' folder.", + "======== Type reference directive 'phaser' was not resolved. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.types b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.types index 20416fc921d6d..2ec6ffcf1be41 100644 --- a/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.types +++ b/tests/baselines/reference/typeReferenceDirectiveWithFailedFromTypeRoot.types @@ -1,8 +1,4 @@ === /a.ts === a; ->a : number - -=== /node_modules/phaser/types/phaser.d.ts === -declare const a: number; ->a : number +>a : any diff --git a/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json b/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json index b4a6fcf3f916b..86af7fccc374e 100644 --- a/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json +++ b/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json @@ -56,20 +56,23 @@ "File '/node_modules/abc.js' does not exist.", "File '/node_modules/abc.jsx' does not exist.", "======== Module name 'abc' was not resolved. ========", - "======== Resolving type reference directive 'grumpy', containing file '/foo/bar/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========", - "Resolving with primary search path '/foo/node_modules/@types, /node_modules/@types'.", + "======== Resolving type reference directive 'grumpy', containing file '/foo/bar/__inferred type names__.ts', root directory '/foo/bar/node_modules/@types,/foo/node_modules/@types,/node_modules/@types'. ========", + "Resolving with primary search path '/foo/bar/node_modules/@types, /foo/node_modules/@types, /node_modules/@types'.", + "Directory '/foo/bar/node_modules/@types' does not exist, skipping all lookups in it.", "File '/foo/node_modules/@types/grumpy/package.json' does not exist.", "File '/foo/node_modules/@types/grumpy/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/foo/node_modules/@types/grumpy/index.d.ts', result '/foo/node_modules/@types/grumpy/index.d.ts'.", "======== Type reference directive 'grumpy' was successfully resolved to '/foo/node_modules/@types/grumpy/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'sneezy', containing file '/foo/bar/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========", - "Resolving with primary search path '/foo/node_modules/@types, /node_modules/@types'.", + "======== Resolving type reference directive 'sneezy', containing file '/foo/bar/__inferred type names__.ts', root directory '/foo/bar/node_modules/@types,/foo/node_modules/@types,/node_modules/@types'. ========", + "Resolving with primary search path '/foo/bar/node_modules/@types, /foo/node_modules/@types, /node_modules/@types'.", + "Directory '/foo/bar/node_modules/@types' does not exist, skipping all lookups in it.", "File '/foo/node_modules/@types/sneezy/package.json' does not exist.", "File '/foo/node_modules/@types/sneezy/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/foo/node_modules/@types/sneezy/index.d.ts', result '/foo/node_modules/@types/sneezy/index.d.ts'.", "======== Type reference directive 'sneezy' was successfully resolved to '/foo/node_modules/@types/sneezy/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'dopey', containing file '/foo/bar/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========", - "Resolving with primary search path '/foo/node_modules/@types, /node_modules/@types'.", + "======== Resolving type reference directive 'dopey', containing file '/foo/bar/__inferred type names__.ts', root directory '/foo/bar/node_modules/@types,/foo/node_modules/@types,/node_modules/@types'. ========", + "Resolving with primary search path '/foo/bar/node_modules/@types, /foo/node_modules/@types, /node_modules/@types'.", + "Directory '/foo/bar/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/@types/dopey/package.json' does not exist.", "File '/node_modules/@types/dopey/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/@types/dopey/index.d.ts', result '/node_modules/@types/dopey/index.d.ts'.", diff --git a/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json b/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json index 97cac6a86a6be..150d0d6620fa3 100644 --- a/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json +++ b/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json @@ -12,8 +12,9 @@ "File '/node_modules/xyz.js' does not exist.", "File '/node_modules/xyz.jsx' does not exist.", "======== Module name 'xyz' was not resolved. ========", - "======== Resolving type reference directive 'foo', containing file '/src/__inferred type names__.ts', root directory '/node_modules/@types'. ========", - "Resolving with primary search path '/node_modules/@types'.", + "======== Resolving type reference directive 'foo', containing file '/src/__inferred type names__.ts', root directory '/src/node_modules/@types,/node_modules/@types'. ========", + "Resolving with primary search path '/src/node_modules/@types, /node_modules/@types'.", + "Directory '/src/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/@types/foo/package.json' does not exist.", "File '/node_modules/@types/foo/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/@types/foo/index.d.ts', result '/node_modules/@types/foo/index.d.ts'.", From aff834f6e068029fa19fc2ec15d14ac9acef597d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 22 Nov 2022 22:56:58 -0800 Subject: [PATCH 5/6] Add test that shows types file does not act as ambient module declaration --- ...olutionAsTypeReferenceDirective.errors.txt | 14 ++++++++++++++ ...oduleResolutionAsTypeReferenceDirective.js | 15 +++++++++++++++ ...ResolutionAsTypeReferenceDirective.symbols | 8 ++++++++ ...olutionAsTypeReferenceDirective.trace.json | 19 +++++++++++++++++++ ...leResolutionAsTypeReferenceDirective.types | 8 ++++++++ ...solutionAsTypeReferenceDirectiveAmbient.js | 17 +++++++++++++++++ ...ionAsTypeReferenceDirectiveAmbient.symbols | 12 ++++++++++++ ...AsTypeReferenceDirectiveAmbient.trace.json | 19 +++++++++++++++++++ ...utionAsTypeReferenceDirectiveAmbient.types | 12 ++++++++++++ ...oduleResolutionAsTypeReferenceDirective.ts | 15 +++++++++++++++ ...solutionAsTypeReferenceDirectiveAmbient.ts | 17 +++++++++++++++++ 11 files changed, 156 insertions(+) create mode 100644 tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.errors.txt create mode 100644 tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.js create mode 100644 tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.symbols create mode 100644 tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.trace.json create mode 100644 tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.types create mode 100644 tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.js create mode 100644 tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.symbols create mode 100644 tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.trace.json create mode 100644 tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.types create mode 100644 tests/cases/compiler/moduleResolutionAsTypeReferenceDirective.ts create mode 100644 tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveAmbient.ts diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.errors.txt b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.errors.txt new file mode 100644 index 0000000000000..45467113ce216 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.errors.txt @@ -0,0 +1,14 @@ +/a.ts(1,20): error TS2307: Cannot find module 'phaser' or its corresponding type declarations. + + +==== /a.ts (1 errors) ==== + import { a2 } from "phaser"; + ~~~~~~~~ +!!! error TS2307: Cannot find module 'phaser' or its corresponding type declarations. +==== /typings/phaser/types/phaser.d.ts (0 errors) ==== + export const a2: number; + +==== /typings/phaser/package.json (0 errors) ==== + { "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" } + + \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.js b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.js new file mode 100644 index 0000000000000..5e94a36001582 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/moduleResolutionAsTypeReferenceDirective.ts] //// + +//// [phaser.d.ts] +export const a2: number; + +//// [package.json] +{ "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" } + + +//// [a.ts] +import { a2 } from "phaser"; + +//// [a.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.symbols b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.symbols new file mode 100644 index 0000000000000..412bc680e0c31 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.symbols @@ -0,0 +1,8 @@ +=== /a.ts === +import { a2 } from "phaser"; +>a2 : Symbol(a2, Decl(a.ts, 0, 8)) + +=== /typings/phaser/types/phaser.d.ts === +export const a2: number; +>a2 : Symbol(a2, Decl(phaser.d.ts, 0, 12)) + diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.trace.json b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.trace.json new file mode 100644 index 0000000000000..a593aff95244d --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.trace.json @@ -0,0 +1,19 @@ +[ + "======== Resolving module 'phaser' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module 'phaser' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "Loading module 'phaser' from 'node_modules' folder, target file types: JavaScript.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "======== Module name 'phaser' was not resolved. ========", + "======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/typings'. ========", + "Resolving with primary search path '/typings'.", + "File '/typings/phaser.d.ts' does not exist.", + "Found 'package.json' at '/typings/phaser/package.json'.", + "'package.json' does not have a 'typesVersions' field.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'types/phaser.d.ts' that references '/typings/phaser/types/phaser.d.ts'.", + "File '/typings/phaser/types/phaser.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/typings/phaser/types/phaser.d.ts', result '/typings/phaser/types/phaser.d.ts'.", + "======== Type reference directive 'phaser' was successfully resolved to '/typings/phaser/types/phaser.d.ts' with Package ID 'phaser/types/phaser.d.ts@1.2.3', primary: true. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.types b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.types new file mode 100644 index 0000000000000..6850ad3d8afef --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.types @@ -0,0 +1,8 @@ +=== /a.ts === +import { a2 } from "phaser"; +>a2 : any + +=== /typings/phaser/types/phaser.d.ts === +export const a2: number; +>a2 : number + diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.js b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.js new file mode 100644 index 0000000000000..deb1772a4e53c --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveAmbient.ts] //// + +//// [phaser.d.ts] +declare module "phaser" { + export const a2: number; +} + +//// [package.json] +{ "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" } + + +//// [a.ts] +import { a2 } from "phaser"; + +//// [a.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.symbols b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.symbols new file mode 100644 index 0000000000000..578a81a43c756 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.symbols @@ -0,0 +1,12 @@ +=== /a.ts === +import { a2 } from "phaser"; +>a2 : Symbol(a2, Decl(a.ts, 0, 8)) + +=== /typings/phaser/types/phaser.d.ts === +declare module "phaser" { +>"phaser" : Symbol("phaser", Decl(phaser.d.ts, 0, 0)) + + export const a2: number; +>a2 : Symbol(a2, Decl(phaser.d.ts, 1, 16)) +} + diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.trace.json b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.trace.json new file mode 100644 index 0000000000000..a593aff95244d --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.trace.json @@ -0,0 +1,19 @@ +[ + "======== Resolving module 'phaser' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module 'phaser' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "Loading module 'phaser' from 'node_modules' folder, target file types: JavaScript.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "======== Module name 'phaser' was not resolved. ========", + "======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/typings'. ========", + "Resolving with primary search path '/typings'.", + "File '/typings/phaser.d.ts' does not exist.", + "Found 'package.json' at '/typings/phaser/package.json'.", + "'package.json' does not have a 'typesVersions' field.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'types/phaser.d.ts' that references '/typings/phaser/types/phaser.d.ts'.", + "File '/typings/phaser/types/phaser.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/typings/phaser/types/phaser.d.ts', result '/typings/phaser/types/phaser.d.ts'.", + "======== Type reference directive 'phaser' was successfully resolved to '/typings/phaser/types/phaser.d.ts' with Package ID 'phaser/types/phaser.d.ts@1.2.3', primary: true. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.types b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.types new file mode 100644 index 0000000000000..6bc892a4e4145 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.types @@ -0,0 +1,12 @@ +=== /a.ts === +import { a2 } from "phaser"; +>a2 : number + +=== /typings/phaser/types/phaser.d.ts === +declare module "phaser" { +>"phaser" : typeof import("phaser") + + export const a2: number; +>a2 : number +} + diff --git a/tests/cases/compiler/moduleResolutionAsTypeReferenceDirective.ts b/tests/cases/compiler/moduleResolutionAsTypeReferenceDirective.ts new file mode 100644 index 0000000000000..c3e2e2396d5e2 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionAsTypeReferenceDirective.ts @@ -0,0 +1,15 @@ +// @noImplicitReferences: true +// @typeRoots: /typings +// @types: phaser +// @traceResolution: true +// @currentDirectory: / + +// @Filename: /typings/phaser/types/phaser.d.ts +export const a2: number; + +// @Filename: /typings/phaser/package.json +{ "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" } + + +// @Filename: /a.ts +import { a2 } from "phaser"; \ No newline at end of file diff --git a/tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveAmbient.ts b/tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveAmbient.ts new file mode 100644 index 0000000000000..a0b7e0d29d1cb --- /dev/null +++ b/tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveAmbient.ts @@ -0,0 +1,17 @@ +// @noImplicitReferences: true +// @typeRoots: /typings +// @types: phaser +// @traceResolution: true +// @currentDirectory: / + +// @Filename: /typings/phaser/types/phaser.d.ts +declare module "phaser" { + export const a2: number; +} + +// @Filename: /typings/phaser/package.json +{ "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" } + + +// @Filename: /a.ts +import { a2 } from "phaser"; \ No newline at end of file From a6fed14f5bb2279bac45f348f49ee984baa3512d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 22 Nov 2022 23:43:23 -0800 Subject: [PATCH 6/6] Resolve module from typeRoot if the resolution doesnt succeed --- src/compiler/moduleNameResolver.ts | 32 ++++++++++++++++--- ...olutionAsTypeReferenceDirective.errors.txt | 14 -------- ...olutionAsTypeReferenceDirective.trace.json | 14 +++++--- ...leResolutionAsTypeReferenceDirective.types | 2 +- ...AsTypeReferenceDirectiveAmbient.trace.json | 14 +++++--- .../when-resolves-to-ambient-module.js | 26 ++++++++------- 6 files changed, 60 insertions(+), 42 deletions(-) delete mode 100644 tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.errors.txt diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index a2d184c9b59a9..7f4ea3ed5a216 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -1552,6 +1552,9 @@ function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleNa } resolved = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference); } + if (extensions & Extensions.Declaration) { + resolved ??= resolveFromTypeRoot(moduleName, state); + } if (!resolved) return undefined; let resolvedValue = resolved.value; @@ -2770,7 +2773,7 @@ export function classicNameResolver(moduleName: string, containingFile: string, if (!isExternalModuleNameRelative(moduleName)) { const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName, /*mode*/ undefined, redirectedReference); // Climb up parent directories looking for a module. - const resolved = forEachAncestorDirectory(containingDirectory, directory => { + let resolved = forEachAncestorDirectory(containingDirectory, directory => { const resolutionFromCache = tryFindNonRelativeModuleNameInCache(perModuleNameCache, moduleName, directory, state); if (resolutionFromCache) { return resolutionFromCache; @@ -2778,12 +2781,12 @@ export function classicNameResolver(moduleName: string, containingFile: string, const searchName = normalizePath(combinePaths(directory, moduleName)); return toSearchResult(loadModuleFromFileNoPackageId(extensions, searchName, /*onlyRecordFailures*/ false, state)); }); - if (resolved) { - return resolved; - } + if (resolved) return resolved; if (extensions & (Extensions.TypeScript | Extensions.Declaration)) { // If we didn't find the file normally, look it up in @types. - return loadModuleFromNearestNodeModulesDirectoryTypesScope(moduleName, containingDirectory, state); + resolved = loadModuleFromNearestNodeModulesDirectoryTypesScope(moduleName, containingDirectory, state); + if (extensions & Extensions.Declaration) resolved ??= resolveFromTypeRoot(moduleName, state); + return resolved; } } else { @@ -2793,6 +2796,25 @@ 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 directoryExists = directoryProbablyExists(typeRoot, state.host); + if (!directoryExists && state.traceEnabled) { + trace(state.host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, typeRoot); + } + const resolvedFromFile = loadModuleFromFile(Extensions.Declaration, candidate, !directoryExists, state); + if (resolvedFromFile) { + const packageDirectory = parseNodeModuleFromPath(resolvedFromFile.path); + const packageInfo = packageDirectory ? getPackageJsonInfo(packageDirectory, /*onlyRecordFailures*/ false, state) : undefined; + return toSearchResult(withPackageId(packageInfo, resolvedFromFile)); + } + const resolved = loadNodeModuleFromDirectory(Extensions.Declaration, candidate, !directoryExists, state); + if (resolved) return toSearchResult(resolved); + } +} + /** * A host may load a module from a global cache of typings. * This is the minumum code needed to expose that functionality; the rest is in the host. diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.errors.txt b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.errors.txt deleted file mode 100644 index 45467113ce216..0000000000000 --- a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -/a.ts(1,20): error TS2307: Cannot find module 'phaser' or its corresponding type declarations. - - -==== /a.ts (1 errors) ==== - import { a2 } from "phaser"; - ~~~~~~~~ -!!! error TS2307: Cannot find module 'phaser' or its corresponding type declarations. -==== /typings/phaser/types/phaser.d.ts (0 errors) ==== - export const a2: number; - -==== /typings/phaser/package.json (0 errors) ==== - { "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" } - - \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.trace.json b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.trace.json index a593aff95244d..89c7a094d2773 100644 --- a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.trace.json +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.trace.json @@ -3,11 +3,6 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'phaser' from 'node_modules' folder, target file types: TypeScript, Declaration.", "Directory '/node_modules' does not exist, skipping all lookups in it.", - "Loading module 'phaser' from 'node_modules' folder, target file types: JavaScript.", - "Directory '/node_modules' does not exist, skipping all lookups in it.", - "======== Module name 'phaser' was not resolved. ========", - "======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/typings'. ========", - "Resolving with primary search path '/typings'.", "File '/typings/phaser.d.ts' does not exist.", "Found 'package.json' at '/typings/phaser/package.json'.", "'package.json' does not have a 'typesVersions' field.", @@ -15,5 +10,14 @@ "'package.json' has 'types' field 'types/phaser.d.ts' that references '/typings/phaser/types/phaser.d.ts'.", "File '/typings/phaser/types/phaser.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/typings/phaser/types/phaser.d.ts', result '/typings/phaser/types/phaser.d.ts'.", + "======== Module name 'phaser' was successfully resolved to '/typings/phaser/types/phaser.d.ts' with Package ID 'phaser/types/phaser.d.ts@1.2.3'. ========", + "======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/typings'. ========", + "Resolving with primary search path '/typings'.", + "File '/typings/phaser.d.ts' does not exist.", + "File '/typings/phaser/package.json' exists according to earlier cached lookups.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'types/phaser.d.ts' that references '/typings/phaser/types/phaser.d.ts'.", + "File '/typings/phaser/types/phaser.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/typings/phaser/types/phaser.d.ts', result '/typings/phaser/types/phaser.d.ts'.", "======== Type reference directive 'phaser' was successfully resolved to '/typings/phaser/types/phaser.d.ts' with Package ID 'phaser/types/phaser.d.ts@1.2.3', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.types b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.types index 6850ad3d8afef..b1b60c24349da 100644 --- a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.types +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirective.types @@ -1,6 +1,6 @@ === /a.ts === import { a2 } from "phaser"; ->a2 : any +>a2 : number === /typings/phaser/types/phaser.d.ts === export const a2: number; diff --git a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.trace.json b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.trace.json index a593aff95244d..89c7a094d2773 100644 --- a/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.trace.json +++ b/tests/baselines/reference/moduleResolutionAsTypeReferenceDirectiveAmbient.trace.json @@ -3,11 +3,6 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'phaser' from 'node_modules' folder, target file types: TypeScript, Declaration.", "Directory '/node_modules' does not exist, skipping all lookups in it.", - "Loading module 'phaser' from 'node_modules' folder, target file types: JavaScript.", - "Directory '/node_modules' does not exist, skipping all lookups in it.", - "======== Module name 'phaser' was not resolved. ========", - "======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/typings'. ========", - "Resolving with primary search path '/typings'.", "File '/typings/phaser.d.ts' does not exist.", "Found 'package.json' at '/typings/phaser/package.json'.", "'package.json' does not have a 'typesVersions' field.", @@ -15,5 +10,14 @@ "'package.json' has 'types' field 'types/phaser.d.ts' that references '/typings/phaser/types/phaser.d.ts'.", "File '/typings/phaser/types/phaser.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/typings/phaser/types/phaser.d.ts', result '/typings/phaser/types/phaser.d.ts'.", + "======== Module name 'phaser' was successfully resolved to '/typings/phaser/types/phaser.d.ts' with Package ID 'phaser/types/phaser.d.ts@1.2.3'. ========", + "======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/typings'. ========", + "Resolving with primary search path '/typings'.", + "File '/typings/phaser.d.ts' does not exist.", + "File '/typings/phaser/package.json' exists according to earlier cached lookups.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'types/phaser.d.ts' that references '/typings/phaser/types/phaser.d.ts'.", + "File '/typings/phaser/types/phaser.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/typings/phaser/types/phaser.d.ts', result '/typings/phaser/types/phaser.d.ts'.", "======== Type reference directive 'phaser' was successfully resolved to '/typings/phaser/types/phaser.d.ts' with Package ID 'phaser/types/phaser.d.ts@1.2.3', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/tsserver/resolutionCache/when-resolves-to-ambient-module.js b/tests/baselines/reference/tsserver/resolutionCache/when-resolves-to-ambient-module.js index ebbecdbfdc2b7..6852cae434ce6 100644 --- a/tests/baselines/reference/tsserver/resolutionCache/when-resolves-to-ambient-module.js +++ b/tests/baselines/reference/tsserver/resolutionCache/when-resolves-to-ambient-module.js @@ -85,11 +85,13 @@ Info 17 [00:00:50.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/pr Info 18 [00:00:51.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/node_modules 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations Info 19 [00:00:52.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations Info 20 [00:00:53.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations -Info 21 [00:00:54.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Type roots -Info 22 [00:00:55.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Type roots -Info 23 [00:00:56.000] Finishing updateGraphWorker: Project: /user/username/projects/myproject/src/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms -Info 24 [00:00:57.000] Project '/user/username/projects/myproject/src/tsconfig.json' (Configured) -Info 25 [00:00:58.000] Files (5) +Info 21 [00:00:54.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations +Info 22 [00:00:55.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations +Info 23 [00:00:56.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Type roots +Info 24 [00:00:57.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Type roots +Info 25 [00:00:58.000] Finishing updateGraphWorker: Project: /user/username/projects/myproject/src/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info 26 [00:00:59.000] Project '/user/username/projects/myproject/src/tsconfig.json' (Configured) +Info 27 [00:01:00.000] Files (5) /a/lib/lib.d.ts /user/username/projects/myproject/src/somefolder/module1.ts /user/username/projects/myproject/src/somefolder/srcfile.ts @@ -109,11 +111,11 @@ Info 25 [00:00:58.000] Files (5) typings/node.d.ts Matched by default include pattern '**/*' -Info 26 [00:00:59.000] ----------------------------------------------- -Info 27 [00:01:00.000] Project '/user/username/projects/myproject/src/tsconfig.json' (Configured) -Info 27 [00:01:01.000] Files (5) +Info 28 [00:01:01.000] ----------------------------------------------- +Info 29 [00:01:02.000] Project '/user/username/projects/myproject/src/tsconfig.json' (Configured) +Info 29 [00:01:03.000] Files (5) -Info 27 [00:01:02.000] ----------------------------------------------- -Info 27 [00:01:03.000] Open files: -Info 27 [00:01:04.000] FileName: /user/username/projects/myproject/src/somefolder/srcfile.ts ProjectRootPath: /user/username/projects/myproject -Info 27 [00:01:05.000] Projects: /user/username/projects/myproject/src/tsconfig.json \ No newline at end of file +Info 29 [00:01:04.000] ----------------------------------------------- +Info 29 [00:01:05.000] Open files: +Info 29 [00:01:06.000] FileName: /user/username/projects/myproject/src/somefolder/srcfile.ts ProjectRootPath: /user/username/projects/myproject +Info 29 [00:01:07.000] Projects: /user/username/projects/myproject/src/tsconfig.json \ No newline at end of file