fix(core): report should not include non-plugin packages as local plugins (#18306)
This commit is contained in:
parent
6b43833d2c
commit
1861d6e45f
@ -54,7 +54,10 @@ async function promptForCollection(
|
|||||||
interactive: boolean,
|
interactive: boolean,
|
||||||
projectsConfiguration: ProjectsConfigurations
|
projectsConfiguration: ProjectsConfigurations
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const localPlugins = await getLocalWorkspacePlugins(projectsConfiguration);
|
const localPlugins = await getLocalWorkspacePlugins(
|
||||||
|
projectsConfiguration,
|
||||||
|
readNxJson()
|
||||||
|
);
|
||||||
|
|
||||||
const installedCollections = Array.from(
|
const installedCollections = Array.from(
|
||||||
new Set(findInstalledPlugins().map((x) => x.name))
|
new Set(findInstalledPlugins().map((x) => x.name))
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import {
|
|||||||
createProjectGraphAsync,
|
createProjectGraphAsync,
|
||||||
readProjectsConfigurationFromProjectGraph,
|
readProjectsConfigurationFromProjectGraph,
|
||||||
} from '../../project-graph/project-graph';
|
} from '../../project-graph/project-graph';
|
||||||
|
import { readNxJson } from '../../config/nx-json';
|
||||||
|
|
||||||
export interface ListArgs {
|
export interface ListArgs {
|
||||||
/** The name of an installed plugin to query */
|
/** The name of an installed plugin to query */
|
||||||
@ -33,11 +34,13 @@ export async function listHandler(args: ListArgs): Promise<void> {
|
|||||||
if (args.plugin) {
|
if (args.plugin) {
|
||||||
await listPluginCapabilities(args.plugin);
|
await listPluginCapabilities(args.plugin);
|
||||||
} else {
|
} else {
|
||||||
|
const nxJson = readNxJson();
|
||||||
const corePlugins = fetchCorePlugins();
|
const corePlugins = fetchCorePlugins();
|
||||||
const projectGraph = await createProjectGraphAsync({ exitOnError: true });
|
const projectGraph = await createProjectGraphAsync({ exitOnError: true });
|
||||||
|
|
||||||
const localPlugins = await getLocalWorkspacePlugins(
|
const localPlugins = await getLocalWorkspacePlugins(
|
||||||
readProjectsConfigurationFromProjectGraph(projectGraph)
|
readProjectsConfigurationFromProjectGraph(projectGraph),
|
||||||
|
nxJson
|
||||||
);
|
);
|
||||||
const installedPlugins = await getInstalledPluginsAndCapabilities(
|
const installedPlugins = await getInstalledPluginsAndCapabilities(
|
||||||
workspaceRoot
|
workspaceRoot
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import {
|
|||||||
import { gt, valid } from 'semver';
|
import { gt, valid } from 'semver';
|
||||||
import { findInstalledPlugins } from '../../utils/plugins/installed-plugins';
|
import { findInstalledPlugins } from '../../utils/plugins/installed-plugins';
|
||||||
import { getNxRequirePaths } from '../../utils/installation-directory';
|
import { getNxRequirePaths } from '../../utils/installation-directory';
|
||||||
|
import { NxJsonConfiguration, readNxJson } from '../../config/nx-json';
|
||||||
|
|
||||||
const nxPackageJson = readJsonFile<typeof import('../../../package.json')>(
|
const nxPackageJson = readJsonFile<typeof import('../../../package.json')>(
|
||||||
join(__dirname, '../../../package.json')
|
join(__dirname, '../../../package.json')
|
||||||
@ -148,7 +149,7 @@ export async function getReportData(): Promise<ReportData> {
|
|||||||
const pm = detectPackageManager();
|
const pm = detectPackageManager();
|
||||||
const pmVersion = getPackageManagerVersion(pm);
|
const pmVersion = getPackageManagerVersion(pm);
|
||||||
|
|
||||||
const localPlugins = await findLocalPlugins();
|
const localPlugins = await findLocalPlugins(readNxJson());
|
||||||
const communityPlugins = findInstalledCommunityPlugins();
|
const communityPlugins = findInstalledCommunityPlugins();
|
||||||
|
|
||||||
let projectGraphError: Error | null = null;
|
let projectGraphError: Error | null = null;
|
||||||
@ -185,11 +186,12 @@ export async function getReportData(): Promise<ReportData> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findLocalPlugins() {
|
async function findLocalPlugins(nxJson: NxJsonConfiguration) {
|
||||||
try {
|
try {
|
||||||
const projectGraph = await createProjectGraphAsync({ exitOnError: true });
|
const projectGraph = await createProjectGraphAsync({ exitOnError: true });
|
||||||
const localPlugins = await getLocalWorkspacePlugins(
|
const localPlugins = await getLocalWorkspacePlugins(
|
||||||
readProjectsConfigurationFromProjectGraph(projectGraph)
|
readProjectsConfigurationFromProjectGraph(projectGraph),
|
||||||
|
nxJson
|
||||||
);
|
);
|
||||||
return Array.from(localPlugins.keys());
|
return Array.from(localPlugins.keys());
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@ -9,23 +9,29 @@ import { join } from 'path';
|
|||||||
import { workspaceRoot } from '../workspace-root';
|
import { workspaceRoot } from '../workspace-root';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { getPluginCapabilities } from './plugin-capabilities';
|
import { getPluginCapabilities } from './plugin-capabilities';
|
||||||
|
import { NxJsonConfiguration, readNxJson } from '../../config/nx-json';
|
||||||
|
|
||||||
export async function getLocalWorkspacePlugins(
|
export async function getLocalWorkspacePlugins(
|
||||||
projectsConfiguration: ProjectsConfigurations
|
projectsConfiguration: ProjectsConfigurations,
|
||||||
|
nxJson: NxJsonConfiguration
|
||||||
): Promise<Map<string, PluginCapabilities>> {
|
): Promise<Map<string, PluginCapabilities>> {
|
||||||
const plugins: Map<string, PluginCapabilities> = new Map();
|
const plugins: Map<string, PluginCapabilities> = new Map();
|
||||||
for (const project of Object.values(projectsConfiguration.projects)) {
|
for (const project of Object.values(projectsConfiguration.projects)) {
|
||||||
const packageJsonPath = join(workspaceRoot, project.root, 'package.json');
|
const packageJsonPath = join(workspaceRoot, project.root, 'package.json');
|
||||||
if (existsSync(packageJsonPath)) {
|
if (existsSync(packageJsonPath)) {
|
||||||
const packageJson: PackageJson = readJsonFile(packageJsonPath);
|
const packageJson: PackageJson = readJsonFile(packageJsonPath);
|
||||||
|
const includeRuntimeCapabilities = nxJson?.plugins?.some((p) =>
|
||||||
|
p.startsWith(packageJson.name)
|
||||||
|
);
|
||||||
const capabilities = await getPluginCapabilities(
|
const capabilities = await getPluginCapabilities(
|
||||||
workspaceRoot,
|
workspaceRoot,
|
||||||
packageJson.name
|
packageJson.name,
|
||||||
|
includeRuntimeCapabilities
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
capabilities &&
|
capabilities &&
|
||||||
(capabilities.executors ||
|
(Object.keys(capabilities.executors ?? {}).length ||
|
||||||
capabilities.generators ||
|
Object.keys(capabilities.generators ?? {}).length ||
|
||||||
capabilities.projectGraphExtension ||
|
capabilities.projectGraphExtension ||
|
||||||
capabilities.projectInference)
|
capabilities.projectInference)
|
||||||
) {
|
) {
|
||||||
@ -36,7 +42,6 @@ export async function getLocalWorkspacePlugins(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +58,12 @@ export function listLocalWorkspacePlugins(
|
|||||||
if (hasElements(p.generators)) {
|
if (hasElements(p.generators)) {
|
||||||
capabilities.push('generators');
|
capabilities.push('generators');
|
||||||
}
|
}
|
||||||
|
if (p.projectGraphExtension) {
|
||||||
|
capabilities.push('graph-extension');
|
||||||
|
}
|
||||||
|
if (p.projectInference) {
|
||||||
|
capabilities.push('project-inference');
|
||||||
|
}
|
||||||
bodyLines.push(`${chalk.bold(p.name)} (${capabilities.join()})`);
|
bodyLines.push(`${chalk.bold(p.name)} (${capabilities.join()})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,14 +33,17 @@ function tryGetCollection<T extends object>(
|
|||||||
|
|
||||||
export async function getPluginCapabilities(
|
export async function getPluginCapabilities(
|
||||||
workspaceRoot: string,
|
workspaceRoot: string,
|
||||||
pluginName: string
|
pluginName: string,
|
||||||
|
includeRuntimeCapabilities = false
|
||||||
): Promise<PluginCapabilities | null> {
|
): Promise<PluginCapabilities | null> {
|
||||||
try {
|
try {
|
||||||
const { json: packageJson, path: packageJsonPath } = readPluginPackageJson(
|
const { json: packageJson, path: packageJsonPath } = readPluginPackageJson(
|
||||||
pluginName,
|
pluginName,
|
||||||
getNxRequirePaths(workspaceRoot)
|
getNxRequirePaths(workspaceRoot)
|
||||||
);
|
);
|
||||||
const pluginModule = await tryGetModule(packageJson, workspaceRoot);
|
const pluginModule = includeRuntimeCapabilities
|
||||||
|
? await tryGetModule(packageJson, workspaceRoot)
|
||||||
|
: ({} as Record<string, unknown>);
|
||||||
return {
|
return {
|
||||||
name: pluginName,
|
name: pluginName,
|
||||||
generators: {
|
generators: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user