@@ -67,6 +67,7 @@ export function checker(userConfig: UserPluginConfig): Plugin {
6767 let viteMode : ConfigEnv [ 'command' ] | undefined
6868 let buildWatch = false
6969 let logger : Logger | null = null
70+ let checkerPromise : Promise < void > | null = null
7071
7172 return {
7273 name : 'vite-plugin-checker' ,
@@ -105,7 +106,11 @@ export function checker(userConfig: UserPluginConfig): Plugin {
105106 isProduction ||= config . isProduction || config . command === 'build'
106107 buildWatch = ! ! config . build . watch
107108 } ,
108- buildEnd ( ) {
109+ async buildEnd ( ) {
110+ if ( viteMode !== 'serve' ) {
111+ await checkerPromise
112+ }
113+
109114 if ( initialized ) return
110115
111116 if ( viteMode === 'serve' ) {
@@ -160,19 +165,18 @@ export function checker(userConfig: UserPluginConfig): Plugin {
160165 execPath : process . execPath ,
161166 } )
162167
163- // spawn an async runner that we don't wait for in order to avoid blocking the build from continuing in parallel
164- ; ( async ( ) => {
165- const exitCodes = await Promise . all (
166- checkers . map ( ( checker ) =>
167- spawnChecker ( checker , userConfig , localEnv ) ,
168- ) ,
169- )
168+ const spawnedCheckers = checkers . map ( ( checker ) =>
169+ spawnChecker ( checker , userConfig , localEnv ) ,
170+ )
171+
172+ // wait for checker states while avoiding blocking the build from continuing in parallel
173+ checkerPromise = Promise . all ( spawnedCheckers ) . then ( ( exitCodes ) => {
170174 const exitCode = exitCodes . find ( ( code ) => code !== 0 ) ?? 0
171175 // do not exit the process if run `vite build --watch`
172176 if ( exitCode !== 0 && ! buildWatch ) {
173177 process . exit ( exitCode )
174178 }
175- } ) ( )
179+ } )
176180 } ,
177181 configureServer ( server ) {
178182 if ( initialized ) return
0 commit comments