Skip to content

Commit

Permalink
fix(misc): migration should shutdown plugin workers if it starts them (
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Feb 28, 2024
1 parent 9efde91 commit f6a183c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 28 deletions.
18 changes: 1 addition & 17 deletions packages/nx/src/config/workspaces.spec.ts
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand Down Expand Up @@ -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',
Expand All @@ -67,7 +52,6 @@ describe('Workspaces', () => {
},
},
});
await shutdownPluginWorkers();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/nx/src/migrations/update-15-1-0/set-project-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ 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);
const projectFiles = await retrieveProjectConfigurationPaths(
tree.root,
await loadNxPlugins(nxJson?.plugins)
);
await shutdownPluginWorkers();
const projectJsons = projectFiles.filter((f) => f.endsWith('project.json'));

for (let f of projectJsons) {
Expand Down
5 changes: 0 additions & 5 deletions packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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`,
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/project-graph/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })) {
Expand Down
12 changes: 10 additions & 2 deletions packages/nx/src/project-graph/utils/retrieve-workspace-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f6a183c

Please sign in to comment.