diff --git a/packages/gatsby/src/commands/build-html.ts b/packages/gatsby/src/commands/build-html.ts index a0b7c59fb6c75..5b6c592abb136 100644 --- a/packages/gatsby/src/commands/build-html.ts +++ b/packages/gatsby/src/commands/build-html.ts @@ -1,19 +1,19 @@ import Bluebird from "bluebird" -import webpack from "webpack" import fs from "fs-extra" -// import convertHrtime from "convert-hrtime" -import { chunk } from "lodash" -import webpackConfig from "../utils/webpack.config" import reporter from "gatsby-cli/lib/reporter" import { createErrorFromString } from "gatsby-cli/lib/reporter/errors" import telemetry from "gatsby-telemetry" +import { chunk } from "lodash" +import webpack from "webpack" + +import webpackConfig from "../utils/webpack.config" +import { structureWebpackErrors } from "../utils/webpack-error-utils" + import { BuildHTMLStage, IProgram } from "./types" type IActivity = any // TODO type IWorkerPool = any // TODO -import { structureWebpackErrors } from "../utils/webpack-error-utils" - const runWebpack = (compilerConfig): Bluebird => new Bluebird((resolve, reject) => { webpack(compilerConfig).run((err, stats) => { @@ -26,19 +26,18 @@ const runWebpack = (compilerConfig): Bluebird => }) const doBuildRenderer = async ( - program: IProgram, + { directory }: IProgram, webpackConfig: webpack.Configuration ): Promise => { - const { directory } = program const stats = await runWebpack(webpackConfig) - // render-page.js is hard coded in webpack.config - const outputFile = `${directory}/public/render-page.js` if (stats.hasErrors()) { reporter.panic( structureWebpackErrors(`build-html`, stats.compilation.errors) ) } - return outputFile + + // render-page.js is hard coded in webpack.config + return `${directory}/public/render-page.js` } const buildRenderer = async ( @@ -50,7 +49,8 @@ const buildRenderer = async ( const config = await webpackConfig(program, directory, stage, null, { parentSpan, }) - return await doBuildRenderer(program, config) + + return doBuildRenderer(program, config) } const deleteRenderer = async (rendererPath: string): Promise => { @@ -78,22 +78,16 @@ const renderHTMLQueue = async ( // const start = process.hrtime() const segments = chunk(pages, 50) - // let finished = 0 await Bluebird.map(segments, async pageSegment => { await workerPool.renderHTML({ + envVars, htmlComponentRendererPath, paths: pageSegment, - envVars, }) - // finished += pageSegment.length + if (activity && activity.tick) { activity.tick(pageSegment.length) - // activity.setStatus( - // `${finished}/${pages.length} ${( - // finished / convertHrtime(process.hrtime(start)).seconds - // ).toFixed(2)} pages/second` - // ) } }) } @@ -110,12 +104,12 @@ const doBuildPages = async ( try { await renderHTMLQueue(workerPool, activity, rendererPath, pagePaths) - } catch (e) { + } catch (error) { const prettyError = await createErrorFromString( - e.stack, + error.stack, `${rendererPath}.map` ) - prettyError.context = e.context + prettyError.context = error.context throw prettyError } }