1
1
import Bluebird from "bluebird"
2
- import webpack from "webpack"
3
2
import fs from "fs-extra"
4
- // import convertHrtime from "convert-hrtime"
5
- import { chunk } from "lodash"
6
- import webpackConfig from "../utils/webpack.config"
7
3
import reporter from "gatsby-cli/lib/reporter"
8
4
import { createErrorFromString } from "gatsby-cli/lib/reporter/errors"
9
5
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
+
10
12
import { BuildHTMLStage , IProgram } from "./types"
11
13
12
14
type IActivity = any // TODO
13
15
type IWorkerPool = any // TODO
14
16
15
- import { structureWebpackErrors } from "../utils/webpack-error-utils"
16
-
17
17
const runWebpack = ( compilerConfig ) : Bluebird < webpack . Stats > =>
18
18
new Bluebird ( ( resolve , reject ) => {
19
19
webpack ( compilerConfig ) . run ( ( err , stats ) => {
@@ -26,19 +26,18 @@ const runWebpack = (compilerConfig): Bluebird<webpack.Stats> =>
26
26
} )
27
27
28
28
const doBuildRenderer = async (
29
- program : IProgram ,
29
+ { directory } : IProgram ,
30
30
webpackConfig : webpack . Configuration
31
31
) : Promise < string > => {
32
- const { directory } = program
33
32
const stats = await runWebpack ( webpackConfig )
34
- // render-page.js is hard coded in webpack.config
35
- const outputFile = `${ directory } /public/render-page.js`
36
33
if ( stats . hasErrors ( ) ) {
37
34
reporter . panic (
38
35
structureWebpackErrors ( `build-html` , stats . compilation . errors )
39
36
)
40
37
}
41
- return outputFile
38
+
39
+ // render-page.js is hard coded in webpack.config
40
+ return `${ directory } /public/render-page.js`
42
41
}
43
42
44
43
const buildRenderer = async (
@@ -50,7 +49,8 @@ const buildRenderer = async (
50
49
const config = await webpackConfig ( program , directory , stage , null , {
51
50
parentSpan,
52
51
} )
53
- return await doBuildRenderer ( program , config )
52
+
53
+ return doBuildRenderer ( program , config )
54
54
}
55
55
56
56
const deleteRenderer = async ( rendererPath : string ) : Promise < void > => {
@@ -78,22 +78,16 @@ const renderHTMLQueue = async (
78
78
79
79
// const start = process.hrtime()
80
80
const segments = chunk ( pages , 50 )
81
- // let finished = 0
82
81
83
82
await Bluebird . map ( segments , async pageSegment => {
84
83
await workerPool . renderHTML ( {
84
+ envVars,
85
85
htmlComponentRendererPath,
86
86
paths : pageSegment ,
87
- envVars,
88
87
} )
89
- // finished += pageSegment.length
88
+
90
89
if ( activity && activity . tick ) {
91
90
activity . tick ( pageSegment . length )
92
- // activity.setStatus(
93
- // `${finished}/${pages.length} ${(
94
- // finished / convertHrtime(process.hrtime(start)).seconds
95
- // ).toFixed(2)} pages/second`
96
- // )
97
91
}
98
92
} )
99
93
}
@@ -110,12 +104,12 @@ const doBuildPages = async (
110
104
111
105
try {
112
106
await renderHTMLQueue ( workerPool , activity , rendererPath , pagePaths )
113
- } catch ( e ) {
107
+ } catch ( error ) {
114
108
const prettyError = await createErrorFromString (
115
- e . stack ,
109
+ error . stack ,
116
110
`${ rendererPath } .map`
117
111
)
118
- prettyError . context = e . context
112
+ prettyError . context = error . context
119
113
throw prettyError
120
114
}
121
115
}
0 commit comments