nx 19.4.1 → 19.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "19.4.1",
3
+ "version": "19.4.2",
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.1"
73
+ "@nrwl/tao": "19.4.2"
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.1",
89
- "@nx/nx-darwin-arm64": "19.4.1",
90
- "@nx/nx-linux-x64-gnu": "19.4.1",
91
- "@nx/nx-linux-x64-musl": "19.4.1",
92
- "@nx/nx-win32-x64-msvc": "19.4.1",
93
- "@nx/nx-linux-arm64-gnu": "19.4.1",
94
- "@nx/nx-linux-arm64-musl": "19.4.1",
95
- "@nx/nx-linux-arm-gnueabihf": "19.4.1",
96
- "@nx/nx-win32-arm64-msvc": "19.4.1",
97
- "@nx/nx-freebsd-x64": "19.4.1"
88
+ "@nx/nx-darwin-x64": "19.4.2",
89
+ "@nx/nx-darwin-arm64": "19.4.2",
90
+ "@nx/nx-linux-x64-gnu": "19.4.2",
91
+ "@nx/nx-linux-x64-musl": "19.4.2",
92
+ "@nx/nx-win32-x64-msvc": "19.4.2",
93
+ "@nx/nx-linux-arm64-gnu": "19.4.2",
94
+ "@nx/nx-linux-arm64-musl": "19.4.2",
95
+ "@nx/nx-linux-arm-gnueabihf": "19.4.2",
96
+ "@nx/nx-win32-arm64-msvc": "19.4.2",
97
+ "@nx/nx-freebsd-x64": "19.4.2"
98
98
  },
99
99
  "nx-migrations": {
100
100
  "migrations": "./migrations.json",
@@ -84,7 +84,7 @@ export interface PluginCreateMetadataResult {
84
84
  tx: string;
85
85
  } | {
86
86
  success: false;
87
- error: string;
87
+ error: Error;
88
88
  tx: string;
89
89
  };
90
90
  }
@@ -117,7 +117,11 @@ const server = (0, net_1.createServer)((socket) => {
117
117
  catch (e) {
118
118
  return {
119
119
  type: 'createMetadataResult',
120
- payload: { success: false, error: e.stack, tx },
120
+ payload: {
121
+ success: false,
122
+ error: (0, serializable_error_1.createSerializableError)(e),
123
+ tx,
124
+ },
121
125
  };
122
126
  }
123
127
  },
@@ -253,8 +253,10 @@ plugins) {
253
253
  else {
254
254
  errorBodyLines.push(` - ${e.message}`);
255
255
  }
256
+ const innerStackTrace = ' ' + e.stack.split('\n').join('\n ');
257
+ errorBodyLines.push(innerStackTrace);
256
258
  }
257
- error.message = errorBodyLines.join('\n');
259
+ error.stack = errorBodyLines.join('\n');
258
260
  // This represents a single plugin erroring out with a hard error.
259
261
  errors.push(error);
260
262
  // The plugin didn't return partial results, so we return an empty array.
@@ -11,10 +11,11 @@ export declare class ProcessTasks {
11
11
  readonly dependencies: {
12
12
  [k: string]: string[];
13
13
  };
14
+ private readonly allTargetNames;
14
15
  constructor(extraTargetDependencies: TargetDependencies, projectGraph: ProjectGraph);
15
16
  processTasks(projectNames: string[], targets: string[], configuration: string, overrides: Object, excludeTaskDependencies: boolean): string[];
16
17
  processTask(task: Task, projectUsedToDeriveDependencies: string, configuration: string, overrides: Object): void;
17
- private processTasksForMatchingProjects;
18
+ private processTasksForMultipleProjects;
18
19
  private processTasksForSingleProject;
19
20
  private processTasksForDependencies;
20
21
  createTask(id: string, project: ProjectGraphProjectNode, target: string, resolvedConfiguration: string | undefined, overrides: Object): Task;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapTargetDefaultsToDependencies = exports.createTaskGraph = exports.ProcessTasks = void 0;
4
4
  const utils_1 = require("./utils");
5
5
  const project_graph_utils_1 = require("../utils/project-graph-utils");
6
- const find_matching_projects_1 = require("../utils/find-matching-projects");
7
6
  const output_1 = require("../utils/output");
8
7
  class ProcessTasks {
9
8
  constructor(extraTargetDependencies, projectGraph) {
@@ -12,6 +11,14 @@ class ProcessTasks {
12
11
  this.seen = new Set();
13
12
  this.tasks = {};
14
13
  this.dependencies = {};
14
+ const allTargetNames = new Set();
15
+ for (const projectName in projectGraph.nodes) {
16
+ const project = projectGraph.nodes[projectName];
17
+ for (const targetName in project.data.targets ?? {}) {
18
+ allTargetNames.add(targetName);
19
+ }
20
+ }
21
+ this.allTargetNames = Array.from(allTargetNames);
15
22
  }
16
23
  processTasks(projectNames, targets, configuration, overrides, excludeTaskDependencies) {
17
24
  for (const projectName of projectNames) {
@@ -58,32 +65,13 @@ class ProcessTasks {
58
65
  return;
59
66
  }
60
67
  this.seen.add(seenKey);
61
- const dependencyConfigs = (0, utils_1.getDependencyConfigs)({ project: task.target.project, target: task.target.target }, this.extraTargetDependencies, this.projectGraph);
68
+ const dependencyConfigs = (0, utils_1.getDependencyConfigs)({ project: task.target.project, target: task.target.target }, this.extraTargetDependencies, this.projectGraph, this.allTargetNames);
62
69
  for (const dependencyConfig of dependencyConfigs) {
63
70
  const taskOverrides = dependencyConfig.params === 'forward'
64
71
  ? overrides
65
72
  : { __overrides_unparsed__: [] };
66
73
  if (dependencyConfig.projects) {
67
- /** LERNA SUPPORT START - Remove in v20 */
68
- // Lerna uses `dependencies` in `prepNxOptions`, so we need to maintain
69
- // support for it until lerna can be updated to use the syntax.
70
- //
71
- // This should have been removed in v17, but the updates to lerna had not
72
- // been made yet.
73
- //
74
- // TODO(@agentender): Remove this part in v20
75
- if (typeof dependencyConfig.projects === 'string') {
76
- if (dependencyConfig.projects === 'self') {
77
- this.processTasksForSingleProject(task, task.target.project, dependencyConfig, configuration, taskOverrides, overrides);
78
- continue;
79
- }
80
- else if (dependencyConfig.projects === 'dependencies') {
81
- this.processTasksForDependencies(projectUsedToDeriveDependencies, dependencyConfig, configuration, task, taskOverrides, overrides);
82
- continue;
83
- }
84
- }
85
- /** LERNA SUPPORT END - Remove in v17 */
86
- this.processTasksForMatchingProjects(dependencyConfig, configuration, task, taskOverrides, overrides);
74
+ this.processTasksForMultipleProjects(dependencyConfig, configuration, task, taskOverrides, overrides);
87
75
  }
88
76
  else if (dependencyConfig.dependencies) {
89
77
  this.processTasksForDependencies(projectUsedToDeriveDependencies, dependencyConfig, configuration, task, taskOverrides, overrides);
@@ -93,20 +81,16 @@ class ProcessTasks {
93
81
  }
94
82
  }
95
83
  }
96
- processTasksForMatchingProjects(dependencyConfig, configuration, task, taskOverrides, overrides) {
97
- const targetProjectSpecifiers = typeof dependencyConfig.projects === 'string'
98
- ? [dependencyConfig.projects]
99
- : dependencyConfig.projects;
100
- const matchingProjects = (0, find_matching_projects_1.findMatchingProjects)(targetProjectSpecifiers, this.projectGraph.nodes);
101
- if (matchingProjects.length === 0) {
84
+ processTasksForMultipleProjects(dependencyConfig, configuration, task, taskOverrides, overrides) {
85
+ if (dependencyConfig.projects.length === 0) {
102
86
  output_1.output.warn({
103
87
  title: `\`dependsOn\` is misconfigured for ${task.target.project}:${task.target.target}`,
104
88
  bodyLines: [
105
- `Project patterns "${targetProjectSpecifiers}" does not match any projects.`,
89
+ `Project patterns "${dependencyConfig.projects}" does not match any projects.`,
106
90
  ],
107
91
  });
108
92
  }
109
- for (const projectName of matchingProjects) {
93
+ for (const projectName of dependencyConfig.projects) {
110
94
  this.processTasksForSingleProject(task, projectName, dependencyConfig, configuration, taskOverrides, overrides);
111
95
  }
112
96
  }
@@ -2,12 +2,25 @@ import { Task, TaskGraph } from '../config/task-graph';
2
2
  import { ProjectGraph, ProjectGraphProjectNode } from '../config/project-graph';
3
3
  import { TargetConfiguration, TargetDependencyConfig } from '../config/workspace-json-project-json';
4
4
  import { CustomHasher, ExecutorConfig } from '../config/misc-interfaces';
5
+ export type NormalizedTargetDependencyConfig = TargetDependencyConfig & {
6
+ projects: string[];
7
+ };
5
8
  export declare function getDependencyConfigs({ project, target }: {
6
9
  project: string;
7
10
  target: string;
8
- }, extraTargetDependencies: Record<string, (TargetDependencyConfig | string)[]>, projectGraph: ProjectGraph): TargetDependencyConfig[] | undefined;
9
- export declare function expandDependencyConfigSyntaxSugar(dependencyConfigString: string, graph: ProjectGraph): TargetDependencyConfig;
11
+ }, extraTargetDependencies: Record<string, (TargetDependencyConfig | string)[]>, projectGraph: ProjectGraph, allTargetNames: string[]): NormalizedTargetDependencyConfig[] | undefined;
12
+ export declare function normalizeDependencyConfigDefinition(definition: string | TargetDependencyConfig, currentProject: string, graph: ProjectGraph, allTargetNames: string[]): NormalizedTargetDependencyConfig[];
13
+ export declare function normalizeDependencyConfigProjects(dependencyConfig: TargetDependencyConfig, currentProject: string, graph: ProjectGraph): NormalizedTargetDependencyConfig;
14
+ export declare function expandDependencyConfigSyntaxSugar(dependencyConfigString: string | TargetDependencyConfig, graph: ProjectGraph): TargetDependencyConfig;
15
+ export declare function expandWildcardTargetConfiguration(dependencyConfig: NormalizedTargetDependencyConfig, allTargetNames: string[]): NormalizedTargetDependencyConfig[];
16
+ export declare function readProjectAndTargetFromTargetString(targetString: string, projects: Record<string, ProjectGraphProjectNode>): {
17
+ projects?: string[];
18
+ target: string;
19
+ };
10
20
  export declare function getOutputs(p: Record<string, ProjectGraphProjectNode>, target: Task['target'], overrides: Task['overrides']): string[];
21
+ export declare function normalizeTargetDependencyWithStringProjects(dependencyConfig: TargetDependencyConfig): Omit<TargetDependencyConfig, 'projects'> & {
22
+ projects: string[];
23
+ };
11
24
  declare class InvalidOutputsError extends Error {
12
25
  outputs: string[];
13
26
  invalidOutputs: Set<string>;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unparse = exports.isCacheableTask = exports.shouldStreamOutput = exports.getSerializedArgsForTask = exports.getPrintableCommandArgsForTask = exports.getCliPath = exports.calculateReverseDeps = exports.removeIdsFromGraph = exports.removeTasksFromTaskGraph = exports.getCustomHasher = exports.getExecutorForTask = exports.getExecutorNameForTask = exports.getTargetConfigurationForTask = exports.interpolate = exports.getOutputsForTargetAndConfiguration = exports.transformLegacyOutputs = exports.validateOutputs = exports.getOutputs = exports.expandDependencyConfigSyntaxSugar = exports.getDependencyConfigs = void 0;
4
- const output_1 = require("../utils/output");
3
+ exports.unparse = exports.isCacheableTask = exports.shouldStreamOutput = exports.getSerializedArgsForTask = exports.getPrintableCommandArgsForTask = exports.getCliPath = exports.calculateReverseDeps = exports.removeIdsFromGraph = exports.removeTasksFromTaskGraph = exports.getCustomHasher = exports.getExecutorForTask = exports.getExecutorNameForTask = exports.getTargetConfigurationForTask = exports.interpolate = exports.getOutputsForTargetAndConfiguration = exports.transformLegacyOutputs = exports.validateOutputs = exports.normalizeTargetDependencyWithStringProjects = exports.getOutputs = exports.readProjectAndTargetFromTargetString = exports.expandWildcardTargetConfiguration = exports.expandDependencyConfigSyntaxSugar = exports.normalizeDependencyConfigProjects = exports.normalizeDependencyConfigDefinition = exports.getDependencyConfigs = void 0;
5
4
  const path_1 = require("path");
6
5
  const posix_1 = require("path/posix");
7
6
  const workspace_root_1 = require("../utils/workspace-root");
@@ -11,28 +10,35 @@ const serialize_overrides_into_command_line_1 = require("../utils/serialize-over
11
10
  const split_target_1 = require("../utils/split-target");
12
11
  const executor_utils_1 = require("../command-line/run/executor-utils");
13
12
  const project_graph_1 = require("../project-graph/project-graph");
14
- function getDependencyConfigs({ project, target }, extraTargetDependencies, projectGraph) {
13
+ const find_matching_projects_1 = require("../utils/find-matching-projects");
14
+ const minimatch_1 = require("minimatch");
15
+ function getDependencyConfigs({ project, target }, extraTargetDependencies, projectGraph, allTargetNames) {
15
16
  const dependencyConfigs = (projectGraph.nodes[project].data?.targets[target]?.dependsOn ??
16
17
  // This is passed into `run-command` from programmatic invocations
17
18
  extraTargetDependencies[target] ??
18
- []).map((config) => typeof config === 'string'
19
- ? expandDependencyConfigSyntaxSugar(config, projectGraph)
20
- : config);
21
- for (const dependencyConfig of dependencyConfigs) {
22
- if (dependencyConfig.projects && dependencyConfig.dependencies) {
23
- output_1.output.error({
24
- title: `dependsOn is improperly configured for ${project}:${target}`,
25
- bodyLines: [
26
- `dependsOn.projects and dependsOn.dependencies cannot be used together.`,
27
- ],
28
- });
29
- process.exit(1);
30
- }
31
- }
19
+ []).flatMap((config) => normalizeDependencyConfigDefinition(config, project, projectGraph, allTargetNames));
32
20
  return dependencyConfigs;
33
21
  }
34
22
  exports.getDependencyConfigs = getDependencyConfigs;
23
+ function normalizeDependencyConfigDefinition(definition, currentProject, graph, allTargetNames) {
24
+ return expandWildcardTargetConfiguration(normalizeDependencyConfigProjects(expandDependencyConfigSyntaxSugar(definition, graph), currentProject, graph), allTargetNames);
25
+ }
26
+ exports.normalizeDependencyConfigDefinition = normalizeDependencyConfigDefinition;
27
+ function normalizeDependencyConfigProjects(dependencyConfig, currentProject, graph) {
28
+ const noStringConfig = normalizeTargetDependencyWithStringProjects(dependencyConfig);
29
+ if (noStringConfig.projects) {
30
+ dependencyConfig.projects = (0, find_matching_projects_1.findMatchingProjects)(noStringConfig.projects, graph.nodes);
31
+ }
32
+ else if (!noStringConfig.dependencies) {
33
+ dependencyConfig.projects = [currentProject];
34
+ }
35
+ return dependencyConfig;
36
+ }
37
+ exports.normalizeDependencyConfigProjects = normalizeDependencyConfigProjects;
35
38
  function expandDependencyConfigSyntaxSugar(dependencyConfigString, graph) {
39
+ if (typeof dependencyConfigString !== 'string') {
40
+ return dependencyConfigString;
41
+ }
36
42
  const [dependencies, targetString] = dependencyConfigString.startsWith('^')
37
43
  ? [true, dependencyConfigString.substring(1)]
38
44
  : [false, dependencyConfigString];
@@ -44,26 +50,84 @@ function expandDependencyConfigSyntaxSugar(dependencyConfigString, graph) {
44
50
  dependencies: true,
45
51
  };
46
52
  }
53
+ const { projects, target } = readProjectAndTargetFromTargetString(targetString, graph.nodes);
54
+ return projects ? { projects, target } : { target };
55
+ }
56
+ exports.expandDependencyConfigSyntaxSugar = expandDependencyConfigSyntaxSugar;
57
+ // Weakmap let's the cache get cleared by garbage collector if allTargetNames is no longer used
58
+ const patternResultCache = new WeakMap();
59
+ function expandWildcardTargetConfiguration(dependencyConfig, allTargetNames) {
60
+ if (!find_matching_projects_1.GLOB_CHARACTERS.some((char) => dependencyConfig.target.includes(char))) {
61
+ return [dependencyConfig];
62
+ }
63
+ let cache = patternResultCache.get(allTargetNames);
64
+ if (!cache) {
65
+ cache = new Map();
66
+ patternResultCache.set(allTargetNames, cache);
67
+ }
68
+ const cachedResult = cache.get(dependencyConfig.target);
69
+ if (cachedResult) {
70
+ return cachedResult;
71
+ }
72
+ const matcher = minimatch_1.minimatch.filter(dependencyConfig.target);
73
+ const matchingTargets = allTargetNames.filter((t) => matcher(t));
74
+ const result = matchingTargets.map((t) => ({
75
+ ...dependencyConfig,
76
+ target: t,
77
+ }));
78
+ cache.set(dependencyConfig.target, result);
79
+ return result;
80
+ }
81
+ exports.expandWildcardTargetConfiguration = expandWildcardTargetConfiguration;
82
+ function readProjectAndTargetFromTargetString(targetString, projects) {
47
83
  // Support for both `project:target` and `target:with:colons` syntax
48
84
  const [maybeProject, ...segments] = (0, split_target_1.splitByColons)(targetString);
49
- // if no additional segments are provided, then the string references
50
- // a target of the same project
51
85
  if (!segments.length) {
86
+ // if no additional segments are provided, then the string references
87
+ // a target of the same project
52
88
  return { target: maybeProject };
53
89
  }
54
- return {
90
+ else if (maybeProject in projects) {
55
91
  // Only the first segment could be a project. If it is, the rest is a target.
56
92
  // If its not, then the whole targetString was a target with colons in its name.
57
- target: maybeProject in graph.nodes ? segments.join(':') : targetString,
93
+ return { projects: [maybeProject], target: segments.join(':') };
94
+ }
95
+ else {
58
96
  // If the first segment is a project, then we have a specific project. Otherwise, we don't.
59
- projects: maybeProject in graph.nodes ? [maybeProject] : undefined,
60
- };
97
+ return { target: targetString };
98
+ }
61
99
  }
62
- exports.expandDependencyConfigSyntaxSugar = expandDependencyConfigSyntaxSugar;
100
+ exports.readProjectAndTargetFromTargetString = readProjectAndTargetFromTargetString;
63
101
  function getOutputs(p, target, overrides) {
64
102
  return getOutputsForTargetAndConfiguration(target, overrides, p[target.project]);
65
103
  }
66
104
  exports.getOutputs = getOutputs;
105
+ function normalizeTargetDependencyWithStringProjects(dependencyConfig) {
106
+ if (typeof dependencyConfig.projects === 'string') {
107
+ /** LERNA SUPPORT START - Remove in v20 */
108
+ // Lerna uses `dependencies` in `prepNxOptions`, so we need to maintain
109
+ // support for it until lerna can be updated to use the syntax.
110
+ //
111
+ // This should have been removed in v17, but the updates to lerna had not
112
+ // been made yet.
113
+ //
114
+ // TODO(@agentender): Remove this part in v20
115
+ if (dependencyConfig.projects === 'self') {
116
+ delete dependencyConfig.projects;
117
+ }
118
+ else if (dependencyConfig.projects === 'dependencies') {
119
+ dependencyConfig.dependencies = true;
120
+ delete dependencyConfig.projects;
121
+ return;
122
+ /** LERNA SUPPORT END - Remove in v20 */
123
+ }
124
+ else {
125
+ dependencyConfig.projects = [dependencyConfig.projects];
126
+ }
127
+ }
128
+ return dependencyConfig;
129
+ }
130
+ exports.normalizeTargetDependencyWithStringProjects = normalizeTargetDependencyWithStringProjects;
67
131
  class InvalidOutputsError extends Error {
68
132
  constructor(outputs, invalidOutputs) {
69
133
  super(InvalidOutputsError.createMessage(invalidOutputs));
@@ -1,4 +1,8 @@
1
1
  import type { ProjectGraphProjectNode } from '../config/project-graph';
2
+ /**
3
+ * The presence of these characters in a string indicates that it might be a glob pattern.
4
+ */
5
+ export declare const GLOB_CHARACTERS: string[];
2
6
  /**
3
7
  * Find matching project names given a list of potential project names or globs.
4
8
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMatchingStringsWithCache = exports.findMatchingProjects = void 0;
3
+ exports.getMatchingStringsWithCache = exports.findMatchingProjects = exports.GLOB_CHARACTERS = void 0;
4
4
  const minimatch_1 = require("minimatch");
5
5
  const validPatternTypes = [
6
6
  'name', // Pattern is based on the project's name
@@ -8,7 +8,10 @@ const validPatternTypes = [
8
8
  'directory', // Pattern is based on the project's root directory
9
9
  'unlabeled', // Pattern was passed without specifying a type
10
10
  ];
11
- const globCharacters = ['*', '|', '{', '}', '(', ')'];
11
+ /**
12
+ * The presence of these characters in a string indicates that it might be a glob pattern.
13
+ */
14
+ exports.GLOB_CHARACTERS = ['*', '|', '{', '}', '(', ')'];
12
15
  /**
13
16
  * Find matching project names given a list of potential project names or globs.
14
17
  *
@@ -110,7 +113,7 @@ function addMatchingProjectsByName(projectNames, projects, pattern, matchedProje
110
113
  }
111
114
  return;
112
115
  }
113
- if (!globCharacters.some((c) => pattern.value.includes(c))) {
116
+ if (!exports.GLOB_CHARACTERS.some((c) => pattern.value.includes(c))) {
114
117
  return;
115
118
  }
116
119
  const matchedProjectNames = (0, exports.getMatchingStringsWithCache)(pattern.value, projectNames);
@@ -135,7 +138,7 @@ function addMatchingProjectsByTag(projectNames, projects, pattern, matchedProjec
135
138
  }
136
139
  continue;
137
140
  }
138
- if (!globCharacters.some((c) => pattern.value.includes(c))) {
141
+ if (!exports.GLOB_CHARACTERS.some((c) => pattern.value.includes(c))) {
139
142
  continue;
140
143
  }
141
144
  if ((0, exports.getMatchingStringsWithCache)(pattern.value, tags).length) {
@@ -17,6 +17,12 @@ function createSerializableError(error) {
17
17
  value = value.map((v) => {
18
18
  if (typeof v === 'object' && v instanceof Error) {
19
19
  return createSerializableError(v);
20
+ // Support for AggregateCreateNodesError
21
+ }
22
+ else if (Array.isArray(v) &&
23
+ v.length === 2 &&
24
+ v[1] instanceof Error) {
25
+ return [v[0], createSerializableError(v[1])];
20
26
  }
21
27
  return v;
22
28
  });