Skip to content

Commit f5ca400

Browse files
committed
fixup! feat(@angular/cli): automatic formatting files modified by schematics
1 parent 1b984f1 commit f5ca400

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/angular/cli/src/command-builder/schematics-command-module.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,15 @@ export abstract class SchematicsCommandModule
368368

369369
if (files.size) {
370370
// Note: we could use a task executor to format the files but this is simpler.
371-
await formatFiles(this.context.root, files);
371+
try {
372+
await formatFiles(this.context.root, files);
373+
} catch (error) {
374+
assertIsError(error);
375+
376+
logger.warn(
377+
`WARNING: Formatting of files failed with the following error: ${error.message}`,
378+
);
379+
}
372380
}
373381

374382
return 0;

packages/angular/cli/src/command-builder/utilities/prettier.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import { execFile } from 'node:child_process';
10+
import { readFile } from 'node:fs/promises';
1011
import { createRequire } from 'node:module';
1112
import { dirname, extname, join, relative } from 'node:path';
1213
import { promisify } from 'node:util';
@@ -43,7 +44,10 @@ export async function formatFiles(cwd: string, files: Set<string>): Promise<void
4344
if (prettierCliPath === undefined) {
4445
try {
4546
const prettierPath = createRequire(cwd + '/').resolve('prettier/package.json');
46-
prettierCliPath = join(dirname(prettierPath), 'bin/prettier.cjs');
47+
const prettierPackageJson = JSON.parse(await readFile(prettierPath, 'utf-8')) as {
48+
bin: { prettier: string };
49+
};
50+
prettierCliPath = join(dirname(prettierPath), prettierPackageJson.bin.prettier);
4751
} catch {
4852
// Prettier is not installed.
4953
prettierCliPath = null;

0 commit comments

Comments
 (0)