File tree Expand file tree Collapse file tree
command-config-auto-hooks
command-config-postinstall-auto-hooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import { defineConfig } from 'vite-plus';
1111
1212export default defineConfig({
1313 staged: {
14- "*": " vp check --fix"
14+ '*': ' vp check --fix',
1515 },
16-
1716});
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " command-config-postinstall-auto-hooks"
3+ }
Original file line number Diff line number Diff line change 1+ > git init
2+ > vp config # should install hooks automatically without prompting
3+ > git config --local core.hooksPath # should be .vite-hooks/_
4+ .vite-hooks/_
5+
6+ > cat .vite-hooks/pre-commit # should have vp staged
7+ vp staged
8+
9+ > cat vite.config.ts # should have staged config
10+ import { defineConfig } from 'vite-plus';
11+
12+ export default defineConfig({
13+ staged: {
14+ "*": "vp check --fix"
15+ },
16+
17+ });
Original file line number Diff line number Diff line change 1+ {
2+ "env" : {
3+ "npm_lifecycle_event" : " postinstall"
4+ },
5+ "commands" : [
6+ { "command" : " git init" , "ignoreOutput" : true },
7+ " vp config # should install hooks automatically without prompting" ,
8+ " git config --local core.hooksPath # should be .vite-hooks/_" ,
9+ " cat .vite-hooks/pre-commit # should have vp staged" ,
10+ " cat vite.config.ts # should have staged config"
11+ ]
12+ }
Original file line number Diff line number Diff line change @@ -54,7 +54,8 @@ async function main() {
5454 const dir = args [ 'hooks-dir' ] as string | undefined ;
5555 const hooksOnly = args [ 'hooks-only' ] as boolean ;
5656 const interactive = defaultInteractive ( ) ;
57- const isPrepareScript = process . env . npm_lifecycle_event === 'prepare' ;
57+ const lifecycleEvent = process . env . npm_lifecycle_event ;
58+ const isLifecycleScript = lifecycleEvent === 'prepare' || lifecycleEvent === 'postinstall' ;
5859 const root = process . cwd ( ) ;
5960
6061 // --- Step 1: Hooks setup ---
@@ -66,11 +67,11 @@ async function main() {
6667 interactive &&
6768 isFirstHooksRun &&
6869 ! dir &&
69- ! isPrepareScript &&
70+ ! isLifecycleScript &&
7071 ! hasStagedConfigInViteConfig ( root )
7172 ) {
7273 // --hooks-dir implies agreement; only prompt when using default dir on first run
73- // prepare script implies the project opted into hooks — install automatically
74+ // lifecycle script (prepare/postinstall) implies the project opted into hooks — install automatically
7475 // existing staged config in vite.config.ts implies the project already opted in
7576 shouldSetupHooks = await promptGitHooks ( { interactive } ) ;
7677 }
Original file line number Diff line number Diff line change @@ -296,7 +296,7 @@ vp config
296296│ • Interactive terminal (not CI, not piped)
297297│ • First run (hook shims don't exist yet)
298298│ • No --hooks-dir flag
299- │ • Not running from prepare lifecycle
299+ │ • Not running from lifecycle script (prepare/postinstall)
300300│ • No staged config in vite.config.ts ← NEW (#1154)
301301│
302302│ YES → Prompt "Set up pre-commit hooks?"
@@ -317,7 +317,7 @@ vp config
317317
318318| Caller | Prompts? | Why |
319319| ------------------------------------- | -------- | ------------------------------------------------ |
320- | ` npm install ` → prepare | No | prepare lifecycle = auto-install |
320+ | ` npm install ` → prepare/postinstall | No | lifecycle script = auto-install |
321321| Manual, project has ` staged ` config | No | staged config = already opted in ** (#1154 fix)** |
322322| Manual, no ` staged ` config, first run | ** Yes** | No signal that project wants hooks |
323323| Manual, already ran before | No | Hook shims exist = not first run |
You can’t perform that action at this time.
0 commit comments