From 3ac91d109b4a84f1ae824fa4014165339edc218c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 27 Oct 2017 14:31:48 -0700 Subject: [PATCH] Generate tsconfig in tsc-instrumented instead --- src/harness/loggedIO.ts | 28 ++++++++++++++++++++++++---- src/harness/rwcRunner.ts | 8 +------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index c5d428f3095..ff23458d284 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -159,7 +159,7 @@ namespace Playback { } const canonicalizeForHarness = ts.createGetCanonicalFileName(/*caseSensitive*/ false); // This is done so tests work on windows _and_ linux - export function sanitizeTestFilePath(name: string) { + function sanitizeTestFilePath(name: string) { const path = ts.toPath(ts.normalizeSlashes(name.replace(/[\^<>:"|?*%]/g, "_")).replace(/\.\.\//g, "__dotdot/"), "", canonicalizeForHarness); if (ts.startsWith(path, "/")) { return path.substring(1); @@ -249,13 +249,33 @@ namespace Playback { wrapper.endRecord = () => { if (recordLog !== undefined) { let i = 0; - const fn = () => recordLogFileNameBase + i; - while (underlying.fileExists(ts.combinePaths(fn(), "test.json"))) i++; - underlying.writeFile(ts.combinePaths(fn(), "test.json"), JSON.stringify(oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(path, string), fn()), null, 4)); // tslint:disable-line:no-null-keyword + const getBase = () => recordLogFileNameBase + i; + while (underlying.fileExists(ts.combinePaths(getBase(), "test.json"))) i++; + const newLog = oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(path, string), getBase()); + underlying.writeFile(ts.combinePaths(getBase(), "test.json"), JSON.stringify(newLog, null, 4)); // tslint:disable-line:no-null-keyword + const syntheticTsconfig = generateTsconfig(newLog); + if (syntheticTsconfig) { + underlying.writeFile(ts.combinePaths(getBase(), "tsconfig.json"), JSON.stringify(syntheticTsconfig, null, 4)); // tslint:disable-line:no-null-keyword + } recordLog = undefined; } }; + function generateTsconfig(newLog: IOLog): undefined | { compilerOptions: ts.CompilerOptions, files: string[] } { + if (newLog.filesRead.some(file => /tsconfig.json$/.test(file.path))) { + return; + } + const files = []; + for (const file of newLog.filesRead) { + if (file.result.contentsPath && + !/lib\.d\.ts$/.test(file.result.contentsPath) && + /\.[tj]s$/.test(file.result.contentsPath)) { + files.push(file.result.contentsPath); + } + } + return { compilerOptions: ts.parseCommandLine(newLog.arguments).options, files }; + } + wrapper.fileExists = recordReplay(wrapper.fileExists, underlying)( path => callAndRecord(underlying.fileExists(path), recordLog.fileExists, { path }), memoize(path => { diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 9e17aa84b0c..2b4fc7b24e4 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -70,11 +70,10 @@ namespace RWC { opts.options.noEmitOnError = false; }); - let tsconfigFile: IOLogFile; runWithIOLog(ioLog, oldIO => { let fileNames = opts.fileNames; - tsconfigFile = ts.forEach(ioLog.filesRead, f => isTsConfigFile(f) ? f : undefined); + const tsconfigFile = ts.forEach(ioLog.filesRead, f => isTsConfigFile(f) ? f : undefined); if (tsconfigFile) { const tsconfigFileContents = getHarnessCompilerInputUnit(tsconfigFile.path); tsconfigFiles.push({ unitName: tsconfigFile.path, content: tsconfigFileContents.content }); @@ -156,11 +155,6 @@ namespace RWC { compilerResult = output.result; }); - if (!tsconfigFile) { - const files = inputFiles.map(f => Playback.sanitizeTestFilePath(f.unitName)); - Harness.IO.writeFile(`internal/cases/rwc/${baseName}/read/tsconfig.json`, JSON.stringify({ compilerOptions, files })); - } - function getHarnessCompilerInputUnit(fileName: string): Harness.Compiler.TestFile { const unitName = ts.normalizeSlashes(Harness.IO.resolvePath(fileName)); let content: string;