mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Use symlinks when looking for module names for declaration emit (#24874)
* fix symlink tag, support arbitrary (ie, directory) links via @link Introduce indirect symlink lookup to specifier deriver Use fileset, move exec vfs path resolution :shakes fist: Apply files symlink relative to dirname Use directory function * Accept really bad baseline updates
This commit is contained in:
1 parent
bcd6919e2c
commit
61fb222cd2
22 files changed
+1504
-1171
No files matched your search
+18
-4
@@ -1108,6 +1108,7 @@ namespace Harness {
|
||||
{ name: "noImplicitReferences", type: "boolean" },
|
||||
{ name: "currentDirectory", type: "string" },
|
||||
{ name: "symlink", type: "string" },
|
||||
{ name: "link", type: "string" },
|
||||
// Emitted js baseline will print full paths for every output file
|
||||
{ name: "fullEmitPaths", type: "boolean" }
|
||||
];
|
||||
@@ -1179,7 +1180,9 @@ namespace Harness {
|
||||
harnessSettings: TestCaseParser.CompilerSettings | undefined,
|
||||
compilerOptions: ts.CompilerOptions | undefined,
|
||||
// Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
|
||||
currentDirectory: string | undefined): compiler.CompilationResult {
|
||||
currentDirectory: string | undefined,
|
||||
symlinks?: vfs.FileSet
|
||||
): compiler.CompilationResult {
|
||||
const options: ts.CompilerOptions & HarnessOptions = compilerOptions ? ts.cloneCompilerOptions(compilerOptions) : { noResolve: false };
|
||||
options.target = options.target || ts.ScriptTarget.ES3;
|
||||
options.newLine = options.newLine || ts.NewLineKind.CarriageReturnLineFeed;
|
||||
@@ -1216,6 +1219,9 @@ namespace Harness {
|
||||
|
||||
const docs = inputFiles.concat(otherFiles).map(documents.TextDocument.fromTestFile);
|
||||
const fs = vfs.createFromFileSystem(IO, !useCaseSensitiveFileNames, { documents: docs, cwd: currentDirectory });
|
||||
if (symlinks) {
|
||||
fs.apply(symlinks);
|
||||
}
|
||||
const host = new fakes.CompilerHost(fs, options);
|
||||
return compiler.compileFiles(host, programFileNames, options);
|
||||
}
|
||||
@@ -1836,6 +1842,7 @@ namespace Harness {
|
||||
|
||||
// Regex for parsing options in the format "@Alpha: Value of any sort"
|
||||
const optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*([^\r\n]*)/gm; // multiple matches on multiple lines
|
||||
const linkRegex = /^[\/]{2}\s*@link\s*:\s*([^\r\n]*)\s*->\s*([^\r\n]*)/gm; // multiple matches on multiple lines
|
||||
|
||||
export function extractCompilerSettings(content: string): CompilerSettings {
|
||||
const opts: CompilerSettings = {};
|
||||
@@ -1855,6 +1862,7 @@ namespace Harness {
|
||||
testUnitData: TestUnitData[];
|
||||
tsConfig: ts.ParsedCommandLine | undefined;
|
||||
tsConfigFileUnitData: TestUnitData | undefined;
|
||||
symlinks?: vfs.FileSet;
|
||||
}
|
||||
|
||||
/** Given a test file containing // @FileName directives, return an array of named units of code to be added to an existing compiler instance */
|
||||
@@ -1869,10 +1877,16 @@ namespace Harness {
|
||||
let currentFileOptions: any = {};
|
||||
let currentFileName: any;
|
||||
let refs: string[] = [];
|
||||
let symlinks: vfs.FileSet | undefined;
|
||||
|
||||
for (const line of lines) {
|
||||
const testMetaData = optionRegex.exec(line);
|
||||
if (testMetaData) {
|
||||
let testMetaData: RegExpExecArray | null;
|
||||
const linkMetaData = linkRegex.exec(line);
|
||||
if (linkMetaData) {
|
||||
if (!symlinks) symlinks = {};
|
||||
symlinks[linkMetaData[2].trim()] = new vfs.Symlink(linkMetaData[1].trim());
|
||||
}
|
||||
else if (testMetaData = optionRegex.exec(line)) {
|
||||
// Comment line, check for global/file @options and record them
|
||||
optionRegex.lastIndex = 0;
|
||||
const metaDataName = testMetaData[1].toLowerCase();
|
||||
@@ -1961,7 +1975,7 @@ namespace Harness {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return { settings, testUnitData, tsConfig, tsConfigFileUnitData };
|
||||
return { settings, testUnitData, tsConfig, tsConfigFileUnitData, symlinks };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -911,7 +911,7 @@ namespace vfs {
|
||||
if (this.stringComparer(vpath.dirname(path), path) === 0) {
|
||||
throw new TypeError("Roots cannot be symbolic links.");
|
||||
}
|
||||
this.symlinkSync(entry.symlink, path);
|
||||
this.symlinkSync(vpath.resolve(dirname, entry.symlink), path);
|
||||
this._applyFileExtendedOptions(path, entry);
|
||||
}
|
||||
else if (entry instanceof Link) {
|
||||
@@ -1078,8 +1078,7 @@ namespace vfs {
|
||||
if (symlink) {
|
||||
for (const link of symlink.split(",").map(link => link.trim())) {
|
||||
fs.mkdirpSync(vpath.dirname(link));
|
||||
fs.symlinkSync(document.file, link);
|
||||
fs.filemeta(link).set("document", document);
|
||||
fs.symlinkSync(vpath.resolve(fs.cwd(), document.file), link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user