From 5d01571013e61fc45575874279201c3c9736746a Mon Sep 17 00:00:00 2001 From: soartec-lab Date: Sat, 6 Jan 2024 01:34:42 +0000 Subject: [PATCH] fix: strictly check dependencies import judgment using regular expressions --- packages/core/src/generators/imports.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/core/src/generators/imports.ts b/packages/core/src/generators/imports.ts index e5b4be0c7..9bb361ea4 100644 --- a/packages/core/src/generators/imports.ts +++ b/packages/core/src/generators/imports.ts @@ -181,9 +181,12 @@ export const addDependency = ({ hasSchemaDir: boolean; isAllowSyntheticDefaultImports: boolean; }) => { - const toAdds = exports.filter((e) => - implementation.includes(e.alias || e.name), - ); + const toAdds = exports.filter((e) => { + const searchWords = [e.alias, e.name].filter((p) => p?.length).join('|'); + const pattern = new RegExp(`\\b(${searchWords})\\b`, 'g'); + + return implementation.match(pattern); + }); if (!toAdds.length) { return undefined;