Skip to content

Commit f04af77

Browse files
authoredMar 10, 2020
Cleanup build-html (#22034)
* Cleanup build-html * Update build-html.ts * Cleanup even more
1 parent ac63886 commit f04af77

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed
 

‎packages/gatsby/src/commands/build-html.ts

+17-23
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import Bluebird from "bluebird"
2-
import webpack from "webpack"
32
import fs from "fs-extra"
4-
// import convertHrtime from "convert-hrtime"
5-
import { chunk } from "lodash"
6-
import webpackConfig from "../utils/webpack.config"
73
import reporter from "gatsby-cli/lib/reporter"
84
import { createErrorFromString } from "gatsby-cli/lib/reporter/errors"
95
import telemetry from "gatsby-telemetry"
6+
import { chunk } from "lodash"
7+
import webpack from "webpack"
8+
9+
import webpackConfig from "../utils/webpack.config"
10+
import { structureWebpackErrors } from "../utils/webpack-error-utils"
11+
1012
import { BuildHTMLStage, IProgram } from "./types"
1113

1214
type IActivity = any // TODO
1315
type IWorkerPool = any // TODO
1416

15-
import { structureWebpackErrors } from "../utils/webpack-error-utils"
16-
1717
const runWebpack = (compilerConfig): Bluebird<webpack.Stats> =>
1818
new Bluebird((resolve, reject) => {
1919
webpack(compilerConfig).run((err, stats) => {
@@ -26,19 +26,18 @@ const runWebpack = (compilerConfig): Bluebird<webpack.Stats> =>
2626
})
2727

2828
const doBuildRenderer = async (
29-
program: IProgram,
29+
{ directory }: IProgram,
3030
webpackConfig: webpack.Configuration
3131
): Promise<string> => {
32-
const { directory } = program
3332
const stats = await runWebpack(webpackConfig)
34-
// render-page.js is hard coded in webpack.config
35-
const outputFile = `${directory}/public/render-page.js`
3633
if (stats.hasErrors()) {
3734
reporter.panic(
3835
structureWebpackErrors(`build-html`, stats.compilation.errors)
3936
)
4037
}
41-
return outputFile
38+
39+
// render-page.js is hard coded in webpack.config
40+
return `${directory}/public/render-page.js`
4241
}
4342

4443
const buildRenderer = async (
@@ -50,7 +49,8 @@ const buildRenderer = async (
5049
const config = await webpackConfig(program, directory, stage, null, {
5150
parentSpan,
5251
})
53-
return await doBuildRenderer(program, config)
52+
53+
return doBuildRenderer(program, config)
5454
}
5555

5656
const deleteRenderer = async (rendererPath: string): Promise<void> => {
@@ -78,22 +78,16 @@ const renderHTMLQueue = async (
7878

7979
// const start = process.hrtime()
8080
const segments = chunk(pages, 50)
81-
// let finished = 0
8281

8382
await Bluebird.map(segments, async pageSegment => {
8483
await workerPool.renderHTML({
84+
envVars,
8585
htmlComponentRendererPath,
8686
paths: pageSegment,
87-
envVars,
8887
})
89-
// finished += pageSegment.length
88+
9089
if (activity && activity.tick) {
9190
activity.tick(pageSegment.length)
92-
// activity.setStatus(
93-
// `${finished}/${pages.length} ${(
94-
// finished / convertHrtime(process.hrtime(start)).seconds
95-
// ).toFixed(2)} pages/second`
96-
// )
9791
}
9892
})
9993
}
@@ -110,12 +104,12 @@ const doBuildPages = async (
110104

111105
try {
112106
await renderHTMLQueue(workerPool, activity, rendererPath, pagePaths)
113-
} catch (e) {
107+
} catch (error) {
114108
const prettyError = await createErrorFromString(
115-
e.stack,
109+
error.stack,
116110
`${rendererPath}.map`
117111
)
118-
prettyError.context = e.context
112+
prettyError.context = error.context
119113
throw prettyError
120114
}
121115
}

0 commit comments

Comments
 (0)
Please sign in to comment.