PackageEsmTypeConfig
Defined in: policies/PackageEsmType.ts:28
Configuration for the PackageEsmType policy.
This policy ensures the type field in package.json is correctly set
to indicate whether the package is an ESM or CommonJS module.
Example
Section titled “Example”const config: PackageEsmTypeConfig = { // Require ESM type field for all packages requiredType: "module", // Or detect based on exports/main field detectFromExports: true,};Properties
Section titled “Properties”detectFromExports?
Section titled “detectFromExports?”
optionaldetectFromExports?:boolean
Defined in: policies/PackageEsmType.ts:54
Detect the expected type field from the exports or main field.
When enabled, the policy analyzes the package’s entry points:
- If exports use
.mjsor haveimportconditions →"module" - If exports use
.cjsor haverequireconditions →"commonjs" - If main field uses
.mjs→"module" - If main field uses
.cjs→"commonjs"
Default Value
Section titled “Default Value”falseexcludePackages?
Section titled “excludePackages?”
optionalexcludePackages?:string[]
Defined in: policies/PackageEsmType.ts:64
Package names or scopes to exclude from validation.
Example
Section titled “Example”excludePackages: ["@myorg/legacy-package", "old-cjs-lib"]onDetectionFailure?
Section titled “onDetectionFailure?”
optionalonDetectionFailure?:"warn"|"skip"|"fail"
Defined in: policies/PackageEsmType.ts:77
Behavior when module type cannot be detected from exports/main.
"skip"(default) - Skip validation for packages where type cannot be detected"warn"- Pass validation but include a warning in the output"fail"- Fail validation when type cannot be detected
This only applies when detectFromExports is true and no requiredType is set.
Default Value
Section titled “Default Value”"skip"requiredType?
Section titled “requiredType?”
optionalrequiredType?:"module"|"commonjs"
Defined in: policies/PackageEsmType.ts:41
The required type field value for all packages.
"module"- All packages must be ESM (use import/export)"commonjs"- All packages must be CommonJS (use require)undefined- Use detection logic based on exports/main
Remarks
Section titled “Remarks”If set, this overrides automatic detection. Use detectFromExports
for more flexible per-package type detection.