fix(core): support prettier v3 when run nx format (#19207)

This commit is contained in:
Abel 2023-10-18 02:03:06 +08:00 committed by GitHub
parent c05337481b
commit b51bd04746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,7 @@ import { calculateFileChanges, FileData } from '../../project-graph/file-utils';
import * as yargs from 'yargs';
import * as prettier from 'prettier';
import type { SupportInfo } from 'prettier';
import { sortObjectByKeys } from '../../utils/object-sort';
import { readModulePackageJson } from '../../utils/package-json';
import {
@ -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