Use opaque types for command graph nodes

Switch CommandGraph and CliInitializer to use OpaqueCommandTreeNode and
OpaqueCommandLeafNode from @internal/cli instead of raw $$type markers.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-03-12 22:27:33 +01:00
parent 28a438a9f2
commit a90939e138
4 changed files with 146 additions and 59 deletions
@@ -0,0 +1,54 @@
/*
* Copyright 2024 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.
*/
import { BackstageCommand } from '@backstage/cli-plugin-api';
import { OpaqueType } from '@internal/opaque';
/** @internal */
export interface CommandTreeNode {
readonly $$type: '@backstage/CommandTreeNode';
}
/** @internal */
export interface CommandLeafNode {
readonly $$type: '@backstage/CommandLeafNode';
}
export type CommandNode = CommandTreeNode | CommandLeafNode;
export const OpaqueCommandTreeNode = OpaqueType.create<{
public: CommandTreeNode;
versions: {
readonly version: 'v1';
readonly name: string;
readonly children: CommandNode[];
};
}>({
type: '@backstage/CommandTreeNode',
versions: ['v1'],
});
export const OpaqueCommandLeafNode = OpaqueType.create<{
public: CommandLeafNode;
versions: {
readonly version: 'v1';
readonly name: string;
readonly command: BackstageCommand;
};
}>({
type: '@backstage/CommandLeafNode',
versions: ['v1'],
});
+9
View File
@@ -15,3 +15,12 @@
*/
export { OpaqueCliPlugin } from './InternalCliPlugin';
export type {
CommandNode,
CommandTreeNode,
CommandLeafNode,
} from './InternalCommandNode';
export {
OpaqueCommandTreeNode,
OpaqueCommandLeafNode,
} from './InternalCommandNode';