Skip to content

Commit

Permalink
fix(isValidNodeImport): check type: module before other detections
Browse files Browse the repository at this point in the history
fix issue with `swiper`
  • Loading branch information
pi0 committed Sep 19, 2022
1 parent e22ead6 commit 8e866c3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ export async function isValidNodeImport (id: string, _opts: ValidNodeImportOptio
return false
}

const pkg = await readPackageJSON(resolvedPath).catch(() => null)
if (pkg?.type === 'module') { return true }

if (resolvedPath.match(/\.(\w+-)?esm?(-\w+)?\.js$/)) {
return false
}

const pkg = await readPackageJSON(resolvedPath).catch(() => null)
if (pkg?.type === 'module') { return true }

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

return hasCJSSyntax(code) || !hasESMSyntax(code)
Expand Down

0 comments on commit 8e866c3

Please sign in to comment.