feat: run prettier after npm updates so format bumps stay green #1

Merged
mars3142 merged 1 commits from feat/prettier-postupgrade into main 2026-07-28 18:39:19 +00:00
Owner

Problem

A Prettier version bump changes Prettier's canonical output. Files that were correctly formatted under the old version then fail prettier --check in CI — so the Renovate update PR goes red and never automerges.

Observed on mars3142/castaway right now: both open Renovate PRs (#30 devDependencies, #33 lockfile maintenance) bump prettier 3.8.3 → 3.9.6. The new Prettier reformats two pre-existing files:

File Change wanted by 3.9
src/lib/server/db/index.ts union type ShellReason collapsed from 6 lines to one
src/lib/components/ui/textarea/textarea.svelte {...restProps} pulled onto the closing-tag line

main is green (it runs 3.8.3), so the fix cannot live on main — 3.8.3 would then reject the 3.9 style. The reformat must travel with the bump, which is exactly what a post-upgrade task does.

Change

A single npm-scoped postUpgradeTasks:

{
  "matchManagers": ["npm"],
  "postUpgradeTasks": {
    "commands": ["npm run format --if-present"],
    "fileFilters": ["**/*"],
    "executionMode": "branch"
  }
}
  • --if-present → no-op in npm repos that have no format script (no failure).
  • matchManagers: ["npm"] → never fires in the gradle/maven (spring + kotlin) or firmware repos that share this preset.
  • executionMode: "branch" → runs once per branch after all upgrades, then commits the reformatted files.

⚠️ Second half is not in this repo

postUpgradeTasks only executes if the self-hosted Renovate instance whitelists the command. That is a global/self-hosted-only option and cannot be set from this preset:

RENOVATE_ALLOWED_COMMANDS=^npm run format

(or the equivalent allowedCommands in the bot's config.js). Without it, the task is silently skipped and the PRs stay red.

Effect on the two castaway PRs

Once the bot has allowedCommands, Renovate's Monday rebase of #30/#33 will run npm run format, commit the reformat, CI turns green, and both automerge — no manual push, so they stay Renovate-owned.

🤖 Generated with Claude Code

https://claude.ai/code/session_018dVH5RiPsudxH4wV74ucEs

## Problem A Prettier **version bump** changes Prettier's canonical output. Files that were correctly formatted under the old version then fail `prettier --check` in CI — so the Renovate update PR goes **red and never automerges**. Observed on `mars3142/castaway` right now: both open Renovate PRs (#30 devDependencies, #33 lockfile maintenance) bump prettier `3.8.3 → 3.9.6`. The new Prettier reformats two pre-existing files: | File | Change wanted by 3.9 | |---|---| | `src/lib/server/db/index.ts` | union type `ShellReason` collapsed from 6 lines to one | | `src/lib/components/ui/textarea/textarea.svelte` | `{...restProps}` pulled onto the closing-tag line | `main` is green (it runs 3.8.3), so the fix **cannot** live on `main` — 3.8.3 would then reject the 3.9 style. The reformat must travel *with* the bump, which is exactly what a post-upgrade task does. ## Change A single npm-scoped `postUpgradeTasks`: ```json { "matchManagers": ["npm"], "postUpgradeTasks": { "commands": ["npm run format --if-present"], "fileFilters": ["**/*"], "executionMode": "branch" } } ``` - **`--if-present`** → no-op in npm repos that have no `format` script (no failure). - **`matchManagers: ["npm"]`** → never fires in the gradle/maven (`spring + kotlin`) or firmware repos that share this preset. - **`executionMode: "branch"`** → runs once per branch after all upgrades, then commits the reformatted files. ## ⚠️ Second half is not in this repo `postUpgradeTasks` only executes if the **self-hosted** Renovate instance whitelists the command. That is a global/self-hosted-only option and **cannot** be set from this preset: ``` RENOVATE_ALLOWED_COMMANDS=^npm run format ``` (or the equivalent `allowedCommands` in the bot's `config.js`). Without it, the task is silently skipped and the PRs stay red. ## Effect on the two castaway PRs Once the bot has `allowedCommands`, Renovate's Monday rebase of #30/#33 will run `npm run format`, commit the reformat, CI turns green, and both automerge — no manual push, so they stay Renovate-owned. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018dVH5RiPsudxH4wV74ucEs
mars3142 added 1 commit 2026-07-25 00:00:04 +00:00
A prettier version bump changes prettier's canonical output, so files
that were correctly formatted under the old version now fail
`prettier --check` in CI — the update PR goes red and never automerges.
This happened on castaway with prettier 3.8.3 -> 3.9.6 (two files
reformatted: a union type collapsed to one line, a Svelte closing tag
pulled onto the attribute line).

Add a npm-scoped postUpgradeTasks that runs `npm run format` once per
branch after the upgrade and commits the result. `--if-present` makes it
a no-op in npm repos without a format script; matchManagers npm keeps it
away from the gradle/maven and firmware repos that share this preset.

Requires the self-hosted Renovate instance to whitelist the command via
allowedCommands (e.g. RENOVATE_ALLOWED_COMMANDS='^npm run format') — that
is a global/self-hosted-only option and cannot be set from this preset.

Signed-off-by: Peter Siegmund <peter.siegmund@entwicklung.eq-3.de>
mars3142 merged commit 200f660205 into main 2026-07-28 18:39:19 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mars3142/renovate-config#1