From 57441b62639ec90db3b1aef573980f80e72c22d2 Mon Sep 17 00:00:00 2001 From: Ron Netzer Date: Sun, 17 Jul 2022 17:10:36 +0300 Subject: [PATCH] fix: with-deps removed in nx 14 (#51) --- packages/nx-distributed-task/src/app/nx.ts | 18 +++++++++++++++++- packages/utils/src/lib/inputs.ts | 10 ++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/nx-distributed-task/src/app/nx.ts b/packages/nx-distributed-task/src/app/nx.ts index 3aa956f9..297d8cd3 100644 --- a/packages/nx-distributed-task/src/app/nx.ts +++ b/packages/nx-distributed-task/src/app/nx.ts @@ -4,7 +4,7 @@ import { NxArgs } from '@nrwl/workspace/src/command-line/utils'; import { names } from '@nrwl/devkit/src/utils/names'; import { Exec } from '@e-square/utils/exec'; -import { debug, group, logger } from '@e-square/utils/logger'; +import { debug, group, logger, warning } from '@e-square/utils/logger'; export async function assertNxInstalled(exec: Exec) { const command = getPackageManagerCommand().list; @@ -17,7 +17,23 @@ export async function assertNxInstalled(exec: Exec) { if (!path) throw new Error("Couldn't find Nx binary, Have you run npm/yarn install?"); } +export async function getNxVersion(exec: Exec): Promise { + const command = getPackageManagerCommand().exec; + return await exec.withCommand(`${command} nx --version`).build()(); +} + export async function nxCommand(nxCommand: string, args: NxArgs, exec: Exec): Promise { + const [nxMajorVersion] = (await getNxVersion(exec)).split('.'); + if (args.withDeps) { + warning(`with-deps was removed in NX 14. Please replace its usage with 'targetDefaults'`); + } + + // override with-deps because it was removed in NX 14 + if (nxMajorVersion >= '14') { + args.withDeps = undefined; + args['with-deps'] = undefined; + } + const [pmMajorVersion] = getPackageManagerVersion().split('.'); let command = getPackageManagerCommand().exec; const isNpx = command === 'npx'; diff --git a/packages/utils/src/lib/inputs.ts b/packages/utils/src/lib/inputs.ts index aabd34c2..62464219 100644 --- a/packages/utils/src/lib/inputs.ts +++ b/packages/utils/src/lib/inputs.ts @@ -52,8 +52,14 @@ export function parseNxArgs(args: Record): NxArgs { export function shouldRunWithDeps(target: string): boolean { const nxJson = readNxJson(tree); - - return Boolean(nxJson?.targetDependencies?.[target]?.some?.(({ projects }) => projects === 'dependencies')); + const isNx14 = (nxJson as any).targetDefaults !== undefined; + if (isNx14) { + return Boolean( + ((nxJson as any)?.targetDefaults?.[target]?.dependsOn as string[]).some?.((dep) => dep.includes(target)) + ); + } else { + return Boolean(nxJson?.targetDependencies?.[target]?.some?.(({ projects }) => projects === 'dependencies')); + } } export function getArgsInput(