@backstage/backend-app-api 0.5.0-next.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @backstage/backend-app-api might be problematic. Click here for more details.
- package/CHANGELOG.md +51 -0
- package/alpha/package.json +6 -0
- package/dist/alpha.cjs.js +89 -0
- package/dist/alpha.cjs.js.map +1 -0
- package/dist/alpha.d.ts +7 -0
- package/dist/index.cjs.js +550 -315
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/package.json +27 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @backstage/backend-app-api
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b9c57a4f857e: **BREAKING**: Renamed `configServiceFactory` to `rootConfigServiceFactory`.
|
|
8
|
+
- a6d7983f349c: **BREAKING**: Removed the `services` option from `createBackend`. Service factories are now `BackendFeature`s and should be installed with `backend.add(...)` instead. The following should be migrated:
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
const backend = createBackend({ services: [myCustomServiceFactory] });
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
To instead pass the service factory via `backend.add(...)`:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
const backend = createBackend();
|
|
18
|
+
backend.add(customRootLoggerServiceFactory);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- e65c4896f755: Do not throw in backend.stop, if start failed
|
|
24
|
+
- c7aa4ff1793c: Allow modules to register extension points.
|
|
25
|
+
- 57a10c6c69cc: Add validation to make sure that extension points do not cross plugin boundaries.
|
|
26
|
+
- cc9256a33bcc: Added new experimental `featureDiscoveryServiceFactory`, available as an `/alpha` export.
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
- @backstage/backend-common@0.19.2
|
|
29
|
+
- @backstage/config-loader@1.4.0
|
|
30
|
+
- @backstage/backend-plugin-api@0.6.0
|
|
31
|
+
- @backstage/cli-node@0.1.3
|
|
32
|
+
- @backstage/plugin-auth-node@0.2.17
|
|
33
|
+
- @backstage/backend-tasks@0.5.5
|
|
34
|
+
- @backstage/plugin-permission-node@0.7.11
|
|
35
|
+
- @backstage/cli-common@0.1.12
|
|
36
|
+
- @backstage/config@1.0.8
|
|
37
|
+
- @backstage/errors@1.2.1
|
|
38
|
+
- @backstage/types@1.1.0
|
|
39
|
+
|
|
40
|
+
## 0.5.0-next.2
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- e65c4896f755: Do not throw in backend.stop, if start failed
|
|
45
|
+
- cc9256a33bcc: Added new experimental `featureDiscoveryServiceFactory`, available as an `/alpha` export.
|
|
46
|
+
- Updated dependencies
|
|
47
|
+
- @backstage/backend-plugin-api@0.6.0-next.2
|
|
48
|
+
- @backstage/backend-tasks@0.5.5-next.2
|
|
49
|
+
- @backstage/backend-common@0.19.2-next.2
|
|
50
|
+
- @backstage/plugin-permission-node@0.7.11-next.2
|
|
51
|
+
- @backstage/plugin-auth-node@0.2.17-next.2
|
|
52
|
+
- @backstage/config-loader@1.4.0-next.1
|
|
53
|
+
|
|
3
54
|
## 0.5.0-next.1
|
|
4
55
|
|
|
5
56
|
### Minor Changes
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
|
+
var alpha = require('@backstage/backend-plugin-api/alpha');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var fs = require('fs-extra');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
13
|
+
|
|
14
|
+
const LOADED_PACKAGE_ROLES = ["backend-plugin", "backend-module"];
|
|
15
|
+
async function findClosestPackageDir(searchDir) {
|
|
16
|
+
let path$1 = searchDir;
|
|
17
|
+
for (let i = 0; i < 1e3; i++) {
|
|
18
|
+
const packagePath = path.resolve(path$1, "package.json");
|
|
19
|
+
const exists = await fs__default["default"].pathExists(packagePath);
|
|
20
|
+
if (exists) {
|
|
21
|
+
return path$1;
|
|
22
|
+
}
|
|
23
|
+
const newPath = path.dirname(path$1);
|
|
24
|
+
if (newPath === path$1) {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
path$1 = newPath;
|
|
28
|
+
}
|
|
29
|
+
throw new Error(
|
|
30
|
+
`Iteration limit reached when searching for root package.json at ${searchDir}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
class PackageDiscoveryService {
|
|
34
|
+
constructor(config) {
|
|
35
|
+
this.config = config;
|
|
36
|
+
}
|
|
37
|
+
async getBackendFeatures() {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
if (this.config.getOptionalString("backend.packages") !== "all") {
|
|
40
|
+
return { features: [] };
|
|
41
|
+
}
|
|
42
|
+
const packageDir = await findClosestPackageDir(process.argv[1]);
|
|
43
|
+
if (!packageDir) {
|
|
44
|
+
throw new Error("Package discovery failed to find package.json");
|
|
45
|
+
}
|
|
46
|
+
const { dependencies } = require(path.resolve(
|
|
47
|
+
packageDir,
|
|
48
|
+
"package.json"
|
|
49
|
+
));
|
|
50
|
+
const dependencyNames = Object.keys(dependencies || {});
|
|
51
|
+
const features = [];
|
|
52
|
+
for (const name of dependencyNames) {
|
|
53
|
+
const depPkg = require(require.resolve(`${name}/package.json`, {
|
|
54
|
+
paths: [packageDir]
|
|
55
|
+
}));
|
|
56
|
+
if (!LOADED_PACKAGE_ROLES.includes((_b = (_a = depPkg == null ? void 0 : depPkg.backstage) == null ? void 0 : _a.role) != null ? _b : "")) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const depModule = require(require.resolve(name, { paths: [packageDir] }));
|
|
60
|
+
for (const exportValue of Object.values(depModule)) {
|
|
61
|
+
if (isBackendFeature(exportValue)) {
|
|
62
|
+
features.push(exportValue);
|
|
63
|
+
}
|
|
64
|
+
if (isBackendFeatureFactory(exportValue)) {
|
|
65
|
+
features.push(exportValue());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { features };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const featureDiscoveryServiceFactory = backendPluginApi.createServiceFactory({
|
|
73
|
+
service: alpha.featureDiscoveryServiceRef,
|
|
74
|
+
deps: {
|
|
75
|
+
config: backendPluginApi.coreServices.rootConfig
|
|
76
|
+
},
|
|
77
|
+
factory({ config }) {
|
|
78
|
+
return new PackageDiscoveryService(config);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
function isBackendFeature(value) {
|
|
82
|
+
return !!value && typeof value === "object" && value.$$type === "@backstage/BackendFeature";
|
|
83
|
+
}
|
|
84
|
+
function isBackendFeatureFactory(value) {
|
|
85
|
+
return !!value && typeof value === "function" && value.$$type === "@backstage/BackendFeatureFactory";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exports.featureDiscoveryServiceFactory = featureDiscoveryServiceFactory;
|
|
89
|
+
//# sourceMappingURL=alpha.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alpha.cjs.js","sources":["../src/alpha/featureDiscoveryServiceFactory.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n BackendFeature,\n RootConfigService,\n coreServices,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport {\n featureDiscoveryServiceRef,\n FeatureDiscoveryService,\n} from '@backstage/backend-plugin-api/alpha';\nimport { resolve as resolvePath, dirname } from 'path';\nimport fs from 'fs-extra';\nimport { BackstagePackageJson } from '@backstage/cli-node';\n\nconst LOADED_PACKAGE_ROLES = ['backend-plugin', 'backend-module'];\n\n/** @internal */\nasync function findClosestPackageDir(\n searchDir: string,\n): Promise<string | undefined> {\n let path = searchDir;\n\n // Some confidence check to avoid infinite loop\n for (let i = 0; i < 1000; i++) {\n const packagePath = resolvePath(path, 'package.json');\n const exists = await fs.pathExists(packagePath);\n if (exists) {\n return path;\n }\n\n const newPath = dirname(path);\n if (newPath === path) {\n return undefined;\n }\n path = newPath;\n }\n\n throw new Error(\n `Iteration limit reached when searching for root package.json at ${searchDir}`,\n );\n}\n\n/** @internal */\nclass PackageDiscoveryService implements FeatureDiscoveryService {\n constructor(private readonly config: RootConfigService) {}\n\n async getBackendFeatures(): Promise<{ features: Array<BackendFeature> }> {\n if (this.config.getOptionalString('backend.packages') !== 'all') {\n return { features: [] };\n }\n\n const packageDir = await findClosestPackageDir(process.argv[1]);\n if (!packageDir) {\n throw new Error('Package discovery failed to find package.json');\n }\n const { dependencies } = require(resolvePath(\n packageDir,\n 'package.json',\n )) as BackstagePackageJson;\n const dependencyNames = Object.keys(dependencies || {});\n\n const features: BackendFeature[] = [];\n\n for (const name of dependencyNames) {\n const depPkg = require(require.resolve(`${name}/package.json`, {\n paths: [packageDir],\n })) as BackstagePackageJson;\n if (!LOADED_PACKAGE_ROLES.includes(depPkg?.backstage?.role ?? '')) {\n continue;\n }\n const depModule = require(require.resolve(name, { paths: [packageDir] }));\n for (const exportValue of Object.values(depModule)) {\n if (isBackendFeature(exportValue)) {\n features.push(exportValue);\n }\n if (isBackendFeatureFactory(exportValue)) {\n features.push(exportValue());\n }\n }\n }\n\n return { features };\n }\n}\n\n/** @alpha */\nexport const featureDiscoveryServiceFactory = createServiceFactory({\n service: featureDiscoveryServiceRef,\n deps: {\n config: coreServices.rootConfig,\n },\n factory({ config }) {\n return new PackageDiscoveryService(config);\n },\n});\n\nfunction isBackendFeature(value: unknown): value is BackendFeature {\n return (\n !!value &&\n typeof value === 'object' &&\n (value as BackendFeature).$$type === '@backstage/BackendFeature'\n );\n}\n\nfunction isBackendFeatureFactory(\n value: unknown,\n): value is () => BackendFeature {\n return (\n !!value &&\n typeof value === 'function' &&\n (value as any).$$type === '@backstage/BackendFeatureFactory'\n );\n}\n"],"names":["path","resolvePath","fs","dirname","createServiceFactory","featureDiscoveryServiceRef","coreServices"],"mappings":";;;;;;;;;;;;;AA8BA,MAAM,oBAAA,GAAuB,CAAC,gBAAA,EAAkB,gBAAgB,CAAA,CAAA;AAGhE,eAAe,sBACb,SAC6B,EAAA;AAC7B,EAAA,IAAIA,MAAO,GAAA,SAAA,CAAA;AAGX,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,GAAA,EAAM,CAAK,EAAA,EAAA;AAC7B,IAAM,MAAA,WAAA,GAAcC,YAAY,CAAAD,MAAA,EAAM,cAAc,CAAA,CAAA;AACpD,IAAA,MAAM,MAAS,GAAA,MAAME,sBAAG,CAAA,UAAA,CAAW,WAAW,CAAA,CAAA;AAC9C,IAAA,IAAI,MAAQ,EAAA;AACV,MAAO,OAAAF,MAAA,CAAA;AAAA,KACT;AAEA,IAAM,MAAA,OAAA,GAAUG,aAAQH,MAAI,CAAA,CAAA;AAC5B,IAAA,IAAI,YAAYA,MAAM,EAAA;AACpB,MAAO,OAAA,KAAA,CAAA,CAAA;AAAA,KACT;AACA,IAAOA,MAAA,GAAA,OAAA,CAAA;AAAA,GACT;AAEA,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,mEAAmE,SAAS,CAAA,CAAA;AAAA,GAC9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+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import { FeatureDiscoveryService } from '@backstage/backend-plugin-api/alpha';
|
|
3
|
+
|
|
4
|
+
/** @alpha */
|
|
5
|
+
declare const featureDiscoveryServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<FeatureDiscoveryService, "root">;
|
|
6
|
+
|
|
7
|
+
export { featureDiscoveryServiceFactory };
|