-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Look for source of dts file only if dts is not from node_modules unless we have project references in node_modules #61739
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
Conversation
…ss we have project references in node_modules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
Copilot
AI
May 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
Copilot
AI
May 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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) { |
Copilot
AI
May 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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