From 8ccf0af3ac56f026e01790097bc18d74c50a346d Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 26 Oct 2017 15:05:56 -0700 Subject: [PATCH] Add tsconfig.json for RWC projects that lack them. This should make all RWC projects browseable with an editor on Windows (except two, see below). On Linux it still works pretty well if you are willing to lowercase the imports of the file you're interested in. Many RWC projects already have tsconfig.json files, but this change creates one for projects that don't -- *after* running their respective RWC test. That's because all the information is most easily available at that time, and you probably won't need it until then anyway. Note that two RWC projects use relative paths in their list of stored files and don't work with this simple scheme. I'll look at that next, but if I can't figure it out in the next hour or two, I'd prefer to merge this since it's immediately useful for all the other projects. --- src/harness/loggedIO.ts | 2 +- src/harness/rwcRunner.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index fcc163e77f3..c5d428f3095 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 - function sanitizeTestFilePath(name: string) { + export 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); diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 2b4fc7b24e4..9e17aa84b0c 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -70,10 +70,11 @@ namespace RWC { opts.options.noEmitOnError = false; }); + let tsconfigFile: IOLogFile; runWithIOLog(ioLog, oldIO => { let fileNames = opts.fileNames; - const tsconfigFile = ts.forEach(ioLog.filesRead, f => isTsConfigFile(f) ? f : undefined); + 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 }); @@ -155,6 +156,11 @@ 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;