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): remove resource query from warnings #36439

Merged
merged 1 commit into from
Aug 23, 2022
Merged
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
20 changes: 18 additions & 2 deletions packages/gatsby/src/utils/webpack-error-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ const transformWebpackError = (
}
}

// With the introduction of Head API, the modulePath can have a resourceQuery so this function can be used to remove it
const removeResourceQuery = (
moduleName: string | undefined
): string | undefined => {
const moduleNameWithoutQuery = moduleName?.replace(
/(\?|&)export=(default|head)$/,
``
)

return moduleNameWithoutQuery
}

export const structureWebpackErrors = (
stage: StageEnum,
webpackError: WebpackError | Array<WebpackError>
Expand All @@ -150,9 +162,13 @@ export const reportWebpackWarnings = (
let warningMessages: Array<string> = []
if (typeof warnings[0] === `string`) {
warningMessages = warnings as unknown as Array<string>
} else if (warnings[0]?.message && warnings[0]?.moduleName) {
} else if (
warnings[0]?.message &&
removeResourceQuery(warnings[0]?.moduleName)
) {
warningMessages = warnings.map(
warning => `${warning.moduleName}\n\n${warning.message}`
warning =>
`${removeResourceQuery(warning.moduleName)}\n\n${warning.message}`
)
} else if (warnings[0]?.message) {
warningMessages = warnings.map(warning => warning.message)
Expand Down