Skip to content

Commit

Permalink
fix(core): load core plugins as part of loading plugins (#18826)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Aug 25, 2023
1 parent aa9526f commit cf1175f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { basename } from 'node:path';

import { getNxPackageJsonWorkspacesPlugin } from '../../../plugins/package-json-workspaces';
import { CreateProjectJsonProjectsPlugin } from '../../plugins/project-json/build-nodes/project-json';
import { NxJsonConfiguration, TargetDefaults } from '../../config/nx-json';
import { ProjectGraphExternalNode } from '../../config/project-graph';
import {
Expand Down Expand Up @@ -90,12 +88,6 @@ export function buildProjectsConfigurationsFromProjectPathsAndPlugins(
const projectRootMap: Map<string, ProjectConfiguration> = new Map();
const externalNodes: Record<string, ProjectGraphExternalNode> = {};

// We push the nx core node builder onto the end, s.t. it overwrites any user specified behavior
plugins.push(
getNxPackageJsonWorkspacesPlugin(root),
CreateProjectJsonProjectsPlugin
);

// We iterate over plugins first - this ensures that plugins specified first take precedence.
for (const plugin of plugins) {
const [pattern, createNodes] = plugin.createNodes ?? [];
Expand Down
17 changes: 9 additions & 8 deletions packages/nx/src/project-graph/utils/retrieve-workspace-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ import {
ProjectGraphExternalNode,
} from '../../config/project-graph';
import type { NxWorkspaceFiles } from '../../native';
import { getGlobPatternsFromPackageManagerWorkspaces } from '../../../plugins/package-json-workspaces';
import {
getGlobPatternsFromPackageManagerWorkspaces,
getNxPackageJsonWorkspacesPlugin,
} from '../../../plugins/package-json-workspaces';
import { buildProjectsConfigurationsFromProjectPathsAndPlugins } from './project-configuration-utils';
import {
loadNxPlugins,
loadNxPluginsSync,
NxPlugin,
NxPluginV2,
} from '../../utils/nx-plugin';
import { CreateProjectJsonProjectsPlugin } from '../../plugins/project-json/build-nodes/project-json';

/**
* Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles`
Expand Down Expand Up @@ -229,12 +232,10 @@ export function retrieveProjectConfigurationsWithoutPluginInference(
root,
projectGlobPatterns,
(configs: string[]) => {
const { projects } = createProjectConfigurations(
root,
nxJson,
configs,
[]
);
const { projects } = createProjectConfigurations(root, nxJson, configs, [
getNxPackageJsonWorkspacesPlugin(root),
CreateProjectJsonProjectsPlugin,
]);
return {
projectNodes: projects,
externalNodes: {},
Expand Down
18 changes: 18 additions & 0 deletions packages/nx/src/utils/nx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import {
NxAngularJsonPlugin,
shouldMergeAngularProjects,
} from '../adapter/angular-json';
import { getNxPackageJsonWorkspacesPlugin } from '../../plugins/package-json-workspaces';
import { CreateProjectJsonProjectsPlugin } from '../plugins/project-json/build-nodes/project-json';

/**
* Context for {@link CreateNodesFunction}
Expand Down Expand Up @@ -225,6 +227,10 @@ export function loadNxPluginsSync(
jsPlugin.name = 'nx-js-graph-plugin';
result.push(jsPlugin as NxPlugin);

if (shouldMergeAngularProjects(root, false)) {
result.push(NxAngularJsonPlugin);
}

plugins ??= [];
for (const plugin of plugins) {
try {
Expand All @@ -239,6 +245,12 @@ export function loadNxPluginsSync(
}
}

// We push the nx core node plugins onto the end, s.t. it overwrites any other plugins
result.push(
getNxPackageJsonWorkspacesPlugin(root),
CreateProjectJsonProjectsPlugin
);

return result.map(ensurePluginIsV2);
}

Expand All @@ -265,6 +277,12 @@ export async function loadNxPlugins(
result.push(await loadNxPluginAsync(plugin, paths, root));
}

// We push the nx core node plugins onto the end, s.t. it overwrites any other plugins
result.push(
getNxPackageJsonWorkspacesPlugin(root),
CreateProjectJsonProjectsPlugin
);

return result.map(ensurePluginIsV2);
}

Expand Down

0 comments on commit cf1175f

Please sign in to comment.