Auto-patching
Keep lazy locale loader wiring aligned with your locale JSON files and src/i18n/config.json after generate, sync, locales edit, or locales delete — without hand-editing the generated module whenever locales change.
When to use it
Use auto-patching if you adopt the loader_generated recipe: CLI-owned loaders.generated.ts plus config.json under src/i18n/ (typical layout). See Loader integration for ownership and Patching config for every field.
Enable patching
- Set
patching.enabled: trueini18nprune.config.*withrecipe,loaderPath, andconfigPathfilled in, or - Pass the global
--patchflag on a mutation command for that run only (it overridespatching.enabled: falsefor that process).
Flag placement: --patch is a global option — it goes before the subcommand:
bash
i18nprune --patch sync --yes --target fr
i18nprune --patch generate --yes --target frNot: (unsupported).i18nprune sync --patch
Operator workflow
- Run locale-changing commands with
--patchwhen you want loader files updated in the same run, or omit--patchand runi18nprune patchafterward to inspect state. - If
patchshows fixable metadata or config/file drift, runi18nprune patch --fix(add--yesin CI so writes are allowed). - If
config.json/loaders.generated.tsare missing or corrupt, runi18nprune patch --init. To replace only those two CLI-owned files and reset thepatchingblock in config, usei18nprune patch --init --force(destructive — read the CLI warnings first).
patch subcommand
| Command | What it does |
|---|---|
i18nprune patch | Analyze patching health and print diagnostics. |
i18nprune patch --fix | Apply supported auto-fixes (metadata, drift, safe regeneration). |
i18nprune patch --init | Create missing scaffold files under <src>/i18n/ and may inject a patching block into i18nprune.config.*. |
i18nprune patch --init --force | Renew only config.json and loaders.generated.ts and reset patching defaults in config; see loader.md § patch --init. |
In non-interactive runs, pair --fix / --init with the global --yes flag when the CLI would otherwise require confirmation.
Principles
- Opt-in: no loader or config mutation unless
patching.enabledor--patchapplies. - Recipe-driven:
loader_generatedis the supported recipe today. - Deterministic and bounded: edits stay within configured paths and size limits (config reference).
- Safe failure model: default
patching.mode: 'warn_skip'reports and skips;strictallows the hosting command to fail when patching preconditions are not met.
Runtime behavior
patchingmissing orenabled: false: patching is skipped unless--patchis set (per-command behavior is documented on each command).- Enabled with valid paths: a plan is built and applicable writes are applied.
- Invalid paths, parse/schema errors, oversized files, unsupported patterns: behavior depends on
patching.mode— see Failure and mode behavior.
Output and automation
--json: emits stable JSON envelopes on stdout where the command supports it. Human[i18nprune] [info]lines — including short “patching (sync)” / “patching (generate)” summaries after--patchmutations — are hidden under--json. Use envelopeissues[], payload fields, and exit codes for CI; omit--jsonwhen you need those log lines for debugging.--quiet/--silent: further reduce human output; with--json, machine output stays the contract. See CLI verbosity.
Documentation map
- Loader contract and generated-module behavior
- Patching config reference and policy
- Patching-related issue codes
- ADR 004 — Opt-in auto-patching
- ADR 003 — User-project i18n loader integration
Troubleshooting
generate/sync/localessays patching was skipped — Patching is opt-in: setpatching.enabled: trueor pass--patchbefore the subcommand. Ifpatchingexists butconfigPathorloaderPathis empty, the CLI warns and skips until you fix the block (often viapatch --init).patch --initwarns thati18nprune.config.*already has a patching block — Scaffold files may still be created, but an existingpatching:section is not silently overwritten. Edit paths, remove the block and re-run init, or usepatch --init --forcefor the renewal path (see the warning text).patch --fixreports no changes — Nothing auto-fixable may remain; runi18nprune patch(no flags) for diagnostics. Underpatching.mode: 'strict', invalid state can fail the command instead of warn-skip — see config reference.src/i18n/config.jsonis invalid JSON or wrong shape —patch --fixcannot repair it until the file parses. Usepatch --init --forceto replace onlyconfig.jsonandloaders.generated.tsfrom locale*.jsonfiles on disk plus catalog defaults (hand-edited locale row fields are not preserved by that renewal).generate/syncwith--patchwhileconfig.jsonis broken — Post-command patching uses the same engine aspatch; it skips until the file is valid or you runpatch --init --force.