Skip to content

Commit

Permalink
Cleanup build-html (#22034)
Browse files Browse the repository at this point in the history
* Cleanup build-html

* Update build-html.ts

* Cleanup even more
  • Loading branch information
MichaelDeBoey committed Mar 10, 2020
1 parent ac63886 commit f04af77
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions packages/gatsby/src/commands/build-html.ts
Original file line number Diff line number Diff line change
@@ -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<webpack.Stats> =>
new Bluebird((resolve, reject) => {
webpack(compilerConfig).run((err, stats) => {
Expand All @@ -26,19 +26,18 @@ const runWebpack = (compilerConfig): Bluebird<webpack.Stats> =>
})

const doBuildRenderer = async (
program: IProgram,
{ directory }: IProgram,
webpackConfig: webpack.Configuration
): Promise<string> => {
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 (
Expand All @@ -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<void> => {
Expand Down Expand Up @@ -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`
// )
}
})
}
Expand All @@ -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
}
}
Expand Down

0 comments on commit f04af77

Please sign in to comment.