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

This commit is contained in:
Craigory Coppola 2023-10-17 20:14:39 -04:00 committed by GitHub
parent 7d095d59ad
commit 2a18fd1f3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 16 deletions

View File

@ -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
@ -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`

View File

@ -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)\>\>

View File

@ -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"
}
}
}

View File

@ -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"
}
}
}

View File

@ -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,

View File

@ -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;
}

View File

@ -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;
}