File tree Expand file tree Collapse file tree
snap-tests-global/command-config-prepare-auto-hooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22> vp config # should install hooks automatically without prompting
33> git config --local core.hooksPath # should be .vite-hooks/_
44.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 55 "commands" : [
66 { "command" : " git init" , "ignoreOutput" : true },
77 " vp config # should install hooks automatically without prompting" ,
8- " git config --local core.hooksPath # should be .vite-hooks/_"
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"
911 ]
1012}
Original file line number Diff line number Diff line change @@ -10,6 +10,11 @@ import { join } from 'node:path';
1010import mri from 'mri' ;
1111
1212import { vitePlusHeader } from '../../binding/index.js' ;
13+ import {
14+ createPreCommitHook ,
15+ hasStagedConfigInViteConfig ,
16+ mergeStagedConfigToViteConfig ,
17+ } from '../migration/migrator.js' ;
1318import { updateExistingAgentInstructions } from '../utils/agent.js' ;
1419import { renderCliDoc } from '../utils/help.js' ;
1520import { defaultInteractive , promptGitHooks } from '../utils/prompts.js' ;
@@ -75,6 +80,15 @@ async function main() {
7580 process . exit ( 1 ) ;
7681 }
7782 }
83+
84+ // Create pre-commit hook if missing, and ensure staged config exists
85+ const preCommitPath = join ( root , hooksDir , 'pre-commit' ) ;
86+ if ( ! existsSync ( preCommitPath ) ) {
87+ if ( ! hasStagedConfigInViteConfig ( root ) ) {
88+ mergeStagedConfigToViteConfig ( root , { '*' : 'vp check --fix' } , true ) ;
89+ }
90+ createPreCommitHook ( root , hooksDir ) ;
91+ }
7892 }
7993
8094 // --- Step 2: Update agent instructions if Vite+ header exists and is outdated ---
Original file line number Diff line number Diff line change @@ -1394,7 +1394,7 @@ function mergeAndRemoveJsonConfig(
13941394 * Merge a staged config object into vite.config.ts as `staged: { ... }`.
13951395 * Writes the config to a temp JSON file, calls mergeJsonConfig NAPI, then cleans up.
13961396 */
1397- function mergeStagedConfigToViteConfig (
1397+ export function mergeStagedConfigToViteConfig (
13981398 projectPath : string ,
13991399 stagedConfig : Record < string , string | string [ ] > ,
14001400 silent = false ,
@@ -1440,7 +1440,7 @@ function mergeStagedConfigToViteConfig(
14401440/**
14411441 * Check if vite.config.ts already has a `staged` config key.
14421442 */
1443- function hasStagedConfigInViteConfig ( projectPath : string ) : boolean {
1443+ export function hasStagedConfigInViteConfig ( projectPath : string ) : boolean {
14441444 const configs = detectConfigs ( projectPath ) ;
14451445 if ( ! configs . viteConfig ) {
14461446 return false ;
You can’t perform that action at this time.
0 commit comments