forked from microsoft/TypeScript
/
moduleResolution.ts
89 lines (86 loc) · 4.1 KB
/
moduleResolution.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
namespace ts.tscWatch {
describe("unittests:: tsbuild:: moduleResolution:: handles the modules and options from referenced project correctly", () => {
function sys(optionsToExtend?: CompilerOptions) {
return createWatchedSystem([
{
path: `${projectRoot}/packages/pkg1/index.ts`,
content: Utils.dedent`
import type { TheNum } from 'pkg2'
export const theNum: TheNum = 42;`
},
{
path: `${projectRoot}/packages/pkg1/tsconfig.json`,
content: JSON.stringify({
compilerOptions: { outDir: "build", ...optionsToExtend },
references: [{ path: "../pkg2" }]
})
},
{
path: `${projectRoot}/packages/pkg2/const.ts`,
content: `export type TheNum = 42;`
},
{
path: `${projectRoot}/packages/pkg2/index.ts`,
content: `export type { TheNum } from 'const';`
},
{
path: `${projectRoot}/packages/pkg2/tsconfig.json`,
content: JSON.stringify({
compilerOptions: {
composite: true,
outDir: "build",
baseUrl: ".",
...optionsToExtend
}
})
},
{
path: `${projectRoot}/packages/pkg2/package.json`,
content: JSON.stringify({
name: "pkg2",
version: "1.0.0",
main: "build/index.js",
})
},
{
path: `${projectRoot}/node_modules/pkg2`,
symLink: `${projectRoot}/packages/pkg2`,
},
libFile
], { currentDirectory: projectRoot });
}
verifyTscWatch({
scenario: "moduleResolution",
subScenario: `resolves specifier in output declaration file from referenced project correctly`,
sys,
commandLineArgs: ["-b", "packages/pkg1", "--verbose", "--traceResolution"],
changes: emptyArray
});
verifyTscWatch({
scenario: "moduleResolution",
subScenario: `resolves specifier in output declaration file from referenced project correctly with preserveSymlinks`,
sys: () => sys({ preserveSymlinks: true }),
commandLineArgs: ["-b", "packages/pkg1", "--verbose", "--traceResolution"],
changes: emptyArray
});
verifyTsc({
scenario: "moduleResolution",
subScenario: `type reference resolution uses correct options for different resolution options referenced project`,
fs: () => loadProjectFromFiles({
"/src/packages/pkg1_index.ts": `export const theNum: TheNum = "type1";`,
"/src/packages/pkg1.tsconfig.json": JSON.stringify({
compilerOptions: { composite: true, typeRoots: ["./typeroot1"] },
files: ["./pkg1_index.ts"]
}),
"/src/packages/typeroot1/sometype/index.d.ts": Utils.dedent`declare type TheNum = "type1";`,
"/src/packages/pkg2_index.ts": `export const theNum: TheNum2 = "type2";`,
"/src/packages/pkg2.tsconfig.json": JSON.stringify({
compilerOptions: { composite: true, typeRoots: ["./typeroot2"] },
files: ["./pkg2_index.ts"]
}),
"/src/packages/typeroot2/sometype/index.d.ts": Utils.dedent`declare type TheNum2 = "type2";`,
}),
commandLineArgs: ["-b", "/src/packages/pkg1.tsconfig.json", "/src/packages/pkg2.tsconfig.json", "--verbose", "--traceResolution"],
});
});
}