Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup build-html #22034

Merged
merged 3 commits into from
Mar 10, 2020
Merged
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
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