@backstage/frontend-plugin-api 0.10.1 → 0.10.2-next.1
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.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @backstage/frontend-plugin-api
|
|
2
2
|
|
|
3
|
+
## 0.10.2-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/core-plugin-api@1.10.7-next.0
|
|
9
|
+
- @backstage/core-components@0.17.2-next.1
|
|
10
|
+
- @backstage/types@1.2.1
|
|
11
|
+
- @backstage/version-bridge@1.0.11
|
|
12
|
+
|
|
13
|
+
## 0.10.2-next.0
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- fb58f20: The `id` option of `createFrontendPlugin` has been renamed to `pluginId` in order to better align with similar APIs in the frontend and backend systems.
|
|
18
|
+
|
|
19
|
+
The old `id` option is deprecated and will be removed in a future release.
|
|
20
|
+
|
|
21
|
+
- 72d019d: Removed various typos
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
- @backstage/core-components@0.17.2-next.0
|
|
24
|
+
- @backstage/core-plugin-api@1.10.6
|
|
25
|
+
- @backstage/types@1.2.1
|
|
26
|
+
- @backstage/version-bridge@1.0.11
|
|
27
|
+
|
|
3
28
|
## 0.10.1
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -404,7 +404,7 @@ interface FrontendPlugin<TRoutes extends AnyRoutes = AnyRoutes, TExternalRoutes
|
|
|
404
404
|
}
|
|
405
405
|
/** @public */
|
|
406
406
|
interface PluginOptions<TId extends string, TRoutes extends AnyRoutes, TExternalRoutes extends AnyExternalRoutes, TExtensions extends readonly ExtensionDefinition[]> {
|
|
407
|
-
|
|
407
|
+
pluginId: TId;
|
|
408
408
|
routes?: TRoutes;
|
|
409
409
|
externalRoutes?: TExternalRoutes;
|
|
410
410
|
extensions?: TExtensions;
|
|
@@ -412,6 +412,13 @@ interface PluginOptions<TId extends string, TRoutes extends AnyRoutes, TExternal
|
|
|
412
412
|
}
|
|
413
413
|
/** @public */
|
|
414
414
|
declare function createFrontendPlugin<TId extends string, TRoutes extends AnyRoutes = {}, TExternalRoutes extends AnyExternalRoutes = {}, TExtensions extends readonly ExtensionDefinition[] = []>(options: PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>): FrontendPlugin<TRoutes, TExternalRoutes, MakeSortedExtensionsMap<TExtensions[number], TId>>;
|
|
415
|
+
/**
|
|
416
|
+
* @public
|
|
417
|
+
* @deprecated The `id` option is deprecated, use `pluginId` instead.
|
|
418
|
+
*/
|
|
419
|
+
declare function createFrontendPlugin<TId extends string, TRoutes extends AnyRoutes = {}, TExternalRoutes extends AnyExternalRoutes = {}, TExtensions extends readonly ExtensionDefinition[] = []>(options: Omit<PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>, 'pluginId'> & {
|
|
420
|
+
id: string;
|
|
421
|
+
}): FrontendPlugin<TRoutes, TExternalRoutes, MakeSortedExtensionsMap<TExtensions[number], TId>>;
|
|
415
422
|
|
|
416
423
|
/**
|
|
417
424
|
* Feature flag configuration.
|
|
@@ -3,15 +3,21 @@ import { OpaqueFrontendPlugin } from '../frontend-internal/src/wiring/InternalFr
|
|
|
3
3
|
import { OpaqueExtensionDefinition } from '../frontend-internal/src/wiring/InternalExtensionDefinition.esm.js';
|
|
4
4
|
|
|
5
5
|
function createFrontendPlugin(options) {
|
|
6
|
+
const pluginId = "pluginId" in options ? options.pluginId : options.id;
|
|
7
|
+
if (!pluginId) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"Either 'id' or 'pluginId' must be provided to createFrontendPlugin"
|
|
10
|
+
);
|
|
11
|
+
}
|
|
6
12
|
const extensions = new Array();
|
|
7
13
|
const extensionDefinitionsById = /* @__PURE__ */ new Map();
|
|
8
14
|
for (const def of options.extensions ?? []) {
|
|
9
15
|
const internal = OpaqueExtensionDefinition.toInternal(def);
|
|
10
|
-
const ext = resolveExtensionDefinition(def, { namespace:
|
|
16
|
+
const ext = resolveExtensionDefinition(def, { namespace: pluginId });
|
|
11
17
|
extensions.push(ext);
|
|
12
18
|
extensionDefinitionsById.set(ext.id, {
|
|
13
19
|
...internal,
|
|
14
|
-
namespace:
|
|
20
|
+
namespace: pluginId
|
|
15
21
|
});
|
|
16
22
|
}
|
|
17
23
|
if (extensions.length !== extensionDefinitionsById.size) {
|
|
@@ -22,13 +28,13 @@ function createFrontendPlugin(options) {
|
|
|
22
28
|
)
|
|
23
29
|
);
|
|
24
30
|
throw new Error(
|
|
25
|
-
`Plugin '${
|
|
31
|
+
`Plugin '${pluginId}' provided duplicate extensions: ${duplicates.join(
|
|
26
32
|
", "
|
|
27
33
|
)}`
|
|
28
34
|
);
|
|
29
35
|
}
|
|
30
36
|
return OpaqueFrontendPlugin.createInstance("v1", {
|
|
31
|
-
id:
|
|
37
|
+
id: pluginId,
|
|
32
38
|
routes: options.routes ?? {},
|
|
33
39
|
externalRoutes: options.externalRoutes ?? {},
|
|
34
40
|
featureFlags: options.featureFlags ?? [],
|
|
@@ -37,27 +43,28 @@ function createFrontendPlugin(options) {
|
|
|
37
43
|
const ext = extensionDefinitionsById.get(id);
|
|
38
44
|
if (!ext) {
|
|
39
45
|
throw new Error(
|
|
40
|
-
`Attempted to get non-existent extension '${id}' from plugin '${
|
|
46
|
+
`Attempted to get non-existent extension '${id}' from plugin '${pluginId}'`
|
|
41
47
|
);
|
|
42
48
|
}
|
|
43
49
|
return ext;
|
|
44
50
|
},
|
|
45
51
|
toString() {
|
|
46
|
-
return `Plugin{id=${
|
|
52
|
+
return `Plugin{id=${pluginId}}`;
|
|
47
53
|
},
|
|
48
54
|
withOverrides(overrides) {
|
|
49
55
|
const overriddenExtensionIds = new Set(
|
|
50
56
|
overrides.extensions.map(
|
|
51
|
-
(e) => resolveExtensionDefinition(e, { namespace:
|
|
57
|
+
(e) => resolveExtensionDefinition(e, { namespace: pluginId }).id
|
|
52
58
|
)
|
|
53
59
|
);
|
|
54
60
|
const nonOverriddenExtensions = (options.extensions ?? []).filter(
|
|
55
61
|
(e) => !overriddenExtensionIds.has(
|
|
56
|
-
resolveExtensionDefinition(e, { namespace:
|
|
62
|
+
resolveExtensionDefinition(e, { namespace: pluginId }).id
|
|
57
63
|
)
|
|
58
64
|
);
|
|
59
65
|
return createFrontendPlugin({
|
|
60
66
|
...options,
|
|
67
|
+
pluginId,
|
|
61
68
|
extensions: [...nonOverriddenExtensions, ...overrides.extensions]
|
|
62
69
|
});
|
|
63
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFrontendPlugin.esm.js","sources":["../../src/wiring/createFrontendPlugin.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 OpaqueExtensionDefinition,\n OpaqueFrontendPlugin,\n} from '@internal/frontend';\nimport { ExtensionDefinition } from './createExtension';\nimport {\n Extension,\n resolveExtensionDefinition,\n} from './resolveExtensionDefinition';\nimport { AnyExternalRoutes, AnyRoutes, FeatureFlagConfig } from './types';\nimport { MakeSortedExtensionsMap } from './MakeSortedExtensionsMap';\n\n/** @public */\nexport interface FrontendPlugin<\n TRoutes extends AnyRoutes = AnyRoutes,\n TExternalRoutes extends AnyExternalRoutes = AnyExternalRoutes,\n TExtensionMap extends { [id in string]: ExtensionDefinition } = {\n [id in string]: ExtensionDefinition;\n },\n> {\n readonly $$type: '@backstage/FrontendPlugin';\n readonly id: string;\n readonly routes: TRoutes;\n readonly externalRoutes: TExternalRoutes;\n getExtension<TId extends keyof TExtensionMap>(id: TId): TExtensionMap[TId];\n withOverrides(options: {\n extensions: Array<ExtensionDefinition>;\n }): FrontendPlugin<TRoutes, TExternalRoutes, TExtensionMap>;\n}\n\n/** @public */\nexport interface PluginOptions<\n TId extends string,\n TRoutes extends AnyRoutes,\n TExternalRoutes extends AnyExternalRoutes,\n TExtensions extends readonly ExtensionDefinition[],\n> {\n
|
|
1
|
+
{"version":3,"file":"createFrontendPlugin.esm.js","sources":["../../src/wiring/createFrontendPlugin.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 OpaqueExtensionDefinition,\n OpaqueFrontendPlugin,\n} from '@internal/frontend';\nimport { ExtensionDefinition } from './createExtension';\nimport {\n Extension,\n resolveExtensionDefinition,\n} from './resolveExtensionDefinition';\nimport { AnyExternalRoutes, AnyRoutes, FeatureFlagConfig } from './types';\nimport { MakeSortedExtensionsMap } from './MakeSortedExtensionsMap';\n\n/** @public */\nexport interface FrontendPlugin<\n TRoutes extends AnyRoutes = AnyRoutes,\n TExternalRoutes extends AnyExternalRoutes = AnyExternalRoutes,\n TExtensionMap extends { [id in string]: ExtensionDefinition } = {\n [id in string]: ExtensionDefinition;\n },\n> {\n readonly $$type: '@backstage/FrontendPlugin';\n readonly id: string;\n readonly routes: TRoutes;\n readonly externalRoutes: TExternalRoutes;\n getExtension<TId extends keyof TExtensionMap>(id: TId): TExtensionMap[TId];\n withOverrides(options: {\n extensions: Array<ExtensionDefinition>;\n }): FrontendPlugin<TRoutes, TExternalRoutes, TExtensionMap>;\n}\n\n/** @public */\nexport interface PluginOptions<\n TId extends string,\n TRoutes extends AnyRoutes,\n TExternalRoutes extends AnyExternalRoutes,\n TExtensions extends readonly ExtensionDefinition[],\n> {\n pluginId: TId;\n routes?: TRoutes;\n externalRoutes?: TExternalRoutes;\n extensions?: TExtensions;\n featureFlags?: FeatureFlagConfig[];\n}\n\n/** @public */\nexport function createFrontendPlugin<\n TId extends string,\n TRoutes extends AnyRoutes = {},\n TExternalRoutes extends AnyExternalRoutes = {},\n TExtensions extends readonly ExtensionDefinition[] = [],\n>(\n options: PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>,\n): FrontendPlugin<\n TRoutes,\n TExternalRoutes,\n MakeSortedExtensionsMap<TExtensions[number], TId>\n>;\n/**\n * @public\n * @deprecated The `id` option is deprecated, use `pluginId` instead.\n */\nexport function createFrontendPlugin<\n TId extends string,\n TRoutes extends AnyRoutes = {},\n TExternalRoutes extends AnyExternalRoutes = {},\n TExtensions extends readonly ExtensionDefinition[] = [],\n>(\n options: Omit<\n PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>,\n 'pluginId'\n > & { id: string },\n): FrontendPlugin<\n TRoutes,\n TExternalRoutes,\n MakeSortedExtensionsMap<TExtensions[number], TId>\n>;\nexport function createFrontendPlugin<\n TId extends string,\n TRoutes extends AnyRoutes = {},\n TExternalRoutes extends AnyExternalRoutes = {},\n TExtensions extends readonly ExtensionDefinition[] = [],\n>(\n options:\n | PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>\n | (Omit<\n PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>,\n 'pluginId'\n > & { id: string }),\n): FrontendPlugin<\n TRoutes,\n TExternalRoutes,\n MakeSortedExtensionsMap<TExtensions[number], TId>\n> {\n const pluginId = 'pluginId' in options ? options.pluginId : options.id;\n if (!pluginId) {\n throw new Error(\n \"Either 'id' or 'pluginId' must be provided to createFrontendPlugin\",\n );\n }\n const extensions = new Array<Extension<any>>();\n const extensionDefinitionsById = new Map<\n string,\n typeof OpaqueExtensionDefinition.TInternal\n >();\n\n for (const def of options.extensions ?? []) {\n const internal = OpaqueExtensionDefinition.toInternal(def);\n const ext = resolveExtensionDefinition(def, { namespace: pluginId });\n extensions.push(ext);\n extensionDefinitionsById.set(ext.id, {\n ...internal,\n namespace: pluginId,\n });\n }\n\n if (extensions.length !== extensionDefinitionsById.size) {\n const extensionIds = extensions.map(e => e.id);\n const duplicates = Array.from(\n new Set(\n extensionIds.filter((id, index) => extensionIds.indexOf(id) !== index),\n ),\n );\n // TODO(Rugvip): This could provide some more information about the kind + name of the extensions\n throw new Error(\n `Plugin '${pluginId}' provided duplicate extensions: ${duplicates.join(\n ', ',\n )}`,\n );\n }\n\n return OpaqueFrontendPlugin.createInstance('v1', {\n id: pluginId,\n routes: options.routes ?? ({} as TRoutes),\n externalRoutes: options.externalRoutes ?? ({} as TExternalRoutes),\n featureFlags: options.featureFlags ?? [],\n extensions: extensions,\n getExtension(id) {\n const ext = extensionDefinitionsById.get(id);\n if (!ext) {\n throw new Error(\n `Attempted to get non-existent extension '${id}' from plugin '${pluginId}'`,\n );\n }\n return ext;\n },\n toString() {\n return `Plugin{id=${pluginId}}`;\n },\n withOverrides(overrides) {\n const overriddenExtensionIds = new Set(\n overrides.extensions.map(\n e => resolveExtensionDefinition(e, { namespace: pluginId }).id,\n ),\n );\n const nonOverriddenExtensions = (options.extensions ?? []).filter(\n e =>\n !overriddenExtensionIds.has(\n resolveExtensionDefinition(e, { namespace: pluginId }).id,\n ),\n );\n return createFrontendPlugin({\n ...options,\n pluginId,\n extensions: [...nonOverriddenExtensions, ...overrides.extensions],\n });\n },\n });\n}\n"],"names":[],"mappings":";;;;AA4FO,SAAS,qBAMd,OAUA,EAAA;AACA,EAAA,MAAM,QAAW,GAAA,UAAA,IAAc,OAAU,GAAA,OAAA,CAAQ,WAAW,OAAQ,CAAA,EAAA;AACpE,EAAA,IAAI,CAAC,Q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.2-next.1",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "web-library"
|
|
6
6
|
},
|
|
@@ -31,20 +31,20 @@
|
|
|
31
31
|
"test": "backstage-cli package test"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@backstage/core-components": "
|
|
35
|
-
"@backstage/core-plugin-api": "
|
|
36
|
-
"@backstage/types": "
|
|
37
|
-
"@backstage/version-bridge": "
|
|
34
|
+
"@backstage/core-components": "0.17.2-next.1",
|
|
35
|
+
"@backstage/core-plugin-api": "1.10.7-next.0",
|
|
36
|
+
"@backstage/types": "1.2.1",
|
|
37
|
+
"@backstage/version-bridge": "1.0.11",
|
|
38
38
|
"@material-ui/core": "^4.12.4",
|
|
39
39
|
"lodash": "^4.17.21",
|
|
40
40
|
"zod": "^3.22.4",
|
|
41
41
|
"zod-to-json-schema": "^3.21.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@backstage/cli": "
|
|
45
|
-
"@backstage/frontend-app-api": "
|
|
46
|
-
"@backstage/frontend-test-utils": "
|
|
47
|
-
"@backstage/test-utils": "
|
|
44
|
+
"@backstage/cli": "0.32.1-next.2",
|
|
45
|
+
"@backstage/frontend-app-api": "0.11.2-next.2",
|
|
46
|
+
"@backstage/frontend-test-utils": "0.3.2-next.2",
|
|
47
|
+
"@backstage/test-utils": "1.7.8-next.1",
|
|
48
48
|
"@testing-library/jest-dom": "^6.0.0",
|
|
49
49
|
"@testing-library/react": "^16.0.0",
|
|
50
50
|
"@types/react": "^18.0.0",
|