Skip to content

Commit 57a916c

Browse files
authored
Emit buildinfo if file deleted isnt global (#51472)
* Add test for when file is deleted * Emit buildinfo if file deleted isnt global
1 parent 9f64a3a commit 57a916c

File tree

3 files changed

+207
-1
lines changed

3 files changed

+207
-1
lines changed

src/compiler/builder.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,13 @@ function createBuilderProgramState(newProgram: Program, getCanonicalFileName: Ge
313313
});
314314

315315
// If the global file is removed, add all files as changed
316-
if (useOldState && forEachEntry(oldState!.fileInfos, (info, sourceFilePath) => (outFilePath || info.affectsGlobalScope) && !state.fileInfos.has(sourceFilePath))) {
316+
if (useOldState && forEachEntry(oldState!.fileInfos, (info, sourceFilePath) => {
317+
if (state.fileInfos.has(sourceFilePath)) return false;
318+
if (outFilePath || info.affectsGlobalScope) return true;
319+
// if file is deleted we need to write buildInfo again
320+
state.buildInfoEmitPending = true;
321+
return false;
322+
})) {
317323
BuilderState.getAllFilesExcludingDefaultLibraryFile(state, newProgram, /*firstSourceFile*/ undefined)
318324
.forEach(file => addFileToChangeSet(state, file.resolvedPath));
319325
}

src/testRunner/unittests/tsc/incremental.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,4 +819,26 @@ console.log(a);`,
819819
baselinePrograms: true,
820820
});
821821
});
822+
823+
verifyTscWithEdits({
824+
scenario: "incremental",
825+
subScenario: "when file is deleted",
826+
commandLineArgs: ["-p", `/src/project`],
827+
fs: () => loadProjectFromFiles({
828+
"/src/project/tsconfig.json": JSON.stringify({
829+
compilerOptions: {
830+
composite: true,
831+
outDir: "outDir",
832+
},
833+
}),
834+
"/src/project/file1.ts": `export class C { }`,
835+
"/src/project/file2.ts": `export class D { }`,
836+
}),
837+
edits: [
838+
{
839+
subScenario: "delete file with imports",
840+
modifyFs: fs => fs.unlinkSync("/src/project/file2.ts"),
841+
},
842+
]
843+
});
822844
});
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
Input::
2+
//// [/lib/lib.d.ts]
3+
/// <reference no-default-lib="true"/>
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
interface ReadonlyArray<T> {}
15+
declare const console: { log(msg: any): void; };
16+
17+
//// [/src/project/file1.ts]
18+
export class C { }
19+
20+
//// [/src/project/file2.ts]
21+
export class D { }
22+
23+
//// [/src/project/tsconfig.json]
24+
{"compilerOptions":{"composite":true,"outDir":"outDir"}}
25+
26+
27+
28+
Output::
29+
/lib/tsc -p /src/project
30+
exitCode:: ExitStatus.Success
31+
32+
33+
//// [/src/project/outDir/file1.d.ts]
34+
export declare class C {
35+
}
36+
37+
38+
//// [/src/project/outDir/file1.js]
39+
"use strict";
40+
exports.__esModule = true;
41+
exports.C = void 0;
42+
var C = /** @class */ (function () {
43+
function C() {
44+
}
45+
return C;
46+
}());
47+
exports.C = C;
48+
49+
50+
//// [/src/project/outDir/file2.d.ts]
51+
export declare class D {
52+
}
53+
54+
55+
//// [/src/project/outDir/file2.js]
56+
"use strict";
57+
exports.__esModule = true;
58+
exports.D = void 0;
59+
var D = /** @class */ (function () {
60+
function D() {
61+
}
62+
return D;
63+
}());
64+
exports.D = D;
65+
66+
67+
//// [/src/project/outDir/tsconfig.tsbuildinfo]
68+
{"program":{"fileNames":["../../../lib/lib.d.ts","../file1.ts","../file2.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-9819564552-export class C { }","signature":"-10192454122-export declare class C {\r\n}\r\n"},{"version":"-7804761415-export class D { }","signature":"-10523684105-export declare class D {\r\n}\r\n"}],"options":{"composite":true,"outDir":"./"},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3],"latestChangedDtsFile":"./file2.d.ts"},"version":"FakeTSVersion"}
69+
70+
//// [/src/project/outDir/tsconfig.tsbuildinfo.readable.baseline.txt]
71+
{
72+
"program": {
73+
"fileNames": [
74+
"../../../lib/lib.d.ts",
75+
"../file1.ts",
76+
"../file2.ts"
77+
],
78+
"fileInfos": {
79+
"../../../lib/lib.d.ts": {
80+
"original": {
81+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
82+
"affectsGlobalScope": true
83+
},
84+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
85+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
86+
"affectsGlobalScope": true
87+
},
88+
"../file1.ts": {
89+
"original": {
90+
"version": "-9819564552-export class C { }",
91+
"signature": "-10192454122-export declare class C {\r\n}\r\n"
92+
},
93+
"version": "-9819564552-export class C { }",
94+
"signature": "-10192454122-export declare class C {\r\n}\r\n"
95+
},
96+
"../file2.ts": {
97+
"original": {
98+
"version": "-7804761415-export class D { }",
99+
"signature": "-10523684105-export declare class D {\r\n}\r\n"
100+
},
101+
"version": "-7804761415-export class D { }",
102+
"signature": "-10523684105-export declare class D {\r\n}\r\n"
103+
}
104+
},
105+
"options": {
106+
"composite": true,
107+
"outDir": "./"
108+
},
109+
"referencedMap": {},
110+
"exportedModulesMap": {},
111+
"semanticDiagnosticsPerFile": [
112+
"../../../lib/lib.d.ts",
113+
"../file1.ts",
114+
"../file2.ts"
115+
],
116+
"latestChangedDtsFile": "./file2.d.ts"
117+
},
118+
"version": "FakeTSVersion",
119+
"size": 972
120+
}
121+
122+
123+
124+
Change:: delete file with imports
125+
Input::
126+
//// [/src/project/file2.ts] unlink
127+
128+
129+
Output::
130+
/lib/tsc -p /src/project
131+
exitCode:: ExitStatus.Success
132+
133+
134+
//// [/src/project/outDir/tsconfig.tsbuildinfo]
135+
{"program":{"fileNames":["../../../lib/lib.d.ts","../file1.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-9819564552-export class C { }","signature":"-10192454122-export declare class C {\r\n}\r\n"}],"options":{"composite":true,"outDir":"./"},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"./file2.d.ts"},"version":"FakeTSVersion"}
136+
137+
//// [/src/project/outDir/tsconfig.tsbuildinfo.readable.baseline.txt]
138+
{
139+
"program": {
140+
"fileNames": [
141+
"../../../lib/lib.d.ts",
142+
"../file1.ts"
143+
],
144+
"fileInfos": {
145+
"../../../lib/lib.d.ts": {
146+
"original": {
147+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
148+
"affectsGlobalScope": true
149+
},
150+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
151+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
152+
"affectsGlobalScope": true
153+
},
154+
"../file1.ts": {
155+
"original": {
156+
"version": "-9819564552-export class C { }",
157+
"signature": "-10192454122-export declare class C {\r\n}\r\n"
158+
},
159+
"version": "-9819564552-export class C { }",
160+
"signature": "-10192454122-export declare class C {\r\n}\r\n"
161+
}
162+
},
163+
"options": {
164+
"composite": true,
165+
"outDir": "./"
166+
},
167+
"referencedMap": {},
168+
"exportedModulesMap": {},
169+
"semanticDiagnosticsPerFile": [
170+
"../../../lib/lib.d.ts",
171+
"../file1.ts"
172+
],
173+
"latestChangedDtsFile": "./file2.d.ts"
174+
},
175+
"version": "FakeTSVersion",
176+
"size": 850
177+
}
178+

0 commit comments

Comments
 (0)