Skip to content

Commit 409d6c9

Browse files
committed
Add compiler version to buildInfo
1 parent d4cfa41 commit 409d6c9

File tree

96 files changed

+492
-265
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+492
-265
lines changed

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ namespace ts {
200200
emitSkipped = true;
201201
return;
202202
}
203-
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText({ bundle, program }), /*writeByteOrderMark*/ false);
203+
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText({ bundle, program, version }), /*writeByteOrderMark*/ false);
204204
}
205205

206206
function emitJsFileOrBundle(sourceFileOrBundle: SourceFile | Bundle | undefined, jsFilePath: string | undefined, sourceMapFilePath: string | undefined) {

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5612,6 +5612,7 @@ namespace ts {
56125612
export interface BuildInfo {
56135613
bundle?: BundleBuildInfo;
56145614
program?: ProgramBuildInfo;
5615+
version: string;
56155616
}
56165617

56175618
export interface PrintHandlers {

src/harness/fakes.ts

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -388,68 +388,71 @@ namespace fakes {
388388
return ts.compareStringsCaseSensitive(ts.isString(a) ? a : a[0], ts.isString(b) ? b : b[0]);
389389
}
390390

391+
export const version = "FakeTSVersion";
392+
391393
export class SolutionBuilderHost extends CompilerHost implements ts.SolutionBuilderHost<ts.BuilderProgram> {
392394
createProgram = ts.createEmitAndSemanticDiagnosticsBuilderProgram;
393395

394396
readFile(path: string) {
395397
const value = super.readFile(path);
396398
if (!value || !ts.isBuildInfoFile(path)) return value;
397399
const buildInfo = JSON.parse(value) as ts.BuildInfo;
398-
if (!buildInfo.program) return value;
399-
// Fix lib signatures
400-
for (const path of ts.getOwnKeys(buildInfo.program.fileInfos)) {
401-
if (ts.startsWith(path, "/lib/")) {
402-
const currentValue = buildInfo.program.fileInfos[path];
403-
ts.Debug.assert(currentValue.signature === path);
404-
ts.Debug.assert(currentValue.signature === currentValue.version);
405-
const text = super.readFile(path)!;
406-
const signature = ts.generateDjb2Hash(text);
407-
buildInfo.program.fileInfos[path] = { version: signature, signature };
400+
if (buildInfo.program) {
401+
// Fix lib signatures
402+
for (const path of ts.getOwnKeys(buildInfo.program.fileInfos)) {
403+
if (ts.startsWith(path, "/lib/")) {
404+
const currentValue = buildInfo.program.fileInfos[path];
405+
ts.Debug.assert(currentValue.signature === path);
406+
ts.Debug.assert(currentValue.signature === currentValue.version);
407+
const text = super.readFile(path)!;
408+
const signature = ts.generateDjb2Hash(text);
409+
buildInfo.program.fileInfos[path] = { version: signature, signature };
410+
}
408411
}
409412
}
413+
ts.Debug.assert(buildInfo.version === version);
414+
buildInfo.version = ts.version;
410415
return ts.getBuildInfoText(buildInfo);
411416
}
412417

413418
public writeFile(fileName: string, content: string, writeByteOrderMark: boolean) {
414-
if (ts.isBuildInfoFile(fileName)) {
415-
const buildInfo = JSON.parse(content) as ts.BuildInfo;
416-
if (buildInfo.program) {
417-
// Fix lib signatures
418-
for (const path of ts.getOwnKeys(buildInfo.program.fileInfos)) {
419-
if (ts.startsWith(path, "/lib/")) {
420-
const currentValue = buildInfo.program.fileInfos[path];
421-
ts.Debug.assert(currentValue.signature === currentValue.version);
422-
buildInfo.program.fileInfos[path] = { version: path, signature: path };
423-
}
424-
}
425-
426-
// reference Map
427-
if (buildInfo.program.referencedMap) {
428-
const referencedMap: ts.MapLike<string[]> = {};
429-
for (const path of ts.getOwnKeys(buildInfo.program.referencedMap).sort()) {
430-
referencedMap[path] = buildInfo.program.referencedMap[path].sort();
431-
}
432-
buildInfo.program.referencedMap = referencedMap;
419+
if (!ts.isBuildInfoFile(fileName)) return super.writeFile(fileName, content, writeByteOrderMark);
420+
const buildInfo = JSON.parse(content) as ts.BuildInfo;
421+
if (buildInfo.program) {
422+
// Fix lib signatures
423+
for (const path of ts.getOwnKeys(buildInfo.program.fileInfos)) {
424+
if (ts.startsWith(path, "/lib/")) {
425+
const currentValue = buildInfo.program.fileInfos[path];
426+
ts.Debug.assert(currentValue.signature === currentValue.version);
427+
buildInfo.program.fileInfos[path] = { version: path, signature: path };
433428
}
429+
}
434430

435-
// exportedModulesMap
436-
if (buildInfo.program.exportedModulesMap) {
437-
const exportedModulesMap: ts.MapLike<string[]> = {};
438-
for (const path of ts.getOwnKeys(buildInfo.program.exportedModulesMap).sort()) {
439-
exportedModulesMap[path] = buildInfo.program.exportedModulesMap[path].sort();
440-
}
441-
buildInfo.program.exportedModulesMap = exportedModulesMap;
431+
// reference Map
432+
if (buildInfo.program.referencedMap) {
433+
const referencedMap: ts.MapLike<string[]> = {};
434+
for (const path of ts.getOwnKeys(buildInfo.program.referencedMap).sort()) {
435+
referencedMap[path] = buildInfo.program.referencedMap[path].sort();
442436
}
437+
buildInfo.program.referencedMap = referencedMap;
438+
}
443439

444-
// semanticDiagnosticsPerFile
445-
if (buildInfo.program.semanticDiagnosticsPerFile) {
446-
buildInfo.program.semanticDiagnosticsPerFile.sort(compareProgramBuildInfoDiagnostic);
440+
// exportedModulesMap
441+
if (buildInfo.program.exportedModulesMap) {
442+
const exportedModulesMap: ts.MapLike<string[]> = {};
443+
for (const path of ts.getOwnKeys(buildInfo.program.exportedModulesMap).sort()) {
444+
exportedModulesMap[path] = buildInfo.program.exportedModulesMap[path].sort();
447445
}
446+
buildInfo.program.exportedModulesMap = exportedModulesMap;
447+
}
448448

449-
content = ts.getBuildInfoText(buildInfo);
449+
// semanticDiagnosticsPerFile
450+
if (buildInfo.program.semanticDiagnosticsPerFile) {
451+
buildInfo.program.semanticDiagnosticsPerFile.sort(compareProgramBuildInfoDiagnostic);
450452
}
451453
}
452-
super.writeFile(fileName, content, writeByteOrderMark);
454+
buildInfo.version = version;
455+
super.writeFile(fileName, ts.getBuildInfoText(buildInfo), writeByteOrderMark);
453456
}
454457

455458
now() {

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/modules-and-globals-mixed-in-amd.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ sourceFile:file4.ts
270270
}
271271
]
272272
}
273-
}
273+
},
274+
"version": "FakeTSVersion"
274275
}
275276

276277
//// [/src/app/module.tsbuildinfo.baseline.txt]
@@ -520,7 +521,8 @@ sourceFile:global.ts
520521
}
521522
]
522523
}
523-
}
524+
},
525+
"version": "FakeTSVersion"
524526
}
525527

526528
//// [/src/lib/module.tsbuildinfo.baseline.txt]

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/multiple-emitHelpers-in-all-projects.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ sourceFile:file4.ts
663663
}
664664
]
665665
}
666-
}
666+
},
667+
"version": "FakeTSVersion"
667668
}
668669

669670
//// [/src/app/module.tsbuildinfo.baseline.txt]
@@ -1210,7 +1211,8 @@ sourceFile:global.ts
12101211
}
12111212
]
12121213
}
1213-
}
1214+
},
1215+
"version": "FakeTSVersion"
12141216
}
12151217

12161218
//// [/src/lib/module.tsbuildinfo.baseline.txt]

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/multiple-prologues-in-all-projects.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ sourceFile:file4.ts
406406
}
407407
]
408408
}
409-
}
409+
},
410+
"version": "FakeTSVersion"
410411
}
411412

412413
//// [/src/app/module.tsbuildinfo.baseline.txt]
@@ -783,7 +784,8 @@ sourceFile:global.ts
783784
}
784785
]
785786
}
786-
}
787+
},
788+
"version": "FakeTSVersion"
787789
}
788790

789791
//// [/src/lib/module.tsbuildinfo.baseline.txt]

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/shebang-in-all-projects.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ sourceFile:file4.ts
275275
}
276276
]
277277
}
278-
}
278+
},
279+
"version": "FakeTSVersion"
279280
}
280281

281282
//// [/src/app/module.tsbuildinfo.baseline.txt]
@@ -530,7 +531,8 @@ sourceFile:global.ts
530531
}
531532
]
532533
}
533-
}
534+
},
535+
"version": "FakeTSVersion"
534536
}
535537

536538
//// [/src/lib/module.tsbuildinfo.baseline.txt]

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/stripInternal.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,8 @@ sourceFile:file4.ts
17131713
}
17141714
]
17151715
}
1716-
}
1716+
},
1717+
"version": "FakeTSVersion"
17171718
}
17181719

17191720
//// [/src/app/module.tsbuildinfo.baseline.txt]
@@ -3559,7 +3560,8 @@ sourceFile:global.ts
35593560
}
35603561
]
35613562
}
3562-
}
3563+
},
3564+
"version": "FakeTSVersion"
35633565
}
35643566

35653567
//// [/src/lib/module.tsbuildinfo.baseline.txt]

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/triple-slash-refs-in-all-projects.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ sourceFile:file4.ts
358358
}
359359
]
360360
}
361-
}
361+
},
362+
"version": "FakeTSVersion"
362363
}
363364

364365
//// [/src/app/module.tsbuildinfo.baseline.txt]
@@ -664,7 +665,8 @@ sourceFile:global.ts
664665
}
665666
]
666667
}
667-
}
668+
},
669+
"version": "FakeTSVersion"
668670
}
669671

670672
//// [/src/lib/module.tsbuildinfo.baseline.txt]

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-headers-change-without-dts-changes/multiple-emitHelpers-in-all-projects.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ sourceFile:file4.ts
602602
}
603603
]
604604
}
605-
}
605+
},
606+
"version": "FakeTSVersion"
606607
}
607608

608609
//// [/src/app/module.tsbuildinfo.baseline.txt]
@@ -1058,7 +1059,8 @@ sourceFile:global.ts
10581059
}
10591060
]
10601061
}
1061-
}
1062+
},
1063+
"version": "FakeTSVersion"
10621064
}
10631065

10641066
//// [/src/lib/module.tsbuildinfo.baseline.txt]

0 commit comments

Comments
 (0)