From 6fcb9231a092e595fa25a87adbb4fdf53effc00d Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Fri, 27 Sep 2024 14:38:33 +0100 Subject: [PATCH] feat(core): add support for community cache. --- docs/generated/devkit/NxJsonConfiguration.md | 9 +++++++++ docs/generated/devkit/Workspace.md | 13 +++++++++++++ packages/nx/src/adapter/compat.ts | 1 + packages/nx/src/config/nx-json.ts | 5 +++++ packages/nx/src/tasks-runner/cache.ts | 7 ++++--- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/docs/generated/devkit/NxJsonConfiguration.md b/docs/generated/devkit/NxJsonConfiguration.md index 93d50df8a539f..d1f6f4f198115 100644 --- a/docs/generated/devkit/NxJsonConfiguration.md +++ b/docs/generated/devkit/NxJsonConfiguration.md @@ -21,6 +21,7 @@ Nx.json configuration - [affected](../../devkit/documents/NxJsonConfiguration#affected): NxAffectedConfig - [cacheDirectory](../../devkit/documents/NxJsonConfiguration#cachedirectory): string - [cli](../../devkit/documents/NxJsonConfiguration#cli): Object +- [communityCache](../../devkit/documents/NxJsonConfiguration#communitycache): string - [defaultBase](../../devkit/documents/NxJsonConfiguration#defaultbase): string - [defaultProject](../../devkit/documents/NxJsonConfiguration#defaultproject): string - [enableDbCache](../../devkit/documents/NxJsonConfiguration#enabledbcache): boolean @@ -82,6 +83,14 @@ Default generator collection. It is used when no collection is provided. --- +### communityCache + +• `Optional` **communityCache**: `string` + +community support for custom cache + +--- + ### defaultBase • `Optional` **defaultBase**: `string` diff --git a/docs/generated/devkit/Workspace.md b/docs/generated/devkit/Workspace.md index 1778f5ba0af7d..1455a253e4b35 100644 --- a/docs/generated/devkit/Workspace.md +++ b/docs/generated/devkit/Workspace.md @@ -19,6 +19,7 @@ use ProjectsConfigurations or NxJsonConfiguration - [affected](../../devkit/documents/Workspace#affected): NxAffectedConfig - [cacheDirectory](../../devkit/documents/Workspace#cachedirectory): string - [cli](../../devkit/documents/Workspace#cli): Object +- [communityCache](../../devkit/documents/Workspace#communitycache): string - [defaultBase](../../devkit/documents/Workspace#defaultbase): string - [defaultProject](../../devkit/documents/Workspace#defaultproject): string - [enableDbCache](../../devkit/documents/Workspace#enabledbcache): boolean @@ -94,6 +95,18 @@ Default generator collection. It is used when no collection is provided. --- +### communityCache + +• `Optional` **communityCache**: `string` + +community support for custom cache + +#### Inherited from + +[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[communityCache](../../devkit/documents/NxJsonConfiguration#communitycache) + +--- + ### defaultBase • `Optional` **defaultBase**: `string` diff --git a/packages/nx/src/adapter/compat.ts b/packages/nx/src/adapter/compat.ts index f24befda7e90a..929ee4a464c7e 100644 --- a/packages/nx/src/adapter/compat.ts +++ b/packages/nx/src/adapter/compat.ts @@ -81,6 +81,7 @@ export const allowedWorkspaceExtensions = [ 'neverConnectToCloud', 'sync', 'enableDbCache', + 'communityCache', ] as const; if (!patched) { diff --git a/packages/nx/src/config/nx-json.ts b/packages/nx/src/config/nx-json.ts index 4848d417d817d..0d85a1e20debc 100644 --- a/packages/nx/src/config/nx-json.ts +++ b/packages/nx/src/config/nx-json.ts @@ -519,6 +519,11 @@ export interface NxJsonConfiguration { * Enable the new experimental db based cache */ enableDbCache?: boolean; + + /** + * community support for custom cache + */ + communityCache?: string; } export type PluginConfiguration = string | ExpandedPluginConfiguration; diff --git a/packages/nx/src/tasks-runner/cache.ts b/packages/nx/src/tasks-runner/cache.ts index 3416e555b817b..db3cf1ed7bd0d 100644 --- a/packages/nx/src/tasks-runner/cache.ts +++ b/packages/nx/src/tasks-runner/cache.ts @@ -152,6 +152,7 @@ export class DbCache { } } else { return ( + (await this.getCustomCache(nxJson.communityCache)) ?? (await this.getPowerpackS3Cache()) ?? (await this.getPowerpackSharedCache()) ?? null @@ -160,14 +161,14 @@ export class DbCache { } private getPowerpackS3Cache(): Promise { - return this.getPowerpackCache('@nx/powerpack-s3-cache'); + return this.getCustomCache('@nx/powerpack-s3-cache'); } private getPowerpackSharedCache(): Promise { - return this.getPowerpackCache('@nx/powerpack-shared-fs-cache'); + return this.getCustomCache('@nx/powerpack-shared-fs-cache'); } - private async getPowerpackCache(pkg: string): Promise { + private async getCustomCache(pkg: string): Promise { let getRemoteCache = null; try { getRemoteCache = (await import(this.resolvePackage(pkg))).getRemoteCache;