Skip to content

Commit

Permalink
fix(core): normalize to v2 when needed, leave as mixed where we suppo…
Browse files Browse the repository at this point in the history
…rt both
  • Loading branch information
AgentEnder committed Aug 10, 2023
1 parent 5d8b3f9 commit f3748ed
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
8 changes: 6 additions & 2 deletions packages/nx/src/config/workspaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { dirname, join } from 'path';
import { workspaceRoot } from '../utils/workspace-root';
import { readJsonFile } from '../utils/fileutils';
import { loadNxPlugins, loadNxPluginsSync } from '../utils/nx-plugin';
import {
ensurePluginIsV2,
loadNxPlugins,
loadNxPluginsSync,
} from '../utils/nx-plugin';

import type { NxJsonConfiguration } from './nx-json';
import { readNxJson } from './nx-json';
Expand Down Expand Up @@ -43,7 +47,7 @@ export class Workspaces {
buildProjectsConfigurationsFromProjectPathsAndPlugins(
nxJson,
projectPaths,
loadNxPluginsSync(),
loadNxPluginsSync().map((p) => ensurePluginIsV2(p)),
this.root
).projects;
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getNxRequirePaths } from '../../../utils/installation-directory';
import { join } from 'path';
import { existsSync } from 'fs';
import { configurationGlobs } from '../../utils/retrieve-workspace-files';
import { loadNxPlugins } from '../../../utils/nx-plugin';
import { ensurePluginIsV2, loadNxPlugins } from '../../../utils/nx-plugin';
import { combineGlobPatterns } from '../../../utils/globs';

export const getTouchedProjectsFromProjectGlobChanges: TouchedProjectLocator =
Expand All @@ -17,7 +17,7 @@ export const getTouchedProjectsFromProjectGlobChanges: TouchedProjectLocator =
nxJson?.plugins,
getNxRequirePaths(workspaceRoot),
workspaceRoot
)
).then((p) => p.map((plugin) => ensurePluginIsV2(plugin)))
)
);

Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ async function updateProjectGraphWithPlugins(
}
for (const plugin of plugins) {
try {
if (isNxPluginV2(plugin)) {
if (isNxPluginV2(plugin) && plugin.createDependencies) {
const builder = new ProjectDependencyBuilder(graph);
const newDependencies = await plugin.createDependencies?.({
const newDependencies = await plugin.createDependencies({
...context,
graph,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getProjectConfigurationFiles, NxWorkspaceFiles } from '../../native';
import { getGlobPatternsFromPackageManagerWorkspaces } from '../../../plugins/package-json-workspaces';
import { buildProjectsConfigurationsFromProjectPathsAndPlugins } from './project-configuration-utils';
import {
ensurePluginIsV2,
loadNxPlugins,
loadNxPluginsSync,
NxPluginV2,
Expand All @@ -43,7 +44,7 @@ export async function retrieveWorkspaceFiles(
nxJson?.plugins ?? [],
getNxRequirePaths(workspaceRoot),
workspaceRoot
);
).then((plugins) => plugins.map((p) => ensurePluginIsV2(p)));
let globs = configurationGlobs(workspaceRoot, plugins);
performance.mark('native-file-deps:end');
performance.measure(
Expand Down Expand Up @@ -105,7 +106,7 @@ export async function retrieveProjectConfigurations(
nxJson?.plugins ?? [],
getNxRequirePaths(workspaceRoot),
workspaceRoot
);
).then((plugins) => plugins.map((p) => ensurePluginIsV2(p)));
const globs = configurationGlobs(workspaceRoot, plugins);
return getProjectConfigurations(workspaceRoot, globs, (configs: string[]) => {
const projectConfigurations = createProjectConfigurations(
Expand All @@ -131,7 +132,9 @@ export function retrieveProjectConfigurationPaths(
): string[] {
const projectGlobPatterns = configurationGlobs(
root,
loadNxPluginsSync(nxJson?.plugins ?? [], getNxRequirePaths(root), root)
loadNxPluginsSync(nxJson?.plugins ?? [], getNxRequirePaths(root), root).map(
(p) => ensurePluginIsV2(p)
)
);
const { getProjectConfigurationFiles } =
require('../../native') as typeof import('../../native');
Expand Down
10 changes: 5 additions & 5 deletions packages/nx/src/utils/nx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export function loadNxPluginsSync(
plugins?: string[],
paths = getNxRequirePaths(),
root = workspaceRoot
): (NxPluginV2 & Pick<NxPluginV1, 'processProjectGraph'>)[] {
): NxPlugin[] {
const result: NxPlugin[] = [];

// TODO: This should be specified in nx.json
Expand All @@ -236,14 +236,14 @@ export function loadNxPluginsSync(
}
}

return result.map(ensurePluginIsV2);
return result;
}

export async function loadNxPlugins(
plugins?: string[],
paths = getNxRequirePaths(),
root = workspaceRoot
): Promise<(NxPluginV2 & Pick<NxPluginV1, 'processProjectGraph'>)[]> {
): Promise<NxPlugin[]> {
const result: NxPlugin[] = [];

// TODO: This should be specified in nx.json
Expand All @@ -258,10 +258,10 @@ export async function loadNxPlugins(
result.push(await loadNxPluginAsync(plugin, paths, root));
}

return result.map(ensurePluginIsV2);
return result;
}

function ensurePluginIsV2(plugin: NxPlugin): NxPluginV2 {
export function ensurePluginIsV2(plugin: NxPlugin): NxPluginV2 {
if (isNxPluginV1(plugin) && plugin.projectFilePatterns) {
return {
...plugin,
Expand Down

0 comments on commit f3748ed

Please sign in to comment.