-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Only resolve symlinks in node_modules
#12020
Conversation
@dotnet-bot test this please |
I thought we were not going to resolve symlinks in resolveModuleNames at all, so what is the reason for the change of strategy? |
@@ -563,7 +563,8 @@ namespace ts { | |||
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName); | |||
} | |||
const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state, /*checkOneLevel*/ false); | |||
return resolved && { resolved, isExternalLibraryImport: true }; | |||
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files. | |||
return resolved && { resolved: resolvedWithRealpath(resolved, host, traceEnabled), isExternalLibraryImport: true }; | |||
} |
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.
you need to do the same for resolveTypeReferenceDirectives as well.
if (typeof commonSourceDirectory === "undefined") { | ||
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { | ||
if (commonSourceDirectory === undefined) { | ||
const emittedFiles = filterSourceFilesInDirectory(files, isSourceFileFromExternalLibrary); |
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.
don't think that changes in the way how common subpath is computed should not be the part of this PR since it is not related to original issue
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.
Review #11993, then I'll rebase.
Can/will this fix be included in the next release of TypeScript (2.0.10)? |
Yes it will be included in the next release; and the next release is TypeScript 2.1.3 (and not 2.0.10). |
@andy-ms whether did you remember why? Could you please try to remember the reason or what can happen if provide |
I think this was just the simplest place to do the resolving. |
@andy-ms Thank you for clarification!
What can happen in this case except getting multiple |
In that case it will be just like you had to separate files with no symlink. It could cause compile errors if the file contained a class with a private member, since a class instance coming from one file won't be assignable to the other file's class. E.g.: foo/index.d.ts: export class C { private x: number; } user.ts: import { C as C1 } from "foo";
import { C as C2 } from "other/foo";
const c: C1 = new C2(); // Error |
Oh, I get it. Thank you! |
Fixes #10364 and fixes #9552.
This is based on #11993 and will be rebased onto master once that is merged.
Based on the issues I've seen, the best heuristic to decide whether to resolve a symlink is whether it comes from
node_modules
. So we now do not resolve symlinks for ordinary files. (This is a breaking change.)The change to
moduleNameResolver
is simple. However, our test harness did not accurately reflect what the command line compiler really did, so I had to change how it treated symlinks. I've tested the new tests with the command line compiler as well; instructions for doing so are at the bottom of each test file.