-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Use symlinks when looking for module names for declaration emit #24874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
weswigham
merged 3 commits into
microsoft:master
from
weswigham:symlink-modulename-betterness
Jun 12, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
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 }; | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure i understand why we are adding the original name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we find a symlinked path that we know is correct, we make a choice to ignore the original path and not present is as an option. Since the file in this case wasn't imported directly via a symlink in the compilation already, in this case I think it's more appropriate to keep it around, that way you can still get, eg
./foo
as an option even thoughmodule/foo
is possible.