Skip to content

Add "preserveSymlinks" option #16661

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
5 commits merged into from
Aug 11, 2017
Merged

Add "preserveSymlinks" option #16661

5 commits merged into from
Aug 11, 2017

Conversation

ghost
Copy link

@ghost ghost commented Jun 20, 2017

Fixes #14760

If this option is turned on, we will not resolve symlinks for imports from node_modules. (We already don't resolve them outside.)

  • Name chosen to be like node. We could also go with --resolveSymlinks false to be like webpack.
  • Are there alternatives to a new option? None that I can see, because node itself uses an option to change the default behavior too.
  • If accepted, we should document this in the handbook.

@ghost ghost requested a review from aozgaa June 20, 2017 21:55
@ghost ghost force-pushed the preserveSymlinks branch from 6f7be21 to b7d8d41 Compare June 20, 2017 22:02
@ghost ghost force-pushed the preserveSymlinks branch from b7d8d41 to 89b198f Compare June 20, 2017 22:12

// @filename: /linked/index.d.ts
// @symlink: /app/node_modules/linked/index.d.ts,/app/node_modules/linked2/index.d.ts
export { real } from "real";
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to write a unit test (possible replacing this)? We seem to test similar behavior in src/harness/unittests/moduleResolution.ts

Copy link
Author

Choose a reason for hiding this comment

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

Added a test to moduleResolution.ts. I think the compiler test is valuable though, since it covers some assumptions we have about the effects of resolving / not resolving symlinks.

@@ -39,6 +39,7 @@
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
Copy link
Contributor

Choose a reason for hiding this comment

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

my eyes!

@@ -188,7 +188,10 @@ namespace ts {

let resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined;
if (resolved) {
resolved = realpath(resolved, host, traceEnabled);
if (!options.preserveSymlinks) {
resolved = realpath(resolved, host, traceEnabled);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a doc-comment describing what ModuleResolutionHost.realpath (called by realpath) is supposed to do? It's not obvious to me from the name that it is supposed to resolve symbolic links.

Copy link
Member

Choose a reason for hiding this comment

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

realpath is declared optional but oyu never check for its functionality. tsc should check if the current host supports realpath, and we should probably be resilient or throw if realpath isn't available.

Also, I think that realpath should be camelCase to be consistent with the rest of the APIs.

Copy link
Author

Choose a reason for hiding this comment

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

The first action taken by realpath here is to test if (!host.realpath) return path;
I can change the name of the local function but wouldn't changing the name of the host method break existing hosts?

@ghost ghost force-pushed the preserveSymlinks branch from b7bd493 to 06b655d Compare June 23, 2017 18:37
@ghost ghost merged commit f64b8ad into master Aug 11, 2017
@ghost ghost deleted the preserveSymlinks branch August 11, 2017 17:03
@wclr
Copy link

wclr commented Aug 12, 2017

cool

This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search symlinks dependency relative to symlink location
4 participants