Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/gatsby/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -79,7 +78,7 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {
const buildSpan = buildActivity.span
buildSpan.setTag(`directory`, program.directory)

const { gatsbyNodeGraphQLFunction } = await bootstrap({
const { gatsbyNodeGraphQLFunction, workerPool } = await bootstrap({
program,
parentSpan: buildSpan,
})
Expand Down Expand Up @@ -137,8 +136,6 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {
buildActivityTimer.end()
}

const workerPool = WorkerPool.create()

const webpackCompilationHash = stats.hash
if (
webpackCompilationHash !== store.getState().webpackCompilationHash ||
Expand Down
91 changes: 51 additions & 40 deletions packages/gatsby/src/utils/worker/render-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down Expand Up @@ -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 }
)
}