cli: check link target

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-02-13 12:42:17 +01:00
parent 97f78162c6
commit 90a1edf950
2 changed files with 31 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Add check to make sure that the `--link` option for the `start` command is a valid workspace.
@@ -14,15 +14,41 @@
* limitations under the License.
*/
import fs from 'fs-extra';
import { OptionValues } from 'commander';
import { resolve as resolvePath } from 'node:path';
import { PackageRole } from '@backstage/cli-node';
import { findRoleFromCommand } from '../../lib/role';
import { startBackend, startBackendPlugin } from './startBackend';
import { startFrontend } from './startFrontend';
import { ForwardedError } from '@backstage/errors';
export async function command(opts: OptionValues): Promise<void> {
const role = await findRoleFromCommand(opts);
if (opts.link) {
const dir = resolvePath(opts.link);
if (!fs.pathExistsSync(dir)) {
throw new Error(
`Invalid workspace link, directory does not exist: ${dir}`,
);
}
const pkgJson = await fs
.readJson(resolvePath(dir, 'package.json'))
.catch(error => {
throw new ForwardedError(
'Failed to read package.json in linked workspace',
error,
);
});
if (!pkgJson.workspaces) {
throw new Error(
`Invalid workspace link, directory is not a workspace: ${dir}`,
);
}
}
const options = {
configPaths: opts.config as string[],
checksEnabled: Boolean(opts.check),