From 41d51ba5657360c75898e694a307fbe60b180a97 Mon Sep 17 00:00:00 2001 From: Justin Hall Date: Wed, 5 Jun 2024 17:43:17 -0600 Subject: [PATCH] fix(eslint): fix package detection Fixes #5. --- eslint.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/eslint.js b/eslint.js index ec6bfb8..a3f6a37 100644 --- a/eslint.js +++ b/eslint.js @@ -7,17 +7,20 @@ import { const ERROR = 'error' const WARN = 'warn' -const has = pkg => - import(pkg).then( - () => true, - () => false, - ) +const has = pkg => { + try { + import.meta.resolve(pkg, import.meta.url) + return true + } catch { + return false + } +} -const hasTypeScript = await has('typescript') -const hasReact = await has('react') -const hasTestingLibrary = await has('@testing-library/dom') -const hasJestDom = await has('@testing-library/jest-dom') -const hasVitest = await has('vitest') +const hasTypeScript = has('typescript') +const hasReact = has('react') +const hasTestingLibrary = has('@testing-library/dom') +const hasJestDom = has('@testing-library/jest-dom') +const hasVitest = has('vitest') const vitestFiles = ['**/__tests__/**/*', '**/*.test.*'] const testFiles = ['**/tests/**', '**/#tests/**', ...vitestFiles] const playwrightFiles = ['**/e2e/**']