scripts/check-type-dependencies: update to also consider referenced declarations

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-04-07 13:37:17 +02:00
parent 06bbaf96df
commit 698b1f16f1
+11 -3
View File
@@ -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 = [];