Skip to content

For import fix, prefer symlink over a real path#20395

Merged
5 commits merged into
masterfrom
importNameCodeFix_symlink
Dec 6, 2017
Merged

For import fix, prefer symlink over a real path#20395
5 commits merged into
masterfrom
importNameCodeFix_symlink

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Dec 1, 2017

Fixes #19893
Replaces #19910

@ghost ghost requested a review from sheetalkamat December 1, 2017 17:18
@ghost ghost force-pushed the importNameCodeFix_symlink branch from 9206617 to 751ad7b Compare December 1, 2017 20:59
@ghost ghost force-pushed the importNameCodeFix_symlink branch from 751ad7b to 52322bd Compare December 1, 2017 21:03
Comment thread src/compiler/types.ts Outdated
*/
export interface ResolvedModuleFull extends ResolvedModule {
/* @internal */
readonly originalPath: string | undefined;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you would want to add check for originalPath in moduleResolutionIsEqualTo as well

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is originalPath not just optional? Also why is it in ResolvedModuleFull and not in ResolvedModule?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The only reason we have both ResolvedModule and ResolvedModuleFull is backwards compatibility. Since this is an internal property it doesn't really matter where it goes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is it then string|undefined.. Looking at the changes it seems like it could be made optional instead to avoid setting it to undefined in all the other cases except 1

Comment thread src/compiler/types.ts Outdated
*/
export interface ResolvedModuleFull extends ResolvedModule {
/* @internal */
readonly originalPath: string | undefined;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is originalPath not just optional? Also why is it in ResolvedModuleFull and not in ResolvedModule?

Comment thread src/services/codefixes/importFixes.ts Outdated
const { baseUrl, paths, rootDirs } = options;
const choicesForEachExportingModule = mapIterator(arrayIterator(moduleSymbols), moduleSymbol => {
const moduleFileName = moduleSymbol.valueDeclaration.getSourceFile().fileName;
const moduleFileName = getOriginalModulePath(program, moduleSymbol.valueDeclaration.getSourceFile());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also this doesnt seem right... If the sourceFile2(from firstDefined call from getOriginalModulePath) which included this moduleSymbol is in different folder than the sourceFile this fix is asked for it might not be correct right? The sourceFile could refer to the symlinked location through some other node_modules symlink... (in the sense orignalFilePath for referencing this moduleSymbol could be different while resolving through sourceFile and sourceFile2?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's possible that there are multiple symlinks to the same module, although it's not technically wrong to use one or the other since it works either way; we could iterate over all known symlinks though and take the best, would that be better?

@ghost ghost force-pushed the importNameCodeFix_symlink branch from cf7ac60 to 0659892 Compare December 1, 2017 22:42
@ghost ghost force-pushed the importNameCodeFix_symlink branch from 5e3d176 to 095cdb9 Compare December 4, 2017 22:35
Comment thread src/compiler/moduleNameResolver.ts Outdated
const resolved = nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true);
// Treat explicit "node_modules" import as an external library import.
return resolved && toSearchResult({ resolved, isExternalLibraryImport: contains(parts, "node_modules") });
return resolved && toSearchResult({ resolved, originalPath: undefined, isExternalLibraryImport: contains(parts, "node_modules") });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do not set originalPath property

@ghost
Copy link
Copy Markdown
Author

ghost commented Dec 5, 2017

@sheetalkamat Good to go?

@ghost ghost merged commit 18a7c3f into master Dec 6, 2017
@ghost ghost deleted the importNameCodeFix_symlink branch December 6, 2017 19:27
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
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.

1 participant