Skip to content

Commit

Permalink
feat(core): allow specifying cacheability per target
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Oct 17, 2023
1 parent 81e8d12 commit 992cbaf
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
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

0 comments on commit 992cbaf

Please sign in to comment.