Skip to content

Commit

Permalink
fix: other fixes to make CLI more robust.
Browse files Browse the repository at this point in the history
Signed-off-by: David Festal <[email protected]>
  • Loading branch information
davidfestal committed Nov 22, 2023
1 parent 3f5de34 commit 4589757
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
64 changes: 34 additions & 30 deletions packages/cli/src/commands/export-dynamic-plugin/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

import { BackstagePackageJson, PackageRoleInfo } from '@backstage/cli-node';
import { ConfigReader } from '@backstage/config';
import { loadConfig } from '@backstage/config-loader';

import { getPackages } from '@manypkg/get-packages';
import { OptionValues } from 'commander';
Expand All @@ -29,7 +31,6 @@ import { Output } from '../../lib/builder';
import { makeRollupConfigs } from '../../lib/builder/config';
import { embedModules } from '../../lib/builder/embedPlugin';
import { buildPackage, formatErrorMessage } from '../../lib/builder/packager';
import { loadCliConfig } from '../../lib/config';
import { readEntryPoints } from '../../lib/entryPoints';
import { productionPack } from '../../lib/packager/productionPack';
import { paths } from '../../lib/paths';
Expand Down Expand Up @@ -357,35 +358,38 @@ export async function backend(
});

if (opts.dev) {
if (opts.dev) {
const { fullConfig } = await loadCliConfig({ args: [] });
const dynamicPlugins = fullConfig.getOptional('dynamicPlugins');
if (
typeof dynamicPlugins === 'object' &&
dynamicPlugins !== null &&
'rootDirectory' in dynamicPlugins &&
typeof dynamicPlugins.rootDirectory === 'string'
) {
await fs.ensureSymlink(
paths.resolveTarget('src'),
path.resolve(target, 'src'),
'dir',
);
const dynamicPluginsRootPath = path.isAbsolute(
dynamicPlugins.rootDirectory,
)
? dynamicPlugins.rootDirectory
: paths.resolveTargetRoot(dynamicPlugins.rootDirectory);
await fs.ensureSymlink(
target,
path.resolve(dynamicPluginsRootPath, basename(paths.targetDir)),
'dir',
);
} else {
throw new Error(
`'dynamicPlugins.rootDirectory' should be configured in the app config in order to use the --dev option.`,
);
}
const appConfigs = await loadConfig({
configRoot: paths.targetRoot,
configTargets: [],
});
const fullConfig = ConfigReader.fromConfigs(appConfigs.appConfigs);

const dynamicPlugins = fullConfig.getOptional('dynamicPlugins');
if (
typeof dynamicPlugins === 'object' &&
dynamicPlugins !== null &&
'rootDirectory' in dynamicPlugins &&
typeof dynamicPlugins.rootDirectory === 'string'
) {
await fs.ensureSymlink(
paths.resolveTarget('src'),
path.resolve(target, 'src'),
'dir',
);
const dynamicPluginsRootPath = path.isAbsolute(
dynamicPlugins.rootDirectory,
)
? dynamicPlugins.rootDirectory
: paths.resolveTargetRoot(dynamicPlugins.rootDirectory);
await fs.ensureSymlink(
target,
path.resolve(dynamicPluginsRootPath, basename(paths.targetDir)),
'dir',
);
} else {
throw new Error(
`'dynamicPlugins.rootDirectory' should be configured in the app config in order to use the --dev option.`,
);
}
}
}
5 changes: 4 additions & 1 deletion packages/cli/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export async function loadCliConfig(options: Options) {
localPackageNames = Array.from(
graph.collectPackageNames([options.fromPackage], node => {
// Workaround for Backstage main repo only, since the CLI has some artificial devDependencies
if (node.name === '@janus-idp/cli') {
if (
node.name === '@janus-idp/cli' ||
node.name === '@backstage/cli'
) {
return undefined;
}
return node.localDependencies.keys();
Expand Down

0 comments on commit 4589757

Please sign in to comment.