/** * 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 * ```typescript * const config: PackageEsmTypeConfig = { * // Require ESM type field for all packages * requiredType: "module", * // Or detect based on exports/main field * detectFromExports: true, * }; * ``` * * @alpha */ export interface PackageEsmTypeConfig { /** * 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 * * If set, this overrides automatic detection. Use `detectFromExports` * for more flexible per-package type detection. */ requiredType?: "module" | "commonjs"; /** * Detect the expected `type` field from the exports or main field. * * When enabled, the policy analyzes the package's entry points: * - If exports use `.mjs` or have `import` conditions → `"module"` * - If exports use `.cjs` or have `require` conditions → `"commonjs"` * - If main field uses `.mjs` → `"module"` * - If main field uses `.cjs` → `"commonjs"` * * @defaultValue false */ detectFromExports?: boolean; /** * Package names or scopes to exclude from validation. * * @example * ```typescript * excludePackages: ["@myorg/legacy-package", "old-cjs-lib"] * ``` */ excludePackages?: string[]; /** * 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. * * @defaultValue "skip" */ onDetectionFailure?: "skip" | "warn" | "fail"; } /** * 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. * * @remarks * * The policy can operate in two modes: * * 1. **Required Type**: Set `requiredType` to enforce a specific type for all packages * 2. **Detection**: Set `detectFromExports: true` to detect the expected type from * the package's exports or main field * * When `detectFromExports` is enabled, the policy looks for: * - `.mjs` extensions or `"import"` conditions → expects `"module"` * - `.cjs` extensions or `"require"` conditions → expects `"commonjs"` * * @example * ```typescript * import { makePolicy } from "repopo"; * import { PackageEsmType } from "repopo/policies"; * * // Require all packages to be ESM * makePolicy(PackageEsmType, { requiredType: "module" }) * * // Or detect based on exports * makePolicy(PackageEsmType, { detectFromExports: true }) * ``` * * @alpha */ export declare const PackageEsmType: import("../policy.js").PolicyShape; //# sourceMappingURL=PackageEsmType.d.ts.map