Skip to content

Commit

Permalink
fix(devkit): await prettier format for v3 compatibility (#18664)
Browse files Browse the repository at this point in the history
(cherry picked from commit 2638bb0)
  • Loading branch information
Michsior14 authored and FrozenPandaz committed Aug 21, 2023
1 parent d168926 commit 495d5f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/devkit/src/generators/format-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export async function formatFiles(tree: Tree): Promise<void> {

tree.write(
file.path,
prettier.format(file.content.toString('utf-8'), options)
// In prettier v3 the format result is a promise
await (prettier.format(file.content.toString('utf-8'), options) as
| Promise<string>
| string)
);
} catch (e) {
console.warn(`Could not format ${file.path}. Error: "${e.message}"`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export async function formatChangedFilesWithPrettierIfAvailable(

tree.write(
file.path,
prettier.format(file.content.toString('utf-8'), options)
// In prettier v3 the format result is a promise
await (prettier.format(file.content.toString('utf-8'), options) as
| Promise<string>
| string)
);
} catch (e) {
console.warn(`Could not format ${file.path}. Error: "${e.message}"`);
Expand Down
8 changes: 7 additions & 1 deletion packages/workspace/src/utils/rules/format-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ export function formatFiles(
}

try {
host.overwrite(file.path, prettier.format(file.content, options));
host.overwrite(
file.path,
// In prettier v3 the format result is a promise
await (prettier.format(file.content, options) as
| Promise<string>
| string)
);
} catch (e) {
context.logger.warn(
`Could not format ${file.path} because ${e.message}`
Expand Down

0 comments on commit 495d5f7

Please # to comment.