Configuration
After your first check, add the policies your repository needs and configure their options.
repopo reads its configuration from repopo.config.ts, repopo.config.mjs, or repopo.config.cjs at the repository root. Use a TypeScript file for type checking. Its default export is a RepopoConfig:
import { makePolicy, type RepopoConfig } from "repopo";import { NoJsFileExtensions, PackageJsonProperties } from "repopo/policies";
export default { excludeFiles: ["^vendor/"], policies: [ makePolicy(NoJsFileExtensions, { exclude: ["^bin/"] }), makePolicy(PackageJsonProperties, { config: { verbatim: { license: "MIT" } }, }), ],} satisfies RepopoConfig;Choosing policies
Section titled “Choosing policies”If you omit policies, check and check-native run the default policies. Set policies: [] to run none. Other built-in policies run only when you add them.
With check --fix, the policies for each file run in configuration order, so one fix can’t overwrite another. Read-only checks process several files at once, but the policies for a single file still run in order.
Configuring a policy
Section titled “Configuring a policy”Configure each policy with makePolicy(definition, options). The options object is optional and has three properties:
| Option | Description |
|---|---|
config | The policy’s configuration. |
exclude | Patterns for files this policy instance skips. See Excluding files. |
instanceId | A stable ID for this instance. Required when the same policy appears more than once. |
makePolicy(PackageJsonSorted);makePolicy(NoJsFileExtensions, { exclude: ["^bin/"] });makePolicy(PackageJsonProperties, { config: { verbatim: { license: "MIT" } } });The options of each built-in policy are documented in Built-in policies.
Defaults and required configuration
Section titled “Defaults and required configuration”- When
configis omitted orundefined, the policy uses its default configuration, if it has one. - An explicit
configreplaces the whole default. repopo doesn’t merge it with the default. Individual fields you leave out still fall back to their documented per-field defaults. - An explicit
null, where a policy allows it, is passed to the policy as-is and doesn’t select the default. - Some policies have no usable default and require configuration, such as
PackageJsonProperties, the file header policies, and the script policies. Configuring one withoutconfigis an error that stops the check before any policy runs. The built-in policy table marks these policies.
A configuration field named exclude is part of the policy’s configuration. It doesn’t exclude files; only the exclude option does.
Using a policy more than once
Section titled “Using a policy more than once”A policy that appears once uses its name as its ID. To configure the same policy twice, for example with different settings for different parts of the repository, give each instance a unique instanceId:
makePolicy(PackageJsonProperties, { instanceId: "published-packages", config: { verbatim: { license: "MIT" } }, exclude: ["^examples/"],});makePolicy(PackageJsonProperties, { instanceId: "examples", config: { verbatim: { private: true } }, exclude: ["^packages/"],});IDs don’t depend on the order of the policies array.
Excluding files
Section titled “Excluding files”repopo checks every file Git knows about: tracked files and untracked files that are not ignored.
excludeFilesat the top level of the configuration removes matching files from all policies.excludein a policy’s options removes matching files from that policy instance only.
Both take an array of strings or RegExp values, matched against repo-relative paths:
- Strings are case-insensitive regular expressions, not globs. Use
"^vendor/", not"**/vendor/**". RegExpvalues keep their own flags./^README/is case-sensitive and does not excludereadme.md./^README/idoes.
An invalid regular expression stops the check before any policy runs.
export default { excludeFiles: ["^vendor/", /\.snap$/], policies: [ makePolicy(PackageJsonProperties, { config: { verbatim: { license: "MIT" } }, exclude: ["^examples/"], }), ],} satisfies RepopoConfig;Repository policies
Section titled “Repository policies”File policies run once per matching selected file. Policies with scope: "repository" run once after all file policies, even when no files are selected. Both kinds go in the same policies array and use the same makePolicy() function.
Repository policies receive the full Git file inventory after global and per-instance exclusions, even with --stdin. Exclusions filter that inventory, but the policy still runs when the filtered inventory is empty. With --fix, repository policies run one at a time in configuration order and can change files outside the stdin selection. The inventory is refreshed before each repository policy runs. These rules apply to both check and check-native.
The built-in repository policies are LicenseFileExists and SharedDependencyVersions. To write your own, see Repository policies.
Change context defaults
Section titled “Change context defaults”When a rule depends on Git changes, such as requiring a documentation update with a source change, configure change collection independently of file selection:
export default { changes: { mode: "pr", base: "main", }, policies: [ // Add a policy with scope: "changes" here. ],} satisfies RepopoConfig;changes.mode accepts pr, local, or staged. changes.base supplies the PR target when CI does not specify one; local and staged modes ignore this default. --change-base overrides both CI and configuration. See change modes and base resolution.
Global and per-policy exclusions filter selected files and repository inventory, including annotated and deleted entries. Use explicit trigger and companion regexes to scope a change-aware rule.
Repository and change definitions can also set one match regex to filter their inventory. It matches either rename endpoint and keeps the full record. This does not change the inventory seen by other policies or prevent a handler from running with no matching entries.