Fix RWC tsconfig and lib paths (#23979)
* Fix RWC tsconfig paths * Fix lints * move helper from utils into vpath
This commit is contained in:
parent
1d7dc6aeb8
commit
cb42086bab
|
@ -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", {
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
||||
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,43 +98,29 @@ 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) {
|
||||
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
|
||||
if (useCustomLibraryFile) {
|
||||
uniqueNames.set(normalized, true);
|
||||
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
|
||||
opts.options.lib = undefined;
|
||||
opts.options.noLib = true;
|
||||
}
|
||||
|
||||
// Emit the results
|
||||
compilerResult = Harness.Compiler.compileFiles(
|
||||
|
@ -151,7 +132,6 @@ namespace RWC {
|
|||
// 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));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue