Skip to content

Commit

Permalink
refactor, move dependents command from legacy to dependencies aspect (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfirst authored Jun 28, 2024
1 parent c081b5e commit c23e218
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from './dependencies-cmd';
import { DependenciesAspect } from './dependencies.aspect';
import { DebugDependencies } from './dependencies-loader/auto-detect-deps';
import { DependentsCmd } from './dependents-cmd';

export type RemoveDependencyResult = { id: ComponentID; removedPackages: string[] };
export type SetDependenciesResult = { changedComps: string[]; addedPackages: Record<string, string> };
Expand Down Expand Up @@ -410,7 +411,13 @@ export class DependenciesMain {
new DependenciesBlameCmd(depsMain),
new DependenciesUsageCmd(depsMain),
];
cli.register(depsCmd, new WhyCmd(depsMain), new SetPeerCmd(depsMain), new UnsetPeerCmd(depsMain));
cli.register(
depsCmd,
new WhyCmd(depsMain),
new SetPeerCmd(depsMain),
new UnsetPeerCmd(depsMain),
new DependentsCmd()
);

ComponentLoader.loadDeps = depsMain.loadDependencies.bind(depsMain);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import chalk from 'chalk';
import { dependents, DependentsResults } from '../../../api/consumer/lib/dependents';
import { Group } from '../../command-groups';
import { CommandOptions, LegacyCommand } from '../../legacy-command';
import { generateDependentsInfoTable } from '../../templates/component-template';
import { Command, CommandOptions } from '@teambit/cli';
import { dependents, DependentsResults } from './dependents';
import { generateDependentsInfoTable } from '@teambit/legacy/dist/cli/templates/component-template';

export default class Dependents implements LegacyCommand {
export class DependentsCmd implements Command {
name = 'dependents <component-name>';
helpUrl = 'reference/dependencies/inspecting-dependencies#review-dependents';
arguments = [
{
names: 'component-name',
name: 'component-name',
description: 'component name or component id',
},
];
description = 'show dependents of the given component';
group: Group = 'info';
group = 'info';
alias = '';
opts = [] as CommandOptions;
options = [] as CommandOptions;

action([id]: [string]): Promise<any> {
return dependents(id);
}

report(results: DependentsResults): string {
async report([id]: [string]) {
const results: DependentsResults = await dependents(id);
if (!results.scopeDependents.length && !results.workspaceDependents.length) {
return `no dependents found for ${results.id.toString()}.
try running "bit cat-component ${results.id.toStringWithoutVersion()}" to see whether the component/version exists locally`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ComponentID } from '@teambit/component-id';
import { BitError } from '@teambit/bit-error';
import { loadConsumerIfExist, Consumer } from '../../../consumer';
import ConsumerNotFound from '../../../consumer/exceptions/consumer-not-found';
import DependencyGraph, { DependenciesInfo } from '../../../scope/graph/scope-graph';
import { loadConsumerIfExist, Consumer } from '@teambit/legacy/dist/consumer';
import ConsumerNotFound from '@teambit/legacy/dist/consumer/exceptions/consumer-not-found';
import DependencyGraph, { DependenciesInfo } from '@teambit/legacy/dist/scope/graph/scope-graph';

export type DependentsResults = {
scopeDependents: DependenciesInfo[];
Expand Down
2 changes: 0 additions & 2 deletions src/cli/command-registry-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import CatLane from './commands/private-cmds/cat-lane-cmd';
import CatObject from './commands/private-cmds/cat-object-cmd';
import CatScope from './commands/private-cmds/cat-scope-cmd';
import Config from './commands/public-cmds/config-cmd';
import Dependents from './commands/public-cmds/dependents-cmd';
import Remote from './commands/public-cmds/remote-cmd';
import ScopeConfig from './commands/public-cmds/scope-config-cmd';
import RunAction from './commands/private-cmds/run-action.cmd';
Expand All @@ -18,7 +17,6 @@ export default function registerCommands(): CommandRegistry {
new CatObject(),
new CatComponent(),
new CatLane(),
new Dependents(),
new CatScope(),
new CatVersionHistoryCmd(),
new ScopeConfig(),
Expand Down

0 comments on commit c23e218

Please sign in to comment.