Fix RWC tsconfig and lib paths (#23979)

* Fix RWC tsconfig paths

* Fix lints

* move helper from utils into vpath
This commit is contained in:
Wesley Wigham 2018-05-08 17:07:54 -07:00 committed by GitHub
parent 1d7dc6aeb8
commit cb42086bab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 49 deletions

View file

@ -10,8 +10,7 @@ namespace compiler {
export function readProject(host: fakes.ParseConfigHost, project: string | undefined, existingOptions?: ts.CompilerOptions): Project | undefined { export function readProject(host: fakes.ParseConfigHost, project: string | undefined, existingOptions?: ts.CompilerOptions): Project | undefined {
if (project) { if (project) {
project = host.vfs.stringComparer(vpath.basename(project), "tsconfig.json") === 0 ? project : project = vpath.isTsConfigFile(project) ? project : vpath.combine(project, "tsconfig.json");
vpath.combine(project, "tsconfig.json");
} }
else { else {
[project] = host.vfs.scanSync(".", "ancestors-or-self", { [project] = host.vfs.scanSync(".", "ancestors-or-self", {

View file

@ -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) { export function runRWCTest(jsonPath: string) {
describe("Testing a rwc project: " + jsonPath, () => { describe("Testing a rwc project: " + jsonPath, () => {
let inputFiles: Harness.Compiler.TestFile[] = []; let inputFiles: Harness.Compiler.TestFile[] = [];
@ -69,11 +65,10 @@ namespace RWC {
// we will set noEmitOnError flag to be false. // we will set noEmitOnError flag to be false.
opts.options.noEmitOnError = false; opts.options.noEmitOnError = false;
}); });
let fileNames = opts.fileNames;
runWithIOLog(ioLog, oldIO => { runWithIOLog(ioLog, () => {
let fileNames = opts.fileNames; const tsconfigFile = ts.forEach(ioLog.filesRead, f => vpath.isTsConfigFile(f.path) ? f : undefined);
const tsconfigFile = ts.forEach(ioLog.filesRead, f => isTsConfigFile(f) ? f : undefined);
if (tsconfigFile) { if (tsconfigFile) {
const tsconfigFileContents = getHarnessCompilerInputUnit(tsconfigFile.path); const tsconfigFileContents = getHarnessCompilerInputUnit(tsconfigFile.path);
tsconfigFiles.push({ unitName: tsconfigFile.path, content: tsconfigFileContents.content }); tsconfigFiles.push({ unitName: tsconfigFile.path, content: tsconfigFileContents.content });
@ -103,55 +98,40 @@ namespace RWC {
} }
// Add files to compilation // Add files to compilation
const isInInputList = (resolvedPath: string) => (inputFile: { unitName: string; content: string; }) => inputFile.unitName === resolvedPath;
for (const fileRead of ioLog.filesRead) { for (const fileRead of ioLog.filesRead) {
// Check if the file is already added into the set of input files. const normalized = ts.normalizeSlashes(fileRead.path);
const resolvedPath = ts.normalizeSlashes(Harness.IO.resolvePath(fileRead.path)); if (!uniqueNames.has(normalized) && !Harness.isDefaultLibraryFile(fileRead.path)) {
const inInputList = ts.forEach(inputFiles, isInInputList(resolvedPath)); uniqueNames.set(normalized, true);
if (isTsConfigFile(fileRead)) {
continue;
}
if (!Harness.isDefaultLibraryFile(fileRead.path)) {
if (inInputList) {
continue;
}
otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); otherFiles.push(getHarnessCompilerInputUnit(fileRead.path));
} }
else if (!opts.options.noLib && Harness.isDefaultLibraryFile(fileRead.path)) { else if (!opts.options.noLib && Harness.isDefaultLibraryFile(fileRead.path) && !uniqueNames.has(normalized) && useCustomLibraryFile) {
if (!inInputList) { // If useCustomLibraryFile is true, we will use lib.d.ts from json object
// If useCustomLibraryFile is true, we will use lib.d.ts from json object // otherwise use the lib.d.ts from built/local
// otherwise use the lib.d.ts from built/local // Majority of RWC code will be using built/local/lib.d.ts instead of
// 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
// 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
// their own version of lib.d.ts because they have customized lib.d.ts uniqueNames.set(normalized, true);
if (useCustomLibraryFile) { inputFiles.push(getHarnessCompilerInputUnit(fileRead.path));
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));
}
}
} }
} }
});
if (useCustomLibraryFile) {
// do not use lib since we already read it in above // do not use lib since we already read it in above
opts.options.lib = undefined; opts.options.lib = undefined;
opts.options.noLib = true; opts.options.noLib = true;
}
// Emit the results // Emit the results
compilerResult = Harness.Compiler.compileFiles( compilerResult = Harness.Compiler.compileFiles(
inputFiles, inputFiles,
otherFiles, otherFiles,
/* harnessOptions */ undefined, /* harnessOptions */ undefined,
opts.options, opts.options,
// Since each RWC json file specifies its current directory in its json file, we need // 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. // to pass this information in explicitly instead of acquiring it from the process.
currentDirectory); currentDirectory);
compilerOptions = compilerResult.options; compilerOptions = compilerResult.options;
});
function getHarnessCompilerInputUnit(fileName: string): Harness.Compiler.TestFile { function getHarnessCompilerInputUnit(fileName: string): Harness.Compiler.TestFile {
const unitName = ts.normalizeSlashes(Harness.IO.resolvePath(fileName)); const unitName = ts.normalizeSlashes(Harness.IO.resolvePath(fileName));

View file

@ -124,4 +124,8 @@ namespace vpath {
return isDeclaration(path) return isDeclaration(path)
&& basename(path).startsWith("lib."); && basename(path).startsWith("lib.");
} }
export function isTsConfigFile(path: string): boolean {
return path.indexOf("tsconfig") !== -1 && path.indexOf("json") !== -1;
}
} }