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
  • Loading branch information
Michsior14 committed Aug 20, 2023
1 parent 7d4e2fe commit 2638bb0
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

1 comment on commit 2638bb0

@vercel
Copy link

@vercel vercel bot commented on 2638bb0 Aug 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.