nx 18.0.0 → 18.0.2

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,4 +1,6 @@
1
+ import { ProjectConfiguration } from '../../config/workspace-json-project-json';
1
2
  import { NxPluginV2 } from '../../utils/nx-plugin';
3
+ import { PackageJson } from '../../utils/package-json';
2
4
  /**
3
5
  * This symbol marks that a target provides information which should modify a target already registered
4
6
  * on the project via other plugins. If the target has not already been registered, and this symbol is true,
@@ -6,3 +8,49 @@ import { NxPluginV2 } from '../../utils/nx-plugin';
6
8
  */
7
9
  export declare const ONLY_MODIFIES_EXISTING_TARGET: unique symbol;
8
10
  export declare const TargetDefaultsPlugin: NxPluginV2;
11
+ /**
12
+ * This fn gets target info that would make a target uniquely compatible
13
+ * with what is described by project.json or package.json. As the merge process
14
+ * for config happens, without this, the target defaults may be compatible
15
+ * with a config from a plugin and then that combined target be incompatible
16
+ * with the project json configuration resulting in the target default values
17
+ * being scrapped. By adding enough information from the project.json / package.json,
18
+ * we can make sure that the target after merging is compatible with the defined target.
19
+ */
20
+ export declare function getTargetInfo(target: string, projectJson: Pick<ProjectConfiguration, 'targets'>, packageJson: Pick<PackageJson, 'scripts' | 'nx'>): {
21
+ command: string;
22
+ executor?: undefined;
23
+ options?: undefined;
24
+ } | {
25
+ executor: string;
26
+ options: {
27
+ command: any;
28
+ commands?: undefined;
29
+ script?: undefined;
30
+ };
31
+ command?: undefined;
32
+ } | {
33
+ executor: string;
34
+ options: {
35
+ commands: any;
36
+ command?: undefined;
37
+ script?: undefined;
38
+ };
39
+ command?: undefined;
40
+ } | {
41
+ executor: string;
42
+ command?: undefined;
43
+ options?: undefined;
44
+ } | {
45
+ executor: string;
46
+ options: {
47
+ script: any;
48
+ command?: undefined;
49
+ commands?: undefined;
50
+ };
51
+ command?: undefined;
52
+ } | {
53
+ command?: undefined;
54
+ executor?: undefined;
55
+ options?: undefined;
56
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TargetDefaultsPlugin = exports.ONLY_MODIFIES_EXISTING_TARGET = void 0;
3
+ exports.getTargetInfo = exports.TargetDefaultsPlugin = exports.ONLY_MODIFIES_EXISTING_TARGET = void 0;
4
4
  const minimatch_1 = require("minimatch");
5
5
  const node_fs_1 = require("node:fs");
6
6
  const node_path_1 = require("node:path");
@@ -57,7 +57,11 @@ exports.TargetDefaultsPlugin = {
57
57
  // Prevents `build` from overwriting `@nx/js:tsc` if both are present
58
58
  // and build is specified later in the ordering.
59
59
  if (!modifiedTargets[targetName] || targetName !== defaultSpecifier) {
60
- modifiedTargets[targetName] = JSON.parse(JSON.stringify(targetDefaults[defaultSpecifier]));
60
+ const defaults = JSON.parse(JSON.stringify(targetDefaults[defaultSpecifier]));
61
+ modifiedTargets[targetName] = {
62
+ ...getTargetInfo(targetName, projectJson, packageJson),
63
+ ...defaults,
64
+ };
61
65
  }
62
66
  // TODO: Remove this after we figure out a way to define new targets
63
67
  // in target defaults
@@ -101,3 +105,74 @@ function readJsonOrNull(path) {
101
105
  return null;
102
106
  }
103
107
  }
108
+ /**
109
+ * This fn gets target info that would make a target uniquely compatible
110
+ * with what is described by project.json or package.json. As the merge process
111
+ * for config happens, without this, the target defaults may be compatible
112
+ * with a config from a plugin and then that combined target be incompatible
113
+ * with the project json configuration resulting in the target default values
114
+ * being scrapped. By adding enough information from the project.json / package.json,
115
+ * we can make sure that the target after merging is compatible with the defined target.
116
+ */
117
+ function getTargetInfo(target, projectJson, packageJson) {
118
+ const projectJsonTarget = projectJson?.targets?.[target];
119
+ const packageJsonTarget = packageJson?.nx?.targets?.[target];
120
+ const executor = getTargetExecutor(target, projectJson, packageJson);
121
+ const targetOptions = {
122
+ ...packageJsonTarget?.options,
123
+ ...projectJsonTarget?.options,
124
+ };
125
+ if (projectJsonTarget?.command) {
126
+ return {
127
+ command: projectJsonTarget?.command,
128
+ };
129
+ }
130
+ if (executor === 'nx:run-commands') {
131
+ if (targetOptions?.command) {
132
+ return {
133
+ executor: 'nx:run-commands',
134
+ options: {
135
+ command: projectJsonTarget.options?.command,
136
+ },
137
+ };
138
+ }
139
+ else if (targetOptions?.commands) {
140
+ return {
141
+ executor: 'nx:run-commands',
142
+ options: {
143
+ commands: targetOptions.commands,
144
+ },
145
+ };
146
+ }
147
+ return {
148
+ executor: 'nx:run-commands',
149
+ };
150
+ }
151
+ if (executor === 'nx:run-script') {
152
+ return {
153
+ executor: 'nx:run-script',
154
+ options: {
155
+ script: targetOptions?.script ?? target,
156
+ },
157
+ };
158
+ }
159
+ if (executor) {
160
+ return { executor };
161
+ }
162
+ return {};
163
+ }
164
+ exports.getTargetInfo = getTargetInfo;
165
+ function getTargetExecutor(target, projectJson, packageJson) {
166
+ const projectJsonTarget = projectJson?.targets?.[target];
167
+ const packageJsonTarget = packageJson?.nx?.targets?.[target];
168
+ const packageJsonScript = packageJson?.scripts?.[target];
169
+ if (projectJsonTarget?.command) {
170
+ return 'nx:run-commands';
171
+ }
172
+ if (!projectJsonTarget?.executor &&
173
+ !packageJsonTarget?.executor &&
174
+ packageJsonScript) {
175
+ return 'nx:run-script';
176
+ }
177
+ return projectJsonTarget?.executor ?? packageJsonTarget?.executor;
178
+ }