backend-plugin-api: removed the deprecated featureDiscoveryServiceRef
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 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.
|
||||
*/
|
||||
|
||||
export { featureDiscoveryServiceFactory } from './alpha/featureDiscoveryServiceFactory';
|
||||
@@ -1,328 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 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 {
|
||||
startTestBackend,
|
||||
mockServices,
|
||||
createMockDirectory,
|
||||
} from '@backstage/backend-test-utils';
|
||||
import { featureDiscoveryServiceFactory } from './featureDiscoveryServiceFactory';
|
||||
|
||||
const mockDir = createMockDirectory();
|
||||
process.argv[1] = mockDir.path;
|
||||
|
||||
const pluginApiPath = require.resolve('@backstage/backend-plugin-api');
|
||||
|
||||
describe('featureDiscoveryServiceFactory', () => {
|
||||
beforeEach(() => {
|
||||
mockDir.setContent({
|
||||
'package.json': JSON.stringify({
|
||||
name: 'example-app',
|
||||
dependencies: {
|
||||
'detected-plugin': '0.0.0',
|
||||
'detected-module': '0.0.0',
|
||||
'detected-plugin-with-alpha': '0.0.0',
|
||||
'detected-library': '0.0.0',
|
||||
},
|
||||
}),
|
||||
'node_modules/detected-plugin': {
|
||||
'package.json': JSON.stringify({
|
||||
name: 'detected-plugin',
|
||||
main: 'index.js',
|
||||
backstage: {
|
||||
role: 'backend-plugin',
|
||||
},
|
||||
}),
|
||||
'index.js': `
|
||||
const { createBackendPlugin, coreServices } = require('${pluginApiPath}');
|
||||
exports.default = createBackendPlugin({
|
||||
pluginId: 'detected',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: { logger: coreServices.rootLogger },
|
||||
async init({ logger }) {
|
||||
logger.warn('detected-plugin');
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
`,
|
||||
},
|
||||
'node_modules/detected-module': {
|
||||
'package.json': JSON.stringify({
|
||||
name: 'detected-module',
|
||||
main: 'index.js',
|
||||
backstage: {
|
||||
role: 'backend-plugin-module',
|
||||
},
|
||||
}),
|
||||
'index.js': `
|
||||
const { createBackendModule, coreServices } = require('${pluginApiPath}');
|
||||
exports.default = createBackendModule({
|
||||
pluginId: 'detected',
|
||||
moduleId: 'derp',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: { logger: coreServices.rootLogger },
|
||||
async init({ logger }) {
|
||||
logger.warn('detected-module');
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
`,
|
||||
},
|
||||
'node_modules/detected-plugin-with-alpha': {
|
||||
'package.json': JSON.stringify({
|
||||
name: 'detected-plugin-with-alpha',
|
||||
main: 'index.js',
|
||||
exports: {
|
||||
'.': {
|
||||
default: 'index.js',
|
||||
},
|
||||
'./alpha': {
|
||||
default: 'alpha.js',
|
||||
},
|
||||
'./package.json': './package.json',
|
||||
},
|
||||
backstage: {
|
||||
role: 'backend-plugin',
|
||||
},
|
||||
}),
|
||||
'index.js': `exports.default = undefined;`,
|
||||
'alpha.js': `
|
||||
const { createBackendPlugin, coreServices } = require('${pluginApiPath}');
|
||||
exports.default = createBackendPlugin({
|
||||
pluginId: 'detected-alpha',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: { logger: coreServices.rootLogger },
|
||||
async init({ logger }) {
|
||||
logger.warn('detected-plugin-with-alpha');
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
`,
|
||||
},
|
||||
'node_modules/detected-library': {
|
||||
'package.json': JSON.stringify({
|
||||
name: 'detected-library',
|
||||
main: 'index.js',
|
||||
backstage: {
|
||||
role: 'node-library',
|
||||
},
|
||||
}),
|
||||
'index.js': `
|
||||
const { createServiceFactory, createServiceRef, coreServices } = require('${pluginApiPath}');
|
||||
exports.default = createServiceFactory({
|
||||
service: createServiceRef({ id: 'test', scope: 'root' }),
|
||||
deps: { logger: coreServices.rootLogger },
|
||||
factory({ logger }) {
|
||||
logger.warn('detected-library');
|
||||
return {};
|
||||
},
|
||||
});
|
||||
`,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should detect plugin and module packages when "all" is specified', async () => {
|
||||
const mock = mockServices.rootLogger.mock({ child: () => mock });
|
||||
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: { backend: { packages: 'all' } },
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-plugin');
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-module');
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-plugin-with-alpha');
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-library');
|
||||
});
|
||||
|
||||
it('detects only the packages that are listed as included', async () => {
|
||||
const mock = mockServices.rootLogger.mock({ child: () => mock });
|
||||
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
backend: {
|
||||
packages: {
|
||||
include: [
|
||||
'detected-plugin',
|
||||
'detected-plugin-with-alpha',
|
||||
'detected-library',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-plugin');
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-plugin-with-alpha');
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-library');
|
||||
expect(mock.warn).not.toHaveBeenCalledWith('detected-module');
|
||||
});
|
||||
|
||||
it('does not detect packages when included is an empty list', async () => {
|
||||
const mock = mockServices.rootLogger.mock({ child: () => mock });
|
||||
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
backend: {
|
||||
packages: {
|
||||
include: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(mock.warn).not.toHaveBeenCalledWith('detected-plugin');
|
||||
expect(mock.warn).not.toHaveBeenCalledWith('detected-plugin-with-alpha');
|
||||
expect(mock.warn).not.toHaveBeenCalledWith('detected-module');
|
||||
expect(mock.warn).not.toHaveBeenCalledWith('detected-library');
|
||||
});
|
||||
|
||||
it('does not detect an excluded packages', async () => {
|
||||
const mock = mockServices.rootLogger.mock({ child: () => mock });
|
||||
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
backend: {
|
||||
packages: {
|
||||
exclude: ['detected-plugin', 'detected-module'],
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(mock.warn).not.toHaveBeenCalledWith('detected-plugin');
|
||||
expect(mock.warn).not.toHaveBeenCalledWith('detected-module');
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-plugin-with-alpha');
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-library');
|
||||
});
|
||||
|
||||
it('does not excluded packages when it is an empty list', async () => {
|
||||
const mock = mockServices.rootLogger.mock({ child: () => mock });
|
||||
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
backend: {
|
||||
packages: {
|
||||
exclude: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-plugin');
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-module');
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-plugin-with-alpha');
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-library');
|
||||
});
|
||||
|
||||
it('does not detect packages that are included and excluded', async () => {
|
||||
const mock = mockServices.rootLogger.mock({ child: () => mock });
|
||||
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
backend: {
|
||||
packages: {
|
||||
include: [
|
||||
'detected-plugin',
|
||||
'detected-module',
|
||||
'detected-plugin-with-alpha',
|
||||
],
|
||||
exclude: ['detected-module'],
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-plugin');
|
||||
expect(mock.warn).not.toHaveBeenCalledWith('detected-library');
|
||||
expect(mock.warn).not.toHaveBeenCalledWith('detected-module');
|
||||
expect(mock.warn).toHaveBeenCalledWith('detected-plugin-with-alpha');
|
||||
});
|
||||
|
||||
it('does not detect any packages when "packages" is empty', async () => {
|
||||
const mock = mockServices.rootLogger.mock({ child: () => mock });
|
||||
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: { backend: { packages: {} } },
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(mock.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not detect any packages when "packages" is not present', async () => {
|
||||
const mock = mockServices.rootLogger.mock({ child: () => mock });
|
||||
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: { backend: {} },
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(mock.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 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 {
|
||||
coreServices,
|
||||
createServiceFactory,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { featureDiscoveryServiceRef } from '@backstage/backend-plugin-api/alpha';
|
||||
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
|
||||
import { PackageDiscoveryService } from '../../../backend-defaults/src/PackageDiscoveryService';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
* @deprecated The `featureDiscoveryServiceFactory` is deprecated in favor of using {@link @backstage/backend-defaults#discoveryFeatureLoader} instead.
|
||||
*/
|
||||
export const featureDiscoveryServiceFactory = createServiceFactory({
|
||||
service: featureDiscoveryServiceRef,
|
||||
deps: {
|
||||
config: coreServices.rootConfig,
|
||||
logger: coreServices.rootLogger,
|
||||
},
|
||||
factory({ config, logger }) {
|
||||
return new PackageDiscoveryService(config, logger);
|
||||
},
|
||||
});
|
||||
@@ -37,7 +37,6 @@ import type { InternalServiceFactory } from '../../../backend-plugin-api/src/ser
|
||||
import { ForwardedError, ConflictError, assertError } from '@backstage/errors';
|
||||
import {
|
||||
instanceMetadataServiceRef,
|
||||
featureDiscoveryServiceRef,
|
||||
BackendFeatureMeta,
|
||||
} from '@backstage/backend-plugin-api/alpha';
|
||||
import { DependencyGraph } from '../lib/DependencyGraph';
|
||||
@@ -252,20 +251,6 @@ export class BackendInitializer {
|
||||
this.#addFeature(await feature);
|
||||
}
|
||||
|
||||
const featureDiscovery = await this.#serviceRegistry.get(
|
||||
// TODO: Let's leave this in place and remove it once the deprecated service is removed. We can do that post-1.0 since it's alpha
|
||||
featureDiscoveryServiceRef,
|
||||
'root',
|
||||
);
|
||||
|
||||
if (featureDiscovery) {
|
||||
const { features } = await featureDiscovery.getBackendFeatures();
|
||||
for (const feature of features) {
|
||||
this.#addFeature(unwrapFeature(feature));
|
||||
}
|
||||
this.#serviceRegistry.checkForCircularDeps();
|
||||
}
|
||||
|
||||
await this.#applyBackendFeatureLoaders(this.#registeredFeatureLoaders);
|
||||
|
||||
this.#serviceRegistry.add(
|
||||
|
||||
Reference in New Issue
Block a user