refactor(frontend-app-api): to inline validation
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -161,38 +161,6 @@ export function createExtensionTree(options: {
|
||||
};
|
||||
}
|
||||
|
||||
function hasCyclicalExtensionDependency(
|
||||
extensionId: string,
|
||||
extensionAncestorIds: string[] = [],
|
||||
) {
|
||||
return extensionAncestorIds.includes(extensionId);
|
||||
}
|
||||
|
||||
function stringifyExtensionDependencyGraph(
|
||||
extensionId: string,
|
||||
extensionAncestorIds: string[] = [],
|
||||
) {
|
||||
const [rootAncestorId, ...rest] = extensionAncestorIds.concat(extensionId);
|
||||
return rest.reduce((graphString, ancestorId) => {
|
||||
return `${graphString} → ${ancestorId}`;
|
||||
}, rootAncestorId);
|
||||
}
|
||||
|
||||
function preventCyclicalExtensionDependency(
|
||||
extensionId: string,
|
||||
extensionAncestorIds: string[],
|
||||
) {
|
||||
if (hasCyclicalExtensionDependency(extensionId, extensionAncestorIds)) {
|
||||
const extensionDependencyGraph = stringifyExtensionDependencyGraph(
|
||||
extensionId,
|
||||
extensionAncestorIds,
|
||||
);
|
||||
throw new Error(
|
||||
`There is a cyclical dependency with the extension "${extensionId}": ${extensionDependencyGraph}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@@ -248,7 +216,15 @@ export function createInstances(options: {
|
||||
return existingInstance;
|
||||
}
|
||||
|
||||
preventCyclicalExtensionDependency(extensionId, extensionAncestorIds);
|
||||
// Prevent cyclical dependencies
|
||||
if (extensionAncestorIds.includes(extensionId)) {
|
||||
const extensionDependencyGraph = extensionAncestorIds
|
||||
.concat(extensionId)
|
||||
.join(' → ');
|
||||
throw new Error(
|
||||
`There is a cyclical dependency with the extension "${extensionId}": ${extensionDependencyGraph}`,
|
||||
);
|
||||
}
|
||||
|
||||
const attachments = new Map(
|
||||
Array.from(attachmentMap.get(extensionId)?.entries() ?? []).map(
|
||||
|
||||
@@ -188,14 +188,6 @@ export interface ExtensionInstanceParameters {
|
||||
config?: unknown;
|
||||
}
|
||||
|
||||
function preventRootExtensionOverride(id: string) {
|
||||
if (id === 'root') {
|
||||
throw new Error(
|
||||
'There is a root extension in the app config file and root extensions are not configurable',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function mergeExtensionParameters(options: {
|
||||
sources: BackstagePlugin[];
|
||||
@@ -229,7 +221,14 @@ export function mergeExtensionParameters(options: {
|
||||
|
||||
for (const overrideParam of parameters) {
|
||||
const extensionId = overrideParam.id;
|
||||
preventRootExtensionOverride(extensionId);
|
||||
|
||||
// Prevent root parametrization
|
||||
if (extensionId === 'root') {
|
||||
throw new Error(
|
||||
'There is a root extension in the app config file and root extensions are not configurable',
|
||||
);
|
||||
}
|
||||
|
||||
const existingIndex = overrides.findIndex(
|
||||
e => e.extension.id === extensionId,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user