diff --git a/projects/cdk/schematics/utils/get-named-import-references.ts b/projects/cdk/schematics/utils/get-named-import-references.ts index b3d9929d0a89..7a58729a72e8 100644 --- a/projects/cdk/schematics/utils/get-named-import-references.ts +++ b/projects/cdk/schematics/utils/get-named-import-references.ts @@ -21,6 +21,17 @@ export function getNamedImportReferences( ); return arrayFlat( - namedImports.map(specifier => specifier?.findReferencesAsNodes() || []), + namedImports.map( + specifier => + specifier?.findReferencesAsNodes().filter( + /** + * Otherwise, each `findReferencesAsNodes` will return references across THE WHOLE project. + * It will cause a lot of duplicates in the result and significantly slow down the process. + */ + ref => + ref.getSourceFile().getFilePath() === + specifier?.getSourceFile().getFilePath(), + ) || [], + ), ); }