nx 19.5.0-canary.20240703-4c76b95 → 19.5.0-canary.20240705-653cad2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,121 +0,0 @@
1
- import { TargetConfiguration } from '../../config/workspace-json-project-json';
2
- import { NxPluginV2 } from '../../project-graph/plugins';
3
- export declare const TargetDefaultsPlugin: NxPluginV2;
4
- export default TargetDefaultsPlugin;
5
- /**
6
- * This fn gets target info that would make a target uniquely compatible
7
- * with what is described by project.json or package.json. As the merge process
8
- * for config happens, without this, the target defaults may be compatible
9
- * with a config from a plugin and then that combined target be incompatible
10
- * with the project json configuration resulting in the target default values
11
- * being scrapped. By adding enough information from the project.json / package.json,
12
- * we can make sure that the target after merging is compatible with the defined target.
13
- */
14
- export declare function getTargetInfo(target: string, projectJsonTargets: Record<string, TargetConfiguration>, packageJsonTargets: Record<string, TargetConfiguration>): {
15
- command: string;
16
- metadata: {
17
- [x: string]: any;
18
- description?: string;
19
- technologies?: string[];
20
- nonAtomizedTarget?: string;
21
- help?: {
22
- command: string;
23
- example: {
24
- options?: Record<string, unknown>;
25
- args?: string[];
26
- };
27
- };
28
- };
29
- executor?: undefined;
30
- options?: undefined;
31
- } | {
32
- executor: string;
33
- options: {
34
- command: any;
35
- commands?: undefined;
36
- script?: undefined;
37
- };
38
- metadata: {
39
- [x: string]: any;
40
- description?: string;
41
- technologies?: string[];
42
- nonAtomizedTarget?: string;
43
- help?: {
44
- command: string;
45
- example: {
46
- options?: Record<string, unknown>;
47
- args?: string[];
48
- };
49
- };
50
- };
51
- command?: undefined;
52
- } | {
53
- executor: string;
54
- options: {
55
- commands: any;
56
- command?: undefined;
57
- script?: undefined;
58
- };
59
- metadata: {
60
- [x: string]: any;
61
- description?: string;
62
- technologies?: string[];
63
- nonAtomizedTarget?: string;
64
- help?: {
65
- command: string;
66
- example: {
67
- options?: Record<string, unknown>;
68
- args?: string[];
69
- };
70
- };
71
- };
72
- command?: undefined;
73
- } | {
74
- executor: string;
75
- metadata: {
76
- [x: string]: any;
77
- description?: string;
78
- technologies?: string[];
79
- nonAtomizedTarget?: string;
80
- help?: {
81
- command: string;
82
- example: {
83
- options?: Record<string, unknown>;
84
- args?: string[];
85
- };
86
- };
87
- };
88
- command?: undefined;
89
- options?: undefined;
90
- } | {
91
- executor: string;
92
- options: {
93
- script: any;
94
- command?: undefined;
95
- commands?: undefined;
96
- };
97
- metadata: {
98
- [x: string]: any;
99
- description?: string;
100
- technologies?: string[];
101
- nonAtomizedTarget?: string;
102
- help?: {
103
- command: string;
104
- example: {
105
- options?: Record<string, unknown>;
106
- args?: string[];
107
- };
108
- };
109
- };
110
- command?: undefined;
111
- } | {
112
- executor: string;
113
- command?: undefined;
114
- metadata?: undefined;
115
- options?: undefined;
116
- } | {
117
- command?: undefined;
118
- metadata?: undefined;
119
- executor?: undefined;
120
- options?: undefined;
121
- };
@@ -1,176 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTargetInfo = exports.TargetDefaultsPlugin = void 0;
4
- const minimatch_1 = require("minimatch");
5
- const node_fs_1 = require("node:fs");
6
- const node_path_1 = require("node:path");
7
- const fileutils_1 = require("../../utils/fileutils");
8
- const globs_1 = require("../../utils/globs");
9
- const package_json_1 = require("../../utils/package-json");
10
- const package_json_workspaces_1 = require("../package-json-workspaces");
11
- const symbols_1 = require("./symbols");
12
- exports.TargetDefaultsPlugin = {
13
- name: 'nx/core/target-defaults',
14
- createNodes: [
15
- '{package.json,**/package.json,project.json,**/project.json}',
16
- (configFile, _, ctx) => {
17
- const fileName = (0, node_path_1.basename)(configFile);
18
- const root = (0, node_path_1.dirname)(configFile);
19
- const packageManagerWorkspacesGlob = (0, globs_1.combineGlobPatterns)((0, package_json_workspaces_1.getGlobPatternsFromPackageManagerWorkspaces)(ctx.workspaceRoot));
20
- // Only process once if package.json + project.json both exist
21
- if (fileName === 'package.json' &&
22
- (0, node_fs_1.existsSync)((0, node_path_1.join)(ctx.workspaceRoot, root, 'project.json'))) {
23
- return {};
24
- }
25
- else if (fileName === 'package.json' &&
26
- !(0, minimatch_1.minimatch)(configFile, packageManagerWorkspacesGlob)) {
27
- return {};
28
- }
29
- // If no target defaults, this does nothing
30
- const targetDefaults = ctx.nxJsonConfiguration?.targetDefaults;
31
- if (!targetDefaults) {
32
- return {};
33
- }
34
- const projectJson = readJsonOrNull((0, node_path_1.join)(ctx.workspaceRoot, root, 'project.json'));
35
- const packageJson = readJsonOrNull((0, node_path_1.join)(ctx.workspaceRoot, root, 'package.json'));
36
- const packageJsonTargets = (0, package_json_1.readTargetsFromPackageJson)(packageJson);
37
- const projectDefinedTargets = new Set([
38
- ...Object.keys(projectJson?.targets ?? {}),
39
- ...(packageJson ? Object.keys(packageJsonTargets) : []),
40
- ]);
41
- const executorToTargetMap = getExecutorToTargetMap(packageJsonTargets, projectJson?.targets);
42
- const modifiedTargets = {};
43
- for (const defaultSpecifier in targetDefaults) {
44
- const targetNames = executorToTargetMap.get(defaultSpecifier) ?? new Set();
45
- targetNames.add(defaultSpecifier);
46
- for (const targetName of targetNames) {
47
- // Prevents `build` from overwriting `@nx/js:tsc` if both are present
48
- // and build is specified later in the ordering.
49
- if (!modifiedTargets[targetName] || targetName !== defaultSpecifier) {
50
- const defaults = JSON.parse(JSON.stringify(targetDefaults[defaultSpecifier]));
51
- modifiedTargets[targetName] = {
52
- ...getTargetInfo(targetName, projectJson?.targets, packageJsonTargets),
53
- ...defaults,
54
- };
55
- }
56
- // TODO: Remove this after we figure out a way to define new targets
57
- // in target defaults
58
- if (!projectDefinedTargets.has(targetName)) {
59
- modifiedTargets[targetName][symbols_1.ONLY_MODIFIES_EXISTING_TARGET] = true;
60
- }
61
- }
62
- }
63
- return {
64
- projects: {
65
- [root]: {
66
- targets: modifiedTargets,
67
- },
68
- },
69
- [symbols_1.OVERRIDE_SOURCE_FILE]: 'nx.json',
70
- };
71
- },
72
- ],
73
- };
74
- exports.default = exports.TargetDefaultsPlugin;
75
- function getExecutorToTargetMap(packageJsonTargets, projectJsonTargets) {
76
- const executorToTargetMap = new Map();
77
- const targets = Object.keys({
78
- ...projectJsonTargets,
79
- ...packageJsonTargets,
80
- });
81
- for (const target of targets) {
82
- const executor = getTargetExecutor(target, projectJsonTargets, packageJsonTargets);
83
- const targetsForExecutor = executorToTargetMap.get(executor) ?? new Set();
84
- targetsForExecutor.add(target);
85
- executorToTargetMap.set(executor, targetsForExecutor);
86
- }
87
- return executorToTargetMap;
88
- }
89
- function readJsonOrNull(path) {
90
- if ((0, node_fs_1.existsSync)(path)) {
91
- return (0, fileutils_1.readJsonFile)(path);
92
- }
93
- else {
94
- return null;
95
- }
96
- }
97
- /**
98
- * This fn gets target info that would make a target uniquely compatible
99
- * with what is described by project.json or package.json. As the merge process
100
- * for config happens, without this, the target defaults may be compatible
101
- * with a config from a plugin and then that combined target be incompatible
102
- * with the project json configuration resulting in the target default values
103
- * being scrapped. By adding enough information from the project.json / package.json,
104
- * we can make sure that the target after merging is compatible with the defined target.
105
- */
106
- function getTargetInfo(target, projectJsonTargets, packageJsonTargets) {
107
- const projectJsonTarget = projectJsonTargets?.[target];
108
- const packageJsonTarget = packageJsonTargets?.[target];
109
- const executor = getTargetExecutor(target, projectJsonTargets, packageJsonTargets);
110
- const targetOptions = {
111
- ...packageJsonTarget?.options,
112
- ...projectJsonTarget?.options,
113
- };
114
- const metadata = {
115
- ...packageJsonTarget?.metadata,
116
- ...projectJsonTarget?.metadata,
117
- };
118
- if (projectJsonTarget?.command) {
119
- return {
120
- command: projectJsonTarget?.command,
121
- metadata,
122
- };
123
- }
124
- if (executor === 'nx:run-commands') {
125
- if (targetOptions?.command) {
126
- return {
127
- executor: 'nx:run-commands',
128
- options: {
129
- command: targetOptions?.command,
130
- },
131
- metadata,
132
- };
133
- }
134
- else if (targetOptions?.commands) {
135
- return {
136
- executor: 'nx:run-commands',
137
- options: {
138
- commands: targetOptions.commands,
139
- },
140
- metadata,
141
- };
142
- }
143
- return {
144
- executor: 'nx:run-commands',
145
- metadata,
146
- };
147
- }
148
- if (executor === 'nx:run-script') {
149
- return {
150
- executor: 'nx:run-script',
151
- options: {
152
- script: targetOptions?.script ?? target,
153
- },
154
- metadata,
155
- };
156
- }
157
- if (executor) {
158
- return { executor };
159
- }
160
- return {};
161
- }
162
- exports.getTargetInfo = getTargetInfo;
163
- function getTargetExecutor(target, projectJsonTargets, packageJsonTargets) {
164
- const projectJsonTargetConfiguration = projectJsonTargets?.[target];
165
- const packageJsonTargetConfiguration = packageJsonTargets?.[target];
166
- if (!projectJsonTargetConfiguration && packageJsonTargetConfiguration) {
167
- return packageJsonTargetConfiguration?.executor;
168
- }
169
- if (projectJsonTargetConfiguration?.executor) {
170
- return projectJsonTargetConfiguration.executor;
171
- }
172
- if (projectJsonTargetConfiguration?.command) {
173
- return 'nx:run-commands';
174
- }
175
- return null;
176
- }