diff --git a/packages/gatsby/src/commands/build.ts b/packages/gatsby/src/commands/build.ts index 30ab3b6f370de..3d99a04f8b517 100644 --- a/packages/gatsby/src/commands/build.ts +++ b/packages/gatsby/src/commands/build.ts @@ -19,7 +19,6 @@ import db from "../db" import { store } from "../redux" import * as appDataUtil from "../utils/app-data" import { flush as flushPendingPageDataWrites } from "../utils/page-data" -import * as WorkerPool from "../utils/worker/pool" import { structureWebpackErrors, reportWebpackWarnings, @@ -79,7 +78,7 @@ module.exports = async function build(program: IBuildArgs): Promise { const buildSpan = buildActivity.span buildSpan.setTag(`directory`, program.directory) - const { gatsbyNodeGraphQLFunction } = await bootstrap({ + const { gatsbyNodeGraphQLFunction, workerPool } = await bootstrap({ program, parentSpan: buildSpan, }) @@ -137,8 +136,6 @@ module.exports = async function build(program: IBuildArgs): Promise { buildActivityTimer.end() } - const workerPool = WorkerPool.create() - const webpackCompilationHash = stats.hash if ( webpackCompilationHash !== store.getState().webpackCompilationHash || diff --git a/packages/gatsby/src/utils/worker/render-html.ts b/packages/gatsby/src/utils/worker/render-html.ts index 32521efe3f5ac..6ceb59f0af362 100644 --- a/packages/gatsby/src/utils/worker/render-html.ts +++ b/packages/gatsby/src/utils/worker/render-html.ts @@ -312,34 +312,38 @@ export const renderHTMLProd = async ({ } } - await Bluebird.map(paths, async pagePath => { - try { - const pageData = await readPageData(publicDir, pagePath) - const resourcesForTemplate = await getResourcesForTemplate(pageData) - - const { html, unsafeBuiltinsUsage } = htmlComponentRenderer.default({ - pagePath, - pageData, - ...resourcesForTemplate, - }) - - if (unsafeBuiltinsUsage.length > 0) { - unsafeBuiltinsUsageByPagePath[pagePath] = unsafeBuiltinsUsage - } - - return fs.outputFile(getPageHtmlFilePath(publicDir, pagePath), html) - } catch (e) { - if (e.unsafeBuiltinsUsage && e.unsafeBuiltinsUsage.length > 0) { - unsafeBuiltinsUsageByPagePath[pagePath] = e.unsafeBuiltinsUsage - } - // add some context to error so we can display more helpful message - e.context = { - path: pagePath, - unsafeBuiltinsUsageByPagePath, + await Bluebird.map( + paths, + async pagePath => { + try { + const pageData = await readPageData(publicDir, pagePath) + const resourcesForTemplate = await getResourcesForTemplate(pageData) + + const { html, unsafeBuiltinsUsage } = htmlComponentRenderer.default({ + pagePath, + pageData, + ...resourcesForTemplate, + }) + + if (unsafeBuiltinsUsage.length > 0) { + unsafeBuiltinsUsageByPagePath[pagePath] = unsafeBuiltinsUsage + } + + return fs.outputFile(getPageHtmlFilePath(publicDir, pagePath), html) + } catch (e) { + if (e.unsafeBuiltinsUsage && e.unsafeBuiltinsUsage.length > 0) { + unsafeBuiltinsUsageByPagePath[pagePath] = e.unsafeBuiltinsUsage + } + // add some context to error so we can display more helpful message + e.context = { + path: pagePath, + unsafeBuiltinsUsageByPagePath, + } + throw e } - throw e - } - }) + }, + { concurrency: 2 } + ) return { unsafeBuiltinsUsageByPagePath } } @@ -372,18 +376,25 @@ export const renderHTMLDev = async ({ lastSessionId = sessionId } - return Bluebird.map(paths, async pagePath => { - try { - const htmlString = htmlComponentRenderer.default({ - pagePath, - }) - return fs.outputFile(getPageHtmlFilePath(outputDir, pagePath), htmlString) - } catch (e) { - // add some context to error so we can display more helpful message - e.context = { - path: pagePath, + return Bluebird.map( + paths, + async pagePath => { + try { + const htmlString = htmlComponentRenderer.default({ + pagePath, + }) + return fs.outputFile( + getPageHtmlFilePath(outputDir, pagePath), + htmlString + ) + } catch (e) { + // add some context to error so we can display more helpful message + e.context = { + path: pagePath, + } + throw e } - throw e - } - }) + }, + { concurrency: 2 } + ) }