Skip to content

Commit

Permalink
fix: use dynamic import => cjs only if native dynamic import is not p…
Browse files Browse the repository at this point in the history
…ossible
  • Loading branch information
pi0 committed Jan 20, 2021
1 parent a2a797d commit 5323175
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/jiti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ export default function createJITI (_filename: string = process.cwd(), opts: JIT
source = getCache(filename, source, () => opts.transform!({ source, filename, ts: true }))
} else {
// ESM ~> CJS
const esmSyntaxDetected = source.match(/^\s*import .* from/m) || source.match(/import\s*\(/) || source.match(/^\s*export /m)
const esmSyntaxDetected = source.match(/^\s*import .* from/m) ||
(!opts.dynamicImport && source.match(/import\s*\(/)) ||
source.match(/^\s*export /m)
if (esmSyntaxDetected) {
debug('[esm]', filename)
source = getCache(filename, source, () => opts.transform!({ source, filename }))
Expand Down

0 comments on commit 5323175

Please sign in to comment.