diff --git a/dev-infra/format/format.ts b/dev-infra/format/format.ts index e3e79f6a40..7f05348148 100644 --- a/dev-infra/format/format.ts +++ b/dev-infra/format/format.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {error, info, promptConfirm} from '../utils/console'; +import {error, info, promptConfirm, red} from '../utils/console'; import {runFormatterInParallel} from './run-commands-parallel'; @@ -24,7 +24,11 @@ export async function formatFiles(files: string[]) { // The process should exit as a failure if any of the files failed to format. if (failures.length !== 0) { - error(`Formatting failed, see errors above for more information.`); + error(red(`The following files could not be formatted:`)); + failures.forEach(({filePath, message}) => { + info(` • ${filePath}: ${message}`); + }); + error(red(`Formatting failed, see errors above for more information.`)); process.exit(1); } info(`√ Formatting complete.`); @@ -46,8 +50,8 @@ export async function checkFiles(files: string[]) { if (failures.length) { // Provide output expressing which files are failing formatting. info.group('\nThe following files are out of format:'); - for (const file of failures) { - info(` - ${file}`); + for (const {filePath} of failures) { + info(` • ${filePath}`); } info.groupEnd(); info(); @@ -60,7 +64,7 @@ export async function checkFiles(files: string[]) { if (runFormatter) { // Format the failing files as requested. - await formatFiles(failures); + await formatFiles(failures.map(f => f.filePath)); process.exit(0); } else { // Inform user how to format files in the future. diff --git a/dev-infra/format/run-commands-parallel.ts b/dev-infra/format/run-commands-parallel.ts index 51dcc34aeb..5671d9486a 100644 --- a/dev-infra/format/run-commands-parallel.ts +++ b/dev-infra/format/run-commands-parallel.ts @@ -17,6 +17,14 @@ import {Formatter, FormatterAction, getActiveFormatters} from './formatters/inde const AVAILABLE_THREADS = Math.max(cpus().length - 1, 1); +/** Interface describing a failure occurred during formatting of a file. */ +export interface FormatFailure { + /** Path to the file that failed. */ + filePath: string; + /** Error message reported by the formatter. */ + message: string; +} + /** * Run the provided commands in parallel for each provided file. * @@ -30,9 +38,9 @@ const AVAILABLE_THREADS = Math.max(cpus().length - 1, 1); * The promise resolves with a list of failures, or `false` if no formatters have matched. */ export function runFormatterInParallel(allFiles: string[], action: FormatterAction) { - return new Promise((resolve) => { + return new Promise((resolve) => { const formatters = getActiveFormatters(); - const failures: string[] = []; + const failures: FormatFailure[] = []; const pendingCommands: {formatter: Formatter, file: string}[] = []; for (const formatter of formatters) { @@ -85,7 +93,7 @@ export function runFormatterInParallel(allFiles: string[], action: FormatterActi // Run the provided callback function. const failed = formatter.callbackFor(action)(file, code, stdout, stderr); if (failed) { - failures.push(file); + failures.push({filePath: file, message: stderr}); } // Note in the progress bar another file being completed. progressBar.increment(1); diff --git a/dev-infra/ng-dev.js b/dev-infra/ng-dev.js index f200d96d10..962be84f09 100755 --- a/dev-infra/ng-dev.js +++ b/dev-infra/ng-dev.js @@ -2591,7 +2591,7 @@ function runFormatterInParallel(allFiles, action) { // Run the provided callback function. const failed = formatter.callbackFor(action)(file, code, stdout, stderr); if (failed) { - failures.push(file); + failures.push({ filePath: file, message: stderr }); } // Note in the progress bar another file being completed. progressBar.increment(1); @@ -2639,7 +2639,11 @@ function formatFiles(files) { } // The process should exit as a failure if any of the files failed to format. if (failures.length !== 0) { - error(`Formatting failed, see errors above for more information.`); + error(red(`The following files could not be formatted:`)); + failures.forEach(({ filePath, message }) => { + info(` • ${filePath}: ${message}`); + }); + error(red(`Formatting failed, see errors above for more information.`)); process.exit(1); } info(`√ Formatting complete.`); @@ -2660,8 +2664,8 @@ function checkFiles(files) { if (failures.length) { // Provide output expressing which files are failing formatting. info.group('\nThe following files are out of format:'); - for (const file of failures) { - info(` - ${file}`); + for (const { filePath } of failures) { + info(` • ${filePath}`); } info.groupEnd(); info(); @@ -2672,7 +2676,7 @@ function checkFiles(files) { } if (runFormatter) { // Format the failing files as requested. - yield formatFiles(failures); + yield formatFiles(failures.map(f => f.filePath)); process.exit(0); } else {