cli: add support for passing package paths to repo start

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-04-08 01:23:20 +02:00
parent fd4fddad77
commit fbb84fbc8c
5 changed files with 22 additions and 16 deletions
+2 -2
View File
@@ -78,12 +78,12 @@ Any `--config` options in the `start` script in `package.json` of the selected p
Any `--require` option in the `start` script in `package.json` of the selected backend package will be picked up and used.
```text
Usage: backstage-cli repo start [options] [packageName...]
Usage: backstage-cli repo start [options] [packageNameOrPath...]
Starts packages in the repo for local development
Arguments:
packageName Run the specified package instead of the defaults.
packageNameOrPath Run the specified packages instead of the defaults.
Options:
--plugin <pluginId> Start the dev entry-point for any matching plugin package in the repo (default: [])
+4 -4
View File
@@ -400,13 +400,13 @@ Options:
-h, --help
Commands:
start [options] [packageName...]
build [options]
clean
fix [options]
help [command]
lint [options]
list-deprecations [options]
start [options] [packageNameOrPath...]
test [options]
```
@@ -471,15 +471,15 @@ Options:
### `backstage-cli repo start`
```
Usage: backstage-cli repo start [options] [packageName...]
Usage: backstage-cli repo start [options] [packageNameOrPath...]
Options:
--plugin <pluginId>
--config <path>
--inspect [host]
--inspect-brk [host]
--require <path...>
--link <path>
--plugin <pluginId>
--require <path...>
-h, --help
```
+1 -1
View File
@@ -62,7 +62,7 @@ export const startPlugin = createCliPlugin({
const defaultCommand = command
.argument(
'[...packageName]',
'[...packageNameOrPath]',
'Run the specified package instead of the defaults.',
)
.option(
@@ -41,8 +41,8 @@ type CommandOptions = {
link?: string;
};
export async function command(packageNames: string[], options: CommandOptions) {
const targetPackages = await findTargetPackages(packageNames, options.plugin);
export async function command(namesOrPaths: string[], options: CommandOptions) {
const targetPackages = await findTargetPackages(namesOrPaths, options.plugin);
const packageOptions = await resolvePackageOptions(targetPackages, options);
@@ -61,7 +61,7 @@ export async function command(packageNames: string[], options: CommandOptions) {
await Promise.all(packageOptions.map(entry => startPackage(entry.options)));
}
async function findTargetPackages(packageNames: string[], pluginIds: string[]) {
async function findTargetPackages(namesOrPaths: string[], pluginIds: string[]) {
const targetPackages = new Array<BackstagePackage>();
const packages = await PackageGraph.listTargetPackages();
@@ -87,12 +87,18 @@ async function findTargetPackages(packageNames: string[], pluginIds: string[]) {
}
// Next check if explicit package names are provided, use them in that case.
for (const packageName of packageNames) {
const matchingPackage = packages.find(pkg => {
return packageName === pkg.packageJson.name;
});
for (const nameOrPath of namesOrPaths) {
let matchingPackage = packages.find(
pkg => nameOrPath === pkg.packageJson.name,
);
if (!matchingPackage) {
throw new Error(`Unable to find package by name '${packageName}'`);
const absPath = paths.resolveTargetRoot(nameOrPath);
matchingPackage = packages.find(
pkg => relativePath(pkg.dir, absPath) === '',
);
}
if (!matchingPackage) {
throw new Error(`Unable to find package by name '${nameOrPath}'`);
}
targetPackages.push(matchingPackage);
}
+1 -1
View File
@@ -22,7 +22,7 @@ export function registerRepoCommands(command: Command) {
.command('start')
.description('Starts packages in the repo for local development')
.argument(
'[packageName...]',
'[packageNameOrPath...]',
'Run the specified package instead of the defaults.',
)
.option(