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 yargs from 'yargs';
import * as prettier from 'prettier'; import * as prettier from 'prettier';
import type { SupportInfo } from 'prettier';
import { sortObjectByKeys } from '../../utils/object-sort'; import { sortObjectByKeys } from '../../utils/object-sort';
import { readModulePackageJson } from '../../utils/package-json'; import { readModulePackageJson } from '../../utils/package-json';
import { import {
@ -81,9 +82,11 @@ async function getPatterns(
const p = parseFiles(args); const p = parseFiles(args);
const supportedExtensions = prettier // In prettier v3 the getSupportInfo result is a promise
.getSupportInfo() const supportedExtensions = (
.languages.flatMap((language) => language.extensions) await (prettier.getSupportInfo() as Promise<SupportInfo> | SupportInfo)
).languages
.flatMap((language) => language.extensions)
.filter((extension) => !!extension) .filter((extension) => !!extension)
// Prettier supports ".swcrc" as a file instead of an extension // Prettier supports ".swcrc" as a file instead of an extension
// So we add ".swcrc" as a supported extension manually // So we add ".swcrc" as a supported extension manually