fix(misc): migration should shutdown plugin workers if it starts them (#22048)
This commit is contained in:
parent
9efde91aeb
commit
f6a183c4f7
@ -1,24 +1,10 @@
|
||||
import { toProjectName, Workspaces } from './workspaces';
|
||||
import { toProjectName } from './workspaces';
|
||||
import { TempFs } from '../internal-testing-utils/temp-fs';
|
||||
import { withEnvironmentVariables } from '../internal-testing-utils/with-environment';
|
||||
import { retrieveProjectConfigurations } from '../project-graph/utils/retrieve-workspace-files';
|
||||
import { readNxJson } from './configuration';
|
||||
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', () => {
|
||||
let fs: TempFs;
|
||||
beforeEach(() => {
|
||||
@ -53,7 +39,6 @@ describe('Workspaces', () => {
|
||||
},
|
||||
() => retrieveProjectConfigurations(fs.tempDir, readNxJson(fs.tempDir))
|
||||
);
|
||||
await shutdownPluginWorkers();
|
||||
expect(projects['my-package']).toEqual({
|
||||
name: 'my-package',
|
||||
root: 'packages/my-package',
|
||||
@ -67,7 +52,6 @@ describe('Workspaces', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
await shutdownPluginWorkers();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -217,6 +217,7 @@ async function processFilesAndCreateAndSerializeProjectGraph(): Promise<Serializ
|
||||
serverLogger.requestLog([...updatedFiles.values()]);
|
||||
serverLogger.requestLog([...deletedFiles]);
|
||||
const nxJson = readNxJson(workspaceRoot);
|
||||
global.NX_GRAPH_CREATION = true;
|
||||
const graphNodes = await retrieveProjectConfigurations(
|
||||
workspaceRoot,
|
||||
nxJson
|
||||
@ -226,7 +227,9 @@ async function processFilesAndCreateAndSerializeProjectGraph(): Promise<Serializ
|
||||
updatedFileHashes,
|
||||
deletedFiles
|
||||
);
|
||||
return createAndSerializeProjectGraph(graphNodes);
|
||||
const g = createAndSerializeProjectGraph(graphNodes);
|
||||
delete global.NX_GRAPH_CREATION;
|
||||
return g;
|
||||
} catch (err) {
|
||||
return Promise.resolve({
|
||||
error: err,
|
||||
|
||||
@ -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 { retrieveProjectConfigurationPaths } from '../../project-graph/utils/retrieve-workspace-files';
|
||||
import { loadNxPlugins } from '../../project-graph/plugins/internal-api';
|
||||
import { shutdownPluginWorkers } from '../../project-graph/plugins/plugin-pool';
|
||||
|
||||
export default async function (tree: Tree) {
|
||||
const nxJson = readNxJson(tree);
|
||||
@ -12,6 +13,7 @@ export default async function (tree: Tree) {
|
||||
tree.root,
|
||||
await loadNxPlugins(nxJson?.plugins)
|
||||
);
|
||||
await shutdownPluginWorkers();
|
||||
const projectJsons = projectFiles.filter((f) => f.endsWith('project.json'));
|
||||
|
||||
for (let f of projectJsons) {
|
||||
|
||||
@ -300,9 +300,6 @@ async function updateProjectGraphWithPlugins(
|
||||
createDependencyPlugins.map(async (plugin) => {
|
||||
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 {
|
||||
// TODO: we shouldn't have to pass null here
|
||||
const dependencies = await plugin.createDependencies(null, {
|
||||
@ -326,8 +323,6 @@ async function updateProjectGraphWithPlugins(
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
delete global.NX_GRAPH_CREATION;
|
||||
|
||||
performance.mark(`${plugin.name}:createDependencies - end`);
|
||||
performance.measure(
|
||||
`${plugin.name}:createDependencies`,
|
||||
|
||||
@ -77,6 +77,7 @@ export function readProjectsConfigurationFromProjectGraph(
|
||||
}
|
||||
|
||||
export async function buildProjectGraphAndSourceMapsWithoutDaemon() {
|
||||
global.NX_GRAPH_CREATION = true;
|
||||
const nxJson = readNxJson();
|
||||
|
||||
performance.mark('retrieve-project-configurations:start');
|
||||
@ -103,7 +104,7 @@ export async function buildProjectGraphAndSourceMapsWithoutDaemon() {
|
||||
)
|
||||
).projectGraph;
|
||||
performance.mark('build-project-graph-using-project-file-map:end');
|
||||
|
||||
delete global.NX_GRAPH_CREATION;
|
||||
return { projectGraph, sourceMaps };
|
||||
}
|
||||
|
||||
|
||||
@ -218,8 +218,6 @@ export function buildProjectsConfigurationsFromProjectPathsAndPlugins(
|
||||
const matchedFiles = [];
|
||||
|
||||
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) {
|
||||
if (minimatch(file, pattern, { dot: true })) {
|
||||
|
||||
@ -17,6 +17,7 @@ import {
|
||||
} from '../../utils/workspace-context';
|
||||
import { buildAllWorkspaceFiles } from './build-all-workspace-files';
|
||||
import { join } from 'path';
|
||||
import { shutdownPluginWorkers } from '../plugins/plugin-pool';
|
||||
|
||||
/**
|
||||
* Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles`
|
||||
@ -68,8 +69,15 @@ export async function retrieveProjectConfigurations(
|
||||
nxJson: NxJsonConfiguration
|
||||
): Promise<RetrievedGraphNodes> {
|
||||
const plugins = await loadNxPlugins(nxJson?.plugins ?? [], workspaceRoot);
|
||||
|
||||
return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins);
|
||||
const projects = await _retrieveProjectConfigurations(
|
||||
workspaceRoot,
|
||||
nxJson,
|
||||
plugins
|
||||
);
|
||||
if (!global.NX_GRAPH_CREATION) {
|
||||
await shutdownPluginWorkers();
|
||||
}
|
||||
return projects;
|
||||
}
|
||||
|
||||
export async function retrieveProjectConfigurationsWithAngularProjects(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user