Skip to content

Commit

Permalink
fix: import detection improvements (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Oct 27, 2021
1 parent e2892a5 commit b99bf2c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { extname } from 'pathe'
import { readPackageJSON } from 'pkg-types'
import { ResolveOptions, resolvePath } from './resolve'

const ESM_RE = /([\s;]|^)(import[\s'"*{]|export\b|import\.meta\b)/m
const ESM_RE = /([\s;]|^)(import[\w,{}\s*]*from|import\s*['"*{]|export\b\s*([*{]|default|type)|import\.meta\b)/m

const BUILTIN_EXTENSIONS = new Set(['.mjs', '.cjs', '.node', '.wasm'])

Expand Down Expand Up @@ -48,5 +48,5 @@ export async function isValidNodeImport (id: string, opts: ResolveOptions & { co

const code = opts.code || await fsp.readFile(resolvedPath, 'utf-8').catch(() => null)

return !hasESMSyntax(code)
return hasCJSSyntax(code) || !hasESMSyntax(code)
}

0 comments on commit b99bf2c

Please sign in to comment.