Skip to content

Commit 9a556f4

Browse files
authored
feat(core): add --exclude-task-dependencies flag (#27137)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior There is no option to exclude dependent tasks when running Nx. ## Expected Behavior There is a flag, `--exclude-task-dependencies`, to exclude task deps from running. This is inline with other tools: - [dotnet cli](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-build#:~:text=%2D%2Dno%2D-,dependencies,-Ignores%20project%2Dto) ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #18053
1 parent 04fb62d commit 9a556f4

File tree

16 files changed

+115
-6
lines changed

16 files changed

+115
-6
lines changed

docs/generated/cli/affected.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ Type: `string`
117117

118118
Exclude certain projects from being processed
119119

120+
### excludeTaskDependencies
121+
122+
Type: `boolean`
123+
124+
Default: `false`
125+
126+
Skips running dependent tasks first
127+
120128
### files
121129

122130
Type: `string`

docs/generated/cli/release.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ Type: `string`
309309

310310
Exclude certain projects from being processed
311311

312+
##### excludeTaskDependencies
313+
314+
Type: `boolean`
315+
316+
Default: `false`
317+
318+
Skips running dependent tasks first
319+
312320
##### first-release
313321

314322
Type: `boolean`

docs/generated/cli/run-many.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ Type: `string`
119119

120120
Exclude certain projects from being processed
121121

122+
### excludeTaskDependencies
123+
124+
Type: `boolean`
125+
126+
Default: `false`
127+
128+
Skips running dependent tasks first
129+
122130
### graph
123131

124132
Type: `string`

docs/generated/cli/run.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ Type: `string`
8787

8888
Exclude certain projects from being processed
8989

90+
### excludeTaskDependencies
91+
92+
Type: `boolean`
93+
94+
Default: `false`
95+
96+
Skips running dependent tasks first
97+
9098
### graph
9199

92100
Type: `string`

docs/generated/packages/nx/documents/affected.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ Type: `string`
117117

118118
Exclude certain projects from being processed
119119

120+
### excludeTaskDependencies
121+
122+
Type: `boolean`
123+
124+
Default: `false`
125+
126+
Skips running dependent tasks first
127+
120128
### files
121129

122130
Type: `string`

docs/generated/packages/nx/documents/release.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ Type: `string`
309309

310310
Exclude certain projects from being processed
311311

312+
##### excludeTaskDependencies
313+
314+
Type: `boolean`
315+
316+
Default: `false`
317+
318+
Skips running dependent tasks first
319+
312320
##### first-release
313321

314322
Type: `boolean`

docs/generated/packages/nx/documents/run-many.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ Type: `string`
119119

120120
Exclude certain projects from being processed
121121

122+
### excludeTaskDependencies
123+
124+
Type: `boolean`
125+
126+
Default: `false`
127+
128+
Skips running dependent tasks first
129+
122130
### graph
123131

124132
Type: `string`

docs/generated/packages/nx/documents/run.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ Type: `string`
8787

8888
Exclude certain projects from being processed
8989

90+
### excludeTaskDependencies
91+
92+
Type: `boolean`
93+
94+
Default: `false`
95+
96+
Skips running dependent tasks first
97+
9098
### graph
9199

92100
Type: `string`

e2e/nx/src/run.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,40 @@ describe('Nx Running Tests', () => {
254254
const output = runCLI(`echo ${mylib}`);
255255
expect(output).toContain('TWO');
256256
});
257+
258+
it('should not run dependencies if --no-dependencies is passed', () => {
259+
const mylib = uniq('mylib');
260+
runCLI(`generate @nx/js:lib ${mylib}`);
261+
262+
updateJson(`libs/${mylib}/project.json`, (c) => {
263+
c.targets['one'] = {
264+
executor: 'nx:run-commands',
265+
options: {
266+
command: 'echo ONE',
267+
},
268+
};
269+
c.targets['two'] = {
270+
executor: 'nx:run-commands',
271+
options: {
272+
command: 'echo TWO',
273+
},
274+
dependsOn: ['one'],
275+
};
276+
c.targets['three'] = {
277+
executor: 'nx:run-commands',
278+
options: {
279+
command: 'echo THREE',
280+
},
281+
dependsOn: ['two'],
282+
};
283+
return c;
284+
});
285+
286+
const output = runCLI(`one ${mylib} --no-deps`);
287+
expect(output).toContain('ONE');
288+
expect(output).not.toContain('TWO');
289+
expect(output).not.toContain('THREE');
290+
});
257291
});
258292

259293
describe('Nx Bail', () => {

packages/nx/src/command-line/affected/affected.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function affected(
3232
(TargetDependencyConfig | string)[]
3333
> = {},
3434
extraOptions = {
35-
excludeTaskDependencies: false,
35+
excludeTaskDependencies: args.excludeTaskDependencies,
3636
loadDotEnvFiles: process.env.NX_LOAD_DOT_ENV_FILES !== 'false',
3737
} as {
3838
excludeTaskDependencies: boolean;

packages/nx/src/command-line/release/publish.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ export async function releasePublish(
7979
* for dependencies, because that could cause projects outset of the filtered set to be published.
8080
*/
8181
const shouldExcludeTaskDependencies =
82-
_args.projects?.length > 0 || _args.groups?.length > 0;
82+
_args.projects?.length > 0 ||
83+
_args.groups?.length > 0 ||
84+
args.excludeTaskDependencies;
8385

8486
let overallExitStatus = 0;
8587

packages/nx/src/command-line/run-many/run-many.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function runMany(
2626
(TargetDependencyConfig | string)[]
2727
> = {},
2828
extraOptions = {
29-
excludeTaskDependencies: false,
29+
excludeTaskDependencies: args.excludeTaskDependencies,
3030
loadDotEnvFiles: process.env.NX_LOAD_DOT_ENV_FILES !== 'false',
3131
} as {
3232
excludeTaskDependencies: boolean;

packages/nx/src/command-line/run/run-one.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function runOne(
2828
(TargetDependencyConfig | string)[]
2929
> = {},
3030
extraOptions = {
31-
excludeTaskDependencies: false,
31+
excludeTaskDependencies: args.excludeTaskDependencies,
3232
loadDotEnvFiles: process.env.NX_LOAD_DOT_ENV_FILES !== 'false',
3333
} as {
3434
excludeTaskDependencies: boolean;

packages/nx/src/command-line/yargs-utils/shared-options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface RunOptions {
2727
dte: boolean;
2828
batch: boolean;
2929
useAgents: boolean;
30+
excludeTaskDependencies: boolean;
3031
}
3132

3233
export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
@@ -79,6 +80,11 @@ export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
7980
type: 'boolean',
8081
default: false,
8182
})
83+
.options('excludeTaskDependencies', {
84+
describe: 'Skips running dependent tasks first',
85+
type: 'boolean',
86+
default: false,
87+
})
8288
.options('cloud', {
8389
type: 'boolean',
8490
hidden: true,

packages/nx/src/commands-runner/create-command-graph.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ export function createCommandGraph(
5050
nxArgs: NxArgs
5151
): CommandGraph {
5252
const dependencies: Record<string, string[]> = {};
53-
for (const projectName of projectNames) {
54-
recursiveResolveDeps(projectGraph, projectName, dependencies);
53+
if (!nxArgs.excludeTaskDependencies) {
54+
for (const projectName of projectNames) {
55+
recursiveResolveDeps(projectGraph, projectName, dependencies);
56+
}
5557
}
5658
const roots = Object.keys(dependencies).filter(
5759
(d) => dependencies[d].length === 0

packages/nx/src/utils/command-line-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface NxArgs {
3636
nxIgnoreCycles?: boolean;
3737
type?: string;
3838
batch?: boolean;
39+
excludeTaskDependencies?: boolean;
3940
}
4041

4142
export function createOverrides(__overrides_unparsed__: string[] = []) {

0 commit comments

Comments
 (0)