Look for source of dts file only if dts is not from node_modules unless we have project references in node_modules#61739
Look for source of dts file only if dts is not from node_modules unless we have project references in node_modules#61739sheetalkamat wants to merge 1 commit intomainfrom
Conversation
…ss we have project references in node_modules
There was a problem hiding this comment.
Pull Request Overview
This PR adjusts how .d.ts files in node_modules are handled by only resolving their source when at least one project reference from node_modules has been encountered.
- Introduces a
hasResolvedReferencencesInNodeModulesflag to gate lookups of.d.tssources innode_modules - Adds a guard in
getSourceOfProjectReferenceRedirectto skipnode_modulespaths until the flag is set - Sets the flag to
trueonce a project reference innode_modulesis actually redirected
Comments suppressed due to low confidence (1)
src/compiler/program.ts:3827
- Consider adding unit tests to verify that
.d.tssource resolution is skipped fornode_modulespaths until a project reference innode_modulesis encountered, and then allowed afterwards.
if (!hasResolvedReferencencesInNodeModules && pathContainsNodeModules(path)) return undefined;
| let projectReferenceRedirects: Map<Path, ResolvedProjectReference | false> | undefined; | ||
| let mapFromFileToProjectReferenceRedirects: Map<Path, Path> | undefined; | ||
| let mapFromToProjectReferenceRedirectSource: Map<Path, SourceOfProjectReferenceRedirect> | undefined; | ||
| let hasResolvedReferencencesInNodeModules = false; |
There was a problem hiding this comment.
There's a typo in the variable name hasResolvedReferencencesInNodeModules. Consider renaming it to hasResolvedReferencesInNodeModules for clarity and consistency.
| let hasResolvedReferencencesInNodeModules = false; | |
| let hasResolvedReferencesInNodeModules = false; |
| let projectReferenceRedirects: Map<Path, ResolvedProjectReference | false> | undefined; | ||
| let mapFromFileToProjectReferenceRedirects: Map<Path, Path> | undefined; | ||
| let mapFromToProjectReferenceRedirectSource: Map<Path, SourceOfProjectReferenceRedirect> | undefined; | ||
| let hasResolvedReferencencesInNodeModules = false; |
There was a problem hiding this comment.
[nitpick] This flag controls when to start resolving .d.ts sources from node_modules. Adding a brief comment above its declaration would improve maintainability and help future readers understand its purpose.
| let hasResolvedReferencencesInNodeModules = false; | |
| // Tracks whether `.d.ts` sources from `node_modules` have been resolved. | |
| let hasResolvedReferencencesInNodeModules = false; |
| function getSourceOfProjectReferenceRedirect(path: Path) { | ||
| if (!isDeclarationFileName(path)) return undefined; | ||
| if (!hasResolvedReferencencesInNodeModules && pathContainsNodeModules(path)) return undefined; | ||
| if (mapFromToProjectReferenceRedirectSource === undefined) { |
There was a problem hiding this comment.
[nitpick] The pathContainsNodeModules check appears in multiple places. Extracting it into a well-named helper (e.g., isInNodeModules(path)) could reduce duplication and improve readability.
| function getSourceOfProjectReferenceRedirect(path: Path) { | |
| if (!isDeclarationFileName(path)) return undefined; | |
| if (!hasResolvedReferencencesInNodeModules && pathContainsNodeModules(path)) return undefined; | |
| if (mapFromToProjectReferenceRedirectSource === undefined) { | |
| function isInNodeModules(path: Path): boolean { | |
| return pathContainsNodeModules(path); | |
| } | |
| function getSourceOfProjectReferenceRedirect(path: Path) { | |
| if (!isDeclarationFileName(path)) return undefined; | |
| if (!hasResolvedReferencencesInNodeModules && isInNodeModules(path)) return undefined; | |
| if (mapFromToProjectReferenceRedirectSource === undefined) { |
|
@typescript-bot pack this |
|
Hey @sheetalkamat, I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
Time to updategraph went from
276173.6424msto33199.64829999999ms