Skip to content

Commit 498b61b

Browse files
Michsior14FrozenPandaz
authored andcommitted
feat(core): support prettier v3 as a formatter (#18644)
(cherry picked from commit 54496e8)
1 parent 8c3822c commit 498b61b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/nx/src/command-line/format/format.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as yargs from 'yargs';
1313

1414
import * as prettier from 'prettier';
1515
import { sortObjectByKeys } from '../../utils/object-sort';
16+
import { readModulePackageJson } from '../../utils/package-json';
1617
import {
1718
getRootTsConfigFileName,
1819
getRootTsConfigPath,
@@ -23,8 +24,9 @@ import { readNxJson } from '../../config/configuration';
2324
import { ProjectGraph } from '../../config/project-graph';
2425
import { chunkify } from '../../utils/chunkify';
2526
import { allFileData } from '../../utils/all-file-data';
27+
import { gte } from 'semver';
2628

27-
const PRETTIER_PATH = require.resolve('prettier/bin-prettier');
29+
const PRETTIER_PATH = getPrettierPath();
2830

2931
export async function format(
3032
command: 'check' | 'write',
@@ -210,3 +212,11 @@ function sortTsConfig() {
210212
// catch noop
211213
}
212214
}
215+
216+
function getPrettierPath() {
217+
const prettierVersion = readModulePackageJson('prettier').packageJson.version;
218+
if (gte(prettierVersion, '3.0.0')) {
219+
return require.resolve('prettier/bin/prettier.cjs');
220+
}
221+
return require.resolve('prettier/bin-prettier');
222+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy