1namespace ts.projectSystem { 2 const appTsconfigJson: File = { 3 path: "/packages/app/tsconfig.json", 4 content: ` 5 { 6 "compilerOptions": { 7 "module": "commonjs", 8 "outDir": "dist", 9 "rootDir": "src", 10 "baseUrl": "." 11 } 12 "references": [{ "path": "../dep" }] 13 }` 14 }; 15 16 const appSrcIndexTs: File = { 17 path: "/packages/app/src/index.ts", 18 content: `import "dep/does/not/exist";` 19 }; 20 21 const depPackageJson: File = { 22 path: "/packages/dep/package.json", 23 content: `{ "name": "dep", "main": "dist/index.js", "types": "dist/index.d.ts" }` 24 }; 25 26 const depTsconfigJson: File = { 27 path: "/packages/dep/tsconfig.json", 28 content: ` 29 { 30 "compilerOptions": { "outDir": "dist", "rootDir": "src", "module": "commonjs" } 31 }` 32 }; 33 34 const depSrcIndexTs: File = { 35 path: "/packages/dep/src/index.ts", 36 content: ` 37 import "./sub/folder";` 38 }; 39 40 const depSrcSubFolderIndexTs: File = { 41 path: "/packages/dep/src/sub/folder/index.ts", 42 content: `export const dep = 0;` 43 }; 44 45 const link: SymLink = { 46 path: "/packages/app/node_modules/dep", 47 symLink: "../../dep", 48 }; 49 50 describe("unittests:: tsserver:: symlinkCache", () => { 51 it("contains symlinks discovered by project references resolution after program creation", () => { 52 const { session, projectService } = setup(); 53 openFilesForSession([appSrcIndexTs], session); 54 const project = projectService.configuredProjects.get(appTsconfigJson.path)!; 55 assert.deepEqual( 56 project.getSymlinkCache()?.getSymlinkedDirectories()?.get(link.path + "/" as Path), 57 { real: "/packages/dep/", realPath: "/packages/dep/" as Path } 58 ); 59 }); 60 61 it("works for paths close to the root", () => { 62 const cache = createSymlinkCache("/", createGetCanonicalFileName(/*useCaseSensitiveFileNames*/ false)); 63 // Used to crash, #44953 64 const map = createModeAwareCache<ResolvedTypeReferenceDirective | undefined>(); 65 map.set("foo", /*mode*/ undefined, { 66 primary: true, 67 originalPath: "/foo", 68 resolvedFileName: "/one/two/foo", 69 }); 70 cache.setSymlinksFromResolutions([], map); 71 }); 72 }); 73 74 function setup() { 75 const host = createServerHost([ 76 appTsconfigJson, 77 appSrcIndexTs, 78 depPackageJson, 79 depTsconfigJson, 80 depSrcIndexTs, 81 depSrcSubFolderIndexTs, 82 link, 83 ]); 84 const session = createSession(host); 85 const projectService = session.getProjectService(); 86 return { 87 host, 88 projectService, 89 session, 90 }; 91 } 92} 93