From b2bc318c154de0858f0ec9850c97fafa4bb65786 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 28 Apr 2022 13:37:03 +0200 Subject: [PATCH] scripts/check-type-dependencies: more robust matching Signed-off-by: Patrik Oldsberg --- scripts/check-type-dependencies.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/check-type-dependencies.js b/scripts/check-type-dependencies.js index 4374e36ae6..ba362bd5ff 100755 --- a/scripts/check-type-dependencies.js +++ b/scripts/check-type-dependencies.js @@ -74,11 +74,13 @@ function shouldCheckTypes(pkg) { } function findAllDeps(declSrc) { - const importedDeps = (declSrc.match(/from '.*'/g) || []) - .map(match => match.replace(/from '(.*)'/, '$1')) + const importedDeps = (declSrc.match(/^import .* from '.*';$/gm) || []) + .map(match => match.match(/from '(.*)'/)[1]) .filter(n => !n.startsWith('.')); - const referencedDeps = (declSrc.match(/types=".*"/g) || []) - .map(match => match.replace(/types="(.*)"/, '$1')) + const referencedDeps = ( + declSrc.match(/^\/\/\/ $/gm) || [] + ) + .map(match => match.match(/types="(.*)"/)[1]) .filter(n => !n.startsWith('.')) // We allow references to these without an explicit dependency. .filter(n => !['node', 'react'].includes(n));