Skip to content

Commit

Permalink
stop builds on errors in built-html step (#6188)
Browse files Browse the repository at this point in the history
* use new babel-code-frame API

* stop build after errors in build-html stage and display nicely formatted error message
  • Loading branch information
pieh authored and m-allanson committed Jun 28, 2018
1 parent 58571be commit 386db39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions packages/gatsby-cli/src/reporter/prepare-stack-trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

const { readFileSync } = require(`fs`)
const babelCodeFrame = require(`@babel/code-frame`)
const { codeFrameColumns } = require(`@babel/code-frame`)
const stackTrace = require(`stack-trace`)
const { SourceMapConsumer } = require(`source-map`)

Expand All @@ -28,10 +28,14 @@ function getErrorSource(map, topFrame) {
let source = map.sourceContentFor(topFrame.getFileName(), true)
return (
source &&
babelCodeFrame(
codeFrameColumns(
source,
topFrame.getLineNumber(),
topFrame.getColumnNumber(),
{
start: {
line: topFrame.getLineNumber(),
column: topFrame.getColumnNumber(),
},
},
{
highlightCode: true,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/commands/build-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = async (program: any) => {
return resolve(null, stats)
})
.catch(e => {
console.log(e)
reject(createErrorFromString(e.stack, `${outputFile}.map`))
})
})
})
Expand Down

0 comments on commit 386db39

Please sign in to comment.