Skip to content
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

Use symlinks when looking for module names for declaration emit #24874

Merged
merged 3 commits into from
Jun 12, 2018

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Jun 11, 2018

Including indirect ones (ie, where the directory is linked and the module's resolution came in as anormal resolution through the parent), which previously we would have ignored, even had we used getModuleSpecifiers.

Fixes #24829

cc @rbuckton for the changes to the compiler harness to support directory/arbitrary symlinks

@weswigham weswigham requested review from rbuckton, mhegazy, sheetalkamat and a user June 11, 2018 22:01

for (const line of lines) {
const testMetaData = optionRegex.exec(line);
if (testMetaData) {
const linkMetaData = linkRegex.exec(line);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why match this as both and option and a link? I would recommend moving the const testMetaData … line into the else branch.

@@ -1244,6 +1247,14 @@ namespace Harness {

const docs = inputFiles.concat(otherFiles).map(documents.TextDocument.fromTestFile);
const fs = vfs.createFromFileSystem(IO, !useCaseSensitiveFileNames, { documents: docs, cwd: currentDirectory });
if (symlinks) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If symlinks were a vfs.FileSet, you could just call fs.apply(symlinks).


for (const line of lines) {
const testMetaData = optionRegex.exec(line);
if (testMetaData) {
const linkMetaData = linkRegex.exec(line);
if (linkMetaData) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If symlinks was a vfs.FileSet, you could just do:

if (!symlinks) symlinks = {};
symlinks[linkMetaData[2].trim()] = new vfs.Symlink(linkMetaData[1].trim());

@weswigham
Copy link
Member Author

@rbuckton 👍 👎?

for (const path of paths) {
const resolved = links.get(path)!;
if (startsWith(target, resolved + "/")) {
const relative = getRelativePathFromFile(resolved + "/file.ts", target, getCanonicalFileName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would create a new a new getRelativePath that takes two folders.

}
const resolvedtarget = host.getCurrentDirectory ? resolvePath(host.getCurrentDirectory(), target) : target;
if (options) {
options.push(resolvedtarget); // Since these are speculative, we also include the original resolved name as a possibility
Copy link
Contributor

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?

Copy link
Member Author

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 though module/foo is possible.

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
@weswigham weswigham force-pushed the symlink-modulename-betterness branch from e44785d to d0c0d1c Compare June 12, 2018 18:19
@mhegazy
Copy link
Contributor

mhegazy commented Jun 12, 2018

merge conflicts

@weswigham weswigham merged commit 61fb222 into microsoft:master Jun 12, 2018
@raymondfeng
Copy link

@mhegazy Is the fix released with typescript@2.9.2? If so, the problem is getting even worse:

const CONTROLLER_CLASS: BindingKey<import("../../../../../../../../Users/rfeng/Projects/loopback4/loopback-next/packages/core/node_modules/@loopback/context/src/value-promise").Constructor<any>>;

Please note the relative path has two issues:

  • It's relative to the absolute root
  • It's not correctly resolved to a module dependency @loopback/context which exports the Constructor type.

@weswigham
Copy link
Member Author

weswigham commented Jun 13, 2018

Assuming all those leading ../'s climb out of the directories I think they do, it looks like the entire leading part of that path, ../../../../../../../../Users/rfeng/Projects/loopback4/loopback-next/packages/core/node_modules/, is totally extraneous...

@raymondfeng do you have any other path-related settings enabled for your build (outDir, sourceRoot, anything)? Are there any symlinks present other than loopback-next/packages/context being linked to loopback-next/packages/core/node_modules/@loopback/context?

@raymondfeng
Copy link

raymondfeng commented Jun 13, 2018

My repo is managed by lerna and the directory layout is illustrated below:

loopback-next
  > packages
    > build (npm module @loopback/build)
    > context (npm module @loopback/context)
    > core (npm module @loopback/core)
      > node_modules
        > @loopback
          > context -> ../../../context (symbolic link to the @loopback/context module)
          > build -> ../../../build (symbolic link to the @loopback/build module)
        ...

@weswigham
Copy link
Member Author

Right, and your TS build settings?

@raymondfeng
Copy link

raymondfeng commented Jun 13, 2018

The npm run build:current command for the project is basically running /Users/rfeng/Projects/loopback4/loopback-next/packages/build/node_modules/typescript/lib/tsc.js -p tsconfig.build.json --outDir /Users/rfeng/Projects/loopback4/loopback-next/packages/core/dist8 --target es2017.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants