Skip to content

Commit

Permalink
Merge pull request #39 from iclanton/fix-webpack-error-formatting
Browse files Browse the repository at this point in the history
Fix an issue with webpack error printing.
  • Loading branch information
iclanton authored Sep 10, 2024
2 parents d7fe48e + 31d115a commit 1df6f05
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/gulp-core-build-webpack",
"comment": "Fix an issue where webpack errors were printed as `[object Object]`.",
"type": "patch"
}
],
"packageName": "@microsoft/gulp-core-build-webpack"
}
3 changes: 3 additions & 0 deletions common/scripts/install-run-rush-pnpm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions common/scripts/install-run-rush.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions common/scripts/install-run-rushx.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 28 additions & 12 deletions common/scripts/install-run.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 30 additions & 13 deletions core-build/gulp-core-build-webpack/src/WebpackTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ export interface IWebpackResources {
webpack: typeof Webpack;
}

function normalizeWebpackError(error: Webpack.StatsError): string {
if (typeof error === 'string') {
return error;
} else {
const { loc, moduleName, moduleIdentifier } = error;
const modulePath: string | undefined = moduleName ?? moduleIdentifier;
if (modulePath) {
if (loc) {
return `${modulePath}:${loc}: ${error.message}`;
} else {
return `${modulePath}: ${error.message}`;
}
} else {
return error.message;
}
}
}

/**
* @public
*/
Expand Down Expand Up @@ -141,7 +159,12 @@ export class WebpackTask<TExtendedConfig = {}> extends GulpTask<IWebpackTaskConf

if (statsResult) {
if (statsResult.errors && statsResult.errors.length) {
this.logError(`'${outputDir}':` + EOL + statsResult.errors.join(EOL) + EOL);
const errorTexts: string[] = [];
for (const error of statsResult.errors) {
errorTexts.push(normalizeWebpackError(error));
}

this.logError(`'${outputDir}':` + EOL + errorTexts.join(EOL) + EOL);
}

if (statsResult.warnings && statsResult.warnings.length) {
Expand All @@ -168,18 +191,12 @@ export class WebpackTask<TExtendedConfig = {}> extends GulpTask<IWebpackTaskConf
}

if (unsuppressedWarnings.length > 0) {
this.logWarning(
`'${outputDir}':` +
EOL +
unsuppressedWarnings
.map(
(unsuppressedWarning) =>
(unsuppressedWarning.loc ? `${unsuppressedWarning.loc}: ` : '') +
unsuppressedWarning.message
)
.join(EOL) +
EOL
);
const warningTexts: string[] = [];
for (const warning of unsuppressedWarnings) {
warningTexts.push(normalizeWebpackError(warning));
}

this.logWarning(`'${outputDir}':` + EOL + warningTexts.join(EOL) + EOL);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* path segment in the "$schema" field for all your Rush config files. This will ensure
* correct error-underlining and tab-completion for editors such as VS Code.
*/
"rushVersion": "5.118.4",
"rushVersion": "5.133.4",

/**
* The next field selects which package manager should be installed and determines its version.
Expand Down

0 comments on commit 1df6f05

Please sign in to comment.