From b6727ea582d1c457228dc37fad1fab070736cd8d Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 3 Nov 2016 06:09:47 -0700 Subject: [PATCH 1/4] Only resolve symlinks in `node_modules` --- src/compiler/moduleNameResolver.ts | 5 +- src/harness/harness.ts | 50 +++++++++++-------- .../importWithTrailingSlash.trace.json | 4 -- .../moduleResolutionWithExtensions.trace.json | 3 -- ...tionWithExtensions_notSupported.trace.json | 3 -- ...ionWithExtensions_notSupported2.trace.json | 1 - ...ionWithExtensions_notSupported3.trace.json | 1 - ...solutionWithExtensions_preferTs.trace.json | 1 - .../reference/moduleResolutionWithSymlinks.js | 50 +++++++++++++++++-- .../moduleResolutionWithSymlinks.symbols | 23 ++++++++- .../moduleResolutionWithSymlinks.trace.json | 2 - .../moduleResolutionWithSymlinks.types | 21 ++++++++ ...ResolutionWithSymlinks_notInNodeModules.js | 32 ++++++++++++ ...utionWithSymlinks_notInNodeModules.symbols | 12 +++++ ...onWithSymlinks_notInNodeModules.trace.json | 12 +++++ ...olutionWithSymlinks_notInNodeModules.types | 13 +++++ ...moduleResolutionWithSymlinks_withOutDir.js | 40 +++++++++++++++ ...eResolutionWithSymlinks_withOutDir.symbols | 38 ++++++++++++++ ...solutionWithSymlinks_withOutDir.trace.json | 30 +++++++++++ ...uleResolutionWithSymlinks_withOutDir.types | 40 +++++++++++++++ ...pingBasedModuleResolution3_node.trace.json | 2 - ...pingBasedModuleResolution4_node.trace.json | 2 - ...pingBasedModuleResolution5_node.trace.json | 3 -- ...pingBasedModuleResolution6_node.trace.json | 2 - ...pingBasedModuleResolution7_node.trace.json | 4 -- .../typeReferenceDirectives10.trace.json | 1 - .../typeReferenceDirectives11.trace.json | 1 - .../typeReferenceDirectives12.trace.json | 3 -- .../typeReferenceDirectives13.trace.json | 1 - .../typeReferenceDirectives5.trace.json | 1 - .../typeReferenceDirectives8.trace.json | 1 - .../typeReferenceDirectives9.trace.json | 3 -- .../compiler/moduleResolutionWithSymlinks.ts | 25 +++++++++- ...ResolutionWithSymlinks_notInNodeModules.ts | 40 +++++++++++++++ ...moduleResolutionWithSymlinks_withOutDir.ts | 22 ++++++++ 35 files changed, 423 insertions(+), 69 deletions(-) create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.js create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.types create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.js create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.types create mode 100644 tests/cases/compiler/moduleResolutionWithSymlinks_notInNodeModules.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSymlinks_withOutDir.ts diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 86e0157d84729..6c9ce00b3b831 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -548,7 +548,7 @@ namespace ts { const result = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript); if (result) { const { resolved, isExternalLibraryImport } = result; - return createResolvedModuleWithFailedLookupLocations(resolved && resolvedWithRealpath(resolved, host, traceEnabled), isExternalLibraryImport, failedLookupLocations); + return createResolvedModuleWithFailedLookupLocations(resolved, isExternalLibraryImport, failedLookupLocations); } return { resolvedModule: undefined, failedLookupLocations }; @@ -563,7 +563,8 @@ namespace ts { trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName); } const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state, /*checkOneLevel*/ false); - return resolved && { resolved, isExternalLibraryImport: true }; + // For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files. + return resolved && { resolved: resolvedWithRealpath(resolved, host, traceEnabled), isExternalLibraryImport: true }; } else { const candidate = normalizePath(combinePaths(containingDirectory, moduleName)); diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 57ee46299b566..b5dd39b1542ba 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -958,28 +958,38 @@ namespace Harness { // Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames const getCanonicalFileName = ts.createGetCanonicalFileName(useCaseSensitiveFileNames); - const realPathMap: ts.FileMap = ts.createFileMap(); - const fileMap: ts.FileMap<() => ts.SourceFile> = ts.createFileMap<() => ts.SourceFile>(); + /** Maps a symlink name to a realpath. Used only for exposing `realpath`. */ + const realPathMap = ts.createFileMap(); + /** + * Maps a file name to a source file. + * This will have a different SourceFile for every symlink pointing to that file; + * if the program resolves realpaths then symlink entries will be ignored. + */ + const fileMap = ts.createFileMap(); for (const file of inputFiles) { if (file.content !== undefined) { const fileName = ts.normalizePath(file.unitName); const path = ts.toPath(file.unitName, currentDirectory, getCanonicalFileName); if (file.fileOptions && file.fileOptions["symlink"]) { - const link = file.fileOptions["symlink"]; - const linkPath = ts.toPath(link, currentDirectory, getCanonicalFileName); - realPathMap.set(linkPath, fileName); - fileMap.set(path, (): ts.SourceFile => { throw new Error("Symlinks should always be resolved to a realpath first"); }); + const links = file.fileOptions["symlink"].split(","); + for (const link of links) { + const linkPath = ts.toPath(link, currentDirectory, getCanonicalFileName); + realPathMap.set(linkPath, fileName); + // Create a different SourceFile for every symlink. + const sourceFile = createSourceFileAndAssertInvariants(linkPath, file.content, scriptTarget); + fileMap.set(linkPath, sourceFile); + } } const sourceFile = createSourceFileAndAssertInvariants(fileName, file.content, scriptTarget); - fileMap.set(path, () => sourceFile); + fileMap.set(path, sourceFile); } } function getSourceFile(fileName: string) { fileName = ts.normalizePath(fileName); - const path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); - if (fileMap.contains(path)) { - return fileMap.get(path)(); + const fromFileMap = fileMap.get(toPath(fileName)); + if (fromFileMap) { + return fromFileMap; } else if (fileName === fourslashFileName) { const tsFn = "tests/cases/fourslash/" + fourslashFileName; @@ -998,6 +1008,9 @@ namespace Harness { newLineKind === ts.NewLineKind.LineFeed ? lineFeed : Harness.IO.newLine(); + function toPath(fileName: string): ts.Path { + return ts.toPath(fileName, currentDirectory, getCanonicalFileName); + } return { getCurrentDirectory: () => currentDirectory, @@ -1007,24 +1020,19 @@ namespace Harness { getCanonicalFileName, useCaseSensitiveFileNames: () => useCaseSensitiveFileNames, getNewLine: () => newLine, - fileExists: fileName => { - const path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); - return fileMap.contains(path) || (realPathMap && realPathMap.contains(path)); - }, - readFile: (fileName: string): string => { - return fileMap.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName))().getText(); + fileExists: fileName => fileMap.contains(toPath(fileName)), + readFile: (fileName: string): string => fileMap.get(toPath(fileName)).getText(), + realpath: (fileName: string): ts.Path => { + const path = toPath(fileName); + return (realPathMap.get(path) as ts.Path) || path; }, - realpath: realPathMap && ((f: string) => { - const path = ts.toPath(f, currentDirectory, getCanonicalFileName); - return realPathMap.get(path) || path; - }), directoryExists: dir => { let path = ts.toPath(dir, currentDirectory, getCanonicalFileName); // Strip trailing /, which may exist if the path is a drive root if (path[path.length - 1] === "/") { path = path.substr(0, path.length - 1); } - return mapHasFileInDirectory(path, fileMap) || mapHasFileInDirectory(path, realPathMap); + return mapHasFileInDirectory(path, fileMap); }, getDirectories: d => { const path = ts.toPath(d, currentDirectory, getCanonicalFileName); diff --git a/tests/baselines/reference/importWithTrailingSlash.trace.json b/tests/baselines/reference/importWithTrailingSlash.trace.json index 3c99d4eb6a010..56de914f39580 100644 --- a/tests/baselines/reference/importWithTrailingSlash.trace.json +++ b/tests/baselines/reference/importWithTrailingSlash.trace.json @@ -3,26 +3,22 @@ "Explicitly specified module resolution kind: 'NodeJs'.", "Loading module as file / folder, candidate module location '/a'.", "File '/a.ts' exist - use it as a name resolution result.", - "Resolving real path for '/a.ts', result '/a.ts'", "======== Module name '.' was successfully resolved to '/a.ts'. ========", "======== Resolving module './' from '/a/test.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", "Loading module as file / folder, candidate module location '/a/'.", "File '/a/package.json' does not exist.", "File '/a/index.ts' exist - use it as a name resolution result.", - "Resolving real path for '/a/index.ts', result '/a/index.ts'", "======== Module name './' was successfully resolved to '/a/index.ts'. ========", "======== Resolving module '..' from '/a/b/test.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", "Loading module as file / folder, candidate module location '/a'.", "File '/a.ts' exist - use it as a name resolution result.", - "Resolving real path for '/a.ts', result '/a.ts'", "======== Module name '..' was successfully resolved to '/a.ts'. ========", "======== Resolving module '../' from '/a/b/test.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", "Loading module as file / folder, candidate module location '/a/'.", "File '/a/package.json' does not exist.", "File '/a/index.ts' exist - use it as a name resolution result.", - "Resolving real path for '/a/index.ts', result '/a/index.ts'", "======== Module name '../' was successfully resolved to '/a/index.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions.trace.json index 5060006ac56bd..6860c61bb1749 100644 --- a/tests/baselines/reference/moduleResolutionWithExtensions.trace.json +++ b/tests/baselines/reference/moduleResolutionWithExtensions.trace.json @@ -3,7 +3,6 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/src/a'.", "File '/src/a.ts' exist - use it as a name resolution result.", - "Resolving real path for '/src/a.ts', result '/src/a.ts'", "======== Module name './a' was successfully resolved to '/src/a.ts'. ========", "======== Resolving module './a.js' from '/src/d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -13,7 +12,6 @@ "File '/src/a.js.d.ts' does not exist.", "File name '/src/a.js' has a '.js' extension - stripping it", "File '/src/a.ts' exist - use it as a name resolution result.", - "Resolving real path for '/src/a.ts', result '/src/a.ts'", "======== Module name './a.js' was successfully resolved to '/src/a.ts'. ========", "======== Resolving module './jquery.js' from '/src/jquery_user_1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -25,6 +23,5 @@ "File '/src/jquery.ts' does not exist.", "File '/src/jquery.tsx' does not exist.", "File '/src/jquery.d.ts' exist - use it as a name resolution result.", - "Resolving real path for '/src/jquery.d.ts', result '/src/jquery.d.ts'", "======== Module name './jquery.js' was successfully resolved to '/src/jquery.d.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_notSupported.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported.trace.json index 0073abaca3a8a..f2b0214602c59 100644 --- a/tests/baselines/reference/moduleResolutionWithExtensions_notSupported.trace.json +++ b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported.trace.json @@ -4,7 +4,6 @@ "Loading module as file / folder, candidate module location '/tsx'.", "File '/tsx.ts' does not exist.", "File '/tsx.tsx' exist - use it as a name resolution result.", - "Resolving real path for '/tsx.tsx', result '/tsx.tsx'", "======== Module name './tsx' was successfully resolved to '/tsx.tsx'. ========", "======== Resolving module './jsx' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -19,7 +18,6 @@ "Loading module as file / folder, candidate module location '/jsx'.", "File '/jsx.js' does not exist.", "File '/jsx.jsx' exist - use it as a name resolution result.", - "Resolving real path for '/jsx.jsx', result '/jsx.jsx'", "======== Module name './jsx' was successfully resolved to '/jsx.jsx'. ========", "======== Resolving module './js' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -33,6 +31,5 @@ "File '/js/index.d.ts' does not exist.", "Loading module as file / folder, candidate module location '/js'.", "File '/js.js' exist - use it as a name resolution result.", - "Resolving real path for '/js.js', result '/js.js'", "======== Module name './js' was successfully resolved to '/js.js'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_notSupported2.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported2.trace.json index c366843ce86e6..89bd061301efa 100644 --- a/tests/baselines/reference/moduleResolutionWithExtensions_notSupported2.trace.json +++ b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported2.trace.json @@ -12,6 +12,5 @@ "Loading module as file / folder, candidate module location '/jsx'.", "File '/jsx.js' does not exist.", "File '/jsx.jsx' exist - use it as a name resolution result.", - "Resolving real path for '/jsx.jsx', result '/jsx.jsx'", "======== Module name './jsx' was successfully resolved to '/jsx.jsx'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.trace.json index c366843ce86e6..89bd061301efa 100644 --- a/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.trace.json +++ b/tests/baselines/reference/moduleResolutionWithExtensions_notSupported3.trace.json @@ -12,6 +12,5 @@ "Loading module as file / folder, candidate module location '/jsx'.", "File '/jsx.js' does not exist.", "File '/jsx.jsx' exist - use it as a name resolution result.", - "Resolving real path for '/jsx.jsx', result '/jsx.jsx'", "======== Module name './jsx' was successfully resolved to '/jsx.jsx'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_preferTs.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions_preferTs.trace.json index 292472c710c7d..f6612b84cc328 100644 --- a/tests/baselines/reference/moduleResolutionWithExtensions_preferTs.trace.json +++ b/tests/baselines/reference/moduleResolutionWithExtensions_preferTs.trace.json @@ -7,6 +7,5 @@ "File '/b.d.ts' does not exist.", "File '/b/package.json' does not exist.", "File '/b/index.ts' exist - use it as a name resolution result.", - "Resolving real path for '/b/index.ts', result '/b/index.ts'", "======== Module name './b' was successfully resolved to '/b/index.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.js b/tests/baselines/reference/moduleResolutionWithSymlinks.js index fa6fea5520b99..fbf97fa3ba06b 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks.js +++ b/tests/baselines/reference/moduleResolutionWithSymlinks.js @@ -1,6 +1,8 @@ //// [tests/cases/compiler/moduleResolutionWithSymlinks.ts] //// //// [index.ts] +// When symlinked files are in node_modules, they are resolved with realpath; +// so a linked file does not create a duplicate SourceFile of the real one. export class MyClass { private x: number; } @@ -15,9 +17,31 @@ import { MyClass2 } from "./library-b"; let x: MyClass; let y: MyClass2; x = y; -y = x; +y = x; + +/* +# To reproduce in a real project: + +mkdir src; cd src +mkdir library-a +echo 'export class MyClass { private x: number; }' > library-a/index.ts + +mkdir library-b; cd library-b +echo 'import {MyClass} from "library-a"; export { MyClass as MyClass2 }' > index.ts +mkdir node_modules; cd node_modules + +ln -s ../../library-a library-a # Linux +# Windows: open command prompt as administrator and run: mklink /D library-a ..\..\library-a + +cd ../.. # back to src +echo 'import { MyClass } from "./library-a"; import { MyClass2 } from "./library-b"; let x: MyClass; let y: MyClass2; x = y; y = x;' > app.ts +tsc app.ts # Should write to library-a/index.js, library-b/index.js, and app.js +*/ -//// [index.js] + +//// [/src/library-a/index.js] +// When symlinked files are in node_modules, they are resolved with realpath; +// so a linked file does not create a duplicate SourceFile of the real one. "use strict"; var MyClass = (function () { function MyClass() { @@ -25,13 +49,31 @@ var MyClass = (function () { return MyClass; }()); exports.MyClass = MyClass; -//// [index.js] +//// [/src/library-b/index.js] "use strict"; var library_a_1 = require("library-a"); exports.MyClass2 = library_a_1.MyClass; -//// [app.js] +//// [/src/app.js] "use strict"; var x; var y; x = y; y = x; +/* +# To reproduce in a real project: + +mkdir src; cd src +mkdir library-a +echo 'export class MyClass { private x: number; }' > library-a/index.ts + +mkdir library-b; cd library-b +echo 'import {MyClass} from "library-a"; export { MyClass as MyClass2 }' > index.ts +mkdir node_modules; cd node_modules + +ln -s ../../library-a library-a # Linux +# Windows: open command prompt as administrator and run: mklink /D library-a ..\..\library-a + +cd ../.. # back to src +echo 'import { MyClass } from "./library-a"; import { MyClass2 } from "./library-b"; let x: MyClass; let y: MyClass2; x = y; y = x;' > app.ts +tsc app.ts # Should write to library-a/index.js, library-b/index.js, and app.js +*/ diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.symbols b/tests/baselines/reference/moduleResolutionWithSymlinks.symbols index 9e9e3ee8a6709..ede12be35556b 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks.symbols +++ b/tests/baselines/reference/moduleResolutionWithSymlinks.symbols @@ -21,11 +21,32 @@ y = x; >y : Symbol(y, Decl(app.ts, 4, 3)) >x : Symbol(x, Decl(app.ts, 3, 3)) +/* +# To reproduce in a real project: + +mkdir src; cd src +mkdir library-a +echo 'export class MyClass { private x: number; }' > library-a/index.ts + +mkdir library-b; cd library-b +echo 'import {MyClass} from "library-a"; export { MyClass as MyClass2 }' > index.ts +mkdir node_modules; cd node_modules + +ln -s ../../library-a library-a # Linux +# Windows: open command prompt as administrator and run: mklink /D library-a ..\..\library-a + +cd ../.. # back to src +echo 'import { MyClass } from "./library-a"; import { MyClass2 } from "./library-b"; let x: MyClass; let y: MyClass2; x = y; y = x;' > app.ts +tsc app.ts # Should write to library-a/index.js, library-b/index.js, and app.js +*/ + === /src/library-a/index.ts === +// When symlinked files are in node_modules, they are resolved with realpath; +// so a linked file does not create a duplicate SourceFile of the real one. export class MyClass { private x: number; } >MyClass : Symbol(MyClass, Decl(index.ts, 0, 0)) ->x : Symbol(MyClass.x, Decl(index.ts, 1, 22)) +>x : Symbol(MyClass.x, Decl(index.ts, 3, 22)) === /src/library-b/index.ts === import {MyClass} from "library-a"; diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json b/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json index 7f1c289018096..bd23ccdb36679 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json +++ b/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json @@ -7,7 +7,6 @@ "File '/src/library-a.d.ts' does not exist.", "File '/src/library-a/package.json' does not exist.", "File '/src/library-a/index.ts' exist - use it as a name resolution result.", - "Resolving real path for '/src/library-a/index.ts', result '/src/library-a/index.ts'", "======== Module name './library-a' was successfully resolved to '/src/library-a/index.ts'. ========", "======== Resolving module './library-b' from '/src/app.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -17,7 +16,6 @@ "File '/src/library-b.d.ts' does not exist.", "File '/src/library-b/package.json' does not exist.", "File '/src/library-b/index.ts' exist - use it as a name resolution result.", - "Resolving real path for '/src/library-b/index.ts', result '/src/library-b/index.ts'", "======== Module name './library-b' was successfully resolved to '/src/library-b/index.ts'. ========", "======== Resolving module 'library-a' from '/src/library-b/index.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.types b/tests/baselines/reference/moduleResolutionWithSymlinks.types index 3c0ccd168dd0d..04781dcac0f53 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks.types +++ b/tests/baselines/reference/moduleResolutionWithSymlinks.types @@ -23,7 +23,28 @@ y = x; >y : MyClass >x : MyClass +/* +# To reproduce in a real project: + +mkdir src; cd src +mkdir library-a +echo 'export class MyClass { private x: number; }' > library-a/index.ts + +mkdir library-b; cd library-b +echo 'import {MyClass} from "library-a"; export { MyClass as MyClass2 }' > index.ts +mkdir node_modules; cd node_modules + +ln -s ../../library-a library-a # Linux +# Windows: open command prompt as administrator and run: mklink /D library-a ..\..\library-a + +cd ../.. # back to src +echo 'import { MyClass } from "./library-a"; import { MyClass2 } from "./library-b"; let x: MyClass; let y: MyClass2; x = y; y = x;' > app.ts +tsc app.ts # Should write to library-a/index.js, library-b/index.js, and app.js +*/ + === /src/library-a/index.ts === +// When symlinked files are in node_modules, they are resolved with realpath; +// so a linked file does not create a duplicate SourceFile of the real one. export class MyClass { private x: number; } >MyClass : MyClass diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.js b/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.js new file mode 100644 index 0000000000000..a927a496a9661 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.js @@ -0,0 +1,32 @@ +//// [tests/cases/compiler/moduleResolutionWithSymlinks_notInNodeModules.ts] //// + +//// [abc.ts] +// When symlinked files are not in node_modules, realpath is not used. +// A symlink file acts like the real thing. So, 2 symlinks act like 2 different files. +// See GH#10364. + +export const x = 0; + +//// [app.ts] +import { x } from "./shared/abc"; +import { x as x2 } from "./shared2/abc"; +x + x2; + + +//// [/src/bin/shared/abc.js] +// When symlinked files are not in node_modules, realpath is not used. +// A symlink file acts like the real thing. So, 2 symlinks act like 2 different files. +// See GH#10364. +"use strict"; +exports.x = 0; +//// [/src/bin/shared2/abc.js] +// When symlinked files are not in node_modules, realpath is not used. +// A symlink file acts like the real thing. So, 2 symlinks act like 2 different files. +// See GH#10364. +"use strict"; +exports.x = 0; +//// [/src/bin/app.js] +"use strict"; +var abc_1 = require("./shared/abc"); +var abc_2 = require("./shared2/abc"); +abc_1.x + abc_2.x; diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.symbols b/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.symbols new file mode 100644 index 0000000000000..b496e1b76ac02 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.symbols @@ -0,0 +1,12 @@ +=== /src/app.ts === +import { x } from "./shared/abc"; +>x : Symbol(x, Decl(app.ts, 0, 8)) + +import { x as x2 } from "./shared2/abc"; +>x : Symbol(x2, Decl(app.ts, 1, 8)) +>x2 : Symbol(x2, Decl(app.ts, 1, 8)) + +x + x2; +>x : Symbol(x, Decl(app.ts, 0, 8)) +>x2 : Symbol(x2, Decl(app.ts, 1, 8)) + diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.trace.json b/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.trace.json new file mode 100644 index 0000000000000..c2f0c04d07f9b --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.trace.json @@ -0,0 +1,12 @@ +[ + "======== Resolving module './shared/abc' from '/src/app.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module as file / folder, candidate module location '/src/shared/abc'.", + "File '/src/shared/abc.ts' exist - use it as a name resolution result.", + "======== Module name './shared/abc' was successfully resolved to '/src/shared/abc.ts'. ========", + "======== Resolving module './shared2/abc' from '/src/app.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module as file / folder, candidate module location '/src/shared2/abc'.", + "File '/src/shared2/abc.ts' exist - use it as a name resolution result.", + "======== Module name './shared2/abc' was successfully resolved to '/src/shared2/abc.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.types b/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.types new file mode 100644 index 0000000000000..0d7fe290334e1 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_notInNodeModules.types @@ -0,0 +1,13 @@ +=== /src/app.ts === +import { x } from "./shared/abc"; +>x : 0 + +import { x as x2 } from "./shared2/abc"; +>x : 0 +>x2 : 0 + +x + x2; +>x + x2 : number +>x : 0 +>x2 : 0 + diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.js b/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.js new file mode 100644 index 0000000000000..312bcf4c174e7 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.js @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/moduleResolutionWithSymlinks_withOutDir.ts] //// + +//// [index.ts] +// Same as moduleResolutionWithSymlinks.ts, but with outDir + +export class MyClass { private x: number; } + +//// [index.ts] +import {MyClass} from "library-a"; +export { MyClass as MyClass2 } + +//// [app.ts] +import { MyClass } from "./library-a"; +import { MyClass2 } from "./library-b"; + +let x: MyClass; +let y: MyClass2; +x = y; +y = x; + + +//// [/src/bin/library-a/index.js] +// Same as moduleResolutionWithSymlinks.ts, but with outDir +"use strict"; +var MyClass = (function () { + function MyClass() { + } + return MyClass; +}()); +exports.MyClass = MyClass; +//// [/src/bin/library-b/index.js] +"use strict"; +var library_a_1 = require("library-a"); +exports.MyClass2 = library_a_1.MyClass; +//// [/src/bin/app.js] +"use strict"; +var x; +var y; +x = y; +y = x; diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.symbols b/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.symbols new file mode 100644 index 0000000000000..3e7598815de48 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.symbols @@ -0,0 +1,38 @@ +=== /src/app.ts === +import { MyClass } from "./library-a"; +>MyClass : Symbol(MyClass, Decl(app.ts, 0, 8)) + +import { MyClass2 } from "./library-b"; +>MyClass2 : Symbol(MyClass2, Decl(app.ts, 1, 8)) + +let x: MyClass; +>x : Symbol(x, Decl(app.ts, 3, 3)) +>MyClass : Symbol(MyClass, Decl(app.ts, 0, 8)) + +let y: MyClass2; +>y : Symbol(y, Decl(app.ts, 4, 3)) +>MyClass2 : Symbol(MyClass2, Decl(app.ts, 1, 8)) + +x = y; +>x : Symbol(x, Decl(app.ts, 3, 3)) +>y : Symbol(y, Decl(app.ts, 4, 3)) + +y = x; +>y : Symbol(y, Decl(app.ts, 4, 3)) +>x : Symbol(x, Decl(app.ts, 3, 3)) + +=== /src/library-a/index.ts === +// Same as moduleResolutionWithSymlinks.ts, but with outDir + +export class MyClass { private x: number; } +>MyClass : Symbol(MyClass, Decl(index.ts, 0, 0)) +>x : Symbol(MyClass.x, Decl(index.ts, 2, 22)) + +=== /src/library-b/index.ts === +import {MyClass} from "library-a"; +>MyClass : Symbol(MyClass, Decl(index.ts, 0, 8)) + +export { MyClass as MyClass2 } +>MyClass : Symbol(MyClass2, Decl(index.ts, 1, 8)) +>MyClass2 : Symbol(MyClass2, Decl(index.ts, 1, 8)) + diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.trace.json b/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.trace.json new file mode 100644 index 0000000000000..bd23ccdb36679 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.trace.json @@ -0,0 +1,30 @@ +[ + "======== Resolving module './library-a' from '/src/app.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module as file / folder, candidate module location '/src/library-a'.", + "File '/src/library-a.ts' does not exist.", + "File '/src/library-a.tsx' does not exist.", + "File '/src/library-a.d.ts' does not exist.", + "File '/src/library-a/package.json' does not exist.", + "File '/src/library-a/index.ts' exist - use it as a name resolution result.", + "======== Module name './library-a' was successfully resolved to '/src/library-a/index.ts'. ========", + "======== Resolving module './library-b' from '/src/app.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module as file / folder, candidate module location '/src/library-b'.", + "File '/src/library-b.ts' does not exist.", + "File '/src/library-b.tsx' does not exist.", + "File '/src/library-b.d.ts' does not exist.", + "File '/src/library-b/package.json' does not exist.", + "File '/src/library-b/index.ts' exist - use it as a name resolution result.", + "======== Module name './library-b' was successfully resolved to '/src/library-b/index.ts'. ========", + "======== Resolving module 'library-a' from '/src/library-b/index.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module 'library-a' from 'node_modules' folder.", + "File '/src/library-b/node_modules/library-a.ts' does not exist.", + "File '/src/library-b/node_modules/library-a.tsx' does not exist.", + "File '/src/library-b/node_modules/library-a.d.ts' does not exist.", + "File '/src/library-b/node_modules/library-a/package.json' does not exist.", + "File '/src/library-b/node_modules/library-a/index.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/library-b/node_modules/library-a/index.ts', result '/src/library-a/index.ts'", + "======== Module name 'library-a' was successfully resolved to '/src/library-a/index.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.types b/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.types new file mode 100644 index 0000000000000..35fa216792052 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_withOutDir.types @@ -0,0 +1,40 @@ +=== /src/app.ts === +import { MyClass } from "./library-a"; +>MyClass : typeof MyClass + +import { MyClass2 } from "./library-b"; +>MyClass2 : typeof MyClass + +let x: MyClass; +>x : MyClass +>MyClass : MyClass + +let y: MyClass2; +>y : MyClass +>MyClass2 : MyClass + +x = y; +>x = y : MyClass +>x : MyClass +>y : MyClass + +y = x; +>y = x : MyClass +>y : MyClass +>x : MyClass + +=== /src/library-a/index.ts === +// Same as moduleResolutionWithSymlinks.ts, but with outDir + +export class MyClass { private x: number; } +>MyClass : MyClass +>x : number + +=== /src/library-b/index.ts === +import {MyClass} from "library-a"; +>MyClass : typeof MyClass + +export { MyClass as MyClass2 } +>MyClass : typeof MyClass +>MyClass2 : typeof MyClass + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json index ab7210d7d020c..12a32edede21f 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json @@ -5,13 +5,11 @@ "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", "Loading module as file / folder, candidate module location 'c:/root/folder2/file2'.", "File 'c:/root/folder2/file2.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/folder2/file2.ts', result 'c:/root/folder2/file2.ts'", "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", "Loading module as file / folder, candidate module location 'c:/root/folder2/file3'.", "File 'c:/root/folder2/file3.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/folder2/file3.ts', result 'c:/root/folder2/file3.ts'", "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json index ab7210d7d020c..12a32edede21f 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json @@ -5,13 +5,11 @@ "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", "Loading module as file / folder, candidate module location 'c:/root/folder2/file2'.", "File 'c:/root/folder2/file2.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/folder2/file2.ts', result 'c:/root/folder2/file2.ts'", "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", "Loading module as file / folder, candidate module location 'c:/root/folder2/file3'.", "File 'c:/root/folder2/file3.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/folder2/file3.ts', result 'c:/root/folder2/file3.ts'", "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json index 2efeefa24e5ca..f883b2afe36e4 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json @@ -7,7 +7,6 @@ "Trying substitution '*', candidate module location: 'folder2/file1'.", "Loading module as file / folder, candidate module location 'c:/root/folder2/file1'.", "File 'c:/root/folder2/file1.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/folder2/file1.ts', result 'c:/root/folder2/file1.ts'", "======== Module name 'folder2/file1' was successfully resolved to 'c:/root/folder2/file1.ts'. ========", "======== Resolving module 'folder3/file2' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -26,7 +25,6 @@ "Trying substitution 'generated/*', candidate module location: 'generated/folder3/file2'.", "Loading module as file / folder, candidate module location 'c:/root/generated/folder3/file2'.", "File 'c:/root/generated/folder3/file2.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/generated/folder3/file2.ts', result 'c:/root/generated/folder3/file2.ts'", "======== Module name 'folder3/file2' was successfully resolved to 'c:/root/generated/folder3/file2.ts'. ========", "======== Resolving module 'components/file3' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -42,7 +40,6 @@ "File 'c:/root/shared/components/file3/index.ts' does not exist.", "File 'c:/root/shared/components/file3/index.tsx' does not exist.", "File 'c:/root/shared/components/file3/index.d.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/shared/components/file3/index.d.ts', result 'c:/root/shared/components/file3/index.d.ts'", "======== Module name 'components/file3' was successfully resolved to 'c:/root/shared/components/file3/index.d.ts'. ========", "======== Resolving module 'file4' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json index 28e51a119152d..7c5e76a28474e 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json @@ -18,7 +18,6 @@ "Loading 'project/file3' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file3'", "Loading module as file / folder, candidate module location 'c:/root/generated/src/project/file3'.", "File 'c:/root/generated/src/project/file3.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/generated/src/project/file3.ts', result 'c:/root/generated/src/project/file3.ts'", "======== Module name './project/file3' was successfully resolved to 'c:/root/generated/src/project/file3.ts'. ========", "======== Resolving module '../file2' from 'c:/root/generated/src/project/file3.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -45,6 +44,5 @@ "File 'c:/root/src/file2/index.ts' does not exist.", "File 'c:/root/src/file2/index.tsx' does not exist.", "File 'c:/root/src/file2/index.d.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/src/file2/index.d.ts', result 'c:/root/src/file2/index.d.ts'", "======== Module name '../file2' was successfully resolved to 'c:/root/src/file2/index.d.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json index 48633c85e3b48..24139361b0ba6 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json @@ -18,7 +18,6 @@ "Loading 'project/file2' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file2'", "Loading module as file / folder, candidate module location 'c:/root/generated/src/project/file2'.", "File 'c:/root/generated/src/project/file2.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/generated/src/project/file2.ts', result 'c:/root/generated/src/project/file2.ts'", "======== Module name './project/file2' was successfully resolved to 'c:/root/generated/src/project/file2.ts'. ========", "======== Resolving module 'module3' from 'c:/root/src/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -100,7 +99,6 @@ "File 'c:/shared/module1/index.ts' does not exist.", "File 'c:/shared/module1/index.tsx' does not exist.", "File 'c:/shared/module1/index.d.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/shared/module1/index.d.ts', result 'c:/shared/module1/index.d.ts'", "======== Module name 'module1' was successfully resolved to 'c:/shared/module1/index.d.ts'. ========", "======== Resolving module 'templates/module2' from 'c:/root/generated/src/project/file2.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -110,7 +108,6 @@ "Trying substitution 'generated/src/templates/*', candidate module location: 'generated/src/templates/module2'.", "Loading module as file / folder, candidate module location 'c:/root/generated/src/templates/module2'.", "File 'c:/root/generated/src/templates/module2.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/generated/src/templates/module2.ts', result 'c:/root/generated/src/templates/module2.ts'", "======== Module name 'templates/module2' was successfully resolved to 'c:/root/generated/src/templates/module2.ts'. ========", "======== Resolving module '../file3' from 'c:/root/generated/src/project/file2.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -137,6 +134,5 @@ "File 'c:/root/src/file3/index.ts' does not exist.", "File 'c:/root/src/file3/index.tsx' does not exist.", "File 'c:/root/src/file3/index.d.ts' exist - use it as a name resolution result.", - "Resolving real path for 'c:/root/src/file3/index.d.ts', result 'c:/root/src/file3/index.d.ts'", "======== Module name '../file3' was successfully resolved to 'c:/root/src/file3/index.d.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives10.trace.json b/tests/baselines/reference/typeReferenceDirectives10.trace.json index 61341afdab3a3..2dfd1fe0939ca 100644 --- a/tests/baselines/reference/typeReferenceDirectives10.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives10.trace.json @@ -10,7 +10,6 @@ "File '/ref.ts' does not exist.", "File '/ref.tsx' does not exist.", "File '/ref.d.ts' exist - use it as a name resolution result.", - "Resolving real path for '/ref.d.ts', result '/ref.d.ts'", "======== Module name './ref' was successfully resolved to '/ref.d.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", diff --git a/tests/baselines/reference/typeReferenceDirectives11.trace.json b/tests/baselines/reference/typeReferenceDirectives11.trace.json index 37fa7900a7c69..862c941079aa1 100644 --- a/tests/baselines/reference/typeReferenceDirectives11.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives11.trace.json @@ -3,7 +3,6 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/mod1'.", "File '/mod1.ts' exist - use it as a name resolution result.", - "Resolving real path for '/mod1.ts', result '/mod1.ts'", "======== 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'", diff --git a/tests/baselines/reference/typeReferenceDirectives12.trace.json b/tests/baselines/reference/typeReferenceDirectives12.trace.json index 1024b0cdef3db..627ad13588a43 100644 --- a/tests/baselines/reference/typeReferenceDirectives12.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives12.trace.json @@ -3,13 +3,11 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/main'.", "File '/main.ts' exist - use it as a name resolution result.", - "Resolving real path for '/main.ts', result '/main.ts'", "======== Module name './main' was successfully resolved to '/main.ts'. ========", "======== Resolving module './mod1' from '/mod2.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/mod1'.", "File '/mod1.ts' exist - use it as a name resolution result.", - "Resolving real path for '/mod1.ts', result '/mod1.ts'", "======== 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'", @@ -20,7 +18,6 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/main'.", "File '/main.ts' exist - use it as a name resolution result.", - "Resolving real path for '/main.ts', result '/main.ts'", "======== Module name './main' was successfully resolved to '/main.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", diff --git a/tests/baselines/reference/typeReferenceDirectives13.trace.json b/tests/baselines/reference/typeReferenceDirectives13.trace.json index 61341afdab3a3..2dfd1fe0939ca 100644 --- a/tests/baselines/reference/typeReferenceDirectives13.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives13.trace.json @@ -10,7 +10,6 @@ "File '/ref.ts' does not exist.", "File '/ref.tsx' does not exist.", "File '/ref.d.ts' exist - use it as a name resolution result.", - "Resolving real path for '/ref.d.ts', result '/ref.d.ts'", "======== Module name './ref' was successfully resolved to '/ref.d.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", diff --git a/tests/baselines/reference/typeReferenceDirectives5.trace.json b/tests/baselines/reference/typeReferenceDirectives5.trace.json index 61341afdab3a3..2dfd1fe0939ca 100644 --- a/tests/baselines/reference/typeReferenceDirectives5.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives5.trace.json @@ -10,7 +10,6 @@ "File '/ref.ts' does not exist.", "File '/ref.tsx' does not exist.", "File '/ref.d.ts' exist - use it as a name resolution result.", - "Resolving real path for '/ref.d.ts', result '/ref.d.ts'", "======== Module name './ref' was successfully resolved to '/ref.d.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", diff --git a/tests/baselines/reference/typeReferenceDirectives8.trace.json b/tests/baselines/reference/typeReferenceDirectives8.trace.json index 37fa7900a7c69..862c941079aa1 100644 --- a/tests/baselines/reference/typeReferenceDirectives8.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives8.trace.json @@ -3,7 +3,6 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/mod1'.", "File '/mod1.ts' exist - use it as a name resolution result.", - "Resolving real path for '/mod1.ts', result '/mod1.ts'", "======== 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'", diff --git a/tests/baselines/reference/typeReferenceDirectives9.trace.json b/tests/baselines/reference/typeReferenceDirectives9.trace.json index 1024b0cdef3db..627ad13588a43 100644 --- a/tests/baselines/reference/typeReferenceDirectives9.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives9.trace.json @@ -3,13 +3,11 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/main'.", "File '/main.ts' exist - use it as a name resolution result.", - "Resolving real path for '/main.ts', result '/main.ts'", "======== Module name './main' was successfully resolved to '/main.ts'. ========", "======== Resolving module './mod1' from '/mod2.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/mod1'.", "File '/mod1.ts' exist - use it as a name resolution result.", - "Resolving real path for '/mod1.ts', result '/mod1.ts'", "======== 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'", @@ -20,7 +18,6 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/main'.", "File '/main.ts' exist - use it as a name resolution result.", - "Resolving real path for '/main.ts', result '/main.ts'", "======== Module name './main' was successfully resolved to '/main.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", diff --git a/tests/cases/compiler/moduleResolutionWithSymlinks.ts b/tests/cases/compiler/moduleResolutionWithSymlinks.ts index 4819b68ffc66d..069f11f85da67 100644 --- a/tests/cases/compiler/moduleResolutionWithSymlinks.ts +++ b/tests/cases/compiler/moduleResolutionWithSymlinks.ts @@ -1,6 +1,8 @@ -// @module: commonjs +// When symlinked files are in node_modules, they are resolved with realpath; +// so a linked file does not create a duplicate SourceFile of the real one. // @noImplicitReferences: true // @traceResolution: true +// @fullEmitPaths: true // @filename: /src/library-a/index.ts // @symlink: /src/library-b/node_modules/library-a/index.ts @@ -17,4 +19,23 @@ import { MyClass2 } from "./library-b"; let x: MyClass; let y: MyClass2; x = y; -y = x; \ No newline at end of file +y = x; + +/* +# To reproduce in a real project: + +mkdir src; cd src +mkdir library-a +echo 'export class MyClass { private x: number; }' > library-a/index.ts + +mkdir library-b; cd library-b +echo 'import {MyClass} from "library-a"; export { MyClass as MyClass2 }' > index.ts +mkdir node_modules; cd node_modules + +ln -s ../../library-a library-a # Linux +# Windows: open command prompt as administrator and run: mklink /D library-a ..\..\library-a + +cd ../.. # back to src +echo 'import { MyClass } from "./library-a"; import { MyClass2 } from "./library-b"; let x: MyClass; let y: MyClass2; x = y; y = x;' > app.ts +tsc app.ts # Should write to library-a/index.js, library-b/index.js, and app.js +*/ diff --git a/tests/cases/compiler/moduleResolutionWithSymlinks_notInNodeModules.ts b/tests/cases/compiler/moduleResolutionWithSymlinks_notInNodeModules.ts new file mode 100644 index 0000000000000..f861813942ff7 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSymlinks_notInNodeModules.ts @@ -0,0 +1,40 @@ +// When symlinked files are not in node_modules, realpath is not used. +// A symlink file acts like the real thing. So, 2 symlinks act like 2 different files. +// See GH#10364. +// @noImplicitReferences: true +// @traceResolution: true +// @fullEmitPaths: true + +// @filename: /shared/abc.ts +// @symlink: /src/shared/abc.ts,/src/shared2/abc.ts +export const x = 0; + +// @filename: /src/app.ts +import { x } from "./shared/abc"; +import { x as x2 } from "./shared2/abc"; +x + x2; + +// @filename: /src/tsconfig.json +{ + "compilerOptions": { + "outDir": "bin" + } +} + +/* +# To reproduce in a real project: + +mkdir shared +echo 'export const x = 0;' > shared/abc.ts + +mkdir src; cd src +echo 'import { x } from "./shared/abc"; import { x as x2 } from "./shared2/abc"; x + x2;' > app.ts + +ln -s ../shared ./shared; ln -s ../shared ./shared2 # Linux +# Windows: Open command prompt as administrator and run: `mklink /D shared ..\shared; mklink /D shared2 ..\shared` + +echo '{ "compilerOptions": { "outDir": "bin" } }' > tsconfig.json +node ../../../../TypeScript/built/local/tsc.js + +# Should create `bin/app.js`, `bin/shared/abc.js`, and `bin/shared2/abc.js` +*/ diff --git a/tests/cases/compiler/moduleResolutionWithSymlinks_withOutDir.ts b/tests/cases/compiler/moduleResolutionWithSymlinks_withOutDir.ts new file mode 100644 index 0000000000000..c17e9091de462 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSymlinks_withOutDir.ts @@ -0,0 +1,22 @@ +// Same as moduleResolutionWithSymlinks.ts, but with outDir +// @noImplicitReferences: true +// @traceResolution: true +// @fullEmitPaths: true +// @outDir: /src/bin + +// @filename: /src/library-a/index.ts +// @symlink: /src/library-b/node_modules/library-a/index.ts +export class MyClass { private x: number; } + +// @filename: /src/library-b/index.ts +import {MyClass} from "library-a"; +export { MyClass as MyClass2 } + +// @filename: /src/app.ts +import { MyClass } from "./library-a"; +import { MyClass2 } from "./library-b"; + +let x: MyClass; +let y: MyClass2; +x = y; +y = x; From 9c80909a90e967535470d811bebe8c088f0824cf Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 9 Nov 2016 07:41:25 -0800 Subject: [PATCH 2/4] Resolve symlinks for type reference directives too. --- src/compiler/moduleNameResolver.ts | 97 ++++++++++--------- src/compiler/program.ts | 23 +++-- src/harness/harness.ts | 9 +- .../reference/library-reference-1.trace.json | 6 +- .../reference/library-reference-10.trace.json | 6 +- .../reference/library-reference-11.trace.json | 1 + .../reference/library-reference-12.trace.json | 1 + .../reference/library-reference-13.trace.json | 1 + .../reference/library-reference-14.trace.json | 1 + .../reference/library-reference-15.trace.json | 3 +- .../reference/library-reference-2.trace.json | 2 + .../reference/library-reference-3.trace.json | 1 + .../reference/library-reference-4.trace.json | 4 + .../reference/library-reference-5.trace.json | 4 + .../reference/library-reference-6.trace.json | 2 + .../reference/library-reference-7.trace.json | 1 + .../reference/library-reference-8.trace.json | 6 ++ ...leResolutionWithSymlinks_referenceTypes.js | 73 ++++++++++++++ ...olutionWithSymlinks_referenceTypes.symbols | 45 +++++++++ ...tionWithSymlinks_referenceTypes.trace.json | 35 +++++++ ...esolutionWithSymlinks_referenceTypes.types | 45 +++++++++ .../typeReferenceDirectives1.trace.json | 2 + .../typeReferenceDirectives10.trace.json | 2 + .../typeReferenceDirectives11.trace.json | 1 + .../typeReferenceDirectives12.trace.json | 2 + .../typeReferenceDirectives13.trace.json | 2 + .../typeReferenceDirectives2.trace.json | 1 + .../typeReferenceDirectives3.trace.json | 2 + .../typeReferenceDirectives4.trace.json | 2 + .../typeReferenceDirectives5.trace.json | 2 + .../typeReferenceDirectives6.trace.json | 2 + .../typeReferenceDirectives7.trace.json | 2 + .../typeReferenceDirectives8.trace.json | 1 + .../typeReferenceDirectives9.trace.json | 2 + ...mMultipleNodeModulesDirectories.trace.json | 3 + ...romNodeModulesInParentDirectory.trace.json | 1 + .../reference/typingsLookup1.trace.json | 2 + .../reference/typingsLookup3.trace.json | 2 + .../reference/typingsLookup4.trace.json | 3 + .../reference/typingsLookupAmd.trace.json | 1 + ...ResolutionWithSymlinks_notInNodeModules.ts | 4 +- ...leResolutionWithSymlinks_referenceTypes.ts | 45 +++++++++ 42 files changed, 384 insertions(+), 66 deletions(-) create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.js create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.types create mode 100644 tests/cases/compiler/moduleResolutionWithSymlinks_referenceTypes.ts diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 6c9ce00b3b831..8019944e8a2ad 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -195,63 +195,66 @@ namespace ts { const failedLookupLocations: string[] = []; - // Check primary library paths - if (typeRoots && typeRoots.length) { + let resolved = primaryLookup(); + let primary = true; + if (!resolved) { + resolved = secondaryLookup(); + primary = false; + } + + let resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined; + if (resolved) { + resolved = realpath(resolved, host, traceEnabled); if (traceEnabled) { - trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", ")); + trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolved, primary); } - for (const typeRoot of typeRoots) { - const candidate = combinePaths(typeRoot, typeReferenceDirectiveName); - const candidateDirectory = getDirectoryPath(candidate); + resolvedTypeReferenceDirective = { primary, resolvedFileName: resolved }; + } - const resolved = resolvedTypeScriptOnly( - loadNodeModuleFromDirectory(Extensions.DtsOnly, candidate, failedLookupLocations, - !directoryProbablyExists(candidateDirectory, host), moduleResolutionState)); + return { resolvedTypeReferenceDirective, failedLookupLocations }; - if (resolved) { - if (traceEnabled) { - trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolved, true); - } - return { - resolvedTypeReferenceDirective: { primary: true, resolvedFileName: resolved }, - failedLookupLocations - }; + function primaryLookup(): string | undefined { + // Check primary library paths + if (typeRoots && typeRoots.length) { + if (traceEnabled) { + trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", ")); } + return forEach(typeRoots, typeRoot => { + const candidate = combinePaths(typeRoot, typeReferenceDirectiveName); + const candidateDirectory = getDirectoryPath(candidate); + return resolvedTypeScriptOnly( + loadNodeModuleFromDirectory(Extensions.DtsOnly, candidate, failedLookupLocations, + !directoryProbablyExists(candidateDirectory, host), moduleResolutionState)); + }); } - } - else { - if (traceEnabled) { - trace(host, Diagnostics.Root_directory_cannot_be_determined_skipping_primary_search_paths); + else { + if (traceEnabled) { + trace(host, Diagnostics.Root_directory_cannot_be_determined_skipping_primary_search_paths); + } } } - let resolvedFile: string; - const initialLocationForSecondaryLookup = containingFile && getDirectoryPath(containingFile); + function secondaryLookup(): string | undefined { + let resolvedFile: string; + 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); - } - resolvedFile = resolvedTypeScriptOnly(loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState, /*checkOneLevel*/ false)); - if (traceEnabled) { - if (resolvedFile) { - trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, false); + if (initialLocationForSecondaryLookup !== undefined) { + // check secondary locations + if (traceEnabled) { + trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup); } - else { + resolvedFile = resolvedTypeScriptOnly(loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState, /*checkOneLevel*/ false)); + if (!resolvedFile && traceEnabled) { trace(host, Diagnostics.Type_reference_directive_0_was_not_resolved, typeReferenceDirectiveName); } + return resolvedFile; } - } - else { - if (traceEnabled) { - trace(host, Diagnostics.Containing_file_is_not_specified_and_root_directory_cannot_be_determined_skipping_lookup_in_node_modules_folder); + else { + if (traceEnabled) { + trace(host, Diagnostics.Containing_file_is_not_specified_and_root_directory_cannot_be_determined_skipping_lookup_in_node_modules_folder); + } } } - return { - resolvedTypeReferenceDirective: resolvedFile ? { primary: false, resolvedFileName: resolvedFile } : undefined, - failedLookupLocations - }; } /** @@ -564,7 +567,7 @@ namespace ts { } const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state, /*checkOneLevel*/ false); // For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files. - return resolved && { resolved: resolvedWithRealpath(resolved, host, traceEnabled), isExternalLibraryImport: true }; + return resolved && { resolved: { path: realpath(resolved.path, host, traceEnabled), extension: resolved.extension }, isExternalLibraryImport: true }; } else { const candidate = normalizePath(combinePaths(containingDirectory, moduleName)); @@ -574,16 +577,16 @@ namespace ts { } } - function resolvedWithRealpath(resolved: Resolved, host: ModuleResolutionHost, traceEnabled: boolean): Resolved { + function realpath(path: string, host: ModuleResolutionHost, traceEnabled: boolean): string { if (!host.realpath) { - return resolved; + return path; } - const real = normalizePath(host.realpath(resolved.path)); + const real = normalizePath(host.realpath(path)); if (traceEnabled) { - trace(host, Diagnostics.Resolving_real_path_for_0_result_1, resolved.path, real); + trace(host, Diagnostics.Resolving_real_path_for_0_result_1, path, real); } - return { path: real, extension: resolved.extension }; + return real; } function nodeLoadModuleByRelativeName(extensions: Extensions, candidate: string, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 35c6818fea839..717df57765ad5 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -480,7 +480,7 @@ namespace ts { return resolveModuleNamesWorker(moduleNames, containingFile); } - // at this point we know that either + // at this point we know that either // - file has local declarations for ambient modules // OR // - old program state is available @@ -674,7 +674,7 @@ namespace ts { } const modifiedFilePaths = modifiedSourceFiles.map(f => f.newFile.path); - // try to verify results of module resolution + // try to verify results of module resolution for (const { oldFile: oldSourceFile, newFile: newSourceFile } of modifiedSourceFiles) { const newSourceFilePath = getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory); if (resolveModuleNamesWorker) { @@ -1395,14 +1395,17 @@ namespace ts { // If we already resolved to this file, it must have been a secondary reference. Check file contents // for sameness and possibly issue an error if (previousResolution) { - const otherFileText = host.readFile(resolvedTypeReferenceDirective.resolvedFileName); - if (otherFileText !== getSourceFile(previousResolution.resolvedFileName).text) { - fileProcessingDiagnostics.add(createDiagnostic(refFile, refPos, refEnd, - Diagnostics.Conflicting_definitions_for_0_found_at_1_and_2_Consider_installing_a_specific_version_of_this_library_to_resolve_the_conflict, - typeReferenceDirective, - resolvedTypeReferenceDirective.resolvedFileName, - previousResolution.resolvedFileName - )); + // Don't bother reading the file again if it's the same file. + if (resolvedTypeReferenceDirective.resolvedFileName !== previousResolution.resolvedFileName) { + const otherFileText = host.readFile(resolvedTypeReferenceDirective.resolvedFileName); + if (otherFileText !== getSourceFile(previousResolution.resolvedFileName).text) { + fileProcessingDiagnostics.add(createDiagnostic(refFile, refPos, refEnd, + Diagnostics.Conflicting_definitions_for_0_found_at_1_and_2_Consider_installing_a_specific_version_of_this_library_to_resolve_the_conflict, + typeReferenceDirective, + resolvedTypeReferenceDirective.resolvedFileName, + previousResolution.resolvedFileName + )); + } } // don't overwrite previous resolution result saveResolution = false; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index b5dd39b1542ba..611c8aa56d902 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1021,7 +1021,14 @@ namespace Harness { useCaseSensitiveFileNames: () => useCaseSensitiveFileNames, getNewLine: () => newLine, fileExists: fileName => fileMap.contains(toPath(fileName)), - readFile: (fileName: string): string => fileMap.get(toPath(fileName)).getText(), + readFile: (fileName: string): string => { + const file = fileMap.get(toPath(fileName)); + if (ts.endsWith(fileName, "json")) { + // strip comments + return file.getText(); + } + return file.text; + }, realpath: (fileName: string): ts.Path => { const path = toPath(fileName); return (realPathMap.get(path) as ts.Path) || path; diff --git a/tests/baselines/reference/library-reference-1.trace.json b/tests/baselines/reference/library-reference-1.trace.json index 715572362407e..d13ac9da45507 100644 --- a/tests/baselines/reference/library-reference-1.trace.json +++ b/tests/baselines/reference/library-reference-1.trace.json @@ -3,10 +3,12 @@ "Resolving with primary search path 'types'", "File 'types/jquery/package.json' does not exist.", "File 'types/jquery/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'jquery' was successfully resolved to 'types/jquery/index.d.ts', primary: true. ========", + "Resolving real path for 'types/jquery/index.d.ts', result '/src/types/jquery/index.d.ts'", + "======== Type reference directive 'jquery' was successfully resolved to '/src/types/jquery/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'jquery', containing file '/src/__inferred type names__.ts', root directory 'types'. ========", "Resolving with primary search path 'types'", "File 'types/jquery/package.json' does not exist.", "File 'types/jquery/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'jquery' was successfully resolved to 'types/jquery/index.d.ts', primary: true. ========" + "Resolving real path for 'types/jquery/index.d.ts', result '/src/types/jquery/index.d.ts'", + "======== Type reference directive 'jquery' was successfully resolved to '/src/types/jquery/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-10.trace.json b/tests/baselines/reference/library-reference-10.trace.json index f4df00fa52ded..760f0c5ec826a 100644 --- a/tests/baselines/reference/library-reference-10.trace.json +++ b/tests/baselines/reference/library-reference-10.trace.json @@ -4,11 +4,13 @@ "Found 'package.json' at './types/jquery/package.json'.", "'package.json' has 'typings' field 'jquery.d.ts' that references 'types/jquery/jquery.d.ts'.", "File 'types/jquery/jquery.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'jquery' was successfully resolved to 'types/jquery/jquery.d.ts', primary: true. ========", + "Resolving real path for 'types/jquery/jquery.d.ts', result '/foo/types/jquery/jquery.d.ts'", + "======== Type reference directive 'jquery' was successfully resolved to '/foo/types/jquery/jquery.d.ts', primary: true. ========", "======== Resolving type reference directive 'jquery', containing file '/foo/__inferred type names__.ts', root directory './types'. ========", "Resolving with primary search path './types'", "Found 'package.json' at './types/jquery/package.json'.", "'package.json' has 'typings' field 'jquery.d.ts' that references 'types/jquery/jquery.d.ts'.", "File 'types/jquery/jquery.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'jquery' was successfully resolved to 'types/jquery/jquery.d.ts', primary: true. ========" + "Resolving real path for 'types/jquery/jquery.d.ts', result '/foo/types/jquery/jquery.d.ts'", + "======== Type reference directive 'jquery' was successfully resolved to '/foo/types/jquery/jquery.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-11.trace.json b/tests/baselines/reference/library-reference-11.trace.json index 6428f421d7e30..78ac53013f7fd 100644 --- a/tests/baselines/reference/library-reference-11.trace.json +++ b/tests/baselines/reference/library-reference-11.trace.json @@ -12,5 +12,6 @@ "Found 'package.json' at '/a/node_modules/jquery/package.json'.", "'package.json' has 'typings' field 'jquery.d.ts' that references '/a/node_modules/jquery/jquery.d.ts'.", "File '/a/node_modules/jquery/jquery.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/a/node_modules/jquery/jquery.d.ts', result '/a/node_modules/jquery/jquery.d.ts'", "======== Type reference directive 'jquery' was successfully resolved to '/a/node_modules/jquery/jquery.d.ts', primary: false. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-12.trace.json b/tests/baselines/reference/library-reference-12.trace.json index 37017c86f0c9e..6e09c7a3f0459 100644 --- a/tests/baselines/reference/library-reference-12.trace.json +++ b/tests/baselines/reference/library-reference-12.trace.json @@ -12,5 +12,6 @@ "Found 'package.json' at '/a/node_modules/jquery/package.json'.", "'package.json' has 'types' field 'dist/jquery.d.ts' that references '/a/node_modules/jquery/dist/jquery.d.ts'.", "File '/a/node_modules/jquery/dist/jquery.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/a/node_modules/jquery/dist/jquery.d.ts', result '/a/node_modules/jquery/dist/jquery.d.ts'", "======== Type reference directive 'jquery' was successfully resolved to '/a/node_modules/jquery/dist/jquery.d.ts', primary: false. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-13.trace.json b/tests/baselines/reference/library-reference-13.trace.json index a23f0ef0ca56e..86f7a5a505d49 100644 --- a/tests/baselines/reference/library-reference-13.trace.json +++ b/tests/baselines/reference/library-reference-13.trace.json @@ -3,5 +3,6 @@ "Resolving with primary search path '/a/types'", "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'", "======== Type reference directive 'jquery' was successfully resolved to '/a/types/jquery/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-14.trace.json b/tests/baselines/reference/library-reference-14.trace.json index fb3a2bb7da48d..338cefbc47e89 100644 --- a/tests/baselines/reference/library-reference-14.trace.json +++ b/tests/baselines/reference/library-reference-14.trace.json @@ -3,5 +3,6 @@ "Resolving with primary search path '/a/types'", "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'", "======== Type reference directive 'jquery' was successfully resolved to '/a/types/jquery/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-15.trace.json b/tests/baselines/reference/library-reference-15.trace.json index e23517976b0e4..6d8b5cf140866 100644 --- a/tests/baselines/reference/library-reference-15.trace.json +++ b/tests/baselines/reference/library-reference-15.trace.json @@ -3,5 +3,6 @@ "Resolving with primary search path 'types'", "File 'types/jquery/package.json' does not exist.", "File 'types/jquery/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'jquery' was successfully resolved to 'types/jquery/index.d.ts', primary: true. ========" + "Resolving real path for 'types/jquery/index.d.ts', result '/a/types/jquery/index.d.ts'", + "======== Type reference directive 'jquery' was successfully resolved to '/a/types/jquery/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-2.trace.json b/tests/baselines/reference/library-reference-2.trace.json index 64cdd8091832f..8837f2c9cb1b8 100644 --- a/tests/baselines/reference/library-reference-2.trace.json +++ b/tests/baselines/reference/library-reference-2.trace.json @@ -4,11 +4,13 @@ "Found 'package.json' at '/types/jquery/package.json'.", "'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", "File '/types/jquery/jquery.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/types/jquery/jquery.d.ts', result '/types/jquery/jquery.d.ts'", "======== 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'", "Found 'package.json' at '/types/jquery/package.json'.", "'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", "File '/types/jquery/jquery.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/types/jquery/jquery.d.ts', result '/types/jquery/jquery.d.ts'", "======== Type reference directive 'jquery' was successfully resolved to '/types/jquery/jquery.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-3.trace.json b/tests/baselines/reference/library-reference-3.trace.json index 72cc8c950779b..d672eb50de846 100644 --- a/tests/baselines/reference/library-reference-3.trace.json +++ b/tests/baselines/reference/library-reference-3.trace.json @@ -5,5 +5,6 @@ "File '/src/node_modules/jquery.d.ts' does not exist.", "File '/src/node_modules/jquery/package.json' does not exist.", "File '/src/node_modules/jquery/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/node_modules/jquery/index.d.ts', result '/src/node_modules/jquery/index.d.ts'", "======== Type reference directive 'jquery' was successfully resolved to '/src/node_modules/jquery/index.d.ts', primary: false. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-4.trace.json b/tests/baselines/reference/library-reference-4.trace.json index 2a128b4fcbef4..b47ba1065f55a 100644 --- a/tests/baselines/reference/library-reference-4.trace.json +++ b/tests/baselines/reference/library-reference-4.trace.json @@ -13,6 +13,7 @@ "File '/node_modules/foo.d.ts' does not exist.", "File '/node_modules/foo/package.json' does not exist.", "File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/foo/index.d.ts', result '/node_modules/foo/index.d.ts'", "======== 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'", @@ -28,6 +29,7 @@ "File '/node_modules/bar.d.ts' does not exist.", "File '/node_modules/bar/package.json' does not exist.", "File '/node_modules/bar/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/bar/index.d.ts', result '/node_modules/bar/index.d.ts'", "======== 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'", @@ -37,6 +39,7 @@ "File '/node_modules/foo/node_modules/alpha.d.ts' does not exist.", "File '/node_modules/foo/node_modules/alpha/package.json' does not exist.", "File '/node_modules/foo/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/foo/node_modules/alpha/index.d.ts', result '/node_modules/foo/node_modules/alpha/index.d.ts'", "======== 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'", @@ -46,5 +49,6 @@ "File '/node_modules/bar/node_modules/alpha.d.ts' does not exist.", "File '/node_modules/bar/node_modules/alpha/package.json' does not exist.", "File '/node_modules/bar/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/bar/node_modules/alpha/index.d.ts', result '/node_modules/bar/node_modules/alpha/index.d.ts'", "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/bar/node_modules/alpha/index.d.ts', primary: false. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-5.trace.json b/tests/baselines/reference/library-reference-5.trace.json index dc9bff30b274e..8f548e04d10a9 100644 --- a/tests/baselines/reference/library-reference-5.trace.json +++ b/tests/baselines/reference/library-reference-5.trace.json @@ -13,6 +13,7 @@ "File '/node_modules/foo.d.ts' does not exist.", "File '/node_modules/foo/package.json' does not exist.", "File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/foo/index.d.ts', result '/node_modules/foo/index.d.ts'", "======== 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 'types'. ========", "Resolving with primary search path 'types'", @@ -28,6 +29,7 @@ "File '/node_modules/bar.d.ts' does not exist.", "File '/node_modules/bar/package.json' does not exist.", "File '/node_modules/bar/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/bar/index.d.ts', result '/node_modules/bar/index.d.ts'", "======== 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 'types'. ========", "Resolving with primary search path 'types'", @@ -37,6 +39,7 @@ "File '/node_modules/foo/node_modules/alpha.d.ts' does not exist.", "File '/node_modules/foo/node_modules/alpha/package.json' does not exist.", "File '/node_modules/foo/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/foo/node_modules/alpha/index.d.ts', result '/node_modules/foo/node_modules/alpha/index.d.ts'", "======== 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 'types'. ========", "Resolving with primary search path 'types'", @@ -46,5 +49,6 @@ "File '/node_modules/bar/node_modules/alpha.d.ts' does not exist.", "File '/node_modules/bar/node_modules/alpha/package.json' does not exist.", "File '/node_modules/bar/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/bar/node_modules/alpha/index.d.ts', result '/node_modules/bar/node_modules/alpha/index.d.ts'", "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/bar/node_modules/alpha/index.d.ts', primary: false. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-6.trace.json b/tests/baselines/reference/library-reference-6.trace.json index fd83c1431b438..6ca81a6c41889 100644 --- a/tests/baselines/reference/library-reference-6.trace.json +++ b/tests/baselines/reference/library-reference-6.trace.json @@ -3,10 +3,12 @@ "Resolving with primary search path '/node_modules/@types'", "File '/node_modules/@types/alpha/package.json' does not exist.", "File '/node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/alpha/index.d.ts', result '/node_modules/@types/alpha/index.d.ts'", "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/@types/alpha/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'alpha', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", "Resolving with primary search path '/node_modules/@types'", "File '/node_modules/@types/alpha/package.json' does not exist.", "File '/node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/alpha/index.d.ts', result '/node_modules/@types/alpha/index.d.ts'", "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/@types/alpha/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-7.trace.json b/tests/baselines/reference/library-reference-7.trace.json index 72cc8c950779b..d672eb50de846 100644 --- a/tests/baselines/reference/library-reference-7.trace.json +++ b/tests/baselines/reference/library-reference-7.trace.json @@ -5,5 +5,6 @@ "File '/src/node_modules/jquery.d.ts' does not exist.", "File '/src/node_modules/jquery/package.json' does not exist.", "File '/src/node_modules/jquery/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/node_modules/jquery/index.d.ts', result '/src/node_modules/jquery/index.d.ts'", "======== Type reference directive 'jquery' was successfully resolved to '/src/node_modules/jquery/index.d.ts', primary: false. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-8.trace.json b/tests/baselines/reference/library-reference-8.trace.json index d34f206e5816b..905c3c2bb36a8 100644 --- a/tests/baselines/reference/library-reference-8.trace.json +++ b/tests/baselines/reference/library-reference-8.trace.json @@ -3,30 +3,36 @@ "Resolving with primary search path '/test/types'", "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/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/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 'alpha', containing file '/test/types/beta/index.d.ts', root directory '/test/types'. ========", "Resolving with primary search path '/test/types'", "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 'alpha', containing file '/test/__inferred type names__.ts', root directory '/test/types'. ========", "Resolving with primary search path '/test/types'", "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/__inferred type names__.ts', root directory '/test/types'. ========", "Resolving with primary search path '/test/types'", "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. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.js b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.js new file mode 100644 index 0000000000000..8fa8ca1c6f111 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.js @@ -0,0 +1,73 @@ +//// [tests/cases/compiler/moduleResolutionWithSymlinks_referenceTypes.ts] //// + +//// [index.d.ts] +// Symlinks are always resolved for type reference directives. +// NOTE: This test would still compile without errors even if they were not, +// because `processTypeReferenceDirective` also checks for textual equivalence of file contents. +// But the `moduleResolutionWithSymlinks_referenceTypes.trace.json` shows the difference. + + +declare class MyClass { private x: number; } + +//// [index.d.ts] +/// + +//// [app.ts] +/// +/// + +/* +# To reproduce in a real project: + +echo '/// ' > app.ts +echo '/// ' >> app.ts + +mkdir node_modules/@types +cd mode_modules/@types +mkdir library-a +echo 'declare class MyClass { private x: number; }' > library-a/index.d.ts + +mkdir library-b +cd library-b +echo '/// ' > index.d.ts + +mkdir node_modules +cd node_modules + +ln -s ../../library-a ./library-a +# Windows: Open command prompt as administrator and run: `mklink /D library-a ..\..\library-a` + +cd ../../.. # back to root + +tsc app.ts # Should create `app.js` +*/ + + +//// [/app.js] +/// +/// +/* +# To reproduce in a real project: + +echo '/// ' > app.ts +echo '/// ' >> app.ts + +mkdir node_modules/@types +cd mode_modules/@types +mkdir library-a +echo 'declare class MyClass { private x: number; }' > library-a/index.d.ts + +mkdir library-b +cd library-b +echo '/// ' > index.d.ts + +mkdir node_modules +cd node_modules + +ln -s ../../library-a ./library-a +# Windows: Open command prompt as administrator and run: `mklink /D library-a ..\..\library-a` + +cd ../../.. # back to root + +tsc app.ts # Should create `app.js` +*/ diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.symbols b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.symbols new file mode 100644 index 0000000000000..efb46a42f7f33 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.symbols @@ -0,0 +1,45 @@ +=== /app.ts === +/// +No type information for this code./// +No type information for this code. +No type information for this code./* +No type information for this code.# To reproduce in a real project: +No type information for this code. +No type information for this code.echo '/// ' > app.ts +No type information for this code.echo '/// ' >> app.ts +No type information for this code. +No type information for this code.mkdir node_modules/@types +No type information for this code.cd mode_modules/@types +No type information for this code.mkdir library-a +No type information for this code.echo 'declare class MyClass { private x: number; }' > library-a/index.d.ts +No type information for this code. +No type information for this code.mkdir library-b +No type information for this code.cd library-b +No type information for this code.echo '/// ' > index.d.ts +No type information for this code. +No type information for this code.mkdir node_modules +No type information for this code.cd node_modules +No type information for this code. +No type information for this code.ln -s ../../library-a ./library-a +No type information for this code.# Windows: Open command prompt as administrator and run: `mklink /D library-a ..\..\library-a` +No type information for this code. +No type information for this code.cd ../../.. # back to root +No type information for this code. +No type information for this code.tsc app.ts # Should create `app.js` +No type information for this code.*/ +No type information for this code. +No type information for this code.=== /node_modules/@types/library-a/index.d.ts === +// Symlinks are always resolved for type reference directives. +// NOTE: This test would still compile without errors even if they were not, +// because `processTypeReferenceDirective` also checks for textual equivalence of file contents. +// But the `moduleResolutionWithSymlinks_referenceTypes.trace.json` shows the difference. + + +declare class MyClass { private x: number; } +>MyClass : Symbol(MyClass, Decl(index.d.ts, 0, 0)) +>x : Symbol(MyClass.x, Decl(index.d.ts, 6, 23)) + +=== /node_modules/@types/library-b/index.d.ts === +/// +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.trace.json b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.trace.json new file mode 100644 index 0000000000000..658f407c42be6 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.trace.json @@ -0,0 +1,35 @@ +[ + "======== Resolving type reference directive 'library-a', containing file '/app.ts', root directory not set. ========", + "Root directory cannot be determined, skipping primary search paths.", + "Looking up in 'node_modules' folder, initial location '/'", + "File '/node_modules/library-a.d.ts' does not exist.", + "File '/node_modules/library-a/package.json' does not exist.", + "File '/node_modules/library-a/index.d.ts' does not exist.", + "File '/node_modules/@types/library-a.d.ts' does not exist.", + "File '/node_modules/@types/library-a/package.json' does not exist.", + "File '/node_modules/@types/library-a/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/library-a/index.d.ts', result '/node_modules/@types/library-a/index.d.ts'", + "======== Type reference directive 'library-a' was successfully resolved to '/node_modules/@types/library-a/index.d.ts', primary: false. ========", + "======== Resolving type reference directive 'library-b', containing file '/app.ts', root directory not set. ========", + "Root directory cannot be determined, skipping primary search paths.", + "Looking up in 'node_modules' folder, initial location '/'", + "File '/node_modules/library-b.d.ts' does not exist.", + "File '/node_modules/library-b/package.json' does not exist.", + "File '/node_modules/library-b/index.d.ts' does not exist.", + "File '/node_modules/@types/library-b.d.ts' does not exist.", + "File '/node_modules/@types/library-b/package.json' does not exist.", + "File '/node_modules/@types/library-b/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/library-b/index.d.ts', result '/node_modules/@types/library-b/index.d.ts'", + "======== Type reference directive 'library-b' was successfully resolved to '/node_modules/@types/library-b/index.d.ts', primary: false. ========", + "======== Resolving type reference directive 'library-a', containing file '/node_modules/@types/library-b/index.d.ts', root directory not set. ========", + "Root directory cannot be determined, skipping primary search paths.", + "Looking up in 'node_modules' folder, initial location '/node_modules/@types/library-b'", + "File '/node_modules/@types/library-b/node_modules/library-a.d.ts' does not exist.", + "File '/node_modules/@types/library-b/node_modules/library-a/package.json' does not exist.", + "File '/node_modules/@types/library-b/node_modules/library-a/index.d.ts' does not exist.", + "File '/node_modules/@types/library-b/node_modules/@types/library-a.d.ts' does not exist.", + "File '/node_modules/@types/library-b/node_modules/@types/library-a/package.json' does not exist.", + "File '/node_modules/@types/library-b/node_modules/@types/library-a/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/library-b/node_modules/@types/library-a/index.d.ts', result '/node_modules/@types/library-a/index.d.ts'", + "======== Type reference directive 'library-a' was successfully resolved to '/node_modules/@types/library-a/index.d.ts', primary: false. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.types b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.types new file mode 100644 index 0000000000000..bee6eb5aae64f --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.types @@ -0,0 +1,45 @@ +=== /app.ts === +/// +No type information for this code./// +No type information for this code. +No type information for this code./* +No type information for this code.# To reproduce in a real project: +No type information for this code. +No type information for this code.echo '/// ' > app.ts +No type information for this code.echo '/// ' >> app.ts +No type information for this code. +No type information for this code.mkdir node_modules/@types +No type information for this code.cd mode_modules/@types +No type information for this code.mkdir library-a +No type information for this code.echo 'declare class MyClass { private x: number; }' > library-a/index.d.ts +No type information for this code. +No type information for this code.mkdir library-b +No type information for this code.cd library-b +No type information for this code.echo '/// ' > index.d.ts +No type information for this code. +No type information for this code.mkdir node_modules +No type information for this code.cd node_modules +No type information for this code. +No type information for this code.ln -s ../../library-a ./library-a +No type information for this code.# Windows: Open command prompt as administrator and run: `mklink /D library-a ..\..\library-a` +No type information for this code. +No type information for this code.cd ../../.. # back to root +No type information for this code. +No type information for this code.tsc app.ts # Should create `app.js` +No type information for this code.*/ +No type information for this code. +No type information for this code.=== /node_modules/@types/library-a/index.d.ts === +// Symlinks are always resolved for type reference directives. +// NOTE: This test would still compile without errors even if they were not, +// because `processTypeReferenceDirective` also checks for textual equivalence of file contents. +// But the `moduleResolutionWithSymlinks_referenceTypes.trace.json` shows the difference. + + +declare class MyClass { private x: number; } +>MyClass : MyClass +>x : number + +=== /node_modules/@types/library-b/index.d.ts === +/// +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives1.trace.json b/tests/baselines/reference/typeReferenceDirectives1.trace.json index 58b23783b0b9d..8532d21da8926 100644 --- a/tests/baselines/reference/typeReferenceDirectives1.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives1.trace.json @@ -3,10 +3,12 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives10.trace.json b/tests/baselines/reference/typeReferenceDirectives10.trace.json index 2dfd1fe0939ca..5bd314197931c 100644 --- a/tests/baselines/reference/typeReferenceDirectives10.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives10.trace.json @@ -3,6 +3,7 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving module './ref' from '/app.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -15,5 +16,6 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives11.trace.json b/tests/baselines/reference/typeReferenceDirectives11.trace.json index 862c941079aa1..a6ab6bc8d686b 100644 --- a/tests/baselines/reference/typeReferenceDirectives11.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives11.trace.json @@ -8,5 +8,6 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives12.trace.json b/tests/baselines/reference/typeReferenceDirectives12.trace.json index 627ad13588a43..f232228a351e4 100644 --- a/tests/baselines/reference/typeReferenceDirectives12.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives12.trace.json @@ -13,6 +13,7 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving module './main' from '/mod1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -23,5 +24,6 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives13.trace.json b/tests/baselines/reference/typeReferenceDirectives13.trace.json index 2dfd1fe0939ca..5bd314197931c 100644 --- a/tests/baselines/reference/typeReferenceDirectives13.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives13.trace.json @@ -3,6 +3,7 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving module './ref' from '/app.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -15,5 +16,6 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives2.trace.json b/tests/baselines/reference/typeReferenceDirectives2.trace.json index 93d3658447dd3..1258ecdaa2be1 100644 --- a/tests/baselines/reference/typeReferenceDirectives2.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives2.trace.json @@ -3,5 +3,6 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives3.trace.json b/tests/baselines/reference/typeReferenceDirectives3.trace.json index 58b23783b0b9d..8532d21da8926 100644 --- a/tests/baselines/reference/typeReferenceDirectives3.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives3.trace.json @@ -3,10 +3,12 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives4.trace.json b/tests/baselines/reference/typeReferenceDirectives4.trace.json index 58b23783b0b9d..8532d21da8926 100644 --- a/tests/baselines/reference/typeReferenceDirectives4.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives4.trace.json @@ -3,10 +3,12 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives5.trace.json b/tests/baselines/reference/typeReferenceDirectives5.trace.json index 2dfd1fe0939ca..5bd314197931c 100644 --- a/tests/baselines/reference/typeReferenceDirectives5.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives5.trace.json @@ -3,6 +3,7 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving module './ref' from '/app.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -15,5 +16,6 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives6.trace.json b/tests/baselines/reference/typeReferenceDirectives6.trace.json index 58b23783b0b9d..8532d21da8926 100644 --- a/tests/baselines/reference/typeReferenceDirectives6.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives6.trace.json @@ -3,10 +3,12 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives7.trace.json b/tests/baselines/reference/typeReferenceDirectives7.trace.json index 58b23783b0b9d..8532d21da8926 100644 --- a/tests/baselines/reference/typeReferenceDirectives7.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives7.trace.json @@ -3,10 +3,12 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives8.trace.json b/tests/baselines/reference/typeReferenceDirectives8.trace.json index 862c941079aa1..a6ab6bc8d686b 100644 --- a/tests/baselines/reference/typeReferenceDirectives8.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives8.trace.json @@ -8,5 +8,6 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives9.trace.json b/tests/baselines/reference/typeReferenceDirectives9.trace.json index 627ad13588a43..f232228a351e4 100644 --- a/tests/baselines/reference/typeReferenceDirectives9.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives9.trace.json @@ -13,6 +13,7 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving module './main' from '/mod1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -23,5 +24,6 @@ "Resolving with primary search path '/types'", "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'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json b/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json index eec78e4019200..8541fd5bee8d5 100644 --- a/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json +++ b/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json @@ -234,11 +234,13 @@ "Resolving with primary search path '/foo/node_modules/@types, /node_modules/@types'", "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 '/src/__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'", "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 '/src/__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'", @@ -246,5 +248,6 @@ "File '/foo/node_modules/@types/dopey/index.d.ts' does not exist.", "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'", "======== Type reference directive 'dopey' was successfully resolved to '/node_modules/@types/dopey/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json b/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json index 4bb62bc255a0e..f7d0b2e40f7f0 100644 --- a/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json +++ b/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json @@ -56,5 +56,6 @@ "Resolving with primary search path '/node_modules/@types'", "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'", "======== Type reference directive 'foo' was successfully resolved to '/node_modules/@types/foo/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typingsLookup1.trace.json b/tests/baselines/reference/typingsLookup1.trace.json index 83b0e91d6c7c1..9445b8564d9fc 100644 --- a/tests/baselines/reference/typingsLookup1.trace.json +++ b/tests/baselines/reference/typingsLookup1.trace.json @@ -3,10 +3,12 @@ "Resolving with primary search path '/node_modules/@types'", "File '/node_modules/@types/jquery/package.json' does not exist.", "File '/node_modules/@types/jquery/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/jquery/index.d.ts', result '/node_modules/@types/jquery/index.d.ts'", "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", "Resolving with primary search path '/node_modules/@types'", "File '/node_modules/@types/jquery/package.json' does not exist.", "File '/node_modules/@types/jquery/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/jquery/index.d.ts', result '/node_modules/@types/jquery/index.d.ts'", "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typingsLookup3.trace.json b/tests/baselines/reference/typingsLookup3.trace.json index 83b0e91d6c7c1..9445b8564d9fc 100644 --- a/tests/baselines/reference/typingsLookup3.trace.json +++ b/tests/baselines/reference/typingsLookup3.trace.json @@ -3,10 +3,12 @@ "Resolving with primary search path '/node_modules/@types'", "File '/node_modules/@types/jquery/package.json' does not exist.", "File '/node_modules/@types/jquery/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/jquery/index.d.ts', result '/node_modules/@types/jquery/index.d.ts'", "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========", "======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", "Resolving with primary search path '/node_modules/@types'", "File '/node_modules/@types/jquery/package.json' does not exist.", "File '/node_modules/@types/jquery/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/jquery/index.d.ts', result '/node_modules/@types/jquery/index.d.ts'", "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typingsLookup4.trace.json b/tests/baselines/reference/typingsLookup4.trace.json index bb9d94f43b510..18c7385c3d287 100644 --- a/tests/baselines/reference/typingsLookup4.trace.json +++ b/tests/baselines/reference/typingsLookup4.trace.json @@ -62,6 +62,7 @@ "Found 'package.json' at '/node_modules/@types/jquery/package.json'.", "'package.json' has 'typings' field 'jquery.d.ts' that references '/node_modules/@types/jquery/jquery.d.ts'.", "File '/node_modules/@types/jquery/jquery.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/jquery/jquery.d.ts', result '/node_modules/@types/jquery/jquery.d.ts'", "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/jquery.d.ts', primary: true. ========", "======== Resolving type reference directive 'kquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", "Resolving with primary search path '/node_modules/@types'", @@ -71,6 +72,7 @@ "File '/node_modules/@types/kquery/kquery.ts' does not exist.", "File '/node_modules/@types/kquery/kquery.tsx' does not exist.", "File '/node_modules/@types/kquery/kquery.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/kquery/kquery.d.ts', result '/node_modules/@types/kquery/kquery.d.ts'", "======== Type reference directive 'kquery' was successfully resolved to '/node_modules/@types/kquery/kquery.d.ts', primary: true. ========", "======== Resolving type reference directive 'lquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", "Resolving with primary search path '/node_modules/@types'", @@ -78,5 +80,6 @@ "'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.", "File '/node_modules/@types/lquery/lquery' does not exist.", "File '/node_modules/@types/lquery/lquery.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/lquery/lquery.ts', result '/node_modules/@types/lquery/lquery.ts'", "======== Type reference directive 'lquery' was successfully resolved to '/node_modules/@types/lquery/lquery.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typingsLookupAmd.trace.json b/tests/baselines/reference/typingsLookupAmd.trace.json index 496166926a804..90ebf07516336 100644 --- a/tests/baselines/reference/typingsLookupAmd.trace.json +++ b/tests/baselines/reference/typingsLookupAmd.trace.json @@ -75,5 +75,6 @@ "Resolving with primary search path '/node_modules/@types'", "File '/node_modules/@types/a/package.json' does not exist.", "File '/node_modules/@types/a/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/a/index.d.ts', result '/node_modules/@types/a/index.d.ts'", "======== Type reference directive 'a' was successfully resolved to '/node_modules/@types/a/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/cases/compiler/moduleResolutionWithSymlinks_notInNodeModules.ts b/tests/cases/compiler/moduleResolutionWithSymlinks_notInNodeModules.ts index f861813942ff7..427fd4d769794 100644 --- a/tests/cases/compiler/moduleResolutionWithSymlinks_notInNodeModules.ts +++ b/tests/cases/compiler/moduleResolutionWithSymlinks_notInNodeModules.ts @@ -34,7 +34,5 @@ ln -s ../shared ./shared; ln -s ../shared ./shared2 # Linux # Windows: Open command prompt as administrator and run: `mklink /D shared ..\shared; mklink /D shared2 ..\shared` echo '{ "compilerOptions": { "outDir": "bin" } }' > tsconfig.json -node ../../../../TypeScript/built/local/tsc.js - -# Should create `bin/app.js`, `bin/shared/abc.js`, and `bin/shared2/abc.js` +tsc # Should create `bin/app.js`, `bin/shared/abc.js`, and `bin/shared2/abc.js` */ diff --git a/tests/cases/compiler/moduleResolutionWithSymlinks_referenceTypes.ts b/tests/cases/compiler/moduleResolutionWithSymlinks_referenceTypes.ts new file mode 100644 index 0000000000000..a07352e8d395c --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSymlinks_referenceTypes.ts @@ -0,0 +1,45 @@ +// Symlinks are always resolved for type reference directives. +// NOTE: This test would still compile without errors even if they were not, +// because `processTypeReferenceDirective` also checks for textual equivalence of file contents. +// But the `moduleResolutionWithSymlinks_referenceTypes.trace.json` shows the difference. + +// @noImplicitReferences: true +// @traceResolution: true +// @fullEmitPaths: true + +// @filename: /node_modules/@types/library-a/index.d.ts +// @symlink: /node_modules/@types/library-b/node_modules/@types/library-a/index.d.ts +declare class MyClass { private x: number; } + +// @filename: /node_modules/@types/library-b/index.d.ts +/// + +// @filename: /app.ts +/// +/// + +/* +# To reproduce in a real project: + +echo '/// ' > app.ts +echo '/// ' >> app.ts + +mkdir node_modules/@types +cd mode_modules/@types +mkdir library-a +echo 'declare class MyClass { private x: number; }' > library-a/index.d.ts + +mkdir library-b +cd library-b +echo '/// ' > index.d.ts + +mkdir node_modules +cd node_modules + +ln -s ../../library-a ./library-a +# Windows: Open command prompt as administrator and run: `mklink /D library-a ..\..\library-a` + +cd ../../.. # back to root + +tsc app.ts # Should create `app.js` +*/ From 7079d0450e9cae09d2845e310b0efe5fe65a99a4 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 9 Nov 2016 09:12:43 -0800 Subject: [PATCH 3/4] Fix duplicate function error --- src/compiler/program.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 7829bfcfb7874..71c79585f66b4 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -450,10 +450,6 @@ namespace ts { return commonSourceDirectory; } - function isSourceFileFromExternalLibrary(file: SourceFile): boolean { - return !!sourceFilesFoundSearchingNodeModules[file.path]; - } - function getClassifiableNames() { if (!classifiableNames) { // Initialize a checker so that all our files are bound. From d8b541afa1312046f02a5132c78fc19e710ac94a Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 9 Nov 2016 10:14:25 -0800 Subject: [PATCH 4/4] Fix test --- ...leResolutionWithSymlinks_referenceTypes.js | 51 ------------------- ...olutionWithSymlinks_referenceTypes.symbols | 26 ---------- ...tionWithSymlinks_referenceTypes.trace.json | 6 +-- ...esolutionWithSymlinks_referenceTypes.types | 26 ---------- ...leResolutionWithSymlinks_referenceTypes.ts | 9 ++++ 5 files changed, 12 insertions(+), 106 deletions(-) diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.js b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.js index 8fa8ca1c6f111..d04dfe0d8a827 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.js +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.js @@ -15,59 +15,8 @@ declare class MyClass { private x: number; } //// [app.ts] /// /// - -/* -# To reproduce in a real project: - -echo '/// ' > app.ts -echo '/// ' >> app.ts - -mkdir node_modules/@types -cd mode_modules/@types -mkdir library-a -echo 'declare class MyClass { private x: number; }' > library-a/index.d.ts - -mkdir library-b -cd library-b -echo '/// ' > index.d.ts - -mkdir node_modules -cd node_modules - -ln -s ../../library-a ./library-a -# Windows: Open command prompt as administrator and run: `mklink /D library-a ..\..\library-a` - -cd ../../.. # back to root - -tsc app.ts # Should create `app.js` -*/ //// [/app.js] /// /// -/* -# To reproduce in a real project: - -echo '/// ' > app.ts -echo '/// ' >> app.ts - -mkdir node_modules/@types -cd mode_modules/@types -mkdir library-a -echo 'declare class MyClass { private x: number; }' > library-a/index.d.ts - -mkdir library-b -cd library-b -echo '/// ' > index.d.ts - -mkdir node_modules -cd node_modules - -ln -s ../../library-a ./library-a -# Windows: Open command prompt as administrator and run: `mklink /D library-a ..\..\library-a` - -cd ../../.. # back to root - -tsc app.ts # Should create `app.js` -*/ diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.symbols b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.symbols index efb46a42f7f33..46806e5313f3f 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.symbols +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.symbols @@ -2,32 +2,6 @@ /// No type information for this code./// No type information for this code. -No type information for this code./* -No type information for this code.# To reproduce in a real project: -No type information for this code. -No type information for this code.echo '/// ' > app.ts -No type information for this code.echo '/// ' >> app.ts -No type information for this code. -No type information for this code.mkdir node_modules/@types -No type information for this code.cd mode_modules/@types -No type information for this code.mkdir library-a -No type information for this code.echo 'declare class MyClass { private x: number; }' > library-a/index.d.ts -No type information for this code. -No type information for this code.mkdir library-b -No type information for this code.cd library-b -No type information for this code.echo '/// ' > index.d.ts -No type information for this code. -No type information for this code.mkdir node_modules -No type information for this code.cd node_modules -No type information for this code. -No type information for this code.ln -s ../../library-a ./library-a -No type information for this code.# Windows: Open command prompt as administrator and run: `mklink /D library-a ..\..\library-a` -No type information for this code. -No type information for this code.cd ../../.. # back to root -No type information for this code. -No type information for this code.tsc app.ts # Should create `app.js` -No type information for this code.*/ -No type information for this code. No type information for this code.=== /node_modules/@types/library-a/index.d.ts === // Symlinks are always resolved for type reference directives. // NOTE: This test would still compile without errors even if they were not, diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.trace.json b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.trace.json index 658f407c42be6..3e0609ee3253e 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.trace.json +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'library-a', containing file '/app.ts', root directory not set. ========", + "======== Resolving type reference directive 'library-a', containing file '/app.ts', root directory ''. ========", "Root directory cannot be determined, skipping primary search paths.", "Looking up in 'node_modules' folder, initial location '/'", "File '/node_modules/library-a.d.ts' does not exist.", @@ -10,7 +10,7 @@ "File '/node_modules/@types/library-a/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/@types/library-a/index.d.ts', result '/node_modules/@types/library-a/index.d.ts'", "======== Type reference directive 'library-a' was successfully resolved to '/node_modules/@types/library-a/index.d.ts', primary: false. ========", - "======== Resolving type reference directive 'library-b', containing file '/app.ts', root directory not set. ========", + "======== Resolving type reference directive 'library-b', containing file '/app.ts', root directory ''. ========", "Root directory cannot be determined, skipping primary search paths.", "Looking up in 'node_modules' folder, initial location '/'", "File '/node_modules/library-b.d.ts' does not exist.", @@ -21,7 +21,7 @@ "File '/node_modules/@types/library-b/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/@types/library-b/index.d.ts', result '/node_modules/@types/library-b/index.d.ts'", "======== Type reference directive 'library-b' was successfully resolved to '/node_modules/@types/library-b/index.d.ts', primary: false. ========", - "======== Resolving type reference directive 'library-a', containing file '/node_modules/@types/library-b/index.d.ts', root directory not set. ========", + "======== Resolving type reference directive 'library-a', containing file '/node_modules/@types/library-b/index.d.ts', root directory ''. ========", "Root directory cannot be determined, skipping primary search paths.", "Looking up in 'node_modules' folder, initial location '/node_modules/@types/library-b'", "File '/node_modules/@types/library-b/node_modules/library-a.d.ts' does not exist.", diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.types b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.types index bee6eb5aae64f..2094265709f6e 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.types +++ b/tests/baselines/reference/moduleResolutionWithSymlinks_referenceTypes.types @@ -2,32 +2,6 @@ /// No type information for this code./// No type information for this code. -No type information for this code./* -No type information for this code.# To reproduce in a real project: -No type information for this code. -No type information for this code.echo '/// ' > app.ts -No type information for this code.echo '/// ' >> app.ts -No type information for this code. -No type information for this code.mkdir node_modules/@types -No type information for this code.cd mode_modules/@types -No type information for this code.mkdir library-a -No type information for this code.echo 'declare class MyClass { private x: number; }' > library-a/index.d.ts -No type information for this code. -No type information for this code.mkdir library-b -No type information for this code.cd library-b -No type information for this code.echo '/// ' > index.d.ts -No type information for this code. -No type information for this code.mkdir node_modules -No type information for this code.cd node_modules -No type information for this code. -No type information for this code.ln -s ../../library-a ./library-a -No type information for this code.# Windows: Open command prompt as administrator and run: `mklink /D library-a ..\..\library-a` -No type information for this code. -No type information for this code.cd ../../.. # back to root -No type information for this code. -No type information for this code.tsc app.ts # Should create `app.js` -No type information for this code.*/ -No type information for this code. No type information for this code.=== /node_modules/@types/library-a/index.d.ts === // Symlinks are always resolved for type reference directives. // NOTE: This test would still compile without errors even if they were not, diff --git a/tests/cases/compiler/moduleResolutionWithSymlinks_referenceTypes.ts b/tests/cases/compiler/moduleResolutionWithSymlinks_referenceTypes.ts index a07352e8d395c..c0e25784c1557 100644 --- a/tests/cases/compiler/moduleResolutionWithSymlinks_referenceTypes.ts +++ b/tests/cases/compiler/moduleResolutionWithSymlinks_referenceTypes.ts @@ -18,6 +18,15 @@ declare class MyClass { private x: number; } /// /// +// @filename: tsconfig.json +{ + "compilerOptions": { + // If this is its default of node_modules/@types, + // node_modules/@types/library-a will be looked up be fore node_modules/@types/library-b/node_modules/@types/library-a + "typeRoots": [] + } +} + /* # To reproduce in a real project: