Skip to content

Commit c267e06

Browse files
committed
docs: update vp config RFC for postinstall and staged config changes
Update all sections to reflect that vp config now recognizes both prepare and postinstall lifecycle events, and skips the interactive prompt when staged config already exists in vite.config.ts.
1 parent 10ea5fa commit c267e06

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

rfcs/config-and-staged-commands.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Summary
44

5-
Add `vp config` and `vp staged` as built-in commands. `vp config` is a `prepare`-lifecycle command that installs git hook shims (husky-compatible reimplementation, not a bundled dependency). `vp staged` bundles lint-staged and reads config from the `staged` key in `vite.config.ts`. Projects get a zero-config pre-commit hook that runs `vp check --fix` on staged files — no extra devDependencies needed.
5+
Add `vp config` and `vp staged` as built-in commands. `vp config` is a lifecycle command (`prepare` or `postinstall`) that installs git hook shims (husky-compatible reimplementation, not a bundled dependency). `vp staged` bundles lint-staged and reads config from the `staged` key in `vite.config.ts`. Projects get a zero-config pre-commit hook that runs `vp check --fix` on staged files — no extra devDependencies needed.
66

77
## Motivation
88

@@ -55,24 +55,27 @@ Flags: `--hooks` (force), `--no-hooks` (skip)
5555

5656
Flags: `--hooks` (force), `--no-hooks` (skip)
5757

58-
### Ongoing use: `vp config` (prepare lifecycle)
58+
### Ongoing use: `vp config` (lifecycle script)
5959

60-
`vp config` is the command that runs on every `npm install` via the `prepare` script. It reinstalls hook shims — it does **not** create the `staged` config or the pre-commit hook file. Those are created by `vp create`/`vp migrate`.
60+
`vp config` is the command that runs on every `npm install` via the `prepare` or `postinstall` script. It reinstalls hook shims — it does **not** create the `staged` config or the pre-commit hook file. Those are created by `vp create`/`vp migrate`.
6161

6262
```json
6363
{ "scripts": { "prepare": "vp config" } }
64+
// or
65+
{ "scripts": { "postinstall": "vp config" } }
6466
```
6567

66-
When `npm_lifecycle_event=prepare` (set by npm/pnpm/yarn during `npm install`), agent setup is skipped automatically — only hooks are reinstalled.
68+
When running from a lifecycle script (`npm_lifecycle_event` is `prepare` or `postinstall`), hooks are installed automatically without prompting.
6769

6870
### Manual setup (without `vp create`/`vp migrate`)
6971

7072
For users who want to set up hooks manually, four steps are required:
7173

72-
1. **Add prepare script** to `package.json`:
74+
1. **Add lifecycle script** to `package.json`:
7375
```json
7476
{ "scripts": { "prepare": "vp config" } }
7577
```
78+
Or use `postinstall` if `prepare` is not suitable for your project.
7679
2. **Add staged config** to `vite.config.ts`:
7780
```typescript
7881
export default defineConfig({
@@ -105,9 +108,10 @@ Behavior:
105108
6. Exits 0 and skips hooks if `VITE_GIT_HOOKS=0` or `HUSKY=0` environment variable is set (backwards compatible)
106109
7. Exits 0 and skips hooks if `.git` directory doesn't exist (safe during `npm install` in consumer projects)
107110
8. Exits 1 on real errors (git command not found, `git config` failed)
108-
9. Agent update runs uniformly in all modes (`prepare`, interactive, non-interactive). New agent file creation is handled by `vp create`/`vp migrate`.
109-
10. Interactive mode: prompts on first run for hooks setup
110-
11. Non-interactive mode: sets up hooks by default
111+
9. Agent update runs uniformly in all modes (lifecycle script, interactive, non-interactive). New agent file creation is handled by `vp create`/`vp migrate`.
112+
10. Lifecycle script mode (`prepare`/`postinstall`): sets up hooks automatically without prompting
113+
11. Interactive mode: prompts on first run — unless the project already has `staged` config in `vite.config.ts` (which implies prior opt-in)
114+
12. Non-interactive mode: sets up hooks by default
111115

112116
### `vp staged`
113117

@@ -275,12 +279,12 @@ Husky <9.0.0 is not supported by auto migration — `vp migrate` detects unsuppo
275279

276280
## Relationship to Existing Commands
277281

278-
| Command | Purpose | When |
279-
| ---------------- | -------------------------------------- | --------------------------- |
280-
| `vp check` | Format + lint + type check | Manual or CI |
281-
| `vp check --fix` | Auto-fix format + lint issues | Manual or pre-commit |
282-
| **`vp config`** | **Reinstall hook shims + agent setup** | **npm `prepare` lifecycle** |
283-
| **`vp staged`** | **Run staged linters on staged files** | **Pre-commit hook** |
282+
| Command | Purpose | When |
283+
| ---------------- | -------------------------------------- | ------------------------------------------- |
284+
| `vp check` | Format + lint + type check | Manual or CI |
285+
| `vp check --fix` | Auto-fix format + lint issues | Manual or pre-commit |
286+
| **`vp config`** | **Reinstall hook shims + agent setup** | **npm lifecycle (`prepare`/`postinstall`)** |
287+
| **`vp staged`** | **Run staged linters on staged files** | **Pre-commit hook** |
284288

285289
## `vp config` Hooks Setup Flow
286290

@@ -297,7 +301,7 @@ vp config
297301
│ • First run (hook shims don't exist yet)
298302
│ • No --hooks-dir flag
299303
│ • Not running from lifecycle script (prepare/postinstall)
300-
│ • No staged config in vite.config.ts ← NEW (#1154)
304+
│ • No staged config in vite.config.ts
301305
302306
│ YES → Prompt "Set up pre-commit hooks?"
303307
│ User declines → skip hooks
@@ -315,14 +319,14 @@ vp config
315319

316320
### When does the prompt appear?
317321

318-
| Caller | Prompts? | Why |
319-
| ------------------------------------- | -------- | ------------------------------------------------ |
320-
| `npm install` → prepare/postinstall | No | lifecycle script = auto-install |
321-
| Manual, project has `staged` config | No | staged config = already opted in **(#1154 fix)** |
322-
| Manual, no `staged` config, first run | **Yes** | No signal that project wants hooks |
323-
| Manual, already ran before | No | Hook shims exist = not first run |
324-
| CI / non-interactive | No | Non-interactive = auto-install |
325-
| `--hooks-dir` flag | No | Explicit flag = intent to install |
322+
| Caller | Prompts? | Why |
323+
| ------------------------------------- | -------- | ---------------------------------- |
324+
| `npm install` → prepare/postinstall | No | lifecycle script = auto-install |
325+
| Manual, project has `staged` config | No | staged config = already opted in |
326+
| Manual, no `staged` config, first run | **Yes** | No signal that project wants hooks |
327+
| Manual, already ran before | No | Hook shims exist = not first run |
328+
| CI / non-interactive | No | Non-interactive = auto-install |
329+
| `--hooks-dir` flag | No | Explicit flag = intent to install |
326330

327331
## Comparison with Other Tools
328332

0 commit comments

Comments
 (0)