Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 7 additions & 15 deletions src/req.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ let { pathToFileURL } = require('node:url')

let TS_EXT_RE = /\.[mc]?ts$/

let tsx

let jiti
let tsx, jiti

let importError = []

Expand All @@ -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 */
}

Expand All @@ -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 */
}
Expand All @@ -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 */
}
Expand Down