1namespace ts.tscWatch { 2 describe("unittests:: tsbuild:: moduleResolution:: handles the modules and options from referenced project correctly", () => { 3 function sys(optionsToExtend?: CompilerOptions) { 4 return createWatchedSystem([ 5 { 6 path: `${projectRoot}/packages/pkg1/index.ts`, 7 content: Utils.dedent` 8 import type { TheNum } from 'pkg2' 9 export const theNum: TheNum = 42;` 10 }, 11 { 12 path: `${projectRoot}/packages/pkg1/tsconfig.json`, 13 content: JSON.stringify({ 14 compilerOptions: { outDir: "build", ...optionsToExtend }, 15 references: [{ path: "../pkg2" }] 16 }) 17 }, 18 { 19 path: `${projectRoot}/packages/pkg2/const.ts`, 20 content: `export type TheNum = 42;` 21 }, 22 { 23 path: `${projectRoot}/packages/pkg2/index.ts`, 24 content: `export type { TheNum } from 'const';` 25 }, 26 { 27 path: `${projectRoot}/packages/pkg2/tsconfig.json`, 28 content: JSON.stringify({ 29 compilerOptions: { 30 composite: true, 31 outDir: "build", 32 baseUrl: ".", 33 ...optionsToExtend 34 } 35 }) 36 }, 37 { 38 path: `${projectRoot}/packages/pkg2/package.json`, 39 content: JSON.stringify({ 40 name: "pkg2", 41 version: "1.0.0", 42 main: "build/index.js", 43 }) 44 }, 45 { 46 path: `${projectRoot}/node_modules/pkg2`, 47 symLink: `${projectRoot}/packages/pkg2`, 48 }, 49 libFile 50 ], { currentDirectory: projectRoot }); 51 } 52 53 verifyTscWatch({ 54 scenario: "moduleResolution", 55 subScenario: `resolves specifier in output declaration file from referenced project correctly`, 56 sys, 57 commandLineArgs: ["-b", "packages/pkg1", "--verbose", "--traceResolution"], 58 changes: emptyArray 59 }); 60 61 verifyTscWatch({ 62 scenario: "moduleResolution", 63 subScenario: `resolves specifier in output declaration file from referenced project correctly with preserveSymlinks`, 64 sys: () => sys({ preserveSymlinks: true }), 65 commandLineArgs: ["-b", "packages/pkg1", "--verbose", "--traceResolution"], 66 changes: emptyArray 67 }); 68 69 verifyTsc({ 70 scenario: "moduleResolution", 71 subScenario: `type reference resolution uses correct options for different resolution options referenced project`, 72 fs: () => loadProjectFromFiles({ 73 "/src/packages/pkg1_index.ts": `export const theNum: TheNum = "type1";`, 74 "/src/packages/pkg1.tsconfig.json": JSON.stringify({ 75 compilerOptions: { composite: true, typeRoots: ["./typeroot1"] }, 76 files: ["./pkg1_index.ts"] 77 }), 78 "/src/packages/typeroot1/sometype/index.d.ts": Utils.dedent`declare type TheNum = "type1";`, 79 "/src/packages/pkg2_index.ts": `export const theNum: TheNum2 = "type2";`, 80 "/src/packages/pkg2.tsconfig.json": JSON.stringify({ 81 compilerOptions: { composite: true, typeRoots: ["./typeroot2"] }, 82 files: ["./pkg2_index.ts"] 83 }), 84 "/src/packages/typeroot2/sometype/index.d.ts": Utils.dedent`declare type TheNum2 = "type2";`, 85 }), 86 commandLineArgs: ["-b", "/src/packages/pkg1.tsconfig.json", "/src/packages/pkg2.tsconfig.json", "--verbose", "--traceResolution"], 87 }); 88 }); 89 90 describe("unittests:: tsbuild:: moduleResolution:: impliedNodeFormat differs between projects for shared file", () => { 91 verifyTscWithEdits({ 92 scenario: "moduleResolution", 93 subScenario: "impliedNodeFormat differs between projects for shared file", 94 fs: () => loadProjectFromFiles({ 95 "/src/projects/a/src/index.ts": "", 96 "/src/projects/a/tsconfig.json": JSON.stringify({ 97 compilerOptions: { strict: true } 98 }), 99 "/src/projects/b/src/index.ts": Utils.dedent` 100 import pg from "pg"; 101 pg.foo(); 102 `, 103 "/src/projects/b/tsconfig.json": JSON.stringify({ 104 compilerOptions: { strict: true, module: "node16" } 105 }), 106 "/src/projects/b/package.json": JSON.stringify({ 107 name: "b", 108 type: "module" 109 }), 110 "/src/projects/node_modules/@types/pg/index.d.ts": "export function foo(): void;", 111 "/src/projects/node_modules/@types/pg/package.json": JSON.stringify({ 112 name: "@types/pg", 113 types: "index.d.ts", 114 }), 115 }), 116 modifyFs: fs => fs.writeFileSync("/lib/lib.es2022.full.d.ts", libFile.content), 117 commandLineArgs: ["-b", "/src/projects/a", "/src/projects/b", "--verbose", "--traceResolution", "--explainFiles"], 118 edits: noChangeOnlyRuns 119 }); 120 }); 121}