PackageEsmType
constPackageEsmType:FilePolicyDefinition<PackageEsmTypeConfig|undefined> &object
Defined in: policies/PackageEsmType.ts:371
A policy that ensures the type field in package.json is correctly set.
This policy helps maintain consistency in how packages declare their module format, which is essential for proper module resolution in Node.js and bundlers.
Type Declaration
Section titled “Type Declaration”requiresConfig
Section titled “requiresConfig”requiresConfig:
true
Remarks
Section titled “Remarks”The policy can operate in two modes:
- Required Type: Set
requiredTypeto enforce a specific type for all packages - Detection: Set
detectFromExports: trueto detect the expected type from the package’s exports or main field
When detectFromExports is enabled, the policy looks for:
.mjsextensions or"import"conditions → expects"module".cjsextensions or"require"conditions → expects"commonjs"
Example
Section titled “Example”import { makePolicy } from "repopo";import { PackageEsmType } from "repopo/policies";
// Require all packages to be ESMmakePolicy(PackageEsmType, { config: { requiredType: "module" } })
// Or detect based on exportsmakePolicy(PackageEsmType, { config: { detectFromExports: true } })