From dd8d9fbe55ad17db1ddb559928a881015fb805f6 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 22 Apr 2022 11:10:34 +0200 Subject: [PATCH] Revert "scripts/check-type-dependencies: always require referenced deps to exist" Signed-off-by: Patrik Oldsberg --- scripts/check-type-dependencies.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/scripts/check-type-dependencies.js b/scripts/check-type-dependencies.js index 9bf3eec9d0..4374e36ae6 100755 --- a/scripts/check-type-dependencies.js +++ b/scripts/check-type-dependencies.js @@ -73,20 +73,16 @@ function shouldCheckTypes(pkg) { ); } -function findImportedDeps(declSrc) { +function findAllDeps(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(referencedDeps)); + return Array.from(new Set([...importedDeps, ...referencedDeps])); } /** @@ -98,13 +94,12 @@ function checkTypes(pkg) { resolvePath(pkg.dir, 'dist/index.d.ts'), 'utf8', ); - const importedDeps = findImportedDeps(typeDecl); - const referencedDeps = findReferencedDeps(typeDecl); + const allDeps = findAllDeps(typeDecl); + const deps = Array.from(new Set(allDeps)); const errors = []; - // Referenced deps always need to exist - const typeDeps = [...referencedDeps]; - for (const dep of importedDeps) { + const typeDeps = []; + for (const dep of deps) { try { const typeDep = findTypesPackage(dep, pkg); if (typeDep) {