nx 20.7.1 → 20.8.0-beta.0

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.
Files changed (67) hide show
  1. package/.eslintrc.json +3 -1
  2. package/package.json +11 -11
  3. package/release/index.d.ts +1 -1
  4. package/release/index.js +2 -1
  5. package/schemas/nx-schema.json +133 -33
  6. package/src/command-line/release/changelog.js +15 -10
  7. package/src/command-line/release/command-object.d.ts +1 -0
  8. package/src/command-line/release/command-object.js +4 -0
  9. package/src/command-line/release/config/config.d.ts +8 -7
  10. package/src/command-line/release/config/config.js +122 -42
  11. package/src/command-line/release/config/use-legacy-versioning.d.ts +2 -0
  12. package/src/command-line/release/config/use-legacy-versioning.js +9 -0
  13. package/src/command-line/release/index.d.ts +4 -0
  14. package/src/command-line/release/index.js +6 -1
  15. package/src/command-line/release/plan-check.js +6 -3
  16. package/src/command-line/release/plan.js +7 -3
  17. package/src/command-line/release/publish.js +5 -3
  18. package/src/command-line/release/release.js +8 -3
  19. package/src/command-line/release/utils/batch-projects-by-generator-config.js +6 -3
  20. package/src/command-line/release/utils/git.d.ts +2 -1
  21. package/src/command-line/release/utils/git.js +10 -2
  22. package/src/command-line/release/utils/github.js +3 -1
  23. package/src/command-line/release/utils/resolve-semver-specifier.d.ts +2 -1
  24. package/src/command-line/release/utils/resolve-semver-specifier.js +2 -1
  25. package/src/command-line/release/utils/semver.d.ts +8 -0
  26. package/src/command-line/release/utils/semver.js +8 -0
  27. package/src/command-line/release/utils/shared-legacy.d.ts +25 -0
  28. package/src/command-line/release/utils/shared-legacy.js +2 -0
  29. package/src/command-line/release/utils/shared.d.ts +11 -17
  30. package/src/command-line/release/version/derive-specifier-from-conventional-commits.d.ts +7 -0
  31. package/src/command-line/release/version/derive-specifier-from-conventional-commits.js +47 -0
  32. package/src/command-line/release/version/deriver-specifier-from-version-plans.d.ts +8 -0
  33. package/src/command-line/release/version/deriver-specifier-from-version-plans.js +59 -0
  34. package/src/command-line/release/version/project-logger.d.ts +8 -0
  35. package/src/command-line/release/version/project-logger.js +45 -0
  36. package/src/command-line/release/version/release-group-processor.d.ts +251 -0
  37. package/src/command-line/release/version/release-group-processor.js +1040 -0
  38. package/src/command-line/release/version/resolve-current-version.d.ts +32 -0
  39. package/src/command-line/release/version/resolve-current-version.js +241 -0
  40. package/src/command-line/release/version/test-utils.d.ts +95 -0
  41. package/src/command-line/release/version/test-utils.js +416 -0
  42. package/src/command-line/release/version/topological-sort.d.ts +9 -0
  43. package/src/command-line/release/version/topological-sort.js +41 -0
  44. package/src/command-line/release/version/version-actions.d.ts +170 -0
  45. package/src/command-line/release/version/version-actions.js +183 -0
  46. package/src/command-line/release/version-legacy.d.ts +46 -0
  47. package/src/command-line/release/version-legacy.js +453 -0
  48. package/src/command-line/release/version.d.ts +0 -40
  49. package/src/command-line/release/version.js +80 -262
  50. package/src/config/nx-json.d.ts +110 -12
  51. package/src/config/workspace-json-project-json.d.ts +2 -2
  52. package/src/core/graph/main.js +1 -1
  53. package/src/core/graph/styles.css +1 -1
  54. package/src/native/index.d.ts +22 -16
  55. package/src/native/native-bindings.js +1 -0
  56. package/src/native/nx.wasi-browser.js +7 -7
  57. package/src/native/nx.wasm32-wasi.wasm +0 -0
  58. package/src/plugins/js/lock-file/utils/package-json.d.ts +1 -1
  59. package/src/plugins/js/lock-file/utils/package-json.js +2 -1
  60. package/src/plugins/js/lock-file/yarn-parser.js +75 -29
  61. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +10 -1
  62. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +59 -6
  63. package/src/project-graph/error-types.js +28 -1
  64. package/src/tasks-runner/cache.d.ts +1 -0
  65. package/src/tasks-runner/cache.js +11 -0
  66. package/src/tasks-runner/run-command.js +9 -9
  67. package/src/utils/handle-errors.js +15 -0
@@ -49,6 +49,9 @@ class TargetProjectLocator {
49
49
  }
50
50
  return acc;
51
51
  }, {});
52
+ if (this.tsConfig.config?.compilerOptions?.paths) {
53
+ this.parsePaths(this.tsConfig.config.compilerOptions.paths);
54
+ }
52
55
  }
53
56
  /**
54
57
  * Resolve any workspace or external project that matches the given import expression,
@@ -63,14 +66,15 @@ class TargetProjectLocator {
63
66
  return this.findProjectOfResolvedModule(resolvedModule);
64
67
  }
65
68
  // find project using tsconfig paths
66
- const results = this.findPaths(importExpr);
69
+ const results = this.findMatchingPaths(importExpr);
67
70
  if (results) {
68
71
  const [path, paths] = results;
72
+ const matchedStar = typeof path === 'string'
73
+ ? undefined
74
+ : importExpr.substring(path.prefix.length, importExpr.length - path.suffix.length);
69
75
  for (let p of paths) {
70
- const r = p.endsWith('/*')
71
- ? (0, node_path_1.join)((0, node_path_1.dirname)(p), (0, node_path_1.relative)(path.replace(/\*$/, ''), importExpr))
72
- : p;
73
- const maybeResolvedProject = this.findProjectOfResolvedModule(r);
76
+ const path = matchedStar ? p.replace('*', matchedStar) : p;
77
+ const maybeResolvedProject = this.findProjectOfResolvedModule(path);
74
78
  if (maybeResolvedProject) {
75
79
  return maybeResolvedProject;
76
80
  }
@@ -172,7 +176,7 @@ class TargetProjectLocator {
172
176
  /**
173
177
  * Return file paths matching the import relative to the repo root
174
178
  * @param normalizedImportExpr
175
- * @returns
179
+ * @deprecated Use `findMatchingPaths` instead. It will be removed in Nx v22.
176
180
  */
177
181
  findPaths(normalizedImportExpr) {
178
182
  if (!this.paths) {
@@ -189,6 +193,29 @@ class TargetProjectLocator {
189
193
  }
190
194
  return undefined;
191
195
  }
196
+ findMatchingPaths(importExpr) {
197
+ if (!this.parsedPathPatterns) {
198
+ return undefined;
199
+ }
200
+ const { matchableStrings, patterns } = this.parsedPathPatterns;
201
+ if (matchableStrings.has(importExpr)) {
202
+ return [importExpr, this.paths[importExpr]];
203
+ }
204
+ // https://github.com/microsoft/TypeScript/blob/29e6d6689dfb422e4f1395546c1917d07e1f664d/src/compiler/core.ts#L2410
205
+ let matchedValue;
206
+ let longestMatchPrefixLength = -1;
207
+ for (let i = 0; i < patterns.length; i++) {
208
+ const pattern = patterns[i];
209
+ if (pattern.prefix.length > longestMatchPrefixLength &&
210
+ this.isPatternMatch(pattern, importExpr)) {
211
+ longestMatchPrefixLength = pattern.prefix.length;
212
+ matchedValue = pattern;
213
+ }
214
+ }
215
+ return matchedValue
216
+ ? [matchedValue, this.paths[matchedValue.pattern]]
217
+ : undefined;
218
+ }
192
219
  findImportInWorkspaceProjects(importPath) {
193
220
  this.packagesMetadata ??= (0, packages_1.getWorkspacePackagesMetadata)(this.nodes);
194
221
  if (this.packagesMetadata.entryPointsToProjectMap[importPath]) {
@@ -201,6 +228,32 @@ class TargetProjectLocator {
201
228
  this.packagesMetadata ??= (0, packages_1.getWorkspacePackagesMetadata)(this.nodes);
202
229
  return this.packagesMetadata.packageToProjectMap[dep]?.name;
203
230
  }
231
+ isPatternMatch({ prefix, suffix }, candidate) {
232
+ return (candidate.length >= prefix.length + suffix.length &&
233
+ candidate.startsWith(prefix) &&
234
+ candidate.endsWith(suffix));
235
+ }
236
+ parsePaths(paths) {
237
+ this.parsedPathPatterns = {
238
+ matchableStrings: new Set(),
239
+ patterns: [],
240
+ };
241
+ for (const key of Object.keys(paths)) {
242
+ const parts = key.split('*');
243
+ if (parts.length > 2) {
244
+ continue;
245
+ }
246
+ if (parts.length === 1) {
247
+ this.parsedPathPatterns.matchableStrings.add(key);
248
+ continue;
249
+ }
250
+ this.parsedPathPatterns.patterns.push({
251
+ pattern: key,
252
+ prefix: parts[0],
253
+ suffix: parts[1],
254
+ });
255
+ }
256
+ }
204
257
  resolveImportWithTypescript(normalizedImportExpr, filePath) {
205
258
  let resolvedModule;
206
259
  if (this.typescriptResolutionCache.has(normalizedImportExpr)) {
@@ -153,10 +153,37 @@ function isProjectWithNoNameError(e) {
153
153
  }
154
154
  class ProjectConfigurationsError extends Error {
155
155
  constructor(errors, partialProjectConfigurationsResult) {
156
- super('Failed to create project configurations');
156
+ const messageFragments = ['Failed to create project configurations.'];
157
+ const mergeNodesErrors = [];
158
+ const unknownErrors = [];
159
+ for (const e of errors) {
160
+ if (
161
+ // Known error type, but unlikely to be caused by the user
162
+ isMergeNodesError(e)) {
163
+ mergeNodesErrors.push(e);
164
+ }
165
+ else if (
166
+ // Known errors that are self-explanatory
167
+ !isAggregateCreateNodesError(e) &&
168
+ !isProjectsWithNoNameError(e) &&
169
+ !isMultipleProjectsWithSameNameError(e)) {
170
+ unknownErrors.push(e);
171
+ }
172
+ }
173
+ if (mergeNodesErrors.length > 0) {
174
+ messageFragments.push(`This type of error most likely points to an issue within Nx. Please report it.`);
175
+ }
176
+ if (unknownErrors.length > 0) {
177
+ messageFragments.push(`If the error cause is not obvious from the below error messages, running "nx reset" may fix it. Please report the issue if you keep seeing it.`);
178
+ }
179
+ super(messageFragments.join(' '));
157
180
  this.errors = errors;
158
181
  this.partialProjectConfigurationsResult = partialProjectConfigurationsResult;
159
182
  this.name = this.constructor.name;
183
+ this.errors = errors;
184
+ this.stack = errors
185
+ .map((error) => indentString(formatErrorStackAndCause(error), 2))
186
+ .join('\n');
160
187
  }
161
188
  }
162
189
  exports.ProjectConfigurationsError = ProjectConfigurationsError;
@@ -38,6 +38,7 @@ export declare class DbCache {
38
38
  private getSharedCache;
39
39
  private getGcsCache;
40
40
  private getAzureCache;
41
+ private getHttpCache;
41
42
  private resolveRemoteCache;
42
43
  private resolvePackage;
43
44
  private assertCacheIsValid;
@@ -169,6 +169,7 @@ class DbCache {
169
169
  (await this.getSharedCache()) ??
170
170
  (await this.getGcsCache()) ??
171
171
  (await this.getAzureCache()) ??
172
+ this.getHttpCache() ??
172
173
  null);
173
174
  }
174
175
  }
@@ -196,6 +197,16 @@ class DbCache {
196
197
  return cache;
197
198
  return this.resolveRemoteCache('@nx/powerpack-azure-cache');
198
199
  }
200
+ getHttpCache() {
201
+ if (process.env.NX_SELF_HOSTED_REMOTE_CACHE_SERVER) {
202
+ if (native_1.IS_WASM) {
203
+ logger_1.logger.warn('The HTTP remote cache is not yet supported in the wasm build of Nx.');
204
+ return null;
205
+ }
206
+ return new native_1.HttpRemoteCache();
207
+ }
208
+ return null;
209
+ }
199
210
  async resolveRemoteCache(pkg) {
200
211
  let getRemoteCache = null;
201
212
  try {
@@ -146,7 +146,7 @@ async function runCommandForTasks(projectsToRun, currentProjectGraph, { nxJson }
146
146
  }
147
147
  async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, projectNames, nxArgs, overrides, extraTargetDependencies, extraOptions) {
148
148
  let taskGraph = createTaskGraphAndRunValidations(projectGraph, extraTargetDependencies ?? {}, projectNames, nxArgs, overrides, extraOptions);
149
- if (nxArgs.skipSync) {
149
+ if (nxArgs.skipSync || (0, is_ci_1.isCI)()) {
150
150
  return { projectGraph, taskGraph };
151
151
  }
152
152
  // collect unique syncGenerators from the tasks
@@ -166,9 +166,8 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, project
166
166
  const outOfSyncTitle = 'The workspace is out of sync';
167
167
  const resultBodyLines = (0, sync_generators_1.getSyncGeneratorSuccessResultsMessageLines)(results);
168
168
  const fixMessage = 'Make sure to run `nx sync` to apply the identified changes or set `sync.applyChanges` to `true` in your `nx.json` to apply them automatically when running tasks in interactive environments.';
169
- const willErrorOnCiMessage = 'This will result in an error in CI.';
170
- if ((0, is_ci_1.isCI)() || !process.stdout.isTTY) {
171
- // If the user is running in CI or is running in a non-TTY environment we
169
+ if (!process.stdout.isTTY) {
170
+ // If the user is running a non-TTY environment we
172
171
  // throw an error to stop the execution of the tasks.
173
172
  if (areAllResultsFailures) {
174
173
  output_1.output.error({
@@ -216,7 +215,6 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, project
216
215
  ...resultBodyLines,
217
216
  '',
218
217
  'Your workspace is set to not apply the identified changes automatically (`sync.applyChanges` is set to `false` in your `nx.json`).',
219
- willErrorOnCiMessage,
220
218
  fixMessage,
221
219
  ],
222
220
  });
@@ -235,10 +233,12 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, project
235
233
  title: outOfSyncTitle,
236
234
  bodyLines: [
237
235
  ...resultBodyLines,
238
- '',
239
- nxJson.sync?.applyChanges === true
240
- ? 'Proceeding to sync the identified changes automatically (`sync.applyChanges` is set to `true` in your `nx.json`).'
241
- : willErrorOnCiMessage,
236
+ ...(nxJson.sync?.applyChanges === true
237
+ ? [
238
+ '',
239
+ 'Proceeding to sync the identified changes automatically (`sync.applyChanges` is set to `true` in your `nx.json`).',
240
+ ]
241
+ : []),
242
242
  ],
243
243
  });
244
244
  const applyChanges = nxJson.sync?.applyChanges === true ||
@@ -31,6 +31,21 @@ async function handleErrors(isVerbose, fn) {
31
31
  : projectGraphError.getErrors().map((e) => e.message),
32
32
  });
33
33
  }
34
+ else if (err.name === 'ProjectConfigurationsError') {
35
+ const projectConfigurationsError = err;
36
+ let title = projectConfigurationsError.message;
37
+ if (projectConfigurationsError.cause &&
38
+ typeof projectConfigurationsError.cause === 'object' &&
39
+ 'message' in projectConfigurationsError.cause) {
40
+ title += ' ' + projectConfigurationsError.cause.message + '.';
41
+ }
42
+ output_1.output.error({
43
+ title,
44
+ bodyLines: isVerbose
45
+ ? formatErrorStackAndCause(projectConfigurationsError, isVerbose)
46
+ : projectConfigurationsError.errors.map((e) => e.message),
47
+ });
48
+ }
34
49
  else {
35
50
  const lines = (err.message ? err.message : err.toString()).split('\n');
36
51
  const bodyLines = lines.slice(1);