@@ -75,7 +75,7 @@ describe('hookScript', () => {
7575 } ) ;
7676
7777 it . skipIf ( process . platform === 'win32' ) (
78- 'should add Vite+ managed bin to PATH before running user hook' ,
78+ 'should add Vite+ managed bin to PATH as a fallback before running user hook' ,
7979 ( ) => {
8080 const tmp = mkdtempSync ( join ( tmpdir ( ) , 'hooks-path-test-' ) ) ;
8181 try {
@@ -108,6 +108,16 @@ describe('hookScript', () => {
108108 '#!/bin/sh\necho "fake-node $*" > "$VP_HOME/node-used"\n' ,
109109 { mode : 0o755 } ,
110110 ) ;
111+ writeFileSync (
112+ join ( vpHomeBin , 'dirname' ) ,
113+ '#!/bin/sh\necho "wrong dirname" > "$VP_HOME/dirname-used"\nexit 1\n' ,
114+ { mode : 0o755 } ,
115+ ) ;
116+ writeFileSync (
117+ join ( vpHomeBin , 'sh' ) ,
118+ '#!/bin/sh\necho "wrong sh" > "$VP_HOME/sh-used"\nexit 1\n' ,
119+ { mode : 0o755 } ,
120+ ) ;
111121
112122 writeFileSync ( join ( systemBin , 'sh' ) , '#!/bin/sh\nexec /bin/sh "$@"\n' , {
113123 mode : 0o755 ,
@@ -129,9 +139,20 @@ describe('hookScript', () => {
129139 } ) ;
130140
131141 expect ( existsSync ( join ( tmp , 'vp-home' , 'node-used' ) ) ) . toBe ( true ) ;
142+ expect ( existsSync ( join ( tmp , 'vp-home' , 'dirname-used' ) ) ) . toBe ( false ) ;
143+ expect ( existsSync ( join ( tmp , 'vp-home' , 'sh-used' ) ) ) . toBe ( false ) ;
132144 } finally {
133145 rmSync ( tmp , { recursive : true , force : true } ) ;
134146 }
135147 } ,
136148 ) ;
149+
150+ it ( 'should compute root and shell before appending Vite+ managed bin' , ( ) => {
151+ const script = hookScript ( '.vite-hooks' ) ;
152+ expect ( script . indexOf ( 'd=' ) ) . toBeLessThan ( script . indexOf ( 'export PATH="$PATH:$__vp_bin"' ) ) ;
153+ expect ( script . indexOf ( '__vp_shell=' ) ) . toBeLessThan (
154+ script . indexOf ( 'export PATH="$PATH:$__vp_bin"' ) ,
155+ ) ;
156+ expect ( script ) . toContain ( '"$__vp_shell" -e "$s" "$@"' ) ;
157+ } ) ;
137158} ) ;
0 commit comments