Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): plugin pool should not clobber promises when called multiple times #21977

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ import {
} from './nx-deps-cache';
import { applyImplicitDependencies } from './utils/implicit-project-dependencies';
import { normalizeProjectNodes } from './utils/normalize-project-nodes';
import {
isNxPluginV1,
isNxPluginV2,
loadNxPlugins,
} from './plugins/internal-api';
import { loadNxPlugins } from './plugins/internal-api';
import { isNxPluginV1, isNxPluginV2 } from './plugins/utils';
import { CreateDependenciesContext } from './plugins';
import { getRootTsConfigPath } from '../plugins/js/utils/typescript';
import {
Expand Down
40 changes: 1 addition & 39 deletions packages/nx/src/project-graph/plugins/internal-api.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// This file contains the bits and bobs of the internal API for loading and interacting with Nx plugins.
// For the public API, used by plugin authors, see `./public-api.ts`.

import { join, dirname } from 'path';
import { join } from 'path';

import { toProjectName } from '../../config/workspaces';
import { combineGlobPatterns } from '../../utils/globs';
import { workspaceRoot } from '../../utils/workspace-root';
import { PluginConfiguration } from '../../config/nx-json';
import { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
Expand Down Expand Up @@ -88,42 +86,6 @@ export async function loadNxPlugin(
return loadedPlugin;
}

export function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2 {
return 'createNodes' in plugin || 'createDependencies' in plugin;
}

export function isNxPluginV1(
plugin: NxPlugin | RemotePlugin
): plugin is NxPluginV1 {
return 'processProjectGraph' in plugin || 'projectFilePatterns' in plugin;
}

export function normalizeNxPlugin(plugin: NxPlugin): NormalizedPlugin {
if (isNxPluginV2(plugin)) {
return plugin;
}
if (isNxPluginV1(plugin) && plugin.projectFilePatterns) {
return {
...plugin,
createNodes: [
`*/**/${combineGlobPatterns(plugin.projectFilePatterns)}`,
(configFilePath) => {
const root = dirname(configFilePath);
return {
projects: {
[root]: {
name: toProjectName(configFilePath),
targets: plugin.registerProjectTargets?.(configFilePath),
},
},
};
},
],
};
}
return plugin;
}

export async function getDefaultPlugins(root: string) {
return [
join(__dirname, '../../plugins/js'),
Expand Down
15 changes: 9 additions & 6 deletions packages/nx/src/project-graph/plugins/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ export interface PluginWorkerLoadResult {
};
}

export interface PluginWorkerShutdownMessage {
type: 'shutdown';
payload: undefined;
}

export interface PluginWorkerCreateNodesMessage {
type: 'createNodes';
payload: {
configFiles: string[];
context: CreateNodesContext;
tx: string;
};
}

Expand All @@ -49,17 +45,20 @@ export interface PluginWorkerCreateNodesResult {
| {
success: true;
result: Awaited<ReturnType<RemotePlugin['createNodes'][1]>>;
tx: string;
}
| {
success: false;
error: string;
tx: string;
};
}

export interface PluginCreateDependenciesMessage {
type: 'createDependencies';
payload: {
context: CreateDependenciesContext;
tx: string;
};
}

Expand All @@ -69,10 +68,12 @@ export interface PluginCreateDependenciesResult {
| {
dependencies: ReturnType<RemotePlugin['createDependencies']>;
success: true;
tx: string;
}
| {
success: false;
error: string;
tx: string;
};
}

Expand All @@ -81,6 +82,7 @@ export interface PluginWorkerProcessProjectGraphMessage {
payload: {
graph: ProjectGraph;
ctx: ProjectGraphProcessorContext;
tx: string;
};
}

Expand All @@ -90,16 +92,17 @@ export interface PluginWorkerProcessProjectGraphResult {
| {
graph: ProjectGraph;
success: true;
tx: string;
}
| {
success: false;
error: string;
tx: string;
};
}

export type PluginWorkerMessage =
| PluginWorkerLoadMessage
| PluginWorkerShutdownMessage
| PluginWorkerCreateNodesMessage
| PluginCreateDependenciesMessage
| PluginWorkerProcessProjectGraphMessage;
Expand Down