Skip to content

tryFindNonRelativeModuleNameInCache should return originalPath if present #26273

Closed
@ajafff

Description

@ajafff

TypeScript Version: 3.1.0-dev.20180807

I'm investigating why createProgram doesn't reuse the program structure in my project.
I found out that this is caused by the moduleNameResolver cache.
When tryFindNonRelativeModuleNameInCache has a cache hit of a symlinked package in node_modules it returns result.resolvedModule.resolvedFileName. That means only the result of the first lookup has originalPath set and every subsequent lookup that hits the cache has originalPath: undefined.

To fix this you could simply replace https://github.com/Microsoft/TypeScript/blob/eaf0d59d354df27dd5915ec814859cdc6322e52a/src/compiler/moduleNameResolver.ts#L1236 with

return { value: result.resolvedModule && { path: result.resolvedModule.originalPath || result.resolvedModule.resolvedFileName, extension: result.resolvedModule.extension, packageId: result.resolvedModule.packageId } };

Though that will cause host.realpath to be called over and over again as the result is not cached.

Expected behavior:

Every lookup returns the same result with warm and cold cache.

Actual behavior:

Lookups with cold cache have a defined value in originalPath while warm cache causes it to be undefined.

Related Issues: #26271

Metadata

Metadata

Assignees

Labels

FixedA PR has been merged for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions