From 3f3f2475beb3f35ca04361bfe6f48c5c09222005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mrozek?= Date: Tue, 22 Aug 2023 16:56:52 +0200 Subject: [PATCH] cleanup(core): improve prettier bin path resolution (#18672) --- packages/nx/src/command-line/format/format.ts | 8 ++------ packages/nx/src/utils/package-json.ts | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/nx/src/command-line/format/format.ts b/packages/nx/src/command-line/format/format.ts index 540f91ffa2b41..65228f820503d 100644 --- a/packages/nx/src/command-line/format/format.ts +++ b/packages/nx/src/command-line/format/format.ts @@ -24,7 +24,6 @@ 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 = getPrettierPath(); @@ -214,9 +213,6 @@ function sortTsConfig() { } 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'); + const { bin } = readModulePackageJson('prettier').packageJson; + return require.resolve(path.join('prettier', bin as string)); } diff --git a/packages/nx/src/utils/package-json.ts b/packages/nx/src/utils/package-json.ts index a57189b56a636..e0d4d58fc0c6c 100644 --- a/packages/nx/src/utils/package-json.ts +++ b/packages/nx/src/utils/package-json.ts @@ -57,7 +57,7 @@ export interface PackageJson { peerDependenciesMeta?: Record; resolutions?: Record; overrides?: PackageOverride; - bin?: Record; + bin?: Record | string; workspaces?: | string[] | {