Skip to content

Commit

Permalink
fix(devkit): await prettier format for v3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Michsior14 committed Aug 17, 2023
1 parent 2034cdd commit 409207f
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 409207f

Please sign in to comment.