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

chore(gatsby): migrate webpack-error-utils to TypeScript #22278

Merged
merged 3 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/gatsby/src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { store, readState } = require(`../redux`)
const queryUtil = require(`../query`)
import * as appDataUtil from "../utils/app-data"
import * as WorkerPool from "../utils/worker/pool"
const { structureWebpackErrors } = require(`../utils/webpack-error-utils`)
import { structureWebpackErrors } from "../utils/webpack-error-utils"
import {
userPassesFeedbackRequestHeuristic,
showFeedbackRequest,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
const reporter = require(`gatsby-cli/lib/reporter`)
import { Stats } from "webpack"

const stageCodeToReadableLabel = {
"build-javascript": `Generating JavaScript bundles`,
"build-html": `Generating SSR bundle`,
develop: `Generating development JavaScript bundle`,
}
} as const

type Stage = keyof typeof stageCodeToReadableLabel
type StageLabel = typeof stageCodeToReadableLabel[Stage]

const transformWebpackError = (stage, webpackError) => {
interface ITransformedWebpackError {
id: "98123"
filePath?: string
location?: {
start: string
}
context: {
stage: Stage
stageLabel: StageLabel
message?: string
}
}
const transformWebpackError = (
stage: keyof typeof stageCodeToReadableLabel,
webpackError: any
): ITransformedWebpackError => {
return {
id: `98123`,
filePath: webpackError?.module?.resource,
Expand All @@ -30,15 +49,18 @@ const transformWebpackError = (stage, webpackError) => {
}
}

exports.structureWebpackErrors = (stage, webpackError) => {
export const structureWebpackErrors = (
stage: Stage,
webpackError: any
): ITransformedWebpackError[] | ITransformedWebpackError => {
if (Array.isArray(webpackError)) {
return webpackError.map(e => transformWebpackError(stage, e))
}

return transformWebpackError(stage, webpackError)
}

exports.reportWebpackWarnings = stats => {
export const reportWebpackWarnings = (stats: Stats): void => {
stats.compilation.warnings.forEach(webpackWarning => {
if (webpackWarning.warning) {
// grab inner Exception if it exists
Expand Down