From cb42086babf7020a826f3f2c6ad818e2888b812a Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 8 May 2018 17:07:54 -0700 Subject: [PATCH] Fix RWC tsconfig and lib paths (#23979) * Fix RWC tsconfig paths * Fix lints * move helper from utils into vpath --- src/harness/compiler.ts | 3 +- src/harness/rwcRunner.ts | 74 +++++++++++++++------------------------- src/harness/vpath.ts | 4 +++ 3 files changed, 32 insertions(+), 49 deletions(-) diff --git a/src/harness/compiler.ts b/src/harness/compiler.ts index 59d636303f..2900c8edbc 100644 --- a/src/harness/compiler.ts +++ b/src/harness/compiler.ts @@ -10,8 +10,7 @@ namespace compiler { export function readProject(host: fakes.ParseConfigHost, project: string | undefined, existingOptions?: ts.CompilerOptions): Project | undefined { if (project) { - project = host.vfs.stringComparer(vpath.basename(project), "tsconfig.json") === 0 ? project : - vpath.combine(project, "tsconfig.json"); + project = vpath.isTsConfigFile(project) ? project : vpath.combine(project, "tsconfig.json"); } else { [project] = host.vfs.scanSync(".", "ancestors-or-self", { diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index bfd0153466..cc1e546611 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -21,10 +21,6 @@ namespace RWC { } } - function isTsConfigFile(file: { path: string }): boolean { - return file.path.indexOf("tsconfig") !== -1 && file.path.indexOf("json") !== -1; - } - export function runRWCTest(jsonPath: string) { describe("Testing a rwc project: " + jsonPath, () => { let inputFiles: Harness.Compiler.TestFile[] = []; @@ -69,11 +65,10 @@ namespace RWC { // we will set noEmitOnError flag to be false. opts.options.noEmitOnError = false; }); + let fileNames = opts.fileNames; - runWithIOLog(ioLog, oldIO => { - let fileNames = opts.fileNames; - - const tsconfigFile = ts.forEach(ioLog.filesRead, f => isTsConfigFile(f) ? f : undefined); + runWithIOLog(ioLog, () => { + const tsconfigFile = ts.forEach(ioLog.filesRead, f => vpath.isTsConfigFile(f.path) ? f : undefined); if (tsconfigFile) { const tsconfigFileContents = getHarnessCompilerInputUnit(tsconfigFile.path); tsconfigFiles.push({ unitName: tsconfigFile.path, content: tsconfigFileContents.content }); @@ -103,55 +98,40 @@ namespace RWC { } // Add files to compilation - const isInInputList = (resolvedPath: string) => (inputFile: { unitName: string; content: string; }) => inputFile.unitName === resolvedPath; for (const fileRead of ioLog.filesRead) { - // Check if the file is already added into the set of input files. - const resolvedPath = ts.normalizeSlashes(Harness.IO.resolvePath(fileRead.path)); - const inInputList = ts.forEach(inputFiles, isInInputList(resolvedPath)); - - if (isTsConfigFile(fileRead)) { - continue; - } - - if (!Harness.isDefaultLibraryFile(fileRead.path)) { - if (inInputList) { - continue; - } + const normalized = ts.normalizeSlashes(fileRead.path); + if (!uniqueNames.has(normalized) && !Harness.isDefaultLibraryFile(fileRead.path)) { + uniqueNames.set(normalized, true); otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); } - else if (!opts.options.noLib && Harness.isDefaultLibraryFile(fileRead.path)) { - if (!inInputList) { - // If useCustomLibraryFile is true, we will use lib.d.ts from json object - // otherwise use the lib.d.ts from built/local - // Majority of RWC code will be using built/local/lib.d.ts instead of - // lib.d.ts inside json file. However, some RWC cases will still use - // their own version of lib.d.ts because they have customized lib.d.ts - if (useCustomLibraryFile) { - inputFiles.push(getHarnessCompilerInputUnit(fileRead.path)); - } - else { - // set the flag to put default library to the beginning of the list - inputFiles.unshift(Harness.getDefaultLibraryFile(fileRead.path, oldIO)); - } - } + else if (!opts.options.noLib && Harness.isDefaultLibraryFile(fileRead.path) && !uniqueNames.has(normalized) && useCustomLibraryFile) { + // If useCustomLibraryFile is true, we will use lib.d.ts from json object + // otherwise use the lib.d.ts from built/local + // Majority of RWC code will be using built/local/lib.d.ts instead of + // lib.d.ts inside json file. However, some RWC cases will still use + // their own version of lib.d.ts because they have customized lib.d.ts + uniqueNames.set(normalized, true); + inputFiles.push(getHarnessCompilerInputUnit(fileRead.path)); } } + }); + if (useCustomLibraryFile) { // do not use lib since we already read it in above opts.options.lib = undefined; opts.options.noLib = true; + } - // Emit the results - compilerResult = Harness.Compiler.compileFiles( - inputFiles, - otherFiles, - /* harnessOptions */ undefined, - opts.options, - // Since each RWC json file specifies its current directory in its json file, we need - // to pass this information in explicitly instead of acquiring it from the process. - currentDirectory); - compilerOptions = compilerResult.options; - }); + // Emit the results + compilerResult = Harness.Compiler.compileFiles( + inputFiles, + otherFiles, + /* harnessOptions */ undefined, + opts.options, + // Since each RWC json file specifies its current directory in its json file, we need + // to pass this information in explicitly instead of acquiring it from the process. + currentDirectory); + compilerOptions = compilerResult.options; function getHarnessCompilerInputUnit(fileName: string): Harness.Compiler.TestFile { const unitName = ts.normalizeSlashes(Harness.IO.resolvePath(fileName)); diff --git a/src/harness/vpath.ts b/src/harness/vpath.ts index 9b42ba2a28..31430b50e2 100644 --- a/src/harness/vpath.ts +++ b/src/harness/vpath.ts @@ -124,4 +124,8 @@ namespace vpath { return isDeclaration(path) && basename(path).startsWith("lib."); } + + export function isTsConfigFile(path: string): boolean { + return path.indexOf("tsconfig") !== -1 && path.indexOf("json") !== -1; + } } \ No newline at end of file