diff --git a/docs/generated/devkit/TargetConfiguration.md b/docs/generated/devkit/TargetConfiguration.md index 251878c7850c0..20d8f68ceac5d 100644 --- a/docs/generated/devkit/TargetConfiguration.md +++ b/docs/generated/devkit/TargetConfiguration.md @@ -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` diff --git a/docs/generated/devkit/TargetDefaults.md b/docs/generated/devkit/TargetDefaults.md index 6bb0ccfefcdc0..56198a1e8a837 100644 --- a/docs/generated/devkit/TargetDefaults.md +++ b/docs/generated/devkit/TargetDefaults.md @@ -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)\>\> diff --git a/packages/nx/schemas/project-schema.json b/packages/nx/schemas/project-schema.json index 0ef64a6417d4f..ece8fde307032 100644 --- a/packages/nx/schemas/project-schema.json +++ b/packages/nx/schemas/project-schema.json @@ -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" } } } diff --git a/packages/nx/schemas/workspace-schema.json b/packages/nx/schemas/workspace-schema.json index 3b31a61fd6f0c..2cd72f6d94098 100644 --- a/packages/nx/schemas/workspace-schema.json +++ b/packages/nx/schemas/workspace-schema.json @@ -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" } } } diff --git a/packages/nx/src/config/nx-json.ts b/packages/nx/src/config/nx-json.ts index c1c1504afbf79..1abe6235872a6 100644 --- a/packages/nx/src/config/nx-json.ts +++ b/packages/nx/src/config/nx-json.ts @@ -25,16 +25,7 @@ export interface NxAffectedConfig { defaultBase?: string; } -export type TargetDefaults = Record< - string, - Partial & { - /** - * Determines if Nx is able to cache a given target. - * Currently only supported in `targetDefaults`. - */ - cache?: boolean; - } ->; +export type TargetDefaults = Record>; export type TargetDependencies = Record< string, diff --git a/packages/nx/src/config/workspace-json-project-json.ts b/packages/nx/src/config/workspace-json-project-json.ts index 86a2904908a1f..f2e150cb96327 100644 --- a/packages/nx/src/config/workspace-json-project-json.ts +++ b/packages/nx/src/config/workspace-json-project-json.ts @@ -181,4 +181,9 @@ export interface TargetConfiguration { * 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; } diff --git a/packages/nx/src/tasks-runner/utils.ts b/packages/nx/src/tasks-runner/utils.ts index d709a094d0b82..aa56a6c71e06f 100644 --- a/packages/nx/src/tasks-runner/utils.ts +++ b/packages/nx/src/tasks-runner/utils.ts @@ -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; }