Skip to content

Commit

Permalink
fix(core): support prettier v3 when run nx format
Browse files Browse the repository at this point in the history
After prettier upgrade to v3, the getSupportInfo will return promise

Closes #18992
  • Loading branch information
abel1105 committed Sep 20, 2023
1 parent f213976 commit 87ec362
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/nx/src/command-line/format/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { calculateFileChanges, FileData } from '../../project-graph/file-utils';
import * as yargs from 'yargs';

import * as prettier from 'prettier';
import { SupportInfo } from 'prettier';
import { sortObjectByKeys } from '../../utils/object-sort';
import { readModulePackageJson } from '../../utils/package-json';
import {
Expand Down Expand Up @@ -81,9 +82,11 @@ async function getPatterns(

const p = parseFiles(args);

const supportedExtensions = prettier
.getSupportInfo()
.languages.flatMap((language) => language.extensions)
// In prettier v3 the getSupportInfo result is a promise
const supportedExtensions = (
await (prettier.getSupportInfo() as Promise<SupportInfo> | SupportInfo)
).languages
.flatMap((language) => language.extensions)
.filter((extension) => !!extension)
// Prettier supports ".swcrc" as a file instead of an extension
// So we add ".swcrc" as a supported extension manually
Expand Down

0 comments on commit 87ec362

Please sign in to comment.