From 98ae4a45ed9327f5cf5ff5b470f05d679764436e Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 17 Jun 2021 18:27:13 -0400 Subject: [PATCH] Ensure all errors are reported when an error occurs in webpack Prior to this we would emit only the first error, leading to **mega** painful games of "whack-a-mole" (get error, fix error, do build, find next error, fix error, do build, find yet another error). --- packages/webpack/package.json | 2 ++ packages/webpack/src/ember-webpack.ts | 14 +++++++++++++- yarn.lock | 7 ++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/webpack/package.json b/packages/webpack/package.json index 6a48994e5..d83664639 100644 --- a/packages/webpack/package.json +++ b/packages/webpack/package.json @@ -27,9 +27,11 @@ "@embroider/hbs-loader": "0.42.0", "@types/loader-utils": "^2.0.2", "@types/source-map": "^0.5.7", + "@types/supports-color": "^8.1.0", "babel-core": "^6.26.3", "babel-loader": "^8.2.2", "babel-preset-env": "^1.7.0", + "supports-color": "^8.1.0", "css-loader": "^5.2.6", "csso": "^4.2.0", "debug": "^4.3.2", diff --git a/packages/webpack/src/ember-webpack.ts b/packages/webpack/src/ember-webpack.ts index 1ce633e49..81d562863 100644 --- a/packages/webpack/src/ember-webpack.ts +++ b/packages/webpack/src/ember-webpack.ts @@ -36,6 +36,7 @@ import { Options, BabelLoaderOptions } from './options'; import crypto from 'crypto'; import type { HbsLoaderConfig } from '@embroider/hbs-loader'; import semverSatisfies from 'semver/functions/satisfies'; +import supportsColor from 'supports-color'; const debug = makeDebug('embroider:debug'); @@ -456,11 +457,22 @@ const Webpack: PackagerConstructor = class Webpack implements Packager throw new Error('bug: no stats and no err'); } if (stats.hasErrors()) { + // write all the stats output to the console + this.consoleWrite( + stats.toString({ + color: Boolean(supportsColor.stdout), + }) + ); + // the typing for MultiCompiler are all foobared. throw this.findBestError(flatMap((stats as any).stats, s => s.compilation.errors)); } if (stats.hasWarnings() || process.env.VANILLA_VERBOSE) { - this.consoleWrite(stats.toString()); + this.consoleWrite( + stats.toString({ + color: Boolean(supportsColor.stdout), + }) + ); } resolve(stats.toJson()); } catch (e) { diff --git a/yarn.lock b/yarn.lock index 8cc38f320..651391673 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2481,6 +2481,11 @@ dependencies: strip-bom "*" +"@types/supports-color@^8.1.0": + version "8.1.0" + resolved "https://registry.yarnpkg.com/@types/supports-color/-/supports-color-8.1.0.tgz#d25609c0c07a257dbc460cea4e693abf78fe6aef" + integrity sha512-yuaTiC8EqSvcb03zAsCXySH18CUcHNJFvOoqCJTMMKG3o5E4Jgnr1ycDR2v1BK9Cj56iMiYgjqX98eiWjRsBeg== + "@types/symlink-or-copy@^1.2.0": version "1.2.0" resolved "https://registry.yarnpkg.com/@types/symlink-or-copy/-/symlink-or-copy-1.2.0.tgz#4151a81b4052c80bc2becbae09f3a9ec010a9c7a" @@ -17758,7 +17763,7 @@ supports-color@^7.1.0: dependencies: has-flag "^4.0.0" -supports-color@^8.0.0: +supports-color@^8.0.0, supports-color@^8.1.0: version "8.1.1" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c" integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==