Skip to content

Commit

Permalink
fix: early exit when enableBuild is true (#61)
Browse files Browse the repository at this point in the history
* Fix early exit

* Throw error instead of process.exit

* Run async on build

* Go back to process.exit

* Add semi-colons
  • Loading branch information
fgblomqvist authored Jul 31, 2021
1 parent ba929c5 commit cc0912f
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/vite-plugin-checker/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ export default function Plugin(userConfig: UserPluginConfig): Plugin {
buildStart: () => {
// for build mode
// run a bin command in a separated process
if (viteMode !== 'build') return
if (viteMode !== 'build') return;

// do not do anything when disable build mode
if (!enableBuild) return
if (!enableBuild) return;

const localEnv = npmRunPath.env({
env: process.env,
cwd: process.cwd(),
execPath: process.execPath,
})

Promise.all(checkers.map((checker) => spawnChecker(checker, userConfig, localEnv))).then(
(exitCodes) => {
const exitCode = exitCodes.find((code) => code !== 0) || 0
process.exit(exitCode)
}
)
});

// spawn an async runner that we don't wait for in order to avoid blocking the build from continuing in parallel
(async () => {
const exitCodes = await Promise.all(checkers.map((checker) => spawnChecker(checker, userConfig, localEnv)));
const exitCode = exitCodes.find((code) => code !== 0) ?? 0;
if (exitCode !== 0) process.exit(exitCode);
})();
},
configureServer(server) {
// for dev mode (2/2)
Expand Down

0 comments on commit cc0912f

Please sign in to comment.