cli: check link target
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user