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

[heft-webpack] Log nested errors/warnings #3801

Merged
merged 1 commit into from
Dec 1, 2022
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
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