Skip to content

Commit

Permalink
fix: properly stop esbuild service for parallel build calls
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 25, 2020
1 parent b805fbc commit 10cf610
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/node/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import hash_sum from 'hash-sum'
import { resolvePostcssOptions, isCSSRequest } from '../utils/cssUtils'
import { createBuildWasmPlugin } from './buildPluginWasm'
import { createBuildManifestPlugin } from './buildPluginManifest'
import { stopService } from '../esbuildService'

interface Build extends InputOptions {
input: InputOption
Expand Down Expand Up @@ -341,13 +342,31 @@ function prepareConfig(config: Partial<BuildConfig>): BuildConfig {
}
}

/**
* Track parallel build calls and only stop the esbuild service when all
* builds are done. (#1098)
*/
let parallelCallCounts = 0

/**
* Bundles the app for production.
* Returns a Promise containing the build result.
*/
export async function build(
options: Partial<BuildConfig>
): Promise<BuildResult[]> {
parallelCallCounts++
try {
return await doBuild(options)
} finally {
parallelCallCounts--
if (parallelCallCounts <= 0) {
await stopService()
}
}
}

async function doBuild(options: Partial<BuildConfig>): Promise<BuildResult[]> {
const builds: Build[] = []

const config = prepareConfig(options)
Expand Down

0 comments on commit 10cf610

Please sign in to comment.