Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix: with-deps removed in nx 14 (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnetzer authored Jul 17, 2022
1 parent e0a1f7f commit 57441b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
18 changes: 17 additions & 1 deletion packages/nx-distributed-task/src/app/nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<string> {
const command = getPackageManagerCommand().exec;
return await exec.withCommand(`${command} nx --version`).build()();
}

export async function nxCommand(nxCommand: string, args: NxArgs, exec: Exec): Promise<string> {
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';
Expand Down
10 changes: 8 additions & 2 deletions packages/utils/src/lib/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ export function parseNxArgs(args: Record<string, unknown>): 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(
Expand Down

0 comments on commit 57441b6

Please sign in to comment.