diff --git a/Jakefile.js b/Jakefile.js index bcc1f1dc650..5112a8db597 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -975,6 +975,8 @@ var servicesLintTargets = [ }); var lintTargets = compilerSources .concat(harnessCoreSources) + // Other harness sources + .concat(["instrumenter.ts"].map(function(f) { return path.join(harnessDirectory, f) })) .concat(serverCoreSources) .concat(["client.ts"].map(function(f) { return path.join(serverDirectory, f); })) .concat(tslintRulesFiles) diff --git a/src/harness/instrumenter.ts b/src/harness/instrumenter.ts index b1b1750b8a8..b8f42e7e8bd 100644 --- a/src/harness/instrumenter.ts +++ b/src/harness/instrumenter.ts @@ -1,6 +1,6 @@ -declare var require: any, process: any; -var fs: any = require('fs'); -var path: any = require('path'); +declare const require: any, process: any; +const fs: any = require("fs"); +const path: any = require("path"); function instrumentForRecording(fn: string, tscPath: string) { instrument(tscPath, ` @@ -14,31 +14,31 @@ ts.sys = Playback.wrapSystem(ts.sys); ts.sys.startReplay("${ logFilename }");`); } -function instrument(tscPath: string, prepareCode: string, cleanupCode: string = '') { - var bak = tscPath + '.bak'; +function instrument(tscPath: string, prepareCode: string, cleanupCode = "") { + const bak = `${tscPath}.bak`; fs.exists(bak, (backupExists: boolean) => { - var filename = tscPath; + let filename = tscPath; if (backupExists) { filename = bak; } - fs.readFile(filename, 'utf-8', (err: any, tscContent: string) => { + fs.readFile(filename, "utf-8", (err: any, tscContent: string) => { if (err) throw err; fs.writeFile(bak, tscContent, (err: any) => { if (err) throw err; - fs.readFile(path.resolve(path.dirname(tscPath) + '/loggedIO.js'), 'utf-8', (err: any, loggerContent: string) => { + fs.readFile(path.resolve(path.dirname(tscPath) + "/loggedIO.js"), "utf-8", (err: any, loggerContent: string) => { if (err) throw err; - var invocationLine = 'ts.executeCommandLine(ts.sys.args);'; - var index1 = tscContent.indexOf(invocationLine); + const invocationLine = "ts.executeCommandLine(ts.sys.args);"; + const index1 = tscContent.indexOf(invocationLine); if (index1 < 0) { - throw new Error("Could not find " + invocationLine); + throw new Error(`Could not find ${invocationLine}`); } - var index2 = index1 + invocationLine.length; - var newContent = tscContent.substr(0, index1) + loggerContent + prepareCode + invocationLine + cleanupCode + tscContent.substr(index2) + '\r\n'; + const index2 = index1 + invocationLine.length; + const newContent = tscContent.substr(0, index1) + loggerContent + prepareCode + invocationLine + cleanupCode + tscContent.substr(index2) + "\r\n"; fs.writeFile(tscPath, newContent); }); }); @@ -46,15 +46,16 @@ function instrument(tscPath: string, prepareCode: string, cleanupCode: string = }); } -var isJson = (arg: string) => arg.indexOf(".json") > 0; +const isJson = (arg: string) => arg.indexOf(".json") > 0; -var record = process.argv.indexOf('record'); -var tscPath = process.argv[process.argv.length - 1]; +const record = process.argv.indexOf("record"); +const tscPath = process.argv[process.argv.length - 1]; if (record >= 0) { - console.log('Instrumenting ' + tscPath + ' for recording'); + console.log(`Instrumenting ${tscPath} for recording`); instrumentForRecording(process.argv[record + 1], tscPath); -} else if (process.argv.some(isJson)) { - var filename = process.argv.filter(isJson)[0]; +} +else if (process.argv.some(isJson)) { + const filename = process.argv.filter(isJson)[0]; instrumentForReplay(filename, tscPath); }