Skip to content

ESM / CJS syntax detection #11

@pi0

Description

@pi0

Provide utilities to use regex based static analyzes detecting if potentially ESM or CommonJS syntax is used in a code

  • hasESMSyntax(code: string, id?: string) (note: dynamic import is not esm syntax`
  • hasCJSSyntax(code: string, id?: string)
  • detectSyntax(code: string, id?: string): esm | cjs | mixed | unknown

Some reference: https://github.com/unjs/jiti/blob/main/src/utils.ts#L27

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions