Address review feedback from freben

- Use cli-defaults instead of listing individual CLI modules in
  create-app template and root package.json
- Move nodeTransform config files from cli-module-build to cli-node
  to avoid cross-module direct imports
- Rename cli-module-create-github-app to cli-module-github
- Start createCliModule init chain with Promise.resolve()
- Deduplicate exitWithError in runCliModule.ts
- Extract shared isCommandNodeHidden to @internal/cli
- Add explanatory comment for fromArray deduplication field
- Restore error for cli role packages missing bin in runCliExtraction

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-03-16 12:55:22 +01:00
parent 26eab3bf83
commit 4d081452b1
47 changed files with 147 additions and 185 deletions
@@ -62,8 +62,8 @@ export function createCliModule(options: {
}
const commands: CliCommand[] = [];
const commandsPromise = options
.init({ addCommand: command => commands.push(command) })
const commandsPromise = Promise.resolve()
.then(() => options.init({ addCommand: command => commands.push(command) }))
.then(() => commands);
return OpaqueCliModule.createInstance('v1', {
@@ -18,6 +18,7 @@ import {
OpaqueCliModule,
OpaqueCommandTreeNode,
OpaqueCommandLeafNode,
isCommandNodeHidden,
} from '@internal/cli';
import type { CommandNode } from '@internal/cli';
import { Command } from 'commander';
@@ -25,15 +26,6 @@ import chalk from 'chalk';
import { isError, stringifyError } from '@backstage/errors';
import type { CliModule, CliCommand } from './types';
function isCommandHidden(node: CommandNode): boolean {
if (OpaqueCommandLeafNode.isType(node)) {
const { command } = OpaqueCommandLeafNode.toInternal(node);
return !!command.deprecated || !!command.experimental;
}
const { children } = OpaqueCommandTreeNode.toInternal(node);
return children.every(child => isCommandHidden(child));
}
function buildCommandGraph(commands: ReadonlyArray<CliCommand>): CommandNode[] {
const graph: CommandNode[] = [];
@@ -70,13 +62,11 @@ function buildCommandGraph(commands: ReadonlyArray<CliCommand>): CommandNode[] {
}
function exitWithError(error: unknown): never {
if (!isError(error)) {
process.stderr.write(`\n${chalk.red(stringifyError(error))}\n\n`);
process.exit(1);
}
process.stderr.write(`\n${chalk.red(stringifyError(error))}\n\n`);
process.exit(
'code' in error && typeof error.code === 'number' ? error.code : 1,
isError(error) && 'code' in error && typeof error.code === 'number'
? error.code
: 1,
);
}
@@ -94,7 +84,7 @@ function registerCommands(
const internal = OpaqueCommandTreeNode.toInternal(node);
const treeParser = argParser
.command(`${internal.name} [command]`, {
hidden: isCommandHidden(node),
hidden: isCommandNodeHidden(node),
})
.description(internal.name);