Skip to content

Commit 82bfe5a

Browse files
authored
Fix issue with some baselines for tsbuildinfo not getting generated (microsoft#43218)
1 parent 496a1d3 commit 82bfe5a

File tree

13 files changed

+2173
-112
lines changed

13 files changed

+2173
-112
lines changed

src/testRunner/unittests/tsbuild/helpers.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ interface Symbol {
186186
}
187187
}
188188

189-
export function generateSourceMapBaselineFiles(sys: System & { writtenFiles: ReadonlyCollection<string>; }) {
189+
export function generateSourceMapBaselineFiles(sys: System & { writtenFiles: ReadonlyCollection<Path>; }) {
190190
const mapFileNames = mapDefinedIterator(sys.writtenFiles.keys(), f => f.endsWith(".map") ? f : undefined);
191191
while (true) {
192192
const result = mapFileNames.next();
@@ -297,14 +297,18 @@ interface Symbol {
297297
}
298298
}
299299

300+
export function toPathWithSystem(sys: System, fileName: string): Path {
301+
return toPath(fileName, sys.getCurrentDirectory(), createGetCanonicalFileName(sys.useCaseSensitiveFileNames));
302+
}
303+
300304
export function baselineBuildInfo(
301305
options: CompilerOptions,
302-
sys: System & { writtenFiles: ReadonlyCollection<string>; },
306+
sys: System & { writtenFiles: ReadonlyCollection<Path>; },
303307
originalReadCall?: System["readFile"],
304308
originalWriteFile?: System["writeFile"],
305309
) {
306310
const buildInfoPath = getTsBuildInfoEmitOutputFilePath(options);
307-
if (!buildInfoPath || !sys.writtenFiles.has(buildInfoPath)) return;
311+
if (!buildInfoPath || !sys.writtenFiles.has(toPathWithSystem(sys, buildInfoPath))) return;
308312
if (!sys.fileExists(buildInfoPath)) return;
309313

310314
const buildInfo = getBuildInfo((originalReadCall || sys.readFile).call(sys, buildInfoPath, "utf8")!);

src/testRunner/unittests/tsc/helpers.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace ts {
22
export type TscCompileSystem = fakes.System & {
3-
writtenFiles: Set<string>;
3+
writtenFiles: Set<Path>;
44
baseLine(): { file: string; text: string; };
55
};
66

@@ -42,7 +42,7 @@ namespace ts {
4242
return !!(program as Program | EmitAndSemanticDiagnosticsBuilderProgram).getCompilerOptions;
4343
}
4444
export function commandLineCallbacks(
45-
sys: System & { writtenFiles: ReadonlyCollection<string>; },
45+
sys: System & { writtenFiles: ReadonlyCollection<Path>; },
4646
originalReadCall?: System["readFile"],
4747
originalWriteFile?: System["writeFile"],
4848
): CommandLineCallbacks {
@@ -84,11 +84,12 @@ namespace ts {
8484
// Create system
8585
const sys = new fakes.System(fs, { executingFilePath: "/lib/tsc" }) as TscCompileSystem;
8686
fakes.patchHostForBuildInfoReadWrite(sys);
87-
const writtenFiles = sys.writtenFiles = new Set<string>();
87+
const writtenFiles = sys.writtenFiles = new Set();
8888
const originalWriteFile = sys.writeFile;
8989
sys.writeFile = (fileName, content, writeByteOrderMark) => {
90-
assert.isFalse(writtenFiles.has(fileName));
91-
writtenFiles.add(fileName);
90+
const path = toPathWithSystem(sys, fileName);
91+
assert.isFalse(writtenFiles.has(path));
92+
writtenFiles.add(path);
9293
return originalWriteFile.call(sys, fileName, content, writeByteOrderMark);
9394
};
9495
const actualReadFileMap: MapLike<number> = {};

tests/baselines/reference/tsbuild/sample1/initial-build/sample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export declare const World = "hello";
140140
//// [/src/core/anotherModule.d.ts.map]
141141
{"version":3,"file":"anotherModule.d.ts","sourceRoot":"","sources":["anotherModule.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,UAAU,CAAC"}
142142

143-
//// [/src/core/anotherModule.d.ts.map.baseline.txt]
143+
//// [/src/core/anothermodule.d.ts.map.baseline.txt]
144144
===================================================================
145145
JsFile: anotherModule.d.ts
146146
mapUrl: anotherModule.d.ts.map

tests/baselines/reference/tsbuild/sample1/initial-build/when-logic-specifies-tsBuildInfoFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export declare const World = "hello";
141141
//// [/src/core/anotherModule.d.ts.map]
142142
{"version":3,"file":"anotherModule.d.ts","sourceRoot":"","sources":["anotherModule.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,UAAU,CAAC"}
143143

144-
//// [/src/core/anotherModule.d.ts.map.baseline.txt]
144+
//// [/src/core/anothermodule.d.ts.map.baseline.txt]
145145
===================================================================
146146
JsFile: anotherModule.d.ts
147147
mapUrl: anotherModule.d.ts.map

tests/baselines/reference/tsbuild/watchMode/noEmitOnError/does-not-emit-any-files-on-error-with-incremental.js

Lines changed: 217 additions & 19 deletions
Large diffs are not rendered by default.

tests/baselines/reference/tsbuild/watchMode/programUpdates/should-not-trigger-recompilation-because-of-program-emit-with-outDir-specified.js

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Output::
3838

3939
[12:00:30 AM] Building project '/user/username/projects/sample1/core/tsconfig.json'...
4040

41-
[[90m12:00:44 AM[0m] Found 0 errors. Watching for file changes.
41+
[[90m12:00:46 AM[0m] Found 0 errors. Watching for file changes.
4242

4343

4444

@@ -102,6 +102,49 @@ export declare function multiply(a: number, b: number): number;
102102
//// [/user/username/projects/sample1/core/outDir/tsconfig.tsbuildinfo]
103103
{"program":{"fileNames":["../../../../../../a/lib/lib.d.ts","../anothermodule.ts","../index.ts"],"fileInfos":[{"version":"-7698705165-/// <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; }","signature":"-7698705165-/// <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; }","affectsGlobalScope":true},{"version":"-2676574883-export const World = \"hello\";\r\n","signature":"-9234818176-export declare const World = \"hello\";\n","affectsGlobalScope":false},{"version":"-18749805970-export const someString: string = \"HELLO WORLD\";\r\nexport function leftPad(s: string, n: number) { return s + n; }\r\nexport function multiply(a: number, b: number) { return a * b; }\r\n","signature":"-7362568283-export declare const someString: string;\nexport declare function leftPad(s: string, n: number): string;\nexport declare function multiply(a: number, b: number): number;\n","affectsGlobalScope":false}],"options":{"composite":true,"outDir":"./","watch":true,"configFilePath":"../tsconfig.json"},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}
104104

105+
//// [/user/username/projects/sample1/core/outDir/tsconfig.tsbuildinfo.readable.baseline.txt]
106+
{
107+
"program": {
108+
"fileNames": [
109+
"../../../../../../a/lib/lib.d.ts",
110+
"../anothermodule.ts",
111+
"../index.ts"
112+
],
113+
"fileInfos": {
114+
"../../../../../../a/lib/lib.d.ts": {
115+
"version": "-7698705165-/// <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; }",
116+
"signature": "-7698705165-/// <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; }",
117+
"affectsGlobalScope": true
118+
},
119+
"../anothermodule.ts": {
120+
"version": "-2676574883-export const World = \"hello\";\r\n",
121+
"signature": "-9234818176-export declare const World = \"hello\";\n",
122+
"affectsGlobalScope": false
123+
},
124+
"../index.ts": {
125+
"version": "-18749805970-export const someString: string = \"HELLO WORLD\";\r\nexport function leftPad(s: string, n: number) { return s + n; }\r\nexport function multiply(a: number, b: number) { return a * b; }\r\n",
126+
"signature": "-7362568283-export declare const someString: string;\nexport declare function leftPad(s: string, n: number): string;\nexport declare function multiply(a: number, b: number): number;\n",
127+
"affectsGlobalScope": false
128+
}
129+
},
130+
"options": {
131+
"composite": true,
132+
"outDir": "./",
133+
"watch": true,
134+
"configFilePath": "../tsconfig.json"
135+
},
136+
"referencedMap": {},
137+
"exportedModulesMap": {},
138+
"semanticDiagnosticsPerFile": [
139+
"../../../../../../a/lib/lib.d.ts",
140+
"../anothermodule.ts",
141+
"../index.ts"
142+
]
143+
},
144+
"version": "FakeTSVersion",
145+
"size": 1681
146+
}
147+
105148

106149
Change:: No change
107150

@@ -135,15 +178,15 @@ export const y = 10;
135178

136179
Output::
137180
>> Screen clear
138-
[[90m12:00:47 AM[0m] File change detected. Starting incremental compilation...
181+
[[90m12:00:49 AM[0m] File change detected. Starting incremental compilation...
139182

140-
[[90m12:00:48 AM[0m] Project 'sample1/core/tsconfig.json' is out of date because oldest output 'sample1/core/outDir/anotherModule.js' is older than newest input 'sample1/core/file3.ts'
183+
[[90m12:00:50 AM[0m] Project 'sample1/core/tsconfig.json' is out of date because oldest output 'sample1/core/outDir/anotherModule.js' is older than newest input 'sample1/core/file3.ts'
141184

142-
[[90m12:00:49 AM[0m] Building project '/user/username/projects/sample1/core/tsconfig.json'...
185+
[[90m12:00:51 AM[0m] Building project '/user/username/projects/sample1/core/tsconfig.json'...
143186

144-
[[90m12:00:58 AM[0m] Updating unchanged output timestamps of project '/user/username/projects/sample1/core/tsconfig.json'...
187+
[[90m12:01:00 AM[0m] Updating unchanged output timestamps of project '/user/username/projects/sample1/core/tsconfig.json'...
145188

146-
[[90m12:00:59 AM[0m] Found 0 errors. Watching for file changes.
189+
[[90m12:01:04 AM[0m] Found 0 errors. Watching for file changes.
147190

148191

149192

@@ -184,6 +227,56 @@ exitCode:: ExitStatus.undefined
184227
//// [/user/username/projects/sample1/core/outDir/tsconfig.tsbuildinfo]
185228
{"program":{"fileNames":["../../../../../../a/lib/lib.d.ts","../anothermodule.ts","../file3.ts","../index.ts"],"fileInfos":[{"version":"-7698705165-/// <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; }","signature":"-7698705165-/// <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; }","affectsGlobalScope":true},{"version":"-2676574883-export const World = \"hello\";\r\n","signature":"-9234818176-export declare const World = \"hello\";\n","affectsGlobalScope":false},{"version":"-13729955264-export const y = 10;","signature":"-7152472870-export declare const y = 10;\n","affectsGlobalScope":false},{"version":"-18749805970-export const someString: string = \"HELLO WORLD\";\r\nexport function leftPad(s: string, n: number) { return s + n; }\r\nexport function multiply(a: number, b: number) { return a * b; }\r\n","signature":"-7362568283-export declare const someString: string;\nexport declare function leftPad(s: string, n: number): string;\nexport declare function multiply(a: number, b: number): number;\n","affectsGlobalScope":false}],"options":{"composite":true,"outDir":"./","watch":true,"configFilePath":"../tsconfig.json"},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3,4]},"version":"FakeTSVersion"}
186229

230+
//// [/user/username/projects/sample1/core/outDir/tsconfig.tsbuildinfo.readable.baseline.txt]
231+
{
232+
"program": {
233+
"fileNames": [
234+
"../../../../../../a/lib/lib.d.ts",
235+
"../anothermodule.ts",
236+
"../file3.ts",
237+
"../index.ts"
238+
],
239+
"fileInfos": {
240+
"../../../../../../a/lib/lib.d.ts": {
241+
"version": "-7698705165-/// <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; }",
242+
"signature": "-7698705165-/// <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; }",
243+
"affectsGlobalScope": true
244+
},
245+
"../anothermodule.ts": {
246+
"version": "-2676574883-export const World = \"hello\";\r\n",
247+
"signature": "-9234818176-export declare const World = \"hello\";\n",
248+
"affectsGlobalScope": false
249+
},
250+
"../file3.ts": {
251+
"version": "-13729955264-export const y = 10;",
252+
"signature": "-7152472870-export declare const y = 10;\n",
253+
"affectsGlobalScope": false
254+
},
255+
"../index.ts": {
256+
"version": "-18749805970-export const someString: string = \"HELLO WORLD\";\r\nexport function leftPad(s: string, n: number) { return s + n; }\r\nexport function multiply(a: number, b: number) { return a * b; }\r\n",
257+
"signature": "-7362568283-export declare const someString: string;\nexport declare function leftPad(s: string, n: number): string;\nexport declare function multiply(a: number, b: number): number;\n",
258+
"affectsGlobalScope": false
259+
}
260+
},
261+
"options": {
262+
"composite": true,
263+
"outDir": "./",
264+
"watch": true,
265+
"configFilePath": "../tsconfig.json"
266+
},
267+
"referencedMap": {},
268+
"exportedModulesMap": {},
269+
"semanticDiagnosticsPerFile": [
270+
"../../../../../../a/lib/lib.d.ts",
271+
"../anothermodule.ts",
272+
"../file3.ts",
273+
"../index.ts"
274+
]
275+
},
276+
"version": "FakeTSVersion",
277+
"size": 1829
278+
}
279+
187280
//// [/user/username/projects/sample1/core/outDir/file3.js]
188281
"use strict";
189282
exports.__esModule = true;

0 commit comments

Comments
 (0)