File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
packages/nx/src/command-line/format Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import * as yargs from 'yargs';
13
13
14
14
import * as prettier from 'prettier' ;
15
15
import { sortObjectByKeys } from '../../utils/object-sort' ;
16
+ import { readModulePackageJson } from '../../utils/package-json' ;
16
17
import {
17
18
getRootTsConfigFileName ,
18
19
getRootTsConfigPath ,
@@ -23,8 +24,9 @@ import { readNxJson } from '../../config/configuration';
23
24
import { ProjectGraph } from '../../config/project-graph' ;
24
25
import { chunkify } from '../../utils/chunkify' ;
25
26
import { allFileData } from '../../utils/all-file-data' ;
27
+ import { gte } from 'semver' ;
26
28
27
- const PRETTIER_PATH = require . resolve ( 'prettier/bin-prettier' ) ;
29
+ const PRETTIER_PATH = getPrettierPath ( ) ;
28
30
29
31
export async function format (
30
32
command : 'check' | 'write' ,
@@ -210,3 +212,11 @@ function sortTsConfig() {
210
212
// catch noop
211
213
}
212
214
}
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
+ }
You can’t perform that action at this time.
0 commit comments