fix(misc): migration should shutdown plugin workers if it starts them (#22048)

This commit is contained in:
Craigory Coppola 2024-02-28 18:07:30 -05:00 committed by GitHub
parent 9efde91aeb
commit f6a183c4f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 19 additions and 28 deletions

View File

@ -1,24 +1,10 @@
import { toProjectName, Workspaces } from './workspaces'; import { toProjectName } from './workspaces';
import { TempFs } from '../internal-testing-utils/temp-fs'; import { TempFs } from '../internal-testing-utils/temp-fs';
import { withEnvironmentVariables } from '../internal-testing-utils/with-environment'; import { withEnvironmentVariables } from '../internal-testing-utils/with-environment';
import { retrieveProjectConfigurations } from '../project-graph/utils/retrieve-workspace-files'; import { retrieveProjectConfigurations } from '../project-graph/utils/retrieve-workspace-files';
import { readNxJson } from './configuration'; import { readNxJson } from './configuration';
import { shutdownPluginWorkers } from '../project-graph/plugins/plugin-pool'; import { shutdownPluginWorkers } from '../project-graph/plugins/plugin-pool';
const libConfig = (root, name?: string) => ({
name: name ?? toProjectName(`${root}/some-file`),
projectType: 'library',
root: `libs/${root}`,
sourceRoot: `libs/${root}/src`,
targets: {
'nx-release-publish': {
dependsOn: ['^nx-release-publish'],
executor: '@nx/js:release-publish',
options: {},
},
},
});
describe('Workspaces', () => { describe('Workspaces', () => {
let fs: TempFs; let fs: TempFs;
beforeEach(() => { beforeEach(() => {
@ -53,7 +39,6 @@ describe('Workspaces', () => {
}, },
() => retrieveProjectConfigurations(fs.tempDir, readNxJson(fs.tempDir)) () => retrieveProjectConfigurations(fs.tempDir, readNxJson(fs.tempDir))
); );
await shutdownPluginWorkers();
expect(projects['my-package']).toEqual({ expect(projects['my-package']).toEqual({
name: 'my-package', name: 'my-package',
root: 'packages/my-package', root: 'packages/my-package',
@ -67,7 +52,6 @@ describe('Workspaces', () => {
}, },
}, },
}); });
await shutdownPluginWorkers();
}); });
}); });
}); });

View File

@ -217,6 +217,7 @@ async function processFilesAndCreateAndSerializeProjectGraph(): Promise<Serializ
serverLogger.requestLog([...updatedFiles.values()]); serverLogger.requestLog([...updatedFiles.values()]);
serverLogger.requestLog([...deletedFiles]); serverLogger.requestLog([...deletedFiles]);
const nxJson = readNxJson(workspaceRoot); const nxJson = readNxJson(workspaceRoot);
global.NX_GRAPH_CREATION = true;
const graphNodes = await retrieveProjectConfigurations( const graphNodes = await retrieveProjectConfigurations(
workspaceRoot, workspaceRoot,
nxJson nxJson
@ -226,7 +227,9 @@ async function processFilesAndCreateAndSerializeProjectGraph(): Promise<Serializ
updatedFileHashes, updatedFileHashes,
deletedFiles deletedFiles
); );
return createAndSerializeProjectGraph(graphNodes); const g = createAndSerializeProjectGraph(graphNodes);
delete global.NX_GRAPH_CREATION;
return g;
} catch (err) { } catch (err) {
return Promise.resolve({ return Promise.resolve({
error: err, error: err,

View File

@ -5,6 +5,7 @@ import { readJson, writeJson } from '../../generators/utils/json';
import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available';
import { retrieveProjectConfigurationPaths } from '../../project-graph/utils/retrieve-workspace-files'; import { retrieveProjectConfigurationPaths } from '../../project-graph/utils/retrieve-workspace-files';
import { loadNxPlugins } from '../../project-graph/plugins/internal-api'; import { loadNxPlugins } from '../../project-graph/plugins/internal-api';
import { shutdownPluginWorkers } from '../../project-graph/plugins/plugin-pool';
export default async function (tree: Tree) { export default async function (tree: Tree) {
const nxJson = readNxJson(tree); const nxJson = readNxJson(tree);
@ -12,6 +13,7 @@ export default async function (tree: Tree) {
tree.root, tree.root,
await loadNxPlugins(nxJson?.plugins) await loadNxPlugins(nxJson?.plugins)
); );
await shutdownPluginWorkers();
const projectJsons = projectFiles.filter((f) => f.endsWith('project.json')); const projectJsons = projectFiles.filter((f) => f.endsWith('project.json'));
for (let f of projectJsons) { for (let f of projectJsons) {

View File

@ -300,9 +300,6 @@ async function updateProjectGraphWithPlugins(
createDependencyPlugins.map(async (plugin) => { createDependencyPlugins.map(async (plugin) => {
performance.mark(`${plugin.name}:createDependencies - start`); performance.mark(`${plugin.name}:createDependencies - start`);
// Set this globally to allow plugins to know if they are being called from the project graph creation
global.NX_GRAPH_CREATION = true;
try { try {
// TODO: we shouldn't have to pass null here // TODO: we shouldn't have to pass null here
const dependencies = await plugin.createDependencies(null, { const dependencies = await plugin.createDependencies(null, {
@ -326,8 +323,6 @@ async function updateProjectGraphWithPlugins(
throw new Error(message); throw new Error(message);
} }
delete global.NX_GRAPH_CREATION;
performance.mark(`${plugin.name}:createDependencies - end`); performance.mark(`${plugin.name}:createDependencies - end`);
performance.measure( performance.measure(
`${plugin.name}:createDependencies`, `${plugin.name}:createDependencies`,

View File

@ -77,6 +77,7 @@ export function readProjectsConfigurationFromProjectGraph(
} }
export async function buildProjectGraphAndSourceMapsWithoutDaemon() { export async function buildProjectGraphAndSourceMapsWithoutDaemon() {
global.NX_GRAPH_CREATION = true;
const nxJson = readNxJson(); const nxJson = readNxJson();
performance.mark('retrieve-project-configurations:start'); performance.mark('retrieve-project-configurations:start');
@ -103,7 +104,7 @@ export async function buildProjectGraphAndSourceMapsWithoutDaemon() {
) )
).projectGraph; ).projectGraph;
performance.mark('build-project-graph-using-project-file-map:end'); performance.mark('build-project-graph-using-project-file-map:end');
delete global.NX_GRAPH_CREATION;
return { projectGraph, sourceMaps }; return { projectGraph, sourceMaps };
} }

View File

@ -218,8 +218,6 @@ export function buildProjectsConfigurationsFromProjectPathsAndPlugins(
const matchedFiles = []; const matchedFiles = [];
performance.mark(`${plugin.name}:createNodes - start`); performance.mark(`${plugin.name}:createNodes - start`);
// Set this globally to allow plugins to know if they are being called from the project graph creation
global.NX_GRAPH_CREATION = true;
for (const file of projectFiles) { for (const file of projectFiles) {
if (minimatch(file, pattern, { dot: true })) { if (minimatch(file, pattern, { dot: true })) {

View File

@ -17,6 +17,7 @@ import {
} from '../../utils/workspace-context'; } from '../../utils/workspace-context';
import { buildAllWorkspaceFiles } from './build-all-workspace-files'; import { buildAllWorkspaceFiles } from './build-all-workspace-files';
import { join } from 'path'; import { join } from 'path';
import { shutdownPluginWorkers } from '../plugins/plugin-pool';
/** /**
* Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles` * Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles`
@ -68,8 +69,15 @@ export async function retrieveProjectConfigurations(
nxJson: NxJsonConfiguration nxJson: NxJsonConfiguration
): Promise<RetrievedGraphNodes> { ): Promise<RetrievedGraphNodes> {
const plugins = await loadNxPlugins(nxJson?.plugins ?? [], workspaceRoot); const plugins = await loadNxPlugins(nxJson?.plugins ?? [], workspaceRoot);
const projects = await _retrieveProjectConfigurations(
return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins); workspaceRoot,
nxJson,
plugins
);
if (!global.NX_GRAPH_CREATION) {
await shutdownPluginWorkers();
}
return projects;
} }
export async function retrieveProjectConfigurationsWithAngularProjects( export async function retrieveProjectConfigurationsWithAngularProjects(