Skip to content

Commit

Permalink
Merge pull request #3801 from dmichon-msft/webpack-nested-errors
Browse files Browse the repository at this point in the history
[heft-webpack] Log nested errors/warnings
  • Loading branch information
dmichon-msft authored Dec 1, 2022
2 parents b5d5733 + 2902c74 commit e5df6b9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/heft-webpack4-plugin",
"comment": "Log errors and warnings from nested compilations.",
"type": "patch"
}
],
"packageName": "@rushstack/heft-webpack4-plugin"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/heft-webpack5-plugin",
"comment": "Log errors and warnings from nested compilations.",
"type": "patch"
}
],
"packageName": "@rushstack/heft-webpack5-plugin"
}
29 changes: 24 additions & 5 deletions heft-plugins/heft-webpack4-plugin/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,33 @@ export class WebpackPlugin implements IHeftPlugin {

private _emitErrors(logger: ScopedLogger, stats: WebpackStats | WebpackCompilation.MultiStats): void {
if (stats.hasErrors() || stats.hasWarnings()) {
const serializedStats: WebpackStats.ToJsonOutput = stats.toJson('errors-warnings');
const serializedStats: WebpackStats.ToJsonOutput[] = [stats.toJson('errors-warnings')];

for (const warning of serializedStats.warnings as (string | Error)[]) {
logger.emitWarning(warning instanceof Error ? warning : new Error(warning));
const warnings: Error[] = [];
const errors: Error[] = [];

for (const compilationStats of serializedStats) {
for (const warning of compilationStats.warnings as (string | Error)[]) {
warnings.push(warning instanceof Error ? warning : new Error(warning));
}

for (const error of compilationStats.errors as (string | Error)[]) {
errors.push(error instanceof Error ? error : new Error(error));
}

if (compilationStats.children) {
for (const child of compilationStats.children) {
serializedStats.push(child);
}
}
}

for (const warning of warnings) {
logger.emitWarning(warning);
}

for (const error of serializedStats.errors as (string | Error)[]) {
logger.emitError(error instanceof Error ? error : new Error(error));
for (const error of errors) {
logger.emitError(error);
}
}
}
Expand Down
35 changes: 27 additions & 8 deletions heft-plugins/heft-webpack5-plugin/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,37 @@ export class WebpackPlugin implements IHeftPlugin {
stats: WebpackStats | WebpackMultiStats
): void {
if (stats.hasErrors() || stats.hasWarnings()) {
const serializedStats: WebpackStatsCompilation = stats.toJson('errors-warnings');
const serializedStats: WebpackStatsCompilation[] = [stats.toJson('errors-warnings')];

if (serializedStats.warnings) {
for (const warning of serializedStats.warnings) {
logger.emitWarning(this._normalizeError(buildFolder, warning));
const errors: Error[] = [];
const warnings: Error[] = [];

for (const compilationStats of serializedStats) {
if (compilationStats.warnings) {
for (const warning of compilationStats.warnings) {
warnings.push(this._normalizeError(buildFolder, warning));
}
}
}

if (serializedStats.errors) {
for (const error of serializedStats.errors) {
logger.emitError(this._normalizeError(buildFolder, error));
if (compilationStats.errors) {
for (const error of compilationStats.errors) {
errors.push(this._normalizeError(buildFolder, error));
}
}

if (compilationStats.children) {
for (const child of compilationStats.children) {
serializedStats.push(child);
}
}
}

for (const warning of warnings) {
logger.emitWarning(warning);
}

for (const error of errors) {
logger.emitError(error);
}
}
}
Expand Down

0 comments on commit e5df6b9

Please sign in to comment.