Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions e2e/nx/src/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,48 @@ describe('Nx Commands', () => {
);
}
}, 120000);

it('should list plugins as JSON with --json flag', () => {
const jsonOutput = runCLI('list --json');
const parsed = JSON.parse(jsonOutput);

expect(parsed.installedPlugins).toBeDefined();
expect(Array.isArray(parsed.installedPlugins)).toBe(true);
expect(parsed.localWorkspacePlugins).toBeDefined();
expect(Array.isArray(parsed.localWorkspacePlugins)).toBe(true);

const workspacePlugin = parsed.installedPlugins.find(
(p) => p.name === '@nx/workspace'
);
expect(workspacePlugin).toBeDefined();
expect(workspacePlugin.path).toBeDefined();
expect(workspacePlugin.capabilities).toBeDefined();
expect(Array.isArray(workspacePlugin.capabilities)).toBe(true);
}, 120000);

it('should list plugin capabilities as JSON with --json flag', () => {
const jsonOutput = runCLI('list @nx/js --json');
const parsed = JSON.parse(jsonOutput);

expect(parsed.name).toBe('@nx/js');
expect(parsed.path).toContain('node_modules/@nx/js');

// check generator values
const libGen = parsed.generators['library'];
expect(libGen).toBeDefined();
expect(libGen.description).toEqual(expect.any(String));
expect(libGen.path).toContain('node_modules/@nx/js');
expect(libGen.schema).toContain('node_modules/@nx/js');
expect(libGen.schema).toContain('schema.json');

// check executor values
const tscExec = parsed.executors['tsc'];
expect(tscExec).toBeDefined();
expect(tscExec.description).toEqual(expect.any(String));
expect(tscExec.path).toContain('node_modules/@nx/js');
expect(tscExec.schema).toContain('node_modules/@nx/js');
expect(tscExec.schema).toContain('schema.json');
}, 120000);
});

describe('format', () => {
Expand Down
13 changes: 9 additions & 4 deletions packages/nx/src/command-line/list/command-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ export const yargsListCommand: CommandModule = {
describe:
'Lists installed plugins, capabilities of installed plugins and other available plugins.',
builder: (yargs) =>
yargs.positional('plugin', {
type: 'string',
description: 'The name of an installed plugin to query.',
}),
yargs
.positional('plugin', {
type: 'string',
description: 'The name of an installed plugin to query.',
})
.option('json', {
type: 'boolean',
description: 'Output JSON.',
}),
handler: async (args: any) => {
await (await import('./list')).listHandler(args);
process.exit(0);
Expand Down
20 changes: 18 additions & 2 deletions packages/nx/src/command-line/list/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ import {
listPlugins,
} from '../../utils/plugins';
import { workspaceRoot } from '../../utils/workspace-root';
import { listPowerpackPlugins } from '../../utils/plugins/output';
import {
formatPluginsAsJson,
listPowerpackPlugins,
} from '../../utils/plugins/output';

export interface ListArgs {
/** The name of an installed plugin to query */
plugin?: string | undefined;
/** Output as JSON */
json?: boolean;
}

/**
Expand All @@ -32,7 +37,7 @@ export async function listHandler(args: ListArgs): Promise<void> {
const projects = readProjectsConfigurationFromProjectGraph(projectGraph);

if (args.plugin) {
await listPluginCapabilities(args.plugin, projects.projects);
await listPluginCapabilities(args.plugin, projects.projects, args.json);
} else {
const nxJson = readNxJson();

Expand All @@ -42,6 +47,17 @@ export async function listHandler(args: ListArgs): Promise<void> {
projects.projects
);

if (args.json) {
console.log(
JSON.stringify(
formatPluginsAsJson(localPlugins, installedPlugins),
null,
2
)
);
return;
}

if (localPlugins.size) {
listPlugins(localPlugins, 'Local workspace plugins:');
}
Expand Down
Loading
Loading