Skip to content

Commit 336d834

Browse files
committed
wait for status codes
1 parent ed9c093 commit 336d834

File tree

1 file changed

+13
-16
lines changed
  • packages/vite-plugin-checker/src

1 file changed

+13
-16
lines changed

packages/vite-plugin-checker/src/main.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ import { spawn } from 'child_process'
33
import pick from 'lodash.pick'
44
import npmRunPath from 'npm-run-path'
55

6+
import type { ConfigEnv, Logger, Plugin } from 'vite'
67
import { Checker } from './Checker.js'
78
import {
8-
composePreambleCode,
99
RUNTIME_CLIENT_ENTRY_PATH,
1010
RUNTIME_CLIENT_RUNTIME_PATH,
11+
WS_CHECKER_RECONNECT_EVENT,
12+
composePreambleCode,
1113
runtimeCode,
1214
wrapVirtualPrefix,
13-
WS_CHECKER_RECONNECT_EVENT,
1415
} from './client/index.js'
1516
import {
1617
ACTION_TYPES,
18+
type Action,
1719
type BuildCheckBinStr,
1820
type BuildInCheckerNames,
1921
type ClientDiagnosticPayload,
2022
type ClientReconnectPayload,
21-
type Action,
2223
type PluginConfig,
2324
type ServeAndBuildChecker,
2425
type SharedConfig,
2526
type UserPluginConfig,
2627
} from './types.js'
27-
import type { ConfigEnv, Plugin, Logger } from 'vite'
2828

2929
const sharedConfigKeys: (keyof SharedConfig)[] = ['enableBuild', 'overlay']
3030
const buildInCheckerKeys: BuildInCheckerNames[] = [
@@ -143,7 +143,7 @@ export function checker(userConfig: UserPluginConfig): Plugin {
143143
},
144144
]
145145
},
146-
buildStart: () => {
146+
buildStart: async () => {
147147
if (initialized) return
148148
// only run in build mode
149149
// run a bin command in a separated process
@@ -155,17 +155,14 @@ export function checker(userConfig: UserPluginConfig): Plugin {
155155
execPath: process.execPath,
156156
})
157157

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+
}
169166
},
170167
configureServer(server) {
171168
if (initialized) return

0 commit comments

Comments
 (0)