From fffa2500dbc174b4a368052c588013f501c924a3 Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Wed, 10 Dec 2025 17:54:06 +0700 Subject: [PATCH] refactor: reduce size --- src/plugins.js | 3 +-- src/req.js | 22 +++++++--------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/plugins.js b/src/plugins.js index 9e64d0b..02a1d76 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -15,8 +15,7 @@ let req = require('./req.js') async function load(plugin, options, file) { try { if ( - options === null || - options === undefined || + options == null || Object.keys(options).length === 0 ) { return await req(plugin, file) diff --git a/src/req.js b/src/req.js index b5ade3e..a2b6b67 100644 --- a/src/req.js +++ b/src/req.js @@ -4,9 +4,7 @@ let { pathToFileURL } = require('node:url') let TS_EXT_RE = /\.[mc]?ts$/ -let tsx - -let jiti +let tsx, jiti let importError = [] @@ -21,10 +19,8 @@ async function req(name, rootFile = __filename) { try { return (await import(`${pathToFileURL(url)}?t=${Date.now()}`)).default } catch (err) { - if (!TS_EXT_RE.test(url)) { - /* c8 ignore start */ - throw err - } + /* c8 ignore start */ + if (!TS_EXT_RE.test(url)) throw err /* c8 ignore stop */ } @@ -33,7 +29,7 @@ async function req(name, rootFile = __filename) { tsx = await import('tsx/cjs/api') } catch (error) { /* c8 ignore start */ - importError.push(error) + importError.push(error.message) } /* c8 ignore stop */ } @@ -48,18 +44,14 @@ async function req(name, rootFile = __filename) { try { jiti = (await import('jiti')).default } catch (error) { - importError.push(error) + importError.push(error.message) } } - if (jiti) { - return jiti(rootFile, { interopDefault: true })(name) - } + if (jiti) return jiti(rootFile, { interopDefault: true })(name) throw new Error( - `'tsx' or 'jiti' is required for the TypeScript configuration files. Make sure it is installed\nError: ${importError - .map(error => error.message) - .join('\n')}` + `'tsx' or 'jiti' is required for the TypeScript configuration files. Make sure it is installed\nError: ${importError.join('\n')}` ) /* c8 ignore stop */ }