Skip to content

Commit 92e7fb5

Browse files
authored
Update tsc-instrumented for project build (#45383)
* Update tsc-instrumented for project build loggedIO has a weird build that never got updated for the project build system. This PR just adds a project for it in a straightforward way. It might be less efficient than the old way, but that's not a big concern for recording RWC test cases. However, I may have done things wrong. If anybody knows tsc-instrumented, please comment. * Create a second loggedIO tsconfig for tsc-instrumented The normal tsconfig should not have `prepend`; the standalone one for tsc-instrumented should. * fix semicolon lint
1 parent 6c42d79 commit 92e7fb5

File tree

7 files changed

+68
-47
lines changed

7 files changed

+68
-47
lines changed

Gulpfile.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,21 +510,15 @@ task("baseline-accept").description = "Makes the most recent test results the ne
510510
task("baseline-accept-rwc", () => baselineAccept(localRwcBaseline, refRwcBaseline));
511511
task("baseline-accept-rwc").description = "Makes the most recent rwc test results the new baseline, overwriting the old baseline";
512512

513-
const buildLoggedIO = async () => {
514-
mkdirp.sync("built/local/temp");
515-
await exec(process.execPath, ["lib/tsc", "--types", "--target", "es5", "--lib", "es5", "--outdir", "built/local/temp", "src/harness/loggedIO.ts"]);
516-
fs.renameSync("built/local/temp/harness/loggedIO.js", "built/local/loggedIO.js");
517-
await del("built/local/temp");
518-
};
519-
520-
const cleanLoggedIO = () => del("built/local/temp/loggedIO.js");
513+
const buildLoggedIO = () => buildProject("src/loggedIO/tsconfig-tsc-instrumented.json");
514+
const cleanLoggedIO = () => del("built/local/loggedIO.js");
521515
cleanTasks.push(cleanLoggedIO);
522516

523517
const buildInstrumenter = () => buildProject("src/instrumenter");
524518
const cleanInstrumenter = () => cleanProject("src/instrumenter");
525519
cleanTasks.push(cleanInstrumenter);
526520

527-
const tscInstrumented = () => exec(process.execPath, ["built/local/instrumenter.js", "record", cmdLineOptions.tests || "iocapture", "built/local"]);
521+
const tscInstrumented = () => exec(process.execPath, ["built/local/instrumenter.js", "record", cmdLineOptions.tests || "iocapture", "built/local/tsc.js"]);
528522
task("tsc-instrumented", series(lkgPreBuild, parallel(localize, buildTsc, buildServer, buildServices, buildLssl, buildLoggedIO, buildInstrumenter), tscInstrumented));
529523
task("tsc-instrumented").description = "Builds an instrumented tsc.js";
530524
task("tsc-instrumented").flags = {

src/harness/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"virtualFileSystemWithWatch.ts",
3939
"fourslashImpl.ts",
4040
"fourslashInterfaceImpl.ts",
41-
"typeWriter.ts",
42-
"loggedIO.ts"
41+
"typeWriter.ts"
4342
]
4443
}

src/instrumenter/instrumenter.ts

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,18 @@ ts.sys.startReplay("${ logFilename }");`);
1515

1616
function instrument(tscPath: string, prepareCode: string, cleanupCode = "") {
1717
const bak = `${tscPath}.bak`;
18-
fs.exists(bak, (backupExists: boolean) => {
19-
let filename = tscPath;
20-
if (backupExists) {
21-
filename = bak;
22-
}
23-
24-
fs.readFile(filename, "utf-8", (err: any, tscContent: string) => {
25-
if (err) throw err;
26-
27-
fs.writeFile(bak, tscContent, (err: any) => {
28-
if (err) throw err;
29-
30-
fs.readFile(path.resolve(path.dirname(tscPath) + "/loggedIO.js"), "utf-8", (err: any, loggerContent: string) => {
31-
if (err) throw err;
32-
33-
const invocationLine = "ts.executeCommandLine(ts.sys.args);";
34-
const index1 = tscContent.indexOf(invocationLine);
35-
if (index1 < 0) {
36-
throw new Error(`Could not find ${invocationLine}`);
37-
}
38-
39-
const index2 = index1 + invocationLine.length;
40-
const newContent = tscContent.substr(0, index1) + loggerContent + prepareCode + invocationLine + cleanupCode + tscContent.substr(index2) + "\r\n";
41-
fs.writeFile(tscPath, newContent, err => {
42-
if (err) throw err;
43-
});
44-
});
45-
});
46-
});
47-
});
18+
const filename = fs.existsSync(bak) ? bak : tscPath;
19+
const tscContent = fs.readFileSync(filename, "utf-8");
20+
fs.writeFileSync(bak, tscContent);
21+
const loggerContent = fs.readFileSync(path.resolve(path.dirname(tscPath) + "/loggedIO.js"), "utf-8");
22+
const invocationLine = "ts.executeCommandLine(ts.sys, ts.noop, ts.sys.args);";
23+
const index1 = tscContent.indexOf(invocationLine);
24+
if (index1 < 0) {
25+
throw new Error(`Could not find ${invocationLine}`);
26+
}
27+
const index2 = index1 + invocationLine.length;
28+
const newContent = tscContent.substr(0, index1) + loggerContent + prepareCode + invocationLine + cleanupCode + tscContent.substr(index2) + "\r\n";
29+
fs.writeFileSync(tscPath, newContent);
4830
}
4931

5032
const isJson = (arg: string) => arg.indexOf(".json") > 0;
@@ -59,5 +41,3 @@ else if (process.argv.some(isJson)) {
5941
const filename = process.argv.filter(isJson)[0];
6042
instrumentForReplay(filename, tscPath);
6143
}
62-
63-

src/harness/loggedIO.ts renamed to src/loggedIO/loggedIO.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ namespace Playback {
205205
return log;
206206
}
207207

208-
function initWrapper(wrapper: PlaybackSystem, underlying: ts.System): void;
209-
function initWrapper(wrapper: PlaybackIO, underlying: Harness.IO): void;
210-
function initWrapper(wrapper: PlaybackSystem | PlaybackIO, underlying: ts.System | Harness.IO): void {
208+
export function initWrapper(...[wrapper, underlying]: [PlaybackSystem, ts.System] | [PlaybackIO, Harness.IO]): void {
211209
ts.forEach(Object.keys(underlying), prop => {
212210
(wrapper as any)[prop] = (underlying as any)[prop];
213211
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": "../tsconfig-base",
3+
"compilerOptions": {
4+
"outFile": "../../built/local/loggedIO.js",
5+
"types": [
6+
"node", "mocha", "chai"
7+
],
8+
"lib": [
9+
"es6",
10+
"scripthost"
11+
]
12+
},
13+
"references": [
14+
{ "path": "../compiler", "prepend": true },
15+
{ "path": "../services", "prepend": true },
16+
{ "path": "../jsTyping", "prepend": true },
17+
{ "path": "../server", "prepend": true },
18+
{ "path": "../typingsInstallerCore", "prepend": true },
19+
{ "path": "../harness", "prepend": true },
20+
],
21+
22+
"files": [
23+
"loggedIO.ts"
24+
]
25+
}

src/loggedIO/tsconfig.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"extends": "../tsconfig-base",
3+
"compilerOptions": {
4+
"outFile": "../../built/local/loggedIO.js",
5+
"types": [
6+
],
7+
"lib": [
8+
"es6",
9+
"scripthost"
10+
]
11+
},
12+
"references": [
13+
{ "path": "../compiler" },
14+
{ "path": "../services" },
15+
{ "path": "../jsTyping" },
16+
{ "path": "../server" },
17+
{ "path": "../typingsInstallerCore" },
18+
{ "path": "../harness" },
19+
],
20+
21+
"files": [
22+
"loggedIO.ts"
23+
]
24+
}

src/testRunner/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
{ "path": "../server", "prepend": true },
2424
{ "path": "../webServer", "prepend": true },
2525
{ "path": "../typingsInstallerCore", "prepend": true },
26-
{ "path": "../harness", "prepend": true }
26+
{ "path": "../harness", "prepend": true },
27+
{ "path": "../loggedIO", "prepend": true }
2728
],
2829

2930
"files": [

0 commit comments

Comments
 (0)