diff --git a/.changeset/forty-rice-visit.md b/.changeset/forty-rice-visit.md new file mode 100644 index 0000000000..a7da4b5a1e --- /dev/null +++ b/.changeset/forty-rice-visit.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-common': patch +--- + +Move `cache` implementation and types to the `@backstage/backend-defaults` package. diff --git a/.changeset/lemon-weeks-lay.md b/.changeset/lemon-weeks-lay.md new file mode 100644 index 0000000000..66d1402882 --- /dev/null +++ b/.changeset/lemon-weeks-lay.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-defaults': patch +--- + +Remove dependency with `@backstage/backend-commons` package. diff --git a/package.json b/package.json index 03b152d1e6..c1d099dd5f 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "jest-haste-map@^29.7.0": "patch:jest-haste-map@npm%3A29.7.0#./.yarn/patches/jest-haste-map-npm-29.7.0-e3be419eff.patch" }, "dependencies": { + "@backstage/backend-defaults": "workspace:^", "@backstage/errors": "workspace:^", "@manypkg/get-packages": "^1.1.3", "@useoptic/optic": "^0.50.10" diff --git a/packages/backend-common/api-report.md b/packages/backend-common/api-report.md index c8673da9d2..e259383320 100644 --- a/packages/backend-common/api-report.md +++ b/packages/backend-common/api-report.md @@ -17,9 +17,11 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { BitbucketCloudIntegration } from '@backstage/integration'; import { BitbucketIntegration } from '@backstage/integration'; import { BitbucketServerIntegration } from '@backstage/integration'; +import { CacheManager as CacheManager_2 } from '@backstage/backend-defaults/cache'; +import { CacheManagerOptions as CacheManagerOptions_2 } from '@backstage/backend-defaults/cache'; import { CacheService } from '@backstage/backend-plugin-api'; import { CacheServiceOptions } from '@backstage/backend-plugin-api'; -import type { CacheServiceSetOptions } from '@backstage/backend-plugin-api'; +import { CacheServiceSetOptions } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import cors from 'cors'; import { DiscoveryService } from '@backstage/backend-plugin-api'; @@ -43,6 +45,7 @@ import { Logger } from 'winston'; import { LoggerService } from '@backstage/backend-plugin-api'; import { MergeResult } from 'isomorphic-git'; import { PermissionsService } from '@backstage/backend-plugin-api'; +import { PluginCacheManager as PluginCacheManager_2 } from '@backstage/backend-defaults/cache'; import { DatabaseService as PluginDatabaseManager } from '@backstage/backend-plugin-api'; import { PluginMetadataService } from '@backstage/backend-plugin-api'; import { PushResult } from 'isomorphic-git'; @@ -119,25 +122,11 @@ export type CacheClientOptions = CacheServiceOptions; // @public @deprecated (undocumented) export type CacheClientSetOptions = CacheServiceSetOptions; -// @public -export class CacheManager { - forPlugin(pluginId: string): { - getClient(options?: CacheServiceOptions): CacheService; - }; - static fromConfig( - config: Config, - options?: { - logger?: LoggerService; - onError?: (err: Error) => void; - }, - ): CacheManager; -} +// @public @deprecated (undocumented) +export const CacheManager: typeof CacheManager_2; -// @public -export type CacheManagerOptions = { - logger?: LoggerService; - onError?: (err: Error) => void; -}; +// @public @deprecated (undocumented) +export type CacheManagerOptions = CacheManagerOptions_2; // @public export function cacheToPluginCacheManager(cache: CacheService): { @@ -471,11 +460,8 @@ export function makeLegacyPlugin< // @public @deprecated export function notFoundHandler(): RequestHandler; -// @public (undocumented) -export interface PluginCacheManager { - // (undocumented) - getClient(options?: CacheServiceOptions): CacheService; -} +// @public @deprecated (undocumented) +export type PluginCacheManager = PluginCacheManager_2; export { PluginDatabaseManager }; diff --git a/packages/backend-common/package.json b/packages/backend-common/package.json index 847fefa697..f0bbcc2a2b 100644 --- a/packages/backend-common/package.json +++ b/packages/backend-common/package.json @@ -59,6 +59,7 @@ "@aws-sdk/client-s3": "^3.350.0", "@aws-sdk/credential-providers": "^3.350.0", "@aws-sdk/types": "^3.347.0", + "@backstage/backend-defaults": "workspace:^", "@backstage/backend-dev-utils": "workspace:^", "@backstage/backend-plugin-api": "workspace:^", "@backstage/cli-common": "workspace:^", diff --git a/packages/backend-common/src/cache/index.ts b/packages/backend-common/src/cache/index.ts index 9d05745ebd..bdd857037b 100644 --- a/packages/backend-common/src/cache/index.ts +++ b/packages/backend-common/src/cache/index.ts @@ -15,5 +15,3 @@ */ export { cacheToPluginCacheManager } from './cacheToPluginCacheManager'; -export * from './reexport'; -export * from './types'; diff --git a/packages/backend-common/src/cache/reexport.ts b/packages/backend-common/src/cache/reexport.ts deleted file mode 100644 index 9f6106de60..0000000000 --- a/packages/backend-common/src/cache/reexport.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2024 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * NOTE(freben): This is a temporary hack. We use cross-package imports so that - * we do not have to maintain double implementations for the time being, until - * backend-common is properly removed. - */ - -// eslint-disable-next-line @backstage/no-relative-monorepo-imports -export { CacheManager } from '../../../backend-defaults/src/entrypoints/cache/CacheManager'; -// eslint-disable-next-line @backstage/no-relative-monorepo-imports -export { - type PluginCacheManager, - type CacheManagerOptions, -} from '../../../backend-defaults/src/entrypoints/cache/types'; diff --git a/packages/backend-common/src/cache/types.ts b/packages/backend-common/src/cache/types.ts deleted file mode 100644 index 83b6916843..0000000000 --- a/packages/backend-common/src/cache/types.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import type { - CacheService, - CacheServiceSetOptions, - CacheServiceOptions, -} from '@backstage/backend-plugin-api'; - -/** - * @public - * @deprecated Use `CacheService` from the `@backstage/backend-plugin-api` package instead - */ -export type CacheClient = CacheService; - -/** - * @public - * @deprecated Use `CacheServiceSetOptions` from the `@backstage/backend-plugin-api` package instead - */ -export type CacheClientSetOptions = CacheServiceSetOptions; - -/** - * @public - * @deprecated Use `CacheServiceOptions` from the `@backstage/backend-plugin-api` package instead - */ -export type CacheClientOptions = CacheServiceOptions; diff --git a/packages/backend-common/src/deprecated/index.ts b/packages/backend-common/src/deprecated/index.ts index d9ca795c3a..deb6c24a7f 100644 --- a/packages/backend-common/src/deprecated/index.ts +++ b/packages/backend-common/src/deprecated/index.ts @@ -17,12 +17,57 @@ export * from './scm'; import { + CacheManager as _CacheManager, + CacheManagerOptions as _CacheManagerOptions, + PluginCacheManager as _PluginCacheManager, +} from '@backstage/backend-defaults/cache'; + +import { + CacheService, + CacheServiceOptions, + CacheServiceSetOptions, isDatabaseConflictError as _isDatabaseConflictError, resolvePackagePath as _resolvePackagePath, resolveSafeChildPath as _resolveSafeChildPath, isChildPath as _isChildPath, } from '@backstage/backend-plugin-api'; +/** + * @public + * @deprecated Use `CacheManager` from the `@backstage/backend-defaults` package instead + */ +export const CacheManager = _CacheManager; + +/** + * @public + * @deprecated Use `CacheManagerOptions` from the `@backstage/backend-defaults` package instead + */ +export type CacheManagerOptions = _CacheManagerOptions; + +/** + * @public + * @deprecated Use `PluginCacheManager` from the `@backstage/backend-defaults` package instead + */ +export type PluginCacheManager = _PluginCacheManager; + +/** + * @public + * @deprecated Use `CacheService` from the `@backstage/backend-plugin-api` package instead + */ +export type CacheClient = CacheService; + +/** + * @public + * @deprecated Use `CacheServiceSetOptions` from the `@backstage/backend-plugin-api` package instead + */ +export type CacheClientSetOptions = CacheServiceSetOptions; + +/** + * @public + * @deprecated Use `CacheServiceOptions` from the `@backstage/backend-plugin-api` package instead + */ +export type CacheClientOptions = CacheServiceOptions; + /** * @public * @deprecated This function is deprecated and will be removed in a future release, see https://github.com/backstage/backstage/issues/24493. diff --git a/packages/backend-defaults/api-report-database.md b/packages/backend-defaults/api-report-database.md index 598a3bd1b0..728c228899 100644 --- a/packages/backend-defaults/api-report-database.md +++ b/packages/backend-defaults/api-report-database.md @@ -7,7 +7,6 @@ import { Config } from '@backstage/config'; import { DatabaseService } from '@backstage/backend-plugin-api'; import { LifecycleService } from '@backstage/backend-plugin-api'; import { LoggerService } from '@backstage/backend-plugin-api'; -import { PluginDatabaseManager } from '@backstage/backend-common'; import { PluginMetadataService } from '@backstage/backend-plugin-api'; import { ServiceFactory } from '@backstage/backend-plugin-api'; @@ -34,7 +33,7 @@ export type DatabaseManagerOptions = { // @public (undocumented) export const databaseServiceFactory: () => ServiceFactory< - PluginDatabaseManager, + DatabaseService, 'plugin' >; diff --git a/packages/backend-defaults/package.json b/packages/backend-defaults/package.json index 23c68625ca..2cdf30e0d2 100644 --- a/packages/backend-defaults/package.json +++ b/packages/backend-defaults/package.json @@ -88,7 +88,6 @@ "@aws-sdk/credential-providers": "^3.350.0", "@aws-sdk/types": "^3.347.0", "@backstage/backend-app-api": "workspace:^", - "@backstage/backend-common": "workspace:^", "@backstage/backend-dev-utils": "workspace:^", "@backstage/backend-plugin-api": "workspace:^", "@backstage/config": "workspace:^", diff --git a/packages/backend-defaults/src/entrypoints/database/databaseServiceFactory.ts b/packages/backend-defaults/src/entrypoints/database/databaseServiceFactory.ts index 12e4e569bd..eb38aed9f2 100644 --- a/packages/backend-defaults/src/entrypoints/database/databaseServiceFactory.ts +++ b/packages/backend-defaults/src/entrypoints/database/databaseServiceFactory.ts @@ -14,12 +14,12 @@ * limitations under the License. */ -import { DatabaseManager } from '@backstage/backend-common'; import { coreServices, createServiceFactory, } from '@backstage/backend-plugin-api'; import { ConfigReader } from '@backstage/config'; +import { DatabaseManager } from '../database'; /** * @public diff --git a/packages/backend-defaults/src/entrypoints/rootLifecycle/rootLifecycleServiceFactory.test.ts b/packages/backend-defaults/src/entrypoints/rootLifecycle/rootLifecycleServiceFactory.test.ts index 91cb9031ae..5992e38d50 100644 --- a/packages/backend-defaults/src/entrypoints/rootLifecycle/rootLifecycleServiceFactory.test.ts +++ b/packages/backend-defaults/src/entrypoints/rootLifecycle/rootLifecycleServiceFactory.test.ts @@ -14,12 +14,12 @@ * limitations under the License. */ -import { getVoidLogger } from '@backstage/backend-common'; import { BackendLifecycleImpl } from './rootLifecycleServiceFactory'; +import { mockServices } from '@backstage/backend-test-utils'; describe('lifecycleService', () => { it('should execute registered shutdown hook', async () => { - const service = new BackendLifecycleImpl(getVoidLogger()); + const service = new BackendLifecycleImpl(mockServices.logger.mock()); const hook = jest.fn(); service.addShutdownHook(() => hook()); // should not execute the hook more than once. @@ -30,7 +30,7 @@ describe('lifecycleService', () => { }); it('should not throw errors', async () => { - const service = new BackendLifecycleImpl(getVoidLogger()); + const service = new BackendLifecycleImpl(mockServices.logger.mock()); service.addShutdownHook(() => { throw new Error('oh no'); }); @@ -38,7 +38,7 @@ describe('lifecycleService', () => { }); it('should not throw async errors', async () => { - const service = new BackendLifecycleImpl(getVoidLogger()); + const service = new BackendLifecycleImpl(mockServices.logger.mock()); service.addShutdownHook(async () => { throw new Error('oh no'); }); @@ -46,7 +46,7 @@ describe('lifecycleService', () => { }); it('should reject hooks after trigger', async () => { - const service = new BackendLifecycleImpl(getVoidLogger()); + const service = new BackendLifecycleImpl(mockServices.logger.mock()); await service.startup(); expect(() => { service.addStartupHook(() => {}); diff --git a/packages/backend-defaults/src/entrypoints/scheduler/database/migrateBackendTasks.ts b/packages/backend-defaults/src/entrypoints/scheduler/database/migrateBackendTasks.ts index 959e6097f4..ab8b7a8e73 100644 --- a/packages/backend-defaults/src/entrypoints/scheduler/database/migrateBackendTasks.ts +++ b/packages/backend-defaults/src/entrypoints/scheduler/database/migrateBackendTasks.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { resolvePackagePath } from '@backstage/backend-common'; +import { resolvePackagePath } from '@backstage/backend-plugin-api'; import { Knex } from 'knex'; import { DB_MIGRATIONS_TABLE } from './tables'; diff --git a/packages/backend-defaults/src/entrypoints/scheduler/lib/LocalTaskWorker.test.ts b/packages/backend-defaults/src/entrypoints/scheduler/lib/LocalTaskWorker.test.ts index 4fd4949478..d4d3d16067 100644 --- a/packages/backend-defaults/src/entrypoints/scheduler/lib/LocalTaskWorker.test.ts +++ b/packages/backend-defaults/src/entrypoints/scheduler/lib/LocalTaskWorker.test.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import { getVoidLogger } from '@backstage/backend-common'; import { LocalTaskWorker } from './LocalTaskWorker'; +import { mockServices } from '@backstage/backend-test-utils'; describe('LocalTaskWorker', () => { - const logger = getVoidLogger(); + const logger = mockServices.logger.mock(); it('runs the happy path (with iso duration) and handles cancellation', async () => { const fn = jest.fn(); diff --git a/packages/backend-defaults/src/entrypoints/scheduler/lib/PluginTaskSchedulerImpl.test.ts b/packages/backend-defaults/src/entrypoints/scheduler/lib/PluginTaskSchedulerImpl.test.ts index 57faa6faf8..c5c4c8708a 100644 --- a/packages/backend-defaults/src/entrypoints/scheduler/lib/PluginTaskSchedulerImpl.test.ts +++ b/packages/backend-defaults/src/entrypoints/scheduler/lib/PluginTaskSchedulerImpl.test.ts @@ -14,8 +14,11 @@ * limitations under the License. */ -import { getVoidLogger } from '@backstage/backend-common'; -import { TestDatabaseId, TestDatabases } from '@backstage/backend-test-utils'; +import { + TestDatabaseId, + TestDatabases, + mockServices, +} from '@backstage/backend-test-utils'; import { ConflictError, NotFoundError } from '@backstage/errors'; import { Duration } from 'luxon'; import { migrateBackendTasks } from '../database/migrateBackendTasks'; @@ -53,7 +56,7 @@ describe('PluginTaskManagerImpl', () => { await migrateBackendTasks(knex); const manager = new PluginTaskSchedulerImpl( async () => knex, - getVoidLogger(), + mockServices.logger.mock(), ); return { knex, manager }; } diff --git a/packages/backend-defaults/src/entrypoints/scheduler/lib/PluginTaskSchedulerJanitor.test.ts b/packages/backend-defaults/src/entrypoints/scheduler/lib/PluginTaskSchedulerJanitor.test.ts index 82133a9e54..388f882afc 100644 --- a/packages/backend-defaults/src/entrypoints/scheduler/lib/PluginTaskSchedulerJanitor.test.ts +++ b/packages/backend-defaults/src/entrypoints/scheduler/lib/PluginTaskSchedulerJanitor.test.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { getVoidLogger } from '@backstage/backend-common'; -import { TestDatabases } from '@backstage/backend-test-utils'; +import { TestDatabases, mockServices } from '@backstage/backend-test-utils'; import { Knex } from 'knex'; import { Duration } from 'luxon'; import waitForExpect from 'wait-for-expect'; @@ -36,7 +35,7 @@ const getTask = async (knex: Knex): Promise => { }; describe('PluginTaskSchedulerJanitor', () => { - const logger = getVoidLogger(); + const logger = mockServices.logger.mock(); const databases = TestDatabases.create({ ids: [ /* 'MYSQL_8' not supported yet */ diff --git a/packages/backend-defaults/src/entrypoints/scheduler/lib/TaskWorker.test.ts b/packages/backend-defaults/src/entrypoints/scheduler/lib/TaskWorker.test.ts index 20d9b63859..1cafe00670 100644 --- a/packages/backend-defaults/src/entrypoints/scheduler/lib/TaskWorker.test.ts +++ b/packages/backend-defaults/src/entrypoints/scheduler/lib/TaskWorker.test.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { getVoidLogger } from '@backstage/backend-common'; -import { TestDatabases } from '@backstage/backend-test-utils'; +import { TestDatabases, mockServices } from '@backstage/backend-test-utils'; import { DateTime, Duration } from 'luxon'; import waitForExpect from 'wait-for-expect'; import { migrateBackendTasks } from '../database/migrateBackendTasks'; @@ -27,7 +26,7 @@ import { TaskSettingsV2 } from './types'; jest.setTimeout(60_000); describe('TaskWorker', () => { - const logger = getVoidLogger(); + const logger = mockServices.logger.mock(); const databases = TestDatabases.create(); const testScopedSignal = createTestScopedSignal(); diff --git a/packages/backend-defaults/src/index.ts b/packages/backend-defaults/src/index.ts index d3e36cf0fb..b00c865524 100644 --- a/packages/backend-defaults/src/index.ts +++ b/packages/backend-defaults/src/index.ts @@ -20,9 +20,4 @@ * @packageDocumentation */ -// This import is here as a workaround for a cyclic dependency bug where -// backend-common must be loaded before backend-app-api -// TODO(Rugvip): Remove this once backend-common is no longer used by backend-app-api -import '@backstage/backend-common'; - export { createBackend } from './CreateBackend'; diff --git a/yarn.lock b/yarn.lock index b7ef661552..2fa274021b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3518,6 +3518,7 @@ __metadata: "@aws-sdk/credential-providers": ^3.350.0 "@aws-sdk/types": ^3.347.0 "@aws-sdk/util-stream-node": ^3.350.0 + "@backstage/backend-defaults": "workspace:^" "@backstage/backend-dev-utils": "workspace:^" "@backstage/backend-plugin-api": "workspace:^" "@backstage/backend-test-utils": "workspace:^" @@ -3605,7 +3606,6 @@ __metadata: "@aws-sdk/types": ^3.347.0 "@aws-sdk/util-stream-node": ^3.350.0 "@backstage/backend-app-api": "workspace:^" - "@backstage/backend-common": "workspace:^" "@backstage/backend-dev-utils": "workspace:^" "@backstage/backend-plugin-api": "workspace:^" "@backstage/backend-test-utils": "workspace:^" @@ -39568,6 +39568,7 @@ __metadata: version: 0.0.0-use.local resolution: "root@workspace:." dependencies: + "@backstage/backend-defaults": "workspace:^" "@backstage/cli": "workspace:*" "@backstage/codemods": "workspace:*" "@backstage/create-app": "workspace:*"