Update default schema locator for frontend plugins...

... to match the frontend location of plugins built as module federation remotes.

Signed-off-by: David Festal <dfestal@redhat.com>
This commit is contained in:
David Festal
2025-01-22 19:58:09 +01:00
parent 9c4f72b2db
commit b07bff44eb
3 changed files with 50 additions and 22 deletions
@@ -0,0 +1,27 @@
{
"schemas": [
{
"packageName": "plugin-test-dynamic",
"path": "./test-dynamic",
"value": {
"type": "object",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"test-frontend": {
"type": "object",
"required": [
"frontendValue"
],
"properties": {
"frontendValue": {
"type": "string",
"visibility": "frontend"
}
}
}
}
}
}
],
"backstageConfigSchemaVersion": 1
}
@@ -1,18 +0,0 @@
{
"type": "object",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"test-frontend": {
"type": "object",
"required": [
"frontendValue"
],
"properties": {
"frontendValue": {
"type": "string",
"visibility": "frontend"
}
}
}
}
}
@@ -29,8 +29,13 @@ import { isEmpty } from 'lodash';
import { LoggerService } from '@backstage/backend-plugin-api';
import { JsonObject } from '@backstage/types';
import { PluginScanner } from '../scanner/plugin-scanner';
import { ConfigSchema, loadConfigSchema } from '@backstage/config-loader';
import {
ConfigSchema,
loadConfigSchema,
mergeConfigSchemas,
} from '@backstage/config-loader';
import { dynamicPluginsFeatureLoader } from '../features';
import { PackageRoles } from '@backstage/cli-node';
/**
*
@@ -152,8 +157,16 @@ export const dynamicPluginsSchemasServiceFactory = Object.assign(
async function gatherDynamicPluginsSchemas(
packages: ScannedPluginPackage[],
logger: LoggerService,
schemaLocator: (pluginPackage: ScannedPluginPackage) => string = () =>
path.join('dist', 'configSchema.json'),
schemaLocator: (
pluginPackage: ScannedPluginPackage,
) => string = pluginPackage =>
path.join(
'dist',
PackageRoles.getRoleInfo(pluginPackage.manifest.backstage.role)
.platform === 'node'
? 'configSchema.json'
: '.config-schema.json',
),
): Promise<{ [context: string]: JsonObject }> {
const allSchemas: { [context: string]: JsonObject } = {};
@@ -169,7 +182,7 @@ async function gatherDynamicPluginsSchemas(
continue;
}
const serialized = await fs.readJson(schemaLocation);
let serialized = await fs.readJson(schemaLocation);
if (!serialized) {
continue;
}
@@ -178,6 +191,12 @@ async function gatherDynamicPluginsSchemas(
continue;
}
if (serialized?.backstageConfigSchemaVersion === 1) {
serialized = mergeConfigSchemas(
(serialized?.schemas as JsonObject[]).map(_ => _.value as any),
);
}
if (!serialized?.$schema || serialized?.type !== 'object') {
logger.error(
`Serialized configuration schema is invalid for plugin ${pluginPackage.manifest.name}`,