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