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 ### Properties
- [cache](../../devkit/documents/TargetConfiguration#cache): boolean
- [command](../../devkit/documents/TargetConfiguration#command): string - [command](../../devkit/documents/TargetConfiguration#command): string
- [configurations](../../devkit/documents/TargetConfiguration#configurations): Object - [configurations](../../devkit/documents/TargetConfiguration#configurations): Object
- [defaultConfiguration](../../devkit/documents/TargetConfiguration#defaultconfiguration): string - [defaultConfiguration](../../devkit/documents/TargetConfiguration#defaultconfiguration): string
@ -23,6 +24,14 @@ Target's configuration
## Properties ## Properties
### cache
`Optional` **cache**: `boolean`
Determines if Nx is able to cache a given target.
---
### command ### command
`Optional` **command**: `string` `Optional` **command**: `string`

View File

@ -1,3 +1,3 @@
# Type alias: TargetDefaults # 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": { "command": {
"type": "string", "type": "string",
"description": "A shorthand for using the nx:run-commands executor" "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": { "command": {
"type": "string", "type": "string",
"description": "A shorthand for using the nx:run-commands executor" "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; defaultBase?: string;
} }
export type TargetDefaults = Record< export type TargetDefaults = Record<string, Partial<TargetConfiguration>>;
string,
Partial<TargetConfiguration> & {
/**
* Determines if Nx is able to cache a given target.
* Currently only supported in `targetDefaults`.
*/
cache?: boolean;
}
>;
export type TargetDependencies = Record< export type TargetDependencies = Record<
string, 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. * A default named configuration to use when a target configuration is not provided.
*/ */
defaultConfiguration?: string; 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; cacheableTargets?: string[] | null;
} }
): boolean { ): boolean {
if ( if (task.cache !== undefined && !longRunningTask(task)) {
task.cache !== undefined &&
process.env.NX_ALLOW_PROJECT_LEVEL_CACHE === 'true' &&
!longRunningTask(task)
) {
return task.cache; return task.cache;
} }