Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): allow specifying cacheability per target #19672

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/generated/devkit/TargetConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Target's configuration

### Properties

- [cache](../../devkit/documents/TargetConfiguration#cache): boolean
- [command](../../devkit/documents/TargetConfiguration#command): string
- [configurations](../../devkit/documents/TargetConfiguration#configurations): Object
- [defaultConfiguration](../../devkit/documents/TargetConfiguration#defaultconfiguration): string
Expand All @@ -23,6 +24,14 @@ Target's configuration

## Properties

### cache

• `Optional` **cache**: `boolean`

Determines if Nx is able to cache a given target.

---

### command

• `Optional` **command**: `string`
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/devkit/TargetDefaults.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Type alias: TargetDefaults

Ƭ **TargetDefaults**: `Record`<`string`, `Partial`<[`TargetConfiguration`](../../devkit/documents/TargetConfiguration)\> & { `cache?`: `boolean` }\>
Ƭ **TargetDefaults**: `Record`<`string`, `Partial`<[`TargetConfiguration`](../../devkit/documents/TargetConfiguration)\>\>
4 changes: 4 additions & 0 deletions packages/nx/schemas/project-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
"command": {
"type": "string",
"description": "A shorthand for using the nx:run-commands executor"
},
"cache": {
"type": "boolean",
"description": "Specifies if the given target should be cacheable"
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/nx/schemas/workspace-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
"command": {
"type": "string",
"description": "A shorthand for using the nx:run-commands executor"
},
"cache": {
"type": "boolean",
"description": "Specifies if the given target should be cacheable"
}
}
}
Expand Down
11 changes: 1 addition & 10 deletions packages/nx/src/config/nx-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ export interface NxAffectedConfig {
defaultBase?: string;
}

export type TargetDefaults = Record<
string,
Partial<TargetConfiguration> & {
/**
* Determines if Nx is able to cache a given target.
* Currently only supported in `targetDefaults`.
*/
cache?: boolean;
}
>;
export type TargetDefaults = Record<string, Partial<TargetConfiguration>>;

export type TargetDependencies = Record<
string,
Expand Down
5 changes: 5 additions & 0 deletions packages/nx/src/config/workspace-json-project-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,9 @@ export interface TargetConfiguration<T = any> {
* A default named configuration to use when a target configuration is not provided.
*/
defaultConfiguration?: string;

/**
* Determines if Nx is able to cache a given target.
*/
cache?: boolean;
}
6 changes: 1 addition & 5 deletions packages/nx/src/tasks-runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,7 @@ export function isCacheableTask(
cacheableTargets?: string[] | null;
}
): boolean {
if (
task.cache !== undefined &&
process.env.NX_ALLOW_PROJECT_LEVEL_CACHE === 'true' &&
!longRunningTask(task)
) {
if (task.cache !== undefined && !longRunningTask(task)) {
return task.cache;
}

Expand Down