Skip to content

Commit d8edd19

Browse files
authored
Write version for baselining in buildinfo (#48602)
Also baseline buildinfo so its easier to detect mistakes
1 parent b18141b commit d8edd19

9 files changed

+832
-50
lines changed

src/testRunner/unittests/tsbuild/outFile.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ namespace ts {
146146
commandLineArgs: ["--b", "/src/third", "--verbose"],
147147
compile: sys => {
148148
// Buildinfo will have version which does not match with current ts version
149-
fakes.patchHostForBuildInfoWrite(sys, "FakeTSCurrentVersion");
150-
const buildHost = createSolutionBuilderHost(sys);
149+
const buildHost = createSolutionBuilderHostForBaseline(sys, "FakeTSCurrentVersion");
151150
const builder = ts.createSolutionBuilder(buildHost, ["/src/third"], { verbose: true });
152151
sys.exit(builder.build());
153152
}
@@ -181,7 +180,7 @@ namespace ts {
181180
fs: () => outFileFs,
182181
commandLineArgs: ["--build", "/src/second/tsconfig.json"],
183182
compile: sys => {
184-
const buildHost = createSolutionBuilderHost(sys);
183+
const buildHost = createSolutionBuilderHostForBaseline(sys);
185184
const builder = ts.createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], {});
186185
sys.exit(builder.build("/src/second/tsconfig.json"));
187186
}
@@ -193,7 +192,7 @@ namespace ts {
193192
fs: getOutFileFsAfterBuild,
194193
commandLineArgs: ["--build", "--clean", "/src/second/tsconfig.json"],
195194
compile: sys => {
196-
const buildHost = createSolutionBuilderHost(sys);
195+
const buildHost = createSolutionBuilderHostForBaseline(sys);
197196
const builder = ts.createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], { verbose: true });
198197
sys.exit(builder.clean("/src/second/tsconfig.json"));
199198
}

src/testRunner/unittests/tsbuild/sample.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace ts {
8484
fs: getSampleFsAfterBuild,
8585
commandLineArgs: ["--b", "/src/logic", "--clean"],
8686
compile: sys => {
87-
const buildHost = createSolutionBuilderHost(sys);
87+
const buildHost = createSolutionBuilderHostForBaseline(sys);
8888
const builder = createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], {});
8989
sys.exit(builder.clean("/src/logic"));
9090
}
@@ -96,7 +96,7 @@ namespace ts {
9696
fs: getSampleFsAfterBuild,
9797
commandLineArgs: ["--b", "/src/logic2", "--clean"],
9898
compile: sys => {
99-
const buildHost = createSolutionBuilderHost(sys);
99+
const buildHost = createSolutionBuilderHostForBaseline(sys);
100100
const builder = createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], {});
101101
sys.exit(builder.clean("/src/logic2"));
102102
}
@@ -158,8 +158,7 @@ namespace ts {
158158
commandLineArgs: ["--b", "/src/tests", "--verbose"],
159159
compile: sys => {
160160
// Buildinfo will have version which does not match with current ts version
161-
fakes.patchHostForBuildInfoWrite(sys, "FakeTSCurrentVersion");
162-
const buildHost = createSolutionBuilderHost(sys);
161+
const buildHost = createSolutionBuilderHostForBaseline(sys, "FakeTSCurrentVersion");
163162
const builder = createSolutionBuilder(buildHost, ["/src/tests"], { verbose: true });
164163
sys.exit(builder.build());
165164
}
@@ -179,8 +178,7 @@ namespace ts {
179178
commandLineArgs: ["--b", "/src/tests", "--verbose"],
180179
compile: sys => {
181180
// Buildinfo will have version which does not match with current ts version
182-
fakes.patchHostForBuildInfoWrite(sys, "FakeTSCurrentVersion");
183-
const buildHost = createSolutionBuilderHost(sys);
181+
const buildHost = createSolutionBuilderHostForBaseline(sys, "FakeTSCurrentVersion");
184182
const builder = createSolutionBuilder(buildHost, ["/src/tests"], { verbose: true });
185183
sys.exit(builder.build());
186184
},
@@ -207,7 +205,7 @@ namespace ts {
207205
fs: () => projFs,
208206
commandLineArgs: ["--build", "/src/logic/tsconfig.json"],
209207
compile: sys => {
210-
const buildHost = createSolutionBuilderHost(sys);
208+
const buildHost = createSolutionBuilderHostForBaseline(sys);
211209
const builder = createSolutionBuilder(buildHost, ["/src/tests"], {});
212210
sys.exit(builder.build("/src/logic/tsconfig.json"));
213211
}
@@ -219,7 +217,7 @@ namespace ts {
219217
fs: () => projFs,
220218
commandLineArgs: ["--build", "/src/logic2/tsconfig.json"],
221219
compile: sys => {
222-
const buildHost = createSolutionBuilderHost(sys);
220+
const buildHost = createSolutionBuilderHostForBaseline(sys);
223221
const builder = createSolutionBuilder(buildHost, ["/src/tests"], {});
224222
sys.exit(builder.build("/src/logic2/tsconfig.json"));
225223
}
@@ -278,7 +276,7 @@ namespace ts {
278276
fs: () => projFs,
279277
commandLineArgs: ["--build", "/src/logic2/tsconfig.json"],
280278
compile: sys => {
281-
const buildHost = createSolutionBuilderHost(sys);
279+
const buildHost = createSolutionBuilderHostForBaseline(sys);
282280
const builder = createSolutionBuilder(buildHost, ["/src/tests"], { verbose: true });
283281
sys.exit(builder.buildReferences("/src/tests"));
284282
}

src/testRunner/unittests/tsc/helpers.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,37 @@ ${patch ? vfs.formatPatch(patch) : ""}`
109109
return sys;
110110
}
111111

112+
function makeSystemReadyForBaseline(sys: TscCompileSystem, versionToWrite?: string) {
113+
if (versionToWrite) {
114+
fakes.patchHostForBuildInfoWrite(sys, versionToWrite);
115+
}
116+
else {
117+
fakes.patchHostForBuildInfoReadWrite(sys);
118+
}
119+
const writtenFiles = sys.writtenFiles = new Set();
120+
const originalWriteFile = sys.writeFile;
121+
sys.writeFile = (fileName, content, writeByteOrderMark) => {
122+
const path = toPathWithSystem(sys, fileName);
123+
assert.isFalse(writtenFiles.has(path));
124+
writtenFiles.add(path);
125+
return originalWriteFile.call(sys, fileName, content, writeByteOrderMark);
126+
};
127+
return originalWriteFile;
128+
}
129+
130+
export function createSolutionBuilderHostForBaseline(sys: TscCompileSystem, versionToWrite?: string) {
131+
makeSystemReadyForBaseline(sys, versionToWrite);
132+
const { cb } = commandLineCallbacks(sys);
133+
const host = createSolutionBuilderHost(sys,
134+
/*createProgram*/ undefined,
135+
createDiagnosticReporter(sys, /*pretty*/ true),
136+
createBuilderStatusReporter(sys, /*pretty*/ true),
137+
);
138+
host.afterProgramEmitAndDiagnostics = cb;
139+
host.afterEmitBundle = cb;
140+
return host;
141+
}
142+
112143
/**
113144
* Initialize Fs, execute command line and save baseline
114145
*/
@@ -122,15 +153,7 @@ ${patch ? vfs.formatPatch(patch) : ""}`
122153
});
123154

124155
function commandLineCompile(sys: TscCompileSystem) {
125-
fakes.patchHostForBuildInfoReadWrite(sys);
126-
const writtenFiles = sys.writtenFiles = new Set();
127-
const originalWriteFile = sys.writeFile;
128-
sys.writeFile = (fileName, content, writeByteOrderMark) => {
129-
const path = toPathWithSystem(sys, fileName);
130-
assert.isFalse(writtenFiles.has(path));
131-
writtenFiles.add(path);
132-
return originalWriteFile.call(sys, fileName, content, writeByteOrderMark);
133-
};
156+
const originalWriteFile = makeSystemReadyForBaseline(sys);
134157
actualReadFileMap = {};
135158
const originalReadFile = sys.readFile;
136159
sys.readFile = path => {

tests/baselines/reference/tsbuild/outFile/builds-till-project-specified.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,72 @@ var C = (function () {
153153
{"version":3,"file":"second-output.js","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAIA,IAAU,CAAC,CAMV;AAND,WAAU,CAAC;IACP,SAAS,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IAED,CAAC,EAAE,CAAC;AACR,CAAC,EANS,CAAC,KAAD,CAAC,QAMV;ACVD;IAAA;IAIA,CAAC;IAHG,uBAAW,GAAX;QACI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IACtC,CAAC;IACL,QAAC;AAAD,CAAC,AAJD,IAIC"}
154154

155155
//// [/src/2/second-output.tsbuildinfo]
156-
{"bundle":{"commonSourceDirectory":"../second","sourceFiles":["../second/second_part1.ts","../second/second_part2.ts"],"js":{"sections":[{"pos":0,"end":285,"kind":"text"}]},"dts":{"sections":[{"pos":0,"end":100,"kind":"text"}]}},"version":"4.7.0-dev"}
156+
{"bundle":{"commonSourceDirectory":"../second","sourceFiles":["../second/second_part1.ts","../second/second_part2.ts"],"js":{"sections":[{"pos":0,"end":285,"kind":"text"}]},"dts":{"sections":[{"pos":0,"end":100,"kind":"text"}]}},"version":"FakeTSVersion"}
157+
158+
//// [/src/2/second-output.tsbuildinfo.baseline.txt]
159+
======================================================================
160+
File:: /src/2/second-output.js
161+
----------------------------------------------------------------------
162+
text: (0-285)
163+
var N;
164+
(function (N) {
165+
function f() {
166+
console.log('testing');
167+
}
168+
f();
169+
})(N || (N = {}));
170+
var C = (function () {
171+
function C() {
172+
}
173+
C.prototype.doSomething = function () {
174+
console.log("something got done");
175+
};
176+
return C;
177+
}());
178+
179+
======================================================================
180+
======================================================================
181+
File:: /src/2/second-output.d.ts
182+
----------------------------------------------------------------------
183+
text: (0-100)
184+
declare namespace N {
185+
}
186+
declare namespace N {
187+
}
188+
declare class C {
189+
doSomething(): void;
190+
}
191+
192+
======================================================================
193+
194+
//// [/src/2/second-output.tsbuildinfo.readable.baseline.txt]
195+
{
196+
"bundle": {
197+
"commonSourceDirectory": "../second",
198+
"sourceFiles": [
199+
"../second/second_part1.ts",
200+
"../second/second_part2.ts"
201+
],
202+
"js": {
203+
"sections": [
204+
{
205+
"pos": 0,
206+
"end": 285,
207+
"kind": "text"
208+
}
209+
]
210+
},
211+
"dts": {
212+
"sections": [
213+
{
214+
"pos": 0,
215+
"end": 100,
216+
"kind": "text"
217+
}
218+
]
219+
}
220+
},
221+
"version": "FakeTSVersion",
222+
"size": 255
223+
}
157224

0 commit comments

Comments
 (0)