@@ -3,28 +3,28 @@ import { spawn } from 'child_process'
3
3
import pick from 'lodash.pick'
4
4
import npmRunPath from 'npm-run-path'
5
5
6
+ import type { ConfigEnv , Logger , Plugin } from 'vite'
6
7
import { Checker } from './Checker.js'
7
8
import {
8
- composePreambleCode ,
9
9
RUNTIME_CLIENT_ENTRY_PATH ,
10
10
RUNTIME_CLIENT_RUNTIME_PATH ,
11
+ WS_CHECKER_RECONNECT_EVENT ,
12
+ composePreambleCode ,
11
13
runtimeCode ,
12
14
wrapVirtualPrefix ,
13
- WS_CHECKER_RECONNECT_EVENT ,
14
15
} from './client/index.js'
15
16
import {
16
17
ACTION_TYPES ,
18
+ type Action ,
17
19
type BuildCheckBinStr ,
18
20
type BuildInCheckerNames ,
19
21
type ClientDiagnosticPayload ,
20
22
type ClientReconnectPayload ,
21
- type Action ,
22
23
type PluginConfig ,
23
24
type ServeAndBuildChecker ,
24
25
type SharedConfig ,
25
26
type UserPluginConfig ,
26
27
} from './types.js'
27
- import type { ConfigEnv , Plugin , Logger } from 'vite'
28
28
29
29
const sharedConfigKeys : ( keyof SharedConfig ) [ ] = [ 'enableBuild' , 'overlay' ]
30
30
const buildInCheckerKeys : BuildInCheckerNames [ ] = [
@@ -143,7 +143,7 @@ export function checker(userConfig: UserPluginConfig): Plugin {
143
143
} ,
144
144
]
145
145
} ,
146
- buildStart : ( ) => {
146
+ buildStart : async ( ) => {
147
147
if ( initialized ) return
148
148
// only run in build mode
149
149
// run a bin command in a separated process
@@ -155,17 +155,14 @@ export function checker(userConfig: UserPluginConfig): Plugin {
155
155
execPath : process . execPath ,
156
156
} )
157
157
158
- // spawn an async runner that we don't wait for in order to avoid blocking the build from continuing in parallel
159
- ; ( async ( ) => {
160
- const exitCodes = await Promise . all (
161
- checkers . map ( ( checker ) => spawnChecker ( checker , userConfig , localEnv ) )
162
- )
163
- const exitCode = exitCodes . find ( ( code ) => code !== 0 ) ?? 0
164
- // do not exit the process if run `vite build --watch`
165
- if ( exitCode !== 0 && ! buildWatch ) {
166
- process . exit ( exitCode )
167
- }
168
- } ) ( )
158
+ const exitCodes = await Promise . all (
159
+ checkers . map ( ( checker ) => spawnChecker ( checker , userConfig , localEnv ) )
160
+ )
161
+ const exitCode = exitCodes . find ( ( code ) => code !== 0 ) ?? 0
162
+ // do not exit the process if run `vite build --watch`
163
+ if ( exitCode !== 0 && ! buildWatch ) {
164
+ process . exit ( exitCode )
165
+ }
169
166
} ,
170
167
configureServer ( server ) {
171
168
if ( initialized ) return
0 commit comments