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
This commit is contained in:
Craigory Coppola 2024-07-26 13:48:50 -04:00 committed by GitHub
parent 04fb62dccb
commit 9a556f45b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 115 additions and 6 deletions

View File

@ -117,6 +117,14 @@ Type: `string`
Exclude certain projects from being processed
### excludeTaskDependencies
Type: `boolean`
Default: `false`
Skips running dependent tasks first
### files
Type: `string`

View File

@ -309,6 +309,14 @@ Type: `string`
Exclude certain projects from being processed
##### excludeTaskDependencies
Type: `boolean`
Default: `false`
Skips running dependent tasks first
##### first-release
Type: `boolean`

View File

@ -119,6 +119,14 @@ Type: `string`
Exclude certain projects from being processed
### excludeTaskDependencies
Type: `boolean`
Default: `false`
Skips running dependent tasks first
### graph
Type: `string`

View File

@ -87,6 +87,14 @@ Type: `string`
Exclude certain projects from being processed
### excludeTaskDependencies
Type: `boolean`
Default: `false`
Skips running dependent tasks first
### graph
Type: `string`

View File

@ -117,6 +117,14 @@ Type: `string`
Exclude certain projects from being processed
### excludeTaskDependencies
Type: `boolean`
Default: `false`
Skips running dependent tasks first
### files
Type: `string`

View File

@ -309,6 +309,14 @@ Type: `string`
Exclude certain projects from being processed
##### excludeTaskDependencies
Type: `boolean`
Default: `false`
Skips running dependent tasks first
##### first-release
Type: `boolean`

View File

@ -119,6 +119,14 @@ Type: `string`
Exclude certain projects from being processed
### excludeTaskDependencies
Type: `boolean`
Default: `false`
Skips running dependent tasks first
### graph
Type: `string`

View File

@ -87,6 +87,14 @@ Type: `string`
Exclude certain projects from being processed
### excludeTaskDependencies
Type: `boolean`
Default: `false`
Skips running dependent tasks first
### graph
Type: `string`

View File

@ -254,6 +254,40 @@ describe('Nx Running Tests', () => {
const output = runCLI(`echo ${mylib}`);
expect(output).toContain('TWO');
});
it('should not run dependencies if --no-dependencies is passed', () => {
const mylib = uniq('mylib');
runCLI(`generate @nx/js:lib ${mylib}`);
updateJson(`libs/${mylib}/project.json`, (c) => {
c.targets['one'] = {
executor: 'nx:run-commands',
options: {
command: 'echo ONE',
},
};
c.targets['two'] = {
executor: 'nx:run-commands',
options: {
command: 'echo TWO',
},
dependsOn: ['one'],
};
c.targets['three'] = {
executor: 'nx:run-commands',
options: {
command: 'echo THREE',
},
dependsOn: ['two'],
};
return c;
});
const output = runCLI(`one ${mylib} --no-deps`);
expect(output).toContain('ONE');
expect(output).not.toContain('TWO');
expect(output).not.toContain('THREE');
});
});
describe('Nx Bail', () => {

View File

@ -32,7 +32,7 @@ export async function affected(
(TargetDependencyConfig | string)[]
> = {},
extraOptions = {
excludeTaskDependencies: false,
excludeTaskDependencies: args.excludeTaskDependencies,
loadDotEnvFiles: process.env.NX_LOAD_DOT_ENV_FILES !== 'false',
} as {
excludeTaskDependencies: boolean;

View File

@ -79,7 +79,9 @@ export async function releasePublish(
* for dependencies, because that could cause projects outset of the filtered set to be published.
*/
const shouldExcludeTaskDependencies =
_args.projects?.length > 0 || _args.groups?.length > 0;
_args.projects?.length > 0 ||
_args.groups?.length > 0 ||
args.excludeTaskDependencies;
let overallExitStatus = 0;

View File

@ -26,7 +26,7 @@ export async function runMany(
(TargetDependencyConfig | string)[]
> = {},
extraOptions = {
excludeTaskDependencies: false,
excludeTaskDependencies: args.excludeTaskDependencies,
loadDotEnvFiles: process.env.NX_LOAD_DOT_ENV_FILES !== 'false',
} as {
excludeTaskDependencies: boolean;

View File

@ -28,7 +28,7 @@ export async function runOne(
(TargetDependencyConfig | string)[]
> = {},
extraOptions = {
excludeTaskDependencies: false,
excludeTaskDependencies: args.excludeTaskDependencies,
loadDotEnvFiles: process.env.NX_LOAD_DOT_ENV_FILES !== 'false',
} as {
excludeTaskDependencies: boolean;

View File

@ -27,6 +27,7 @@ export interface RunOptions {
dte: boolean;
batch: boolean;
useAgents: boolean;
excludeTaskDependencies: boolean;
}
export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
@ -79,6 +80,11 @@ export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
type: 'boolean',
default: false,
})
.options('excludeTaskDependencies', {
describe: 'Skips running dependent tasks first',
type: 'boolean',
default: false,
})
.options('cloud', {
type: 'boolean',
hidden: true,

View File

@ -50,8 +50,10 @@ export function createCommandGraph(
nxArgs: NxArgs
): CommandGraph {
const dependencies: Record<string, string[]> = {};
for (const projectName of projectNames) {
recursiveResolveDeps(projectGraph, projectName, dependencies);
if (!nxArgs.excludeTaskDependencies) {
for (const projectName of projectNames) {
recursiveResolveDeps(projectGraph, projectName, dependencies);
}
}
const roots = Object.keys(dependencies).filter(
(d) => dependencies[d].length === 0

View File

@ -36,6 +36,7 @@ export interface NxArgs {
nxIgnoreCycles?: boolean;
type?: string;
batch?: boolean;
excludeTaskDependencies?: boolean;
}
export function createOverrides(__overrides_unparsed__: string[] = []) {