add plugin id format warning on frontend framework
Signed-off-by: Juan Pablo Garcia Ripa <sarabadu@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/frontend-plugin-api': minor
|
||||
---
|
||||
|
||||
new deprecation warninf will be throw by the framework pluginId should have letters, digits,and dashes, starting with a letter
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-app-api': patch
|
||||
---
|
||||
|
||||
add test for new pluginId and moduleId format validations
|
||||
@@ -1,8 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-plugin-api': minor
|
||||
'@backstage/backend-app-api': minor
|
||||
'@backstage/config-loader': patch
|
||||
'@backstage/config': patch
|
||||
---
|
||||
|
||||
The backend will now throw an error if a plugin or a module doesn't have a valid ID
|
||||
@@ -11,10 +11,10 @@ As a rule, all names should be camel case, with the exceptions of plugin and mod
|
||||
|
||||
### Plugins
|
||||
|
||||
| Description | Pattern | Examples | Notes |
|
||||
| ----------- | ----------------- | ------------------------------------- | -------------------------------------------------- |
|
||||
| export | `<camelId>Plugin` | `catalogPlugin`, `userSettingsPlugin` | |
|
||||
| ID | `'<kebab-id>'` | `'catalog'`, `'user-settings'` | letters, digits,and dashes, starting with a letter |
|
||||
| Description | Pattern | Examples | Notes |
|
||||
| ----------- | ----------------- | ------------------------------------- | --------------------------------------------------- |
|
||||
| export | `<camelId>Plugin` | `catalogPlugin`, `userSettingsPlugin` | |
|
||||
| ID | `'<kebab-id>'` | `'catalog'`, `'user-settings'` | letters, digits, and dashes, starting with a letter |
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// NOTE: changing any of these constants need to be reflected in
|
||||
// @backstage/frontend-plugin-api/src/wiring/constants.ts as well
|
||||
|
||||
/**
|
||||
* The pattern that IDs must match.
|
||||
*
|
||||
|
||||
@@ -55,18 +55,18 @@ export interface CreateBackendModuleOptions {
|
||||
export function createBackendModule(
|
||||
options: CreateBackendModuleOptions,
|
||||
): BackendFeature {
|
||||
function getRegistrations() {
|
||||
if (!ID_PATTERN.test(options.moduleId)) {
|
||||
console.warn(
|
||||
`WARNING: The moduleId '${options.moduleId}' for plugin '${options.pluginId}', will be invalid soon please must match the pattern ${ID_PATTERN} (letters, digits, and dashes only, starting with a letter)`,
|
||||
);
|
||||
}
|
||||
if (!ID_PATTERN_OLD.test(options.moduleId)) {
|
||||
throw new Error(
|
||||
`Invalid moduleId '${options.moduleId}' for plugin '${options.pluginId}', must match the pattern ${ID_PATTERN} (letters, digits, and dashes only, starting with a letter)`,
|
||||
);
|
||||
}
|
||||
if (!ID_PATTERN.test(options.moduleId)) {
|
||||
console.warn(
|
||||
`WARNING: The moduleId '${options.moduleId}' for plugin '${options.pluginId}', will be invalid soon, please change it to match the pattern ${ID_PATTERN} (letters, digits, and dashes only, starting with a letter)`,
|
||||
);
|
||||
}
|
||||
if (!ID_PATTERN_OLD.test(options.moduleId)) {
|
||||
throw new Error(
|
||||
`Invalid moduleId '${options.moduleId}' for plugin '${options.pluginId}', must match the pattern ${ID_PATTERN} (letters, digits, and dashes only, starting with a letter)`,
|
||||
);
|
||||
}
|
||||
|
||||
function getRegistrations() {
|
||||
const extensionPoints: InternalBackendPluginRegistration['extensionPoints'] =
|
||||
[];
|
||||
let init: InternalBackendModuleRegistration['init'] | undefined = undefined;
|
||||
|
||||
@@ -49,18 +49,18 @@ export interface CreateBackendPluginOptions {
|
||||
export function createBackendPlugin(
|
||||
options: CreateBackendPluginOptions,
|
||||
): BackendFeature {
|
||||
function getRegistrations() {
|
||||
if (!ID_PATTERN.test(options.pluginId)) {
|
||||
console.warn(
|
||||
`WARNING: The pluginId '${options.pluginId}' will be invalid soon, please change it to match the pattern ${ID_PATTERN} (letters, digits, and dashes only, starting with a letter)`,
|
||||
);
|
||||
}
|
||||
if (!ID_PATTERN_OLD.test(options.pluginId)) {
|
||||
throw new Error(
|
||||
`Invalid pluginId '${options.pluginId}', must match the pattern ${ID_PATTERN} (letters, digits, and dashes only, starting with a letter)`,
|
||||
);
|
||||
}
|
||||
if (!ID_PATTERN.test(options.pluginId)) {
|
||||
console.warn(
|
||||
`WARNING: The pluginId '${options.pluginId}' will be invalid soon, please change it to match the pattern ${ID_PATTERN} (letters, digits, and dashes only, starting with a letter)`,
|
||||
);
|
||||
}
|
||||
if (!ID_PATTERN_OLD.test(options.pluginId)) {
|
||||
throw new Error(
|
||||
`Invalid pluginId '${options.pluginId}', must match the pattern ${ID_PATTERN} (letters, digits, and dashes only, starting with a letter)`,
|
||||
);
|
||||
}
|
||||
|
||||
function getRegistrations() {
|
||||
const extensionPoints: InternalBackendPluginRegistration['extensionPoints'] =
|
||||
[];
|
||||
let init: InternalBackendPluginRegistration['init'] | undefined = undefined;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2025 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.
|
||||
*/
|
||||
|
||||
// NOTE: changing any of these constants need to be reflected in
|
||||
// @backstage/backend-plugin-api/src/wiring/constants.ts as well
|
||||
|
||||
/**
|
||||
* The pattern that IDs must match.
|
||||
*
|
||||
* @remarks
|
||||
* ids must only contain the letters `a` through `z` and digits, in groups separated by
|
||||
* dashes. Additionally, the very first character of the first group
|
||||
* must be a letter, not a digit
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/i;
|
||||
@@ -30,6 +30,7 @@ import { FeatureFlagConfig } from './types';
|
||||
import { MakeSortedExtensionsMap } from './MakeSortedExtensionsMap';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { RouteRef, SubRouteRef, ExternalRouteRef } from '../routing';
|
||||
import { ID_PATTERN } from './constants';
|
||||
|
||||
/**
|
||||
* Information about the plugin.
|
||||
@@ -199,6 +200,13 @@ export function createFrontendPlugin<
|
||||
> {
|
||||
const pluginId = options.pluginId;
|
||||
|
||||
if (!ID_PATTERN.test(pluginId)) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
`WARNING: The pluginId '${pluginId}' will be invalid soon, please change it to match the pattern ${ID_PATTERN} (letters, digits, and dashes only, starting with a letter)`,
|
||||
);
|
||||
}
|
||||
|
||||
const extensions = new Array<Extension<any>>();
|
||||
const extensionDefinitionsById = new Map<
|
||||
string,
|
||||
|
||||
Reference in New Issue
Block a user