From 698b1f16f108d16d6d09993566906bb1792f44c6 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 7 Apr 2022 13:37:17 +0200 Subject: [PATCH] scripts/check-type-dependencies: update to also consider referenced declarations Signed-off-by: Patrik Oldsberg --- scripts/check-type-dependencies.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/check-type-dependencies.js b/scripts/check-type-dependencies.js index ae99e5d7f8..f773e91293 100755 --- a/scripts/check-type-dependencies.js +++ b/scripts/check-type-dependencies.js @@ -73,6 +73,16 @@ function shouldCheckTypes(pkg) { ); } +function findAllDeps(declSrc) { + const importedDeps = (declSrc.match(/from '.*'/g) || []) + .map(match => match.replace(/from '(.*)'/, '$1')) + .filter(n => !n.startsWith('.')); + const referencedDeps = (declSrc.match(/types=".*"/g) || []) + .map(match => match.replace(/types="(.*)"/, '$1')) + .filter(n => !n.startsWith('.')); + return Array.from(new Set([...importedDeps, ...referencedDeps])); +} + /** * Scan index.d.ts for imports and return errors for any dependency that's * missing or incorrect in package.json @@ -82,9 +92,7 @@ function checkTypes(pkg) { resolvePath(pkg.dir, 'dist/index.d.ts'), 'utf8', ); - const allDeps = (typeDecl.match(/from '.*'/g) || []) - .map(match => match.replace(/from '(.*)'/, '$1')) - .filter(n => !n.startsWith('.')); + const allDeps = findAllDeps(typeDecl); const deps = Array.from(new Set(allDeps)); const errors = [];