MCPcopy Create free account
hub / github.com/webpack/webpack-cli / callback

Method callback

packages/webpack-cli/src/webpack-cli.ts:3479–3533  ·  view source on GitHub ↗
(error, stats)

Source from the content-addressed store, hash-verified

3477 }
3478
3479 const callback: WebpackCallback = (error, stats): void => {
3480 if (error) {
3481 this.logger.error(error);
3482 process.exit(2);
3483 }
3484
3485 if (stats && (stats.hasErrors() || (options.failOnWarnings && stats.hasWarnings()))) {
3486 process.exitCode = 1;
3487 }
3488
3489 if (!compiler || !stats) {
3490 return;
3491 }
3492
3493 const statsOptions = this.isMultipleCompiler(compiler)
3494 ? {
3495 children: compiler.compilers.map((compiler) => compiler.options.stats),
3496 }
3497 : compiler.options.stats;
3498
3499 if (options.json) {
3500 const handleWriteError = (error: Error) => {
3501 this.logger.error(error);
3502 process.exit(2);
3503 };
3504
3505 if (options.json === true) {
3506 Readable.from(stringifyChunked(stats.toJson(statsOptions as StatsOptions)))
3507 .on("error", handleWriteError)
3508 .pipe(process.stdout)
3509 .on("error", handleWriteError)
3510 .on("close", () => process.stdout.write("\n"));
3511 } else {
3512 Readable.from(stringifyChunked(stats.toJson(statsOptions as StatsOptions)))
3513 .on("error", handleWriteError)
3514 .pipe(fs.createWriteStream(options.json))
3515 .on("error", handleWriteError)
3516 // Use stderr to logging
3517 .on("close", () => {
3518 process.stderr.write(
3519 `[webpack-cli] ${this.colors.green(
3520 `stats are successfully stored as json to ${options.json}`,
3521 )}\n`,
3522 );
3523 });
3524 }
3525 } else {
3526 const printedStats = stats.toString(statsOptions);
3527
3528 // Avoid extra empty line when `stats: 'none'`
3529 if (printedStats) {
3530 this.logger.raw(printedStats);
3531 }
3532 }
3533 };
3534
3535 const env =
3536 isWatchCommand || options.watch

Callers

nothing calls this directly

Calls 1

isMultipleCompilerMethod · 0.95

Tested by

no test coverage detected