Variants
A variant describes files and values that a package must contain.
import { defineConfig } from "monoswan";
export default defineConfig({ variants: { "my-library": { packageJson: { type: "module", scripts: { check: "tsc --noEmit" }, }, tsConfig: { compilerOptions: { strict: true }, }, tsConfigs: { "tsconfig.build.json": { compilerOptions: { declaration: true }, }, }, additionalJsonFiles: { ".example.json": { enabled: true }, }, additionalTextFiles: { ".node-version": "22\n", }, }, },});Validation behavior
Section titled “Validation behavior”- Objects are checked recursively. Extra keys are allowed.
- Arrays and primitive values must match exactly.
- Configured files must exist.
- Text files must match exactly, including whitespace and trailing newlines.
- JSON-backed files accept JSONC comments and trailing commas.
Dynamic variants
Section titled “Dynamic variants”Use a function when expected values depend on the package.
variants: { named: ({ packageName }) => ({ packageJson: { description: packageName != null ? `${packageName} package` : "My package description", }, }),}Composing variants
Section titled “Composing variants”Packages can select multiple variants. monoswan merges them in the listed order. JSON objects are deeply merged; for text files, the last defined value wins. Unknown variant names produce an INVALID_VARIANTS error.
Variant content is only checked when a rule does so. Add enforceVariants() to validate the fields shown above.
See the variant and file reference for field types, path resolution, missing and invalid files, and initialization behavior.
