-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathplugin.ts
More file actions
82 lines (75 loc) · 2.41 KB
/
plugin.ts
File metadata and controls
82 lines (75 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import type {
CreateNodes,
CreateNodesContext,
CreateNodesContextV2,
CreateNodesResult,
CreateNodesResultV2,
CreateNodesV2,
} from '@nx/devkit';
import { PROJECT_JSON_FILE_NAME } from '../internal/constants.js';
import { PLUGIN_NAME } from './constants.js';
import { createTargets } from './target/targets.js';
import type { CreateNodesOptions } from './types.js';
import {
normalizedCreateNodesContext,
normalizedCreateNodesV2Context,
} from './utils.js';
// name has to be "createNodes" to get picked up by Nx <v20
/**
* @deprecated
*/
export const createNodes: CreateNodes = [
`**/${PROJECT_JSON_FILE_NAME}`,
async (
projectConfigurationFile: string,
createNodesOptions: unknown,
context: CreateNodesContext,
): Promise<CreateNodesResult> => {
const parsedCreateNodesOptions = createNodesOptions as CreateNodesOptions;
const pluginsConfig =
context.nxJsonConfiguration.pluginsConfig?.[PLUGIN_NAME] ?? {};
const mergedOptions = { ...pluginsConfig, ...parsedCreateNodesOptions };
const normalizedContext = await normalizedCreateNodesContext(
context,
projectConfigurationFile,
mergedOptions,
);
return {
projects: {
[normalizedContext.projectRoot]: {
targets: await createTargets(normalizedContext),
},
},
};
},
];
export const createNodesV2: CreateNodesV2<CreateNodesOptions> = [
`**/${PROJECT_JSON_FILE_NAME}`,
async (
projectConfigurationFiles: readonly string[],
createNodesOptions: unknown,
context: CreateNodesContextV2,
): Promise<CreateNodesResultV2> => {
const parsedCreateNodesOptions = createNodesOptions as CreateNodesOptions;
const { pluginsConfig = {} } = context.nxJsonConfiguration;
const pluginsConfigObj = pluginsConfig[PLUGIN_NAME] ?? {};
const mergedOptions = { ...pluginsConfigObj, ...parsedCreateNodesOptions };
return await Promise.all(
projectConfigurationFiles.map(async projectConfigurationFile => {
const normalizedContext = await normalizedCreateNodesV2Context(
context,
projectConfigurationFile,
mergedOptions,
);
const result: CreateNodesResult = {
projects: {
[normalizedContext.projectRoot]: {
targets: await createTargets(normalizedContext),
},
},
};
return [projectConfigurationFile, result] as const;
}),
);
},
];