chore: some renames and supporting both formats
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -22,7 +22,7 @@ import { AppContextProvider } from '../../../core-app-api/src/app/AppContext';
|
||||
import { RouteResolver } from '../../../core-plugin-api/src/routing/useRouteRef';
|
||||
import {
|
||||
createFrontendPlugin as createNewPlugin,
|
||||
BackstagePlugin as NewBackstagePlugin,
|
||||
FrontendPlugin as NewFrontendPlugin,
|
||||
appTreeApiRef,
|
||||
componentsApiRef,
|
||||
coreComponentRefs,
|
||||
@@ -47,11 +47,11 @@ import { convertLegacyRouteRef } from '../convertLegacyRouteRef';
|
||||
// Make sure that we only convert each new plugin instance to its legacy equivalent once
|
||||
const legacyPluginStore = getOrCreateGlobalSingleton(
|
||||
'legacy-plugin-compatibility-store',
|
||||
() => new WeakMap<NewBackstagePlugin, LegacyBackstagePlugin>(),
|
||||
() => new WeakMap<NewFrontendPlugin, LegacyBackstagePlugin>(),
|
||||
);
|
||||
|
||||
export function toLegacyPlugin(
|
||||
plugin: NewBackstagePlugin,
|
||||
plugin: NewFrontendPlugin,
|
||||
): LegacyBackstagePlugin {
|
||||
let legacy = legacyPluginStore.get(plugin);
|
||||
if (legacy) {
|
||||
@@ -83,7 +83,7 @@ export function toLegacyPlugin(
|
||||
}
|
||||
|
||||
// TODO: Currently a very naive implementation, may need some more work
|
||||
function toNewPlugin(plugin: LegacyBackstagePlugin): NewBackstagePlugin {
|
||||
function toNewPlugin(plugin: LegacyBackstagePlugin): NewFrontendPlugin {
|
||||
return createNewPlugin({
|
||||
id: plugin.getId(),
|
||||
});
|
||||
|
||||
@@ -46,7 +46,10 @@ describe('RouteTracker', () => {
|
||||
caseSensitive: false,
|
||||
children: [MATCH_ALL_ROUTE],
|
||||
appNode: {
|
||||
spec: { extension: { id: 'home.page.index' }, source: { id: 'home' } },
|
||||
spec: {
|
||||
extension: { id: 'home.page.index' },
|
||||
source: { id: 'home' },
|
||||
},
|
||||
} as AppNode,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -49,7 +49,7 @@ export function collectRouteIds(features: FrontendFeature[]): RouteRefsById {
|
||||
}
|
||||
|
||||
for (const [name, ref] of Object.entries(feature.routes)) {
|
||||
const refId = `${feature.pluginId}.${name}`;
|
||||
const refId = `${feature.id}.${name}`;
|
||||
if (routesById.has(refId)) {
|
||||
throw new Error(`Unexpected duplicate route '${refId}'`);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export function collectRouteIds(features: FrontendFeature[]): RouteRefsById {
|
||||
}
|
||||
}
|
||||
for (const [name, ref] of Object.entries(feature.externalRoutes)) {
|
||||
const refId = `${feature.pluginId}.${name}`;
|
||||
const refId = `${feature.id}.${name}`;
|
||||
if (externalRoutesById.has(refId)) {
|
||||
throw new Error(`Unexpected duplicate external route '${refId}'`);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ export function resolveAppNodeSpecs(options: {
|
||||
if (pluginExtensions.some(({ id }) => forbidden.has(id))) {
|
||||
const pluginsStr = pluginExtensions
|
||||
.filter(({ id }) => forbidden.has(id))
|
||||
.map(({ source }) => `'${source.pluginId}'`)
|
||||
.map(({ source }) => `'${source.id}'`)
|
||||
.join(', ');
|
||||
const forbiddenStr = [...forbidden].map(id => `'${id}'`).join(', ');
|
||||
throw new Error(
|
||||
@@ -156,7 +156,7 @@ export function resolveAppNodeSpecs(options: {
|
||||
const extensionId = extension.id;
|
||||
const extensionData = data?.[extensionId];
|
||||
if (extensionData) duplicatedExtensionIds.add(extensionId);
|
||||
const pluginId = params.source?.pluginId ?? 'internal';
|
||||
const pluginId = params.source?.id ?? 'internal';
|
||||
const pluginCount = extensionData?.[pluginId] ?? 0;
|
||||
return {
|
||||
...data,
|
||||
|
||||
@@ -100,10 +100,10 @@ function deduplicateFeatures(
|
||||
if (!isInternalFrontendPlugin(feature)) {
|
||||
return true;
|
||||
}
|
||||
if (seenIds.has(feature.pluginId)) {
|
||||
if (seenIds.has(feature.id)) {
|
||||
return false;
|
||||
}
|
||||
seenIds.add(feature.pluginId);
|
||||
seenIds.add(feature.id);
|
||||
return true;
|
||||
})
|
||||
.reverse();
|
||||
@@ -330,7 +330,7 @@ export function createSpecializedApp(options?: {
|
||||
toInternalFrontendPlugin(feature).featureFlags.forEach(flag =>
|
||||
featureFlagApi.registerFlag({
|
||||
name: flag.name,
|
||||
pluginId: feature.pluginId,
|
||||
pluginId: feature.id,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ export interface FrontendPlugin<
|
||||
TExtensionMap extends { [id in string]: ExtensionDefinition } = {},
|
||||
> {
|
||||
readonly $$type: '@backstage/FrontendPlugin';
|
||||
readonly pluginId: string;
|
||||
readonly id: string;
|
||||
readonly routes: TRoutes;
|
||||
readonly externalRoutes: TExternalRoutes;
|
||||
getExtension<TId extends keyof TExtensionMap>(id: TId): TExtensionMap[TId];
|
||||
@@ -59,9 +59,7 @@ export interface PluginOptions<
|
||||
TExternalRoutes extends AnyExternalRoutes,
|
||||
TExtensions extends readonly ExtensionDefinition[],
|
||||
> {
|
||||
/** @deprecated use `pluginId` instead */
|
||||
id?: TId;
|
||||
pluginId?: TId;
|
||||
id: TId;
|
||||
routes?: TRoutes;
|
||||
externalRoutes?: TExternalRoutes;
|
||||
extensions?: TExtensions;
|
||||
@@ -96,11 +94,6 @@ export function createFrontendPlugin<
|
||||
>]: KExtension;
|
||||
}
|
||||
> {
|
||||
const pluginId = options.pluginId ?? options.id;
|
||||
if (!pluginId) {
|
||||
throw new Error('No pluginId provided to createFrontendPlugin');
|
||||
}
|
||||
|
||||
const extensions = new Array<Extension<any>>();
|
||||
const extensionDefinitionsById = new Map<
|
||||
string,
|
||||
@@ -109,11 +102,11 @@ export function createFrontendPlugin<
|
||||
|
||||
for (const def of options.extensions ?? []) {
|
||||
const internal = toInternalExtensionDefinition(def);
|
||||
const ext = resolveExtensionDefinition(def, { namespace: pluginId });
|
||||
const ext = resolveExtensionDefinition(def, { namespace: options.id });
|
||||
extensions.push(ext);
|
||||
extensionDefinitionsById.set(ext.id, {
|
||||
...internal,
|
||||
namespace: pluginId,
|
||||
namespace: options.id,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -126,7 +119,7 @@ export function createFrontendPlugin<
|
||||
);
|
||||
// TODO(Rugvip): This could provide some more information about the kind + name of the extensions
|
||||
throw new Error(
|
||||
`Plugin '${pluginId}' provided duplicate extensions: ${duplicates.join(
|
||||
`Plugin '${options.id}' provided duplicate extensions: ${duplicates.join(
|
||||
', ',
|
||||
)}`,
|
||||
);
|
||||
@@ -135,8 +128,7 @@ export function createFrontendPlugin<
|
||||
return {
|
||||
$$type: '@backstage/FrontendPlugin',
|
||||
version: 'v1',
|
||||
id: pluginId, // TODO: Backwards compat to be able to install in older apps, remove after 1.31
|
||||
pluginId,
|
||||
id: options.id, // TODO: Backwards compat to be able to install in older apps, remove after 1.31
|
||||
routes: options.routes ?? ({} as TRoutes),
|
||||
externalRoutes: options.externalRoutes ?? ({} as TExternalRoutes),
|
||||
featureFlags: options.featureFlags ?? [],
|
||||
@@ -145,18 +137,18 @@ export function createFrontendPlugin<
|
||||
return extensionDefinitionsById.get(id);
|
||||
},
|
||||
toString() {
|
||||
return `Plugin{id=${pluginId}}`;
|
||||
return `Plugin{id=${options.id}}`;
|
||||
},
|
||||
withOverrides(overrides) {
|
||||
const overriddenExtensionIds = new Set(
|
||||
overrides.extensions.map(
|
||||
e => resolveExtensionDefinition(e, { namespace: pluginId }).id,
|
||||
e => resolveExtensionDefinition(e, { namespace: options.id }).id,
|
||||
),
|
||||
);
|
||||
const nonOverriddenExtensions = (options.extensions ?? []).filter(
|
||||
e =>
|
||||
!overriddenExtensionIds.has(
|
||||
resolveExtensionDefinition(e, { namespace: pluginId }).id,
|
||||
resolveExtensionDefinition(e, { namespace: options.id }).id,
|
||||
),
|
||||
);
|
||||
return createFrontendPlugin({
|
||||
@@ -175,7 +167,7 @@ export function isInternalFrontendPlugin(opaque: {
|
||||
opaque.$$type === '@backstage/FrontendPlugin' ||
|
||||
opaque.$$type === '@backstage/BackstagePlugin'
|
||||
) {
|
||||
// Throw if invalid + mutate
|
||||
// Make sure we throw if invalid
|
||||
toInternalFrontendPlugin(opaque as FrontendPlugin);
|
||||
return true;
|
||||
}
|
||||
@@ -198,10 +190,6 @@ export function toInternalFrontendPlugin(
|
||||
`Invalid plugin instance, bad version '${internal.version}'`,
|
||||
);
|
||||
}
|
||||
// Backwards compatibility to support old plugins defined with just an .id
|
||||
if (!internal.pluginId) {
|
||||
(internal as any).pluginId = (internal as any).id;
|
||||
}
|
||||
return internal;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user