Skip to content

Commit 9f3cefb

Browse files
committed
feat(nx-plugin): implement plugin v2 support
1 parent 3d83489 commit 9f3cefb

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

packages/nx-plugin/src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import { createNodes } from './plugin/index.js';
1+
import { createNodes, createNodesV2 } from './plugin/index.js';
22

33
// default export for nx.json#plugins
4-
export default createNodes;
4+
const plugin = {
5+
name: '@code-pushup/nx-plugin',
6+
createNodesV2,
7+
// Keep for backwards compatibility with Nx < 21
8+
createNodes,
9+
};
10+
11+
export default plugin;
512

613
export type { AutorunCommandExecutorOptions } from './executors/cli/schema.js';
714
export { objectToCliArgs } from './executors/internal/cli.js';
@@ -15,4 +22,4 @@ export {
1522
type ProcessConfig,
1623
} from './internal/execute-process.js';
1724
export * from './internal/versions.js';
18-
export { createNodes } from './plugin/index.js';
25+
export { createNodes, createNodesV2 } from './plugin/index.js';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { createNodes } from './plugin.js';
1+
export { createNodes, createNodesV2 } from './plugin.js';
22
export type { CreateNodesOptions } from './types.js';

packages/nx-plugin/src/plugin/plugin.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import type {
22
CreateNodes,
33
CreateNodesContext,
4+
CreateNodesContextV2,
45
CreateNodesResult,
6+
CreateNodesResultV2,
7+
CreateNodesV2,
58
} from '@nx/devkit';
69
import { PROJECT_JSON_FILE_NAME } from '../internal/constants.js';
710
import { createTargets } from './target/targets.js';
811
import type { CreateNodesOptions } from './types.js';
9-
import { normalizedCreateNodesContext } from './utils.js';
12+
import {
13+
normalizedCreateNodesContext,
14+
normalizedCreateNodesV2Context,
15+
} from './utils.js';
1016

1117
// name has to be "createNodes" to get picked up by Nx <v20
1218
export const createNodes: CreateNodes = [
@@ -32,3 +38,36 @@ export const createNodes: CreateNodes = [
3238
};
3339
},
3440
];
41+
42+
export const createNodesV2: CreateNodesV2<CreateNodesOptions> = [
43+
`**/${PROJECT_JSON_FILE_NAME}`,
44+
async (
45+
projectConfigurationFiles: readonly string[],
46+
createNodesOptions: unknown,
47+
context: CreateNodesContextV2,
48+
): Promise<CreateNodesResultV2> => {
49+
const parsedCreateNodesOptions = createNodesOptions as CreateNodesOptions;
50+
51+
const results = await Promise.all(
52+
projectConfigurationFiles.map(async projectConfigurationFile => {
53+
const normalizedContext = await normalizedCreateNodesV2Context(
54+
context,
55+
projectConfigurationFile,
56+
parsedCreateNodesOptions,
57+
);
58+
59+
const result: CreateNodesResult = {
60+
projects: {
61+
[normalizedContext.projectRoot]: {
62+
targets: await createTargets(normalizedContext),
63+
},
64+
},
65+
};
66+
67+
return [projectConfigurationFile, result] as const;
68+
}),
69+
);
70+
71+
return results;
72+
},
73+
];

0 commit comments

Comments
 (0)