From af3117b856c6a4c31ceff393db62a8d338e89538 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 21 Apr 2022 12:14:33 +0200 Subject: [PATCH] scripts/check-type-dependencies: always require referenced deps to exist Signed-off-by: Patrik Oldsberg --- scripts/check-type-dependencies.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/check-type-dependencies.js b/scripts/check-type-dependencies.js index 4374e36ae6..9bf3eec9d0 100755 --- a/scripts/check-type-dependencies.js +++ b/scripts/check-type-dependencies.js @@ -73,16 +73,20 @@ function shouldCheckTypes(pkg) { ); } -function findAllDeps(declSrc) { +function findImportedDeps(declSrc) { const importedDeps = (declSrc.match(/from '.*'/g) || []) .map(match => match.replace(/from '(.*)'/, '$1')) .filter(n => !n.startsWith('.')); + return Array.from(new Set(importedDeps)); +} + +function findReferencedDeps(declSrc) { const referencedDeps = (declSrc.match(/types=".*"/g) || []) .map(match => match.replace(/types="(.*)"/, '$1')) .filter(n => !n.startsWith('.')) // We allow references to these without an explicit dependency. .filter(n => !['node', 'react'].includes(n)); - return Array.from(new Set([...importedDeps, ...referencedDeps])); + return Array.from(new Set(referencedDeps)); } /** @@ -94,12 +98,13 @@ function checkTypes(pkg) { resolvePath(pkg.dir, 'dist/index.d.ts'), 'utf8', ); - const allDeps = findAllDeps(typeDecl); - const deps = Array.from(new Set(allDeps)); + const importedDeps = findImportedDeps(typeDecl); + const referencedDeps = findReferencedDeps(typeDecl); const errors = []; - const typeDeps = []; - for (const dep of deps) { + // Referenced deps always need to exist + const typeDeps = [...referencedDeps]; + for (const dep of importedDeps) { try { const typeDep = findTypesPackage(dep, pkg); if (typeDep) {