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

fix(gatsby): Pass reporter from functions code for reporting warning #31336

Merged
merged 2 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export async function onPreBootstrap({
function callback(err, stats): any {
const rawMessages = stats.toJson({ moduleTrace: false })
if (rawMessages.warnings.length > 0) {
reporter.warn(reportWebpackWarnings(rawMessages.warnings))
reporter.warn(reportWebpackWarnings(rawMessages.warnings, reporter))
KyleAMathews marked this conversation as resolved.
Show resolved Hide resolved
}

if (err) return reject(err)
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby/src/utils/webpack-error-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ export const reportWebpackWarnings = (
warnings: StatsCompilation["warnings"] = [],
reporter: Reporter
): void => {
const warningMessages = warnings.map(warning => warning.message)
const warningMessages = warnings.map(
warning => `${warning.moduleName}\n\n${warning.message}`
Copy link
Contributor Author

@KyleAMathews KyleAMathews May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make the warning a lot more useful — say which file it's from.

Thinking we don't need formatWebpackMessages any more w/ webpack 5? We just pass it a string which it now returns... 🤷

Warnings look like this now:
Screen Shot 2021-05-07 at 4 37 32 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatWebpackMessages does more than formatting. It also rewrites errors to a more actionable ones.

https://github.com/facebook/create-react-app/blob/master/packages/react-dev-utils/formatWebpackMessages.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stats warnings/error object changed in v5 — see #30801 & facebook/create-react-app#9943

Copy link
Contributor Author

@KyleAMathews KyleAMathews May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but yeah, to your point, the message rewritings should still apply so we still want it

)

formatWebpackMessages({
errors: [],
Expand Down