From 920ab1a112cacfb7069c81f32e53b286be5dde95 Mon Sep 17 00:00:00 2001 From: Nikita Barsukov Date: Wed, 13 Mar 2024 13:20:39 +0300 Subject: [PATCH] fix(schematics): improve utility `getNamedImportReferences` --- .../schematics/utils/get-named-import-references.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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(), + ) || [], + ), ); }