Skip to content

Commit f3f2280

Browse files
committed
Ensure we are using d.ts emit as signature even when --declarationMap is on (map files are emitted before d.ts)
1 parent d0a57ab commit f3f2280

13 files changed

+340
-22
lines changed

src/compiler/builderState.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,13 @@ namespace ts.BuilderState {
345345
}
346346
else {
347347
const emitOutput = getFileEmitOutput(programOfThisState, sourceFile, /*emitOnlyDtsFiles*/ true, cancellationToken);
348-
if (emitOutput.outputFiles && emitOutput.outputFiles.length > 0) {
349-
latestSignature = computeHash(emitOutput.outputFiles[0].text);
348+
const firstDts = emitOutput.outputFiles &&
349+
programOfThisState.getCompilerOptions().declarationMap ?
350+
emitOutput.outputFiles.length > 1 ? emitOutput.outputFiles[1] : undefined :
351+
emitOutput.outputFiles.length > 0 ? emitOutput.outputFiles[0] : undefined;
352+
if (firstDts) {
353+
Debug.assert(fileExtensionIs(firstDts.name, Extension.Dts), "File extension for signature expected to be dts", () => `Found: ${getAnyExtensionFromPath(firstDts.name)} for ${firstDts.name}:: All output files: ${JSON.stringify(emitOutput.outputFiles.map(f => f.name))}`);
354+
latestSignature = computeHash(firstDts.text);
350355
if (exportedModulesMapCache && latestSignature !== prevSignature) {
351356
updateExportedModules(sourceFile, emitOutput.exportedModulesFromDeclarationEmit, exportedModulesMapCache);
352357
}

src/testRunner/unittests/tsbuild/emitDeclarationOnly.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,55 @@ namespace ts {
5555
}
5656
verifyEmitDeclarationOnly();
5757
verifyEmitDeclarationOnly(/*disableMap*/ true);
58+
59+
verifyTsbuildOutput({
60+
scenario: `only dts output in non circular imports project with emitDeclarationOnly`,
61+
projFs: () => projFs,
62+
time,
63+
tick,
64+
proj: "emitDeclarationOnly",
65+
rootNames: ["/src"],
66+
lastProjectOutput: `/src/lib/a.d.ts`,
67+
outputFiles: [
68+
"/src/lib/a.d.ts",
69+
"/src/lib/b.d.ts",
70+
"/src/lib/c.d.ts",
71+
"/src/tsconfig.tsbuildinfo",
72+
"/src/lib/a.d.ts.map",
73+
"/src/lib/b.d.ts.map",
74+
"/src/lib/c.d.ts.map",
75+
],
76+
initialBuild: {
77+
modifyFs: fs => {
78+
fs.rimrafSync("/src/src/index.ts");
79+
replaceText(fs, "/src/src/a.ts", `import { B } from "./b";`, `export class B { prop = "hello"; }`);
80+
},
81+
expectedDiagnostics: [
82+
getExpectedDiagnosticForProjectsInBuild("src/tsconfig.json"),
83+
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/tsconfig.json", "src/lib/a.d.ts"],
84+
[Diagnostics.Building_project_0, "/src/tsconfig.json"]
85+
]
86+
},
87+
incrementalDtsChangedBuild: {
88+
modifyFs: fs => replaceText(fs, "/src/src/a.ts", "b: B;", "b: B; foo: any;"),
89+
expectedDiagnostics: [
90+
getExpectedDiagnosticForProjectsInBuild("src/tsconfig.json"),
91+
[Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/tsconfig.json", "src/lib/a.d.ts", "src/src/a.ts"],
92+
[Diagnostics.Building_project_0, "/src/tsconfig.json"]
93+
]
94+
},
95+
incrementalDtsUnchangedBuild: {
96+
modifyFs: fs => replaceText(fs, "/src/src/a.ts", "export interface A {", `class C { }
97+
export interface A {`),
98+
expectedDiagnostics: [
99+
getExpectedDiagnosticForProjectsInBuild("src/tsconfig.json"),
100+
[Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/tsconfig.json", "src/lib/a.d.ts", "src/src/a.ts"],
101+
[Diagnostics.Building_project_0, "/src/tsconfig.json"],
102+
[Diagnostics.Updating_unchanged_output_timestamps_of_project_0, "/src/tsconfig.json"]
103+
]
104+
},
105+
baselineOnly: true,
106+
verifyDiagnostics: true
107+
});
58108
});
59109
}

tests/baselines/reference/tsbuild/emitDeclarationOnly/incremental-declaration-changes/only-dts-output-in-circular-import-project-with-emitDeclarationOnly-and-declarationMap.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ export interface A {
2727
},
2828
"./src/c.ts": {
2929
"version": "429593025",
30-
"signature": "16358263348"
30+
"signature": "-21569163793"
3131
},
3232
"./src/b.ts": {
3333
"version": "-2273488249",
34-
"signature": "-10341094830"
34+
"signature": "25318058868"
3535
},
3636
"./src/a.ts": {
3737
"version": "-14761736732",
38-
"signature": "26895474425"
38+
"signature": "-11119001497"
3939
},
4040
"./src/index.ts": {
4141
"version": "1286756397",
42-
"signature": "3258829224"
42+
"signature": "14762544269"
4343
}
4444
},
4545
"options": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//// [/src/lib/a.d.ts]
2+
export declare class B {
3+
prop: string;
4+
}
5+
export interface A {
6+
b: B;
7+
foo: any;
8+
}
9+
//# sourceMappingURL=a.d.ts.map
10+
11+
//// [/src/lib/a.d.ts.map]
12+
{"version":3,"file":"a.d.ts","sourceRoot":"","sources":["../src/a.ts"],"names":[],"mappings":"AAAA,qBAAa,CAAC;IAAG,IAAI,SAAW;CAAE;AAElC,MAAM,WAAW,CAAC;IAChB,CAAC,EAAE,CAAC,CAAC;IAAC,GAAG,EAAE,GAAG,CAAC;CAChB"}
13+
14+
//// [/src/src/a.ts]
15+
export class B { prop = "hello"; }
16+
17+
export interface A {
18+
b: B; foo: any;
19+
}
20+
21+
22+
//// [/src/tsconfig.tsbuildinfo]
23+
{
24+
"program": {
25+
"fileInfos": {
26+
"../lib/lib.d.ts": {
27+
"version": "3858781397",
28+
"signature": "3858781397"
29+
},
30+
"./src/a.ts": {
31+
"version": "7973388544",
32+
"signature": "3224647069"
33+
},
34+
"./src/c.ts": {
35+
"version": "429593025",
36+
"signature": "-21569163793"
37+
},
38+
"./src/b.ts": {
39+
"version": "-2273488249",
40+
"signature": "25318058868"
41+
}
42+
},
43+
"options": {
44+
"incremental": true,
45+
"target": 1,
46+
"module": 1,
47+
"declaration": true,
48+
"declarationMap": true,
49+
"sourceMap": true,
50+
"outDir": "./lib",
51+
"composite": true,
52+
"strict": true,
53+
"esModuleInterop": true,
54+
"alwaysStrict": true,
55+
"rootDir": "./src",
56+
"emitDeclarationOnly": true,
57+
"configFilePath": "./tsconfig.json"
58+
},
59+
"referencedMap": {
60+
"./src/b.ts": [
61+
"./src/c.ts"
62+
],
63+
"./src/c.ts": [
64+
"./src/a.ts"
65+
]
66+
},
67+
"exportedModulesMap": {
68+
"./src/b.ts": [
69+
"./src/c.ts"
70+
],
71+
"./src/c.ts": [
72+
"./src/a.ts"
73+
]
74+
},
75+
"semanticDiagnosticsPerFile": [
76+
"../lib/lib.d.ts",
77+
"./src/a.ts",
78+
"./src/b.ts",
79+
"./src/c.ts"
80+
]
81+
},
82+
"version": "FakeTSVersion"
83+
}
84+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//// [/src/lib/a.d.ts.map]
2+
{"version":3,"file":"a.d.ts","sourceRoot":"","sources":["../src/a.ts"],"names":[],"mappings":"AAAA,qBAAa,CAAC;IAAG,IAAI,SAAW;CAAE;AAGlC,MAAM,WAAW,CAAC;IAChB,CAAC,EAAE,CAAC,CAAC;CACN"}
3+
4+
//// [/src/src/a.ts]
5+
export class B { prop = "hello"; }
6+
7+
class C { }
8+
export interface A {
9+
b: B;
10+
}
11+
12+
13+
//// [/src/tsconfig.tsbuildinfo]
14+
{
15+
"program": {
16+
"fileInfos": {
17+
"../lib/lib.d.ts": {
18+
"version": "3858781397",
19+
"signature": "3858781397"
20+
},
21+
"./src/a.ts": {
22+
"version": "6651905050",
23+
"signature": "-14608980923"
24+
},
25+
"./src/c.ts": {
26+
"version": "429593025",
27+
"signature": "-21569163793"
28+
},
29+
"./src/b.ts": {
30+
"version": "-2273488249",
31+
"signature": "25318058868"
32+
}
33+
},
34+
"options": {
35+
"incremental": true,
36+
"target": 1,
37+
"module": 1,
38+
"declaration": true,
39+
"declarationMap": true,
40+
"sourceMap": true,
41+
"outDir": "./lib",
42+
"composite": true,
43+
"strict": true,
44+
"esModuleInterop": true,
45+
"alwaysStrict": true,
46+
"rootDir": "./src",
47+
"emitDeclarationOnly": true,
48+
"configFilePath": "./tsconfig.json"
49+
},
50+
"referencedMap": {
51+
"./src/b.ts": [
52+
"./src/c.ts"
53+
],
54+
"./src/c.ts": [
55+
"./src/a.ts"
56+
]
57+
},
58+
"exportedModulesMap": {
59+
"./src/b.ts": [
60+
"./src/c.ts"
61+
],
62+
"./src/c.ts": [
63+
"./src/a.ts"
64+
]
65+
},
66+
"semanticDiagnosticsPerFile": [
67+
"../lib/lib.d.ts",
68+
"./src/a.ts",
69+
"./src/b.ts",
70+
"./src/c.ts"
71+
]
72+
},
73+
"version": "FakeTSVersion"
74+
}
75+

tests/baselines/reference/tsbuild/emitDeclarationOnly/initial-Build/only-dts-output-in-circular-import-project-with-emitDeclarationOnly-and-declarationMap.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ export { C } from "./c";
4747
},
4848
"./src/c.ts": {
4949
"version": "429593025",
50-
"signature": "16358263348"
50+
"signature": "-21569163793"
5151
},
5252
"./src/b.ts": {
5353
"version": "-2273488249",
54-
"signature": "-10341094830"
54+
"signature": "25318058868"
5555
},
5656
"./src/a.ts": {
5757
"version": "-15463561693",
58-
"signature": "35973991024"
58+
"signature": "-4935617457"
5959
},
6060
"./src/index.ts": {
6161
"version": "1286756397",
62-
"signature": "3258829224"
62+
"signature": "14762544269"
6363
}
6464
},
6565
"options": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//// [/src/lib/a.d.ts]
2+
export declare class B {
3+
prop: string;
4+
}
5+
export interface A {
6+
b: B;
7+
}
8+
//# sourceMappingURL=a.d.ts.map
9+
10+
//// [/src/lib/a.d.ts.map]
11+
{"version":3,"file":"a.d.ts","sourceRoot":"","sources":["../src/a.ts"],"names":[],"mappings":"AAAA,qBAAa,CAAC;IAAG,IAAI,SAAW;CAAE;AAElC,MAAM,WAAW,CAAC;IAChB,CAAC,EAAE,CAAC,CAAC;CACN"}
12+
13+
//// [/src/lib/b.d.ts]
14+
import { C } from "./c";
15+
export interface B {
16+
b: C;
17+
}
18+
//# sourceMappingURL=b.d.ts.map
19+
20+
//// [/src/lib/b.d.ts.map]
21+
{"version":3,"file":"b.d.ts","sourceRoot":"","sources":["../src/b.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,CAAC;IAChB,CAAC,EAAE,CAAC,CAAC;CACN"}
22+
23+
//// [/src/lib/c.d.ts]
24+
import { A } from "./a";
25+
export interface C {
26+
a: A;
27+
}
28+
//# sourceMappingURL=c.d.ts.map
29+
30+
//// [/src/lib/c.d.ts.map]
31+
{"version":3,"file":"c.d.ts","sourceRoot":"","sources":["../src/c.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,CAAC;IAChB,CAAC,EAAE,CAAC,CAAC;CACN"}
32+
33+
//// [/src/src/index.ts] unlink
34+
//// [/src/src/a.ts]
35+
export class B { prop = "hello"; }
36+
37+
export interface A {
38+
b: B;
39+
}
40+
41+
42+
//// [/src/tsconfig.tsbuildinfo]
43+
{
44+
"program": {
45+
"fileInfos": {
46+
"../lib/lib.d.ts": {
47+
"version": "3858781397",
48+
"signature": "3858781397"
49+
},
50+
"./src/a.ts": {
51+
"version": "11179224639",
52+
"signature": "-14608980923"
53+
},
54+
"./src/c.ts": {
55+
"version": "429593025",
56+
"signature": "-21569163793"
57+
},
58+
"./src/b.ts": {
59+
"version": "-2273488249",
60+
"signature": "25318058868"
61+
}
62+
},
63+
"options": {
64+
"incremental": true,
65+
"target": 1,
66+
"module": 1,
67+
"declaration": true,
68+
"declarationMap": true,
69+
"sourceMap": true,
70+
"outDir": "./lib",
71+
"composite": true,
72+
"strict": true,
73+
"esModuleInterop": true,
74+
"alwaysStrict": true,
75+
"rootDir": "./src",
76+
"emitDeclarationOnly": true,
77+
"configFilePath": "./tsconfig.json"
78+
},
79+
"referencedMap": {
80+
"./src/b.ts": [
81+
"./src/c.ts"
82+
],
83+
"./src/c.ts": [
84+
"./src/a.ts"
85+
]
86+
},
87+
"exportedModulesMap": {
88+
"./src/b.ts": [
89+
"./src/c.ts"
90+
],
91+
"./src/c.ts": [
92+
"./src/a.ts"
93+
]
94+
},
95+
"semanticDiagnosticsPerFile": [
96+
"../lib/lib.d.ts",
97+
"./src/a.ts",
98+
"./src/b.ts",
99+
"./src/c.ts"
100+
]
101+
},
102+
"version": "FakeTSVersion"
103+
}
104+

tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/sample.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ export class someClass { }
177177
},
178178
"./anothermodule.ts": {
179179
"version": "-2676574883",
180-
"signature": "25219880154"
180+
"signature": "7652028357"
181181
},
182182
"./index.ts": {
183183
"version": "-13387000654",
184-
"signature": "12514354613"
184+
"signature": "-2069755619"
185185
},
186186
"./some_decl.d.ts": {
187187
"version": "-9253692965",

0 commit comments

Comments
 (0)