Skip to content

Commit 15b0a8e

Browse files
author
Andy Hanson
committed
Lint src\harness\instrumenter.ts
1 parent 3f9efa0 commit 15b0a8e

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

Jakefile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,8 @@ var servicesLintTargets = [
975975
});
976976
var lintTargets = compilerSources
977977
.concat(harnessCoreSources)
978+
// Other harness sources
979+
.concat(["instrumenter.ts"].map(function(f) { return path.join(harnessDirectory, f) }))
978980
.concat(serverCoreSources)
979981
.concat(tslintRulesFiles)
980982
.concat(servicesLintTargets);

src/harness/instrumenter.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
declare var require: any, process: any;
2-
var fs: any = require('fs');
3-
var path: any = require('path');
1+
declare const require: any, process: any;
2+
const fs: any = require("fs");
3+
const path: any = require("path");
44

55
function instrumentForRecording(fn: string, tscPath: string) {
66
instrument(tscPath, `
@@ -14,47 +14,48 @@ ts.sys = Playback.wrapSystem(ts.sys);
1414
ts.sys.startReplay("${ logFilename }");`);
1515
}
1616

17-
function instrument(tscPath: string, prepareCode: string, cleanupCode: string = '') {
18-
var bak = tscPath + '.bak';
17+
function instrument(tscPath: string, prepareCode: string, cleanupCode = "") {
18+
const bak = `${tscPath}.bak`;
1919
fs.exists(bak, (backupExists: boolean) => {
20-
var filename = tscPath;
20+
let filename = tscPath;
2121
if (backupExists) {
2222
filename = bak;
2323
}
2424

25-
fs.readFile(filename, 'utf-8', (err: any, tscContent: string) => {
25+
fs.readFile(filename, "utf-8", (err: any, tscContent: string) => {
2626
if (err) throw err;
2727

2828
fs.writeFile(bak, tscContent, (err: any) => {
2929
if (err) throw err;
3030

31-
fs.readFile(path.resolve(path.dirname(tscPath) + '/loggedIO.js'), 'utf-8', (err: any, loggerContent: string) => {
31+
fs.readFile(path.resolve(path.dirname(tscPath) + "/loggedIO.js"), "utf-8", (err: any, loggerContent: string) => {
3232
if (err) throw err;
3333

34-
var invocationLine = 'ts.executeCommandLine(ts.sys.args);';
35-
var index1 = tscContent.indexOf(invocationLine);
34+
const invocationLine = "ts.executeCommandLine(ts.sys.args);";
35+
const index1 = tscContent.indexOf(invocationLine);
3636
if (index1 < 0) {
37-
throw new Error("Could not find " + invocationLine);
37+
throw new Error(`Could not find ${invocationLine}`);
3838
}
3939

40-
var index2 = index1 + invocationLine.length;
41-
var newContent = tscContent.substr(0, index1) + loggerContent + prepareCode + invocationLine + cleanupCode + tscContent.substr(index2) + '\r\n';
40+
const index2 = index1 + invocationLine.length;
41+
const newContent = tscContent.substr(0, index1) + loggerContent + prepareCode + invocationLine + cleanupCode + tscContent.substr(index2) + "\r\n";
4242
fs.writeFile(tscPath, newContent);
4343
});
4444
});
4545
});
4646
});
4747
}
4848

49-
var isJson = (arg: string) => arg.indexOf(".json") > 0;
49+
const isJson = (arg: string) => arg.indexOf(".json") > 0;
5050

51-
var record = process.argv.indexOf('record');
52-
var tscPath = process.argv[process.argv.length - 1];
51+
const record = process.argv.indexOf("record");
52+
const tscPath = process.argv[process.argv.length - 1];
5353
if (record >= 0) {
54-
console.log('Instrumenting ' + tscPath + ' for recording');
54+
console.log(`Instrumenting ${tscPath} for recording`);
5555
instrumentForRecording(process.argv[record + 1], tscPath);
56-
} else if (process.argv.some(isJson)) {
57-
var filename = process.argv.filter(isJson)[0];
56+
}
57+
else if (process.argv.some(isJson)) {
58+
const filename = process.argv.filter(isJson)[0];
5859
instrumentForReplay(filename, tscPath);
5960
}
6061

0 commit comments

Comments
 (0)