fix(core): load isolated plugins in parallel (#26874)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
Plugins are not loading in parallel correctly

## Expected Behavior
Plugins should load in parallel

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Craigory Coppola 2024-07-10 16:57:57 -04:00 committed by GitHub
parent 550de60446
commit a6fde9ba95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 10 deletions

View File

@ -147,8 +147,8 @@ export const nxPluginCache: Map<
export async function loadNxPlugins(
plugins: PluginConfiguration[],
root = workspaceRoot
): Promise<[LoadedNxPlugin[], () => void]> {
const result: Promise<LoadedNxPlugin>[] = [];
): Promise<readonly [LoadedNxPlugin[], () => void]> {
performance.mark('loadNxPlugins:start');
const loadingMethod =
process.env.NX_ISOLATE_PLUGINS === 'true'
@ -157,14 +157,18 @@ export async function loadNxPlugins(
plugins = await normalizePlugins(plugins, root);
const cleanupFunctions: Array<() => void> = [];
for (const plugin of plugins) {
const [loadedPluginPromise, cleanup] = await loadingMethod(plugin, root);
result.push(loadedPluginPromise);
cleanupFunctions.push(cleanup);
}
const result: Promise<LoadedNxPlugin>[] = new Array(plugins?.length);
return [
const cleanupFunctions: Array<() => void> = [];
await Promise.all(
plugins.map(async (plugin, idx) => {
const [loadedPluginPromise, cleanup] = await loadingMethod(plugin, root);
result[idx] = loadedPluginPromise;
cleanupFunctions.push(cleanup);
})
);
const ret = [
await Promise.all(result),
() => {
for (const fn of cleanupFunctions) {
@ -175,6 +179,13 @@ export async function loadNxPlugins(
}
},
] as const;
performance.mark('loadNxPlugins:end');
performance.measure(
'loadNxPlugins',
'loadNxPlugins:start',
'loadNxPlugins:end'
);
return ret;
}
async function normalizePlugins(plugins: PluginConfiguration[], root: string) {

View File

@ -2,8 +2,9 @@ import { consumeMessage, isPluginWorkerMessage } from './messaging';
import { LoadedNxPlugin } from '../internal-api';
import { loadNxPlugin } from '../loader';
import { createSerializableError } from '../../../utils/serializable-error';
import { createServer } from 'net';
import { consumeMessagesFromSocket } from '../../../utils/consume-messages-from-socket';
import { createServer } from 'net';
import { unlinkSync } from 'fs';
if (process.env.NX_PERF_LOGGING === 'true') {