Skip to content

moduleNameResolver: preserve originalPath of symlinked module on cache hit #26310

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

Closed

Conversation

ajafff
Copy link
Contributor

@ajafff ajafff commented Aug 8, 2018

@@ -1233,7 +1233,7 @@ namespace ts {
trace(host, Diagnostics.Resolution_for_module_0_was_found_in_cache_from_location_1, moduleName, containingDirectory);
}
failedLookupLocations.push(...result.failedLookupLocations);
return { value: result.resolvedModule && { path: result.resolvedModule.resolvedFileName, extension: result.resolvedModule.extension, packageId: result.resolvedModule.packageId } };
return { value: result.resolvedModule && { path: result.resolvedModule.originalPath || result.resolvedModule.resolvedFileName, extension: result.resolvedModule.extension, packageId: result.resolvedModule.packageId } };
Copy link
Member

Choose a reason for hiding this comment

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

I think instead of doing this we should also add another field originalPath to resolved so that we don't have to do original path calculation again for symlinks

Copy link
Member

@sheetalkamat sheetalkamat left a comment

Choose a reason for hiding this comment

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

We should pass in originalPath if it exists in resolved so we are not re-calculating it through disk access later when we already have it in cache

also add test for cached realpath result
@@ -29,6 +29,7 @@ namespace ts {
path: string;
extension: Extension;
packageId: PackageId | undefined;
originalPath: string | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Make this optional so you dont need to set it in withPackageId

let originalPath: string | undefined;
if (!compilerOptions.preserveSymlinks && resolvedValue) {
originalPath = resolvedValue.path;
if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm we need better way to identify that its from cache and no need to calculate originalPath since when its not symbollink and its coming from cache we shouldnt need to do realPath logic here. Considering this involves more changes than previously expected, do you mind if i take it over?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't mind you taking over.
I think this could easily be fixed by always setting originalPath to the original path regardless of the result of realpath. If originalPath is present it's from the cache, otherwise resolve the path using realpath

sheetalkamat added a commit that referenced this pull request Aug 10, 2018
sheetalkamat added a commit that referenced this pull request Aug 10, 2018
sheetalkamat added a commit that referenced this pull request Aug 10, 2018
@ajafff
Copy link
Contributor Author

ajafff commented Aug 11, 2018

Superseded by #26377

@ajafff ajafff closed this Aug 11, 2018
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.

2 participants