nx 19.4.0 → 19.5.0-canary.20240704-28939dd

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "19.4.0",
3
+ "version": "19.5.0-canary.20240704-28939dd",
4
4
  "private": false,
5
5
  "description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
6
6
  "repository": {
@@ -70,7 +70,7 @@
70
70
  "yargs-parser": "21.1.1",
71
71
  "node-machine-id": "1.1.12",
72
72
  "ora": "5.3.0",
73
- "@nrwl/tao": "19.4.0"
73
+ "@nrwl/tao": "19.5.0-canary.20240704-28939dd"
74
74
  },
75
75
  "peerDependencies": {
76
76
  "@swc-node/register": "^1.8.0",
@@ -85,16 +85,16 @@
85
85
  }
86
86
  },
87
87
  "optionalDependencies": {
88
- "@nx/nx-darwin-x64": "19.4.0",
89
- "@nx/nx-darwin-arm64": "19.4.0",
90
- "@nx/nx-linux-x64-gnu": "19.4.0",
91
- "@nx/nx-linux-x64-musl": "19.4.0",
92
- "@nx/nx-win32-x64-msvc": "19.4.0",
93
- "@nx/nx-linux-arm64-gnu": "19.4.0",
94
- "@nx/nx-linux-arm64-musl": "19.4.0",
95
- "@nx/nx-linux-arm-gnueabihf": "19.4.0",
96
- "@nx/nx-win32-arm64-msvc": "19.4.0",
97
- "@nx/nx-freebsd-x64": "19.4.0"
88
+ "@nx/nx-darwin-x64": "19.5.0-canary.20240704-28939dd",
89
+ "@nx/nx-darwin-arm64": "19.5.0-canary.20240704-28939dd",
90
+ "@nx/nx-linux-x64-gnu": "19.5.0-canary.20240704-28939dd",
91
+ "@nx/nx-linux-x64-musl": "19.5.0-canary.20240704-28939dd",
92
+ "@nx/nx-win32-x64-msvc": "19.5.0-canary.20240704-28939dd",
93
+ "@nx/nx-linux-arm64-gnu": "19.5.0-canary.20240704-28939dd",
94
+ "@nx/nx-linux-arm64-musl": "19.5.0-canary.20240704-28939dd",
95
+ "@nx/nx-linux-arm-gnueabihf": "19.5.0-canary.20240704-28939dd",
96
+ "@nx/nx-win32-arm64-msvc": "19.5.0-canary.20240704-28939dd",
97
+ "@nx/nx-freebsd-x64": "19.5.0-canary.20240704-28939dd"
98
98
  },
99
99
  "nx-migrations": {
100
100
  "migrations": "./migrations.json",
@@ -79,13 +79,7 @@ function getSwcTranspiler(compilerOptions) {
79
79
  return typeof cleanupFn === 'function' ? cleanupFn : () => { };
80
80
  }
81
81
  exports.getSwcTranspiler = getSwcTranspiler;
82
- const registered = new Set();
83
82
  function getTsNodeTranspiler(compilerOptions) {
84
- // Just return if transpiler was already registered before.
85
- const registrationKey = JSON.stringify(compilerOptions);
86
- if (registered.has(registrationKey)) {
87
- return () => { };
88
- }
89
83
  const { register } = require('ts-node');
90
84
  // ts-node doesn't provide a cleanup method
91
85
  const service = register({
@@ -94,7 +88,6 @@ function getTsNodeTranspiler(compilerOptions) {
94
88
  // we already read and provide the compiler options, so prevent ts-node from reading them again
95
89
  skipProject: true,
96
90
  });
97
- registered.add(registrationKey);
98
91
  const { transpiler, swc } = service.options;
99
92
  // Don't warn if a faster transpiler is enabled
100
93
  if (!transpiler && !swc) {
@@ -147,6 +140,7 @@ function filterRecognizedTsConfigTsNodeOptions(jsonObject) {
147
140
  const catchMissingProps = null;
148
141
  return { recognized: filteredTsConfigOptions, unrecognized };
149
142
  }
143
+ const registered = new Map();
150
144
  function getTranspiler(compilerOptions, tsConfigRaw) {
151
145
  const preferTsNode = process.env.NX_PREFER_TS_NODE === 'true';
152
146
  if (!ts) {
@@ -160,13 +154,35 @@ function getTranspiler(compilerOptions, tsConfigRaw) {
160
154
  compilerOptions.target = ts.ScriptTarget.ES2021;
161
155
  compilerOptions.inlineSourceMap = true;
162
156
  compilerOptions.skipLibCheck = true;
163
- if (swcNodeInstalled && !preferTsNode) {
164
- return () => getSwcTranspiler(compilerOptions);
157
+ // Just return if transpiler was already registered before.
158
+ const registrationKey = JSON.stringify(compilerOptions);
159
+ const registrationEntry = registered.get(registrationKey);
160
+ if (registered.has(registrationKey)) {
161
+ registrationEntry.refCount++;
162
+ return registrationEntry.cleanup;
165
163
  }
166
- // We can fall back on ts-node if it's available
167
- if (tsNodeInstalled) {
168
- const tsNodeOptions = filterRecognizedTsConfigTsNodeOptions(tsConfigRaw).recognized;
169
- return () => getTsNodeTranspiler(compilerOptions);
164
+ const _getTranspiler = swcNodeInstalled && !preferTsNode
165
+ ? getSwcTranspiler
166
+ : tsNodeInstalled
167
+ ? // We can fall back on ts-node if it's available
168
+ getTsNodeTranspiler
169
+ : undefined;
170
+ if (_getTranspiler) {
171
+ const transpilerCleanup = _getTranspiler(compilerOptions);
172
+ const currRegistrationEntry = {
173
+ refCount: 1,
174
+ cleanup: () => {
175
+ return () => {
176
+ currRegistrationEntry.refCount--;
177
+ if (currRegistrationEntry.refCount === 0) {
178
+ registered.delete(registrationKey);
179
+ transpilerCleanup();
180
+ }
181
+ };
182
+ },
183
+ };
184
+ registered.set(registrationKey, currRegistrationEntry);
185
+ return currRegistrationEntry.cleanup;
170
186
  }
171
187
  }
172
188
  exports.getTranspiler = getTranspiler;
@@ -107,7 +107,6 @@ async function normalizePlugins(plugins, root) {
107
107
  async function getDefaultPlugins(root) {
108
108
  return [
109
109
  (0, path_1.join)(__dirname, '../../plugins/js'),
110
- (0, path_1.join)(__dirname, '../../plugins/target-defaults/target-defaults-plugin'),
111
110
  ...((0, angular_json_1.shouldMergeAngularProjects)(root, false)
112
111
  ? [(0, path_1.join)(__dirname, '../../adapter/angular-json')]
113
112
  : []),
@@ -235,7 +235,7 @@ async function startPluginWorker() {
235
235
  workerPath,
236
236
  ipcPath,
237
237
  ], {
238
- stdio: process.stdout.isTTY ? 'inherit' : 'ignore',
238
+ stdio: 'inherit',
239
239
  env,
240
240
  detached: true,
241
241
  shell: false,
@@ -1,15 +1,10 @@
1
1
  import { NxJsonConfiguration, TargetDefaults } from '../../config/nx-json';
2
2
  import { ProjectGraphExternalNode } from '../../config/project-graph';
3
3
  import { ProjectConfiguration, ProjectMetadata, TargetConfiguration, TargetMetadata } from '../../config/workspace-json-project-json';
4
- import { ONLY_MODIFIES_EXISTING_TARGET } from '../../plugins/target-defaults/symbols';
5
4
  import { LoadedNxPlugin } from '../plugins/internal-api';
6
5
  export type SourceInformation = [file: string | null, plugin: string];
7
6
  export type ConfigurationSourceMaps = Record<string, Record<string, SourceInformation>>;
8
- export declare function mergeProjectConfigurationIntoRootMap(projectRootMap: Record<string, ProjectConfiguration>, project: ProjectConfiguration & {
9
- targets?: Record<string, TargetConfiguration & {
10
- [ONLY_MODIFIES_EXISTING_TARGET]?: boolean;
11
- }>;
12
- }, configurationSourceMaps?: ConfigurationSourceMaps, sourceInformation?: SourceInformation, skipTargetNormalization?: boolean): void;
7
+ export declare function mergeProjectConfigurationIntoRootMap(projectRootMap: Record<string, ProjectConfiguration>, project: ProjectConfiguration, configurationSourceMaps?: ConfigurationSourceMaps, sourceInformation?: SourceInformation, skipTargetNormalization?: boolean): void;
13
8
  export declare function mergeMetadata<T = ProjectMetadata | TargetMetadata>(sourceMap: Record<string, [file: string, plugin: string]>, sourceInformation: [file: string, plugin: string], baseSourceMapPath: string, metadata: T, matchingMetadata?: T): T;
14
9
  export type ConfigurationResult = {
15
10
  /**
@@ -44,6 +39,7 @@ export declare function createProjectConfigurations(root: string, nxJson: NxJson
44
39
  plugins: LoadedNxPlugin[]): Promise<ConfigurationResult>;
45
40
  export declare function readProjectConfigurationsFromRootMap(projectRootMap: Record<string, ProjectConfiguration>): Record<string, ProjectConfiguration>;
46
41
  export declare function validateProject(project: ProjectConfiguration, knownProjects: Record<string, ProjectConfiguration>): void;
42
+ export declare function mergeTargetDefaultWithTargetDefinition(targetName: string, project: ProjectConfiguration, targetDefault: Partial<TargetConfiguration>, sourceMap: Record<string, SourceInformation>): TargetConfiguration;
47
43
  /**
48
44
  * Merges two targets.
49
45
  *
@@ -68,4 +64,10 @@ export declare function mergeTargetConfigurations(target: TargetConfiguration, b
68
64
  export declare function isCompatibleTarget(a: TargetConfiguration, b: TargetConfiguration): boolean;
69
65
  export declare function resolveNxTokensInOptions<T extends Object | Array<unknown>>(object: T, project: ProjectConfiguration, key: string): T;
70
66
  export declare function readTargetDefaultsForTarget(targetName: string, targetDefaults: TargetDefaults, executor?: string): TargetDefaults[string];
67
+ /**
68
+ * Expand's `command` syntactic sugar and replaces tokens in options.
69
+ * @param target The target to normalize
70
+ * @param project The project that the target belongs to
71
+ * @returns The normalized target configuration
72
+ */
71
73
  export declare function normalizeTarget(target: TargetConfiguration, project: ProjectConfiguration): TargetConfiguration<any>;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeTarget = exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.validateProject = exports.readProjectConfigurationsFromRootMap = exports.createProjectConfigurations = exports.mergeMetadata = exports.mergeProjectConfigurationIntoRootMap = void 0;
3
+ exports.normalizeTarget = exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.mergeTargetDefaultWithTargetDefinition = exports.validateProject = exports.readProjectConfigurationsFromRootMap = exports.createProjectConfigurations = exports.mergeMetadata = exports.mergeProjectConfigurationIntoRootMap = void 0;
4
4
  const logger_1 = require("../../utils/logger");
5
5
  const fileutils_1 = require("../../utils/fileutils");
6
6
  const workspace_root_1 = require("../../utils/workspace-root");
7
- const symbols_1 = require("../../plugins/target-defaults/symbols");
8
7
  const minimatch_1 = require("minimatch");
9
8
  const path_1 = require("path");
10
9
  const perf_hooks_1 = require("perf_hooks");
@@ -120,22 +119,13 @@ skipTargetNormalization) {
120
119
  // Always set source map info for the target, but don't overwrite info already there
121
120
  // if augmenting an existing target.
122
121
  const target = project.targets?.[targetName];
123
- if (sourceMap && !target?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET]) {
122
+ if (sourceMap) {
124
123
  sourceMap[`targets.${targetName}`] = sourceInformation;
125
124
  }
126
- // If ONLY_MODIFIES_EXISTING_TARGET is true, and its not on the matching project
127
- // we shouldn't merge its info into the graph
128
- if (target?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET] &&
129
- !matchingProject.targets?.[targetName]) {
130
- continue;
131
- }
132
125
  const normalizedTarget = skipTargetNormalization
133
126
  ? target
134
127
  : resolveCommandSyntacticSugar(target, project.root);
135
128
  const mergedTarget = mergeTargetConfigurations(normalizedTarget, matchingProject.targets?.[targetName], sourceMap, sourceInformation, `targets.${targetName}`);
136
- // We don't want the symbol to live on past the merge process
137
- if (mergedTarget?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET])
138
- delete mergedTarget?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET];
139
129
  updatedProjectConfiguration.targets[targetName] = mergedTarget;
140
130
  }
141
131
  }
@@ -263,7 +253,7 @@ plugins) {
263
253
  results.push(r);
264
254
  }
265
255
  return Promise.all(results).then((results) => {
266
- const { projectRootMap, externalNodes, rootMap, configurationSourceMaps } = mergeCreateNodesResults(results, errors);
256
+ const { projectRootMap, externalNodes, rootMap, configurationSourceMaps } = mergeCreateNodesResults(results, nxJson, errors);
267
257
  perf_hooks_1.performance.mark('build-project-configs:end');
268
258
  perf_hooks_1.performance.measure('build-project-configs', 'build-project-configs:start', 'build-project-configs:end');
269
259
  if (errors.length === 0) {
@@ -287,7 +277,7 @@ plugins) {
287
277
  });
288
278
  }
289
279
  exports.createProjectConfigurations = createProjectConfigurations;
290
- function mergeCreateNodesResults(results, errors) {
280
+ function mergeCreateNodesResults(results, nxJsonConfiguration, errors) {
291
281
  perf_hooks_1.performance.mark('createNodes:merge - start');
292
282
  const projectRootMap = {};
293
283
  const externalNodes = {};
@@ -296,9 +286,6 @@ function mergeCreateNodesResults(results, errors) {
296
286
  const [pluginName, file, nodes] = result;
297
287
  const { projects: projectNodes, externalNodes: pluginExternalNodes } = nodes;
298
288
  const sourceInfo = [file, pluginName];
299
- if (result[symbols_1.OVERRIDE_SOURCE_FILE]) {
300
- sourceInfo[0] = result[symbols_1.OVERRIDE_SOURCE_FILE];
301
- }
302
289
  for (const node in projectNodes) {
303
290
  // Handles `{projects: {'libs/foo': undefined}}`.
304
291
  if (!projectNodes[node]) {
@@ -322,7 +309,7 @@ function mergeCreateNodesResults(results, errors) {
322
309
  Object.assign(externalNodes, pluginExternalNodes);
323
310
  }
324
311
  try {
325
- validateAndNormalizeProjectRootMap(projectRootMap);
312
+ validateAndNormalizeProjectRootMap(projectRootMap, nxJsonConfiguration, configurationSourceMaps);
326
313
  }
327
314
  catch (e) {
328
315
  if ((0, error_types_1.isProjectsWithNoNameError)(e) ||
@@ -401,7 +388,7 @@ function readProjectConfigurationsFromRootMap(projectRootMap) {
401
388
  return projects;
402
389
  }
403
390
  exports.readProjectConfigurationsFromRootMap = readProjectConfigurationsFromRootMap;
404
- function validateAndNormalizeProjectRootMap(projectRootMap) {
391
+ function validateAndNormalizeProjectRootMap(projectRootMap, nxJsonConfiguration, sourceMaps = {}) {
405
392
  // Name -> Project, used to validate that all projects have unique names
406
393
  const projects = {};
407
394
  // If there are projects that have the same name, that is an error.
@@ -434,24 +421,7 @@ function validateAndNormalizeProjectRootMap(projectRootMap) {
434
421
  throw e;
435
422
  }
436
423
  }
437
- for (const targetName in project.targets) {
438
- project.targets[targetName] = normalizeTarget(project.targets[targetName], project);
439
- if (
440
- // If the target has no executor or command, it doesn't do anything
441
- !project.targets[targetName].executor &&
442
- !project.targets[targetName].command) {
443
- // But it may have dependencies that do something
444
- if (project.targets[targetName].dependsOn &&
445
- project.targets[targetName].dependsOn.length > 0) {
446
- project.targets[targetName].executor = 'nx:noop';
447
- }
448
- else {
449
- // If it does nothing, and has no depenencies,
450
- // we can remove it.
451
- delete project.targets[targetName];
452
- }
453
- }
454
- }
424
+ normalizeTargets(project, sourceMaps, nxJsonConfiguration);
455
425
  }
456
426
  if (conflicts.size > 0) {
457
427
  throw new error_types_1.MultipleProjectsWithSameNameError(conflicts, projects);
@@ -461,6 +431,33 @@ function validateAndNormalizeProjectRootMap(projectRootMap) {
461
431
  }
462
432
  return projectRootMap;
463
433
  }
434
+ function normalizeTargets(project, sourceMaps, nxJsonConfiguration) {
435
+ for (const targetName in project.targets) {
436
+ project.targets[targetName] = normalizeTarget(project.targets[targetName], project);
437
+ const projectSourceMaps = sourceMaps[project.root];
438
+ const targetConfig = project.targets[targetName];
439
+ const targetDefaults = readTargetDefaultsForTarget(targetName, nxJsonConfiguration.targetDefaults, targetConfig.executor);
440
+ // We only apply defaults if they exist
441
+ if (targetDefaults && isCompatibleTarget(targetConfig, targetDefaults)) {
442
+ project.targets[targetName] = mergeTargetDefaultWithTargetDefinition(targetName, project, normalizeTarget(targetDefaults, project), projectSourceMaps);
443
+ }
444
+ if (
445
+ // If the target has no executor or command, it doesn't do anything
446
+ !project.targets[targetName].executor &&
447
+ !project.targets[targetName].command) {
448
+ // But it may have dependencies that do something
449
+ if (project.targets[targetName].dependsOn &&
450
+ project.targets[targetName].dependsOn.length > 0) {
451
+ project.targets[targetName].executor = 'nx:noop';
452
+ }
453
+ else {
454
+ // If it does nothing, and has no depenencies,
455
+ // we can remove it.
456
+ delete project.targets[targetName];
457
+ }
458
+ }
459
+ }
460
+ }
464
461
  function validateProject(project,
465
462
  // name -> project
466
463
  knownProjects) {
@@ -482,6 +479,75 @@ knownProjects) {
482
479
  }
483
480
  }
484
481
  exports.validateProject = validateProject;
482
+ function targetDefaultShouldBeApplied(key, sourceMap) {
483
+ const sourceInfo = sourceMap[key];
484
+ if (!sourceInfo) {
485
+ return true;
486
+ }
487
+ // The defined value of the target is from a plugin that
488
+ // isn't part of Nx's core plugins, so target defaults are
489
+ // applied on top of it.
490
+ const [, plugin] = sourceInfo;
491
+ return !plugin?.startsWith('nx/');
492
+ }
493
+ function mergeTargetDefaultWithTargetDefinition(targetName, project, targetDefault, sourceMap) {
494
+ const targetDefinition = project.targets[targetName] ?? {};
495
+ const result = JSON.parse(JSON.stringify(targetDefinition));
496
+ for (const key in targetDefault) {
497
+ switch (key) {
498
+ case 'options': {
499
+ const normalizedDefaults = resolveNxTokensInOptions(targetDefault.options, project, targetName);
500
+ for (const optionKey in normalizedDefaults) {
501
+ const sourceMapKey = `targets.${targetName}.options.${optionKey}`;
502
+ if (targetDefinition.options[optionKey] === undefined ||
503
+ targetDefaultShouldBeApplied(sourceMapKey, sourceMap)) {
504
+ result.options[optionKey] = targetDefault.options[optionKey];
505
+ sourceMap[sourceMapKey] = ['nx.json', 'nx/target-defaults'];
506
+ }
507
+ }
508
+ break;
509
+ }
510
+ case 'configurations': {
511
+ if (!result.configurations) {
512
+ result.configurations = {};
513
+ sourceMap[`targets.${targetName}.configurations`] = [
514
+ 'nx.json',
515
+ 'nx/target-defaults',
516
+ ];
517
+ }
518
+ for (const configuration in targetDefault.configurations) {
519
+ if (!result.configurations[configuration]) {
520
+ result.configurations[configuration] = {};
521
+ sourceMap[`targets.${targetName}.configurations.${configuration}`] =
522
+ ['nx.json', 'nx/target-defaults'];
523
+ }
524
+ const normalizedConfigurationDefaults = resolveNxTokensInOptions(targetDefault.configurations[configuration], project, targetName);
525
+ for (const configurationKey in normalizedConfigurationDefaults) {
526
+ const sourceMapKey = `targets.${targetName}.configurations.${configuration}.${configurationKey}`;
527
+ if (targetDefinition.configurations?.[configuration]?.[configurationKey] === undefined ||
528
+ targetDefaultShouldBeApplied(sourceMapKey, sourceMap)) {
529
+ result.configurations[configuration][configurationKey] =
530
+ targetDefault.configurations[configuration][configurationKey];
531
+ sourceMap[sourceMapKey] = ['nx.json', 'nx/target-defaults'];
532
+ }
533
+ }
534
+ }
535
+ break;
536
+ }
537
+ default: {
538
+ const sourceMapKey = `targets.${targetName}.${key}`;
539
+ if (targetDefinition[key] === undefined ||
540
+ targetDefaultShouldBeApplied(sourceMapKey, sourceMap)) {
541
+ result[key] = targetDefault[key];
542
+ sourceMap[sourceMapKey] = ['nx.json', 'nx/target-defaults'];
543
+ }
544
+ break;
545
+ }
546
+ }
547
+ }
548
+ return result;
549
+ }
550
+ exports.mergeTargetDefaultWithTargetDefinition = mergeTargetDefaultWithTargetDefinition;
485
551
  /**
486
552
  * Merges two targets.
487
553
  *
@@ -500,13 +566,6 @@ function mergeTargetConfigurations(target, baseTarget, projectConfigSourceMap, s
500
566
  // Target is "compatible", e.g. executor is defined only once or is the same
501
567
  // in both places. This means that it is likely safe to merge
502
568
  const isCompatible = isCompatibleTarget(baseTarget ?? {}, target);
503
- // If the targets are not compatible, we would normally overwrite the old target
504
- // with the new one. However, we have a special case for targets that have the
505
- // ONLY_MODIFIES_EXISTING_TARGET symbol set. This prevents the merged target
506
- // equaling info that should have only been used to modify the existing target.
507
- if (!isCompatible && target[symbols_1.ONLY_MODIFIES_EXISTING_TARGET]) {
508
- return baseTarget;
509
- }
510
569
  if (!isCompatible && projectConfigSourceMap) {
511
570
  // if the target is not compatible, we will simply override the options
512
571
  // we have to delete old entries from the source map
@@ -680,6 +739,12 @@ function resolveCommandSyntacticSugar(target, key) {
680
739
  };
681
740
  }
682
741
  }
742
+ /**
743
+ * Expand's `command` syntactic sugar and replaces tokens in options.
744
+ * @param target The target to normalize
745
+ * @param project The project that the target belongs to
746
+ * @returns The normalized target configuration
747
+ */
683
748
  function normalizeTarget(target, project) {
684
749
  target = resolveCommandSyntacticSugar(target, project.root);
685
750
  target.options = resolveNxTokensInOptions(target.options, project, `${project.root}:${target}`);
@@ -131,7 +131,7 @@ function getOutputsForTargetAndConfiguration(taskTargetOrTask, overridesOrNode,
131
131
  const { target, configuration } = taskTarget;
132
132
  const targetConfiguration = node.data.targets[target];
133
133
  const options = {
134
- ...targetConfiguration.options,
134
+ ...targetConfiguration?.options,
135
135
  ...targetConfiguration?.configurations?.[configuration],
136
136
  ...overrides,
137
137
  };
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDefaultPluginsSync = void 0;
4
4
  const angular_json_1 = require("../adapter/angular-json");
5
5
  const project_json_1 = require("../plugins/project-json/build-nodes/project-json");
6
- const target_defaults_plugin_1 = require("../plugins/target-defaults/target-defaults-plugin");
7
6
  const PackageJsonWorkspacesPlugin = require("../plugins/package-json-workspaces");
8
7
  /**
9
8
  * @todo(@agentender) v20: Remove this fn when we remove readWorkspaceConfig
@@ -14,7 +13,6 @@ function getDefaultPluginsSync(root) {
14
13
  ...((0, angular_json_1.shouldMergeAngularProjects)(root, false)
15
14
  ? [require('../adapter/angular-json').NxAngularJsonPlugin]
16
15
  : []),
17
- target_defaults_plugin_1.default,
18
16
  PackageJsonWorkspacesPlugin,
19
17
  project_json_1.default,
20
18
  ];
@@ -1,17 +0,0 @@
1
- /**
2
- * This marks that a target provides information which should modify a target already registered
3
- * on the project via other plugins. If the target has not already been registered, and this symbol is true,
4
- * the information provided by it will be discarded.
5
- *
6
- * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
7
- * between the plugin-worker and the main process.
8
- */
9
- export declare const ONLY_MODIFIES_EXISTING_TARGET = "NX_ONLY_MODIFIES_EXISTING_TARGET";
10
- /**
11
- * This is used to override the source file for the target defaults plugin.
12
- * This allows the plugin to use the project files as the context, but point to nx.json as the source file.
13
- *
14
- * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
15
- * between the plugin-worker and the main process.
16
- */
17
- export declare const OVERRIDE_SOURCE_FILE = "NX_OVERRIDE_SOURCE_FILE";
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OVERRIDE_SOURCE_FILE = exports.ONLY_MODIFIES_EXISTING_TARGET = void 0;
4
- /**
5
- * This marks that a target provides information which should modify a target already registered
6
- * on the project via other plugins. If the target has not already been registered, and this symbol is true,
7
- * the information provided by it will be discarded.
8
- *
9
- * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
10
- * between the plugin-worker and the main process.
11
- */
12
- exports.ONLY_MODIFIES_EXISTING_TARGET = 'NX_ONLY_MODIFIES_EXISTING_TARGET';
13
- /**
14
- * This is used to override the source file for the target defaults plugin.
15
- * This allows the plugin to use the project files as the context, but point to nx.json as the source file.
16
- *
17
- * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
18
- * between the plugin-worker and the main process.
19
- */
20
- exports.OVERRIDE_SOURCE_FILE = 'NX_OVERRIDE_SOURCE_FILE';
@@ -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
- }