Skip to content

Commit

Permalink
feat(core): support prettier v3 as a formatter (#18644)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michsior14 committed Aug 16, 2023
1 parent cf0b2fd commit 54496e8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/nx/src/command-line/format/format.ts
Expand Up @@ -12,6 +12,7 @@ import * as yargs from 'yargs';

import * as prettier from 'prettier';
import { sortObjectByKeys } from '../../utils/object-sort';
import { readModulePackageJson } from '../../utils/package-json';
import {
getRootTsConfigFileName,
getRootTsConfigPath,
Expand All @@ -22,8 +23,9 @@ import { readNxJson } from '../../config/configuration';
import { ProjectGraph } from '../../config/project-graph';
import { chunkify } from '../../utils/chunkify';
import { allFileData } from '../../utils/all-file-data';
import { gte } from 'semver';

const PRETTIER_PATH = require.resolve('prettier/bin-prettier');
const PRETTIER_PATH = getPrettierPath();

export async function format(
command: 'check' | 'write',
Expand Down Expand Up @@ -202,3 +204,11 @@ function sortTsConfig() {
// catch noop
}
}

function getPrettierPath() {
const prettierVersion = readModulePackageJson('prettier').packageJson.version;
if (gte(prettierVersion, '3.0.0')) {
return require.resolve('prettier/bin/prettier.cjs');
}
return require.resolve('prettier/bin-prettier');
}

1 comment on commit 54496e8

@vercel
Copy link

@vercel vercel bot commented on 54496e8 Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.