1namespace ts { 2 // https://github.com/microsoft/TypeScript/issues/31696 3 describe("unittests:: tsbuild:: moduleSpecifiers:: synthesized module specifiers to referenced projects resolve correctly", () => { 4 verifyTsc({ 5 scenario: "moduleSpecifiers", 6 subScenario: `synthesized module specifiers resolve correctly`, 7 fs: () => loadProjectFromFiles({ 8 "/src/solution/common/nominal.ts": Utils.dedent` 9 export declare type Nominal<T, Name extends string> = T & { 10 [Symbol.species]: Name; 11 }; 12 `, 13 "/src/solution/common/tsconfig.json": Utils.dedent` 14 { 15 "extends": "../../tsconfig.base.json", 16 "compilerOptions": { 17 "composite": true 18 }, 19 "include": ["nominal.ts"] 20 }`, 21 "/src/solution/sub-project/index.ts": Utils.dedent` 22 import { Nominal } from '../common/nominal'; 23 24 export type MyNominal = Nominal<string, 'MyNominal'>; 25 `, 26 "/src/solution/sub-project/tsconfig.json": Utils.dedent` 27 { 28 "extends": "../../tsconfig.base.json", 29 "compilerOptions": { 30 "composite": true 31 }, 32 "references": [ 33 { "path": "../common" } 34 ], 35 "include": ["./index.ts"] 36 }`, 37 "/src/solution/sub-project-2/index.ts": Utils.dedent` 38 import { MyNominal } from '../sub-project/index'; 39 40 const variable = { 41 key: 'value' as MyNominal, 42 }; 43 44 export function getVar(): keyof typeof variable { 45 return 'key'; 46 } 47 `, 48 "/src/solution/sub-project-2/tsconfig.json": Utils.dedent` 49 { 50 "extends": "../../tsconfig.base.json", 51 "compilerOptions": { 52 "composite": true 53 }, 54 "references": [ 55 { "path": "../sub-project" } 56 ], 57 "include": ["./index.ts"] 58 }`, 59 "/src/solution/tsconfig.json": Utils.dedent` 60 { 61 "compilerOptions": { 62 "composite": true 63 }, 64 "references": [ 65 { "path": "./sub-project" }, 66 { "path": "./sub-project-2" } 67 ], 68 "include": [] 69 }`, 70 "/src/tsconfig.base.json": Utils.dedent` 71 { 72 "compilerOptions": { 73 "skipLibCheck": true, 74 "rootDir": "./", 75 "outDir": "lib", 76 } 77 }`, 78 "/src/tsconfig.json": Utils.dedent`{ 79 "compilerOptions": { 80 "composite": true 81 }, 82 "references": [ 83 { "path": "./solution" } 84 ], 85 "include": [] 86 }` 87 }, symbolLibContent), 88 commandLineArgs: ["-b", "/src", "--verbose"] 89 }); 90 }); 91 92 // https://github.com/microsoft/TypeScript/issues/44434 but with `module: node16`, some `exports` maps blocking direct access, and no `baseUrl` 93 describe("unittests:: tsbuild:: moduleSpecifiers:: synthesized module specifiers across referenced projects resolve correctly", () => { 94 verifyTsc({ 95 scenario: "moduleSpecifiers", 96 subScenario: `synthesized module specifiers across projects resolve correctly`, 97 fs: () => loadProjectFromFiles({ 98 "/src/src-types/index.ts": Utils.dedent` 99 export * from './dogconfig.js';`, 100 "/src/src-types/dogconfig.ts": Utils.dedent` 101 export interface DogConfig { 102 name: string; 103 }`, 104 "/src/src-dogs/index.ts": Utils.dedent` 105 export * from 'src-types'; 106 export * from './lassie/lassiedog.js'; 107 `, 108 "/src/src-dogs/dogconfig.ts": Utils.dedent` 109 import { DogConfig } from 'src-types'; 110 111 export const DOG_CONFIG: DogConfig = { 112 name: 'Default dog', 113 }; 114 `, 115 "/src/src-dogs/dog.ts": Utils.dedent` 116 import { DogConfig } from 'src-types'; 117 import { DOG_CONFIG } from './dogconfig.js'; 118 119 export abstract class Dog { 120 121 public static getCapabilities(): DogConfig { 122 return DOG_CONFIG; 123 } 124 } 125 `, 126 "/src/src-dogs/lassie/lassiedog.ts": Utils.dedent` 127 import { Dog } from '../dog.js'; 128 import { LASSIE_CONFIG } from './lassieconfig.js'; 129 130 export class LassieDog extends Dog { 131 protected static getDogConfig = () => LASSIE_CONFIG; 132 } 133 `, 134 "/src/src-dogs/lassie/lassieconfig.ts": Utils.dedent` 135 import { DogConfig } from 'src-types'; 136 137 export const LASSIE_CONFIG: DogConfig = { name: 'Lassie' }; 138 `, 139 "/src/tsconfig-base.json": Utils.dedent` 140 { 141 "compilerOptions": { 142 "declaration": true, 143 "module": "node16" 144 } 145 }`, 146 "/src/src-types/package.json": Utils.dedent` 147 { 148 "type": "module", 149 "exports": "./index.js" 150 }`, 151 "/src/src-dogs/package.json": Utils.dedent` 152 { 153 "type": "module", 154 "exports": "./index.js" 155 }`, 156 "/src/src-types/tsconfig.json": Utils.dedent` 157 { 158 "extends": "../tsconfig-base.json", 159 "compilerOptions": { 160 "composite": true 161 }, 162 "include": [ 163 "**/*" 164 ] 165 }`, 166 "/src/src-dogs/tsconfig.json": Utils.dedent` 167 { 168 "extends": "../tsconfig-base.json", 169 "compilerOptions": { 170 "composite": true 171 }, 172 "references": [ 173 { "path": "../src-types" } 174 ], 175 "include": [ 176 "**/*" 177 ] 178 }`, 179 }, ""), 180 modifyFs: fs => { 181 fs.writeFileSync("/lib/lib.es2022.full.d.ts", tscWatch.libFile.content); 182 fs.symlinkSync("/src", "/src/src-types/node_modules"); 183 fs.symlinkSync("/src", "/src/src-dogs/node_modules"); 184 }, 185 commandLineArgs: ["-b", "src/src-types", "src/src-dogs", "--verbose"] 186 }); 187 }); 188} 189