Skip to content

Commit

Permalink
feat(core): add parallelism to target configuration (#26820)
Browse files Browse the repository at this point in the history
<!-- 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
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
xiongemi authored Jul 12, 2024
1 parent 37f0cca commit 39e104b
Show file tree
Hide file tree
Showing 24 changed files with 624 additions and 38 deletions.
10 changes: 10 additions & 0 deletions docs/generated/devkit/TargetConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Target's configuration
- [metadata](../../devkit/documents/TargetConfiguration#metadata): TargetMetadata
- [options](../../devkit/documents/TargetConfiguration#options): T
- [outputs](../../devkit/documents/TargetConfiguration#outputs): string[]
- [parallelism](../../devkit/documents/TargetConfiguration#parallelism): boolean

## Properties

Expand Down Expand Up @@ -109,3 +110,12 @@ Target's options. They are passed in to the executor.

List of the target's outputs. The outputs will be cached by the Nx computation
caching engine.

---

### parallelism

`Optional` **parallelism**: `boolean`

Whether this target can be run in parallel with other tasks
Default is true
9 changes: 9 additions & 0 deletions docs/generated/devkit/Task.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ A representation of the invocation of an Executor
- [id](../../devkit/documents/Task#id): string
- [outputs](../../devkit/documents/Task#outputs): string[]
- [overrides](../../devkit/documents/Task#overrides): any
- [parallelism](../../devkit/documents/Task#parallelism): boolean
- [projectRoot](../../devkit/documents/Task#projectroot): string
- [startTime](../../devkit/documents/Task#starttime): number
- [target](../../devkit/documents/Task#target): Object
Expand Down Expand Up @@ -84,6 +85,14 @@ Overrides for the configured options of the target

---

### parallelism

**parallelism**: `boolean`

Determines if a given task should be parallelizable.

---

### projectRoot

`Optional` **projectRoot**: `string`
Expand Down
4 changes: 4 additions & 0 deletions packages/cypress/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('@nx/cypress/plugin', () => {
"{projectRoot}/dist/videos",
"{projectRoot}/dist/screenshots",
],
"parallelism": false,
},
"open-cypress": {
"command": "cypress open",
Expand Down Expand Up @@ -329,6 +330,7 @@ describe('@nx/cypress/plugin', () => {
"{projectRoot}/dist/videos",
"{projectRoot}/dist/screenshots",
],
"parallelism": false,
},
"e2e-ci": {
"cache": true,
Expand Down Expand Up @@ -369,6 +371,7 @@ describe('@nx/cypress/plugin', () => {
"{projectRoot}/dist/videos",
"{projectRoot}/dist/screenshots",
],
"parallelism": false,
},
"e2e-ci--src/test.cy.ts": {
"cache": true,
Expand Down Expand Up @@ -404,6 +407,7 @@ describe('@nx/cypress/plugin', () => {
"{projectRoot}/dist/videos",
"{projectRoot}/dist/screenshots",
],
"parallelism": false,
},
"open-cypress": {
"command": "cypress open",
Expand Down
3 changes: 3 additions & 0 deletions packages/cypress/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ async function buildCypressTargets(
cache: true,
inputs: getInputs(namedInputs),
outputs: getOutputs(projectRoot, cypressConfig, 'e2e'),
parallelism: false,
metadata: {
technologies: ['cypress'],
description: 'Runs Cypress Tests',
Expand Down Expand Up @@ -276,6 +277,7 @@ async function buildCypressTargets(
options: {
cwd: projectRoot,
},
parallelism: false,
metadata: {
technologies: ['cypress'],
description: `Runs Cypress Tests in ${relativeSpecFilePath} in CI`,
Expand All @@ -300,6 +302,7 @@ async function buildCypressTargets(
inputs,
outputs,
dependsOn,
parallelism: false,
metadata: {
technologies: ['cypress'],
description: 'Runs Cypress Tests in CI',
Expand Down
13 changes: 13 additions & 0 deletions packages/js/src/utils/buildable-libs-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,30 +389,35 @@ describe('calculateDependenciesFromTaskGraph', () => {
overrides: {},
target: { project: 'lib1', target: 'build' },
outputs: [],
parallelism: true,
},
'lib2:build': {
id: 'lib2:build',
overrides: {},
target: { project: 'lib2', target: 'build' },
outputs: [],
parallelism: true,
},
'lib2:build-base': {
id: 'lib2:build-base',
overrides: {},
target: { project: 'lib2', target: 'build-base' },
outputs: [],
parallelism: true,
},
'lib3:build': {
id: 'lib3:build',
overrides: {},
target: { project: 'lib3', target: 'build' },
outputs: [],
parallelism: true,
},
'lib4:build': {
id: 'lib4:build',
overrides: {},
target: { project: 'lib4', target: 'build' },
outputs: [],
parallelism: true,
},
},
};
Expand Down Expand Up @@ -559,48 +564,56 @@ describe('calculateDependenciesFromTaskGraph', () => {
overrides: {},
target: { project: 'lib1', target: 'build' },
outputs: [],
parallelism: true,
},
'lib1:build-base': {
id: 'lib1:build-base',
overrides: {},
target: { project: 'lib1', target: 'build-base' },
outputs: [],
parallelism: true,
},
'lib2:build': {
id: 'lib2:build',
overrides: {},
target: { project: 'lib2', target: 'build' },
outputs: [],
parallelism: true,
},
'lib2:build-base': {
id: 'lib2:build-base',
overrides: {},
target: { project: 'lib2', target: 'build-base' },
outputs: [],
parallelism: true,
},
'lib3:build': {
id: 'lib3:build',
overrides: {},
target: { project: 'lib3', target: 'build' },
outputs: [],
parallelism: true,
},
'lib3:build-base': {
id: 'lib3:build-base',
overrides: {},
target: { project: 'lib3', target: 'build-base' },
outputs: [],
parallelism: true,
},
'lib4:build': {
id: 'lib4:build',
overrides: {},
target: { project: 'lib4', target: 'build' },
outputs: [],
parallelism: true,
},
'lib4:build-base': {
id: 'lib4:build-base',
overrides: {},
target: { project: 'lib4', target: 'build-base' },
outputs: [],
parallelism: true,
},
},
};
Expand Down
26 changes: 26 additions & 0 deletions packages/nx/schemas/project-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@
"title": "JSON schema for Nx projects",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Project's name. Optional if specified in workspace.json"
},
"root": {
"type": "string",
"description": "Project's location relative to the root of the workspace"
},
"sourceRoot": {
"type": "string",
"description": "The location of project's sources relative to the root of the workspace"
},
"projectType": {
"type": "string",
"description": "Type of project supported",
"enum": ["library", "application"]
},
"generators": {
"type": "object",
"description": "List of default values used by generators"
},
"namedInputs": {
"type": "object",
"description": "Named inputs used by inputs defined in targets",
Expand Down Expand Up @@ -112,6 +133,11 @@
"cache": {
"type": "boolean",
"description": "Specifies if the given target should be cacheable"
},
"parallelism": {
"type": "boolean",
"default": true,
"description": "Whether this target can be run in parallel with other tasks"
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/nx/src/config/task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export interface Task {
* Determines if a given task should be cacheable.
*/
cache?: boolean;

/**
* Determines if a given task should be parallelizable.
*/
parallelism: boolean;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/nx/src/config/to-project-name.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe('Workspaces', () => {
],
"executor": "@nx/js:release-publish",
"options": {},
"parallelism": true,
},
},
}
Expand Down
6 changes: 6 additions & 0 deletions packages/nx/src/config/workspace-json-project-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,10 @@ export interface TargetConfiguration<T = any> {
* Metadata about the target
*/
metadata?: TargetMetadata;

/**
* Whether this target can be run in parallel with other tasks
* Default is true
*/
parallelism?: boolean;
}
Loading

0 comments on commit 39e104b

Please sign in to comment.