@nx/js 19.2.0-canary.20240604-0594deb → 19.2.0-rc.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "19.2.0-canary.20240604-0594deb",
3
+ "version": "19.2.0-rc.0",
4
4
  "private": false,
5
5
  "description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
6
6
  "repository": {
@@ -58,9 +58,9 @@
58
58
  "semver": "^7.5.3",
59
59
  "source-map-support": "0.5.19",
60
60
  "tslib": "^2.3.0",
61
- "@nx/devkit": "19.2.0-canary.20240604-0594deb",
62
- "@nx/workspace": "19.2.0-canary.20240604-0594deb",
63
- "@nrwl/js": "19.2.0-canary.20240604-0594deb"
61
+ "@nx/devkit": "19.2.0-rc.0",
62
+ "@nx/workspace": "19.2.0-rc.0",
63
+ "@nrwl/js": "19.2.0-rc.0"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "verdaccio": "^5.0.4"
@@ -86,6 +86,7 @@ async function initGenerator(tree, schema) {
86
86
  /dist
87
87
  /coverage
88
88
  /.nx/cache
89
+ /.nx/workspace-data
89
90
  `);
90
91
  }
91
92
  if (tree.exists('.vscode/extensions.json')) {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.releaseVersionGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const chalk = require("chalk");
6
+ const fs_extra_1 = require("fs-extra");
6
7
  const node_child_process_1 = require("node:child_process");
7
8
  const node_path_1 = require("node:path");
8
9
  const config_1 = require("nx/src/command-line/release/config/config");
@@ -15,8 +16,8 @@ const ora = require("ora");
15
16
  const semver_2 = require("semver");
16
17
  const npm_config_1 = require("../../utils/npm-config");
17
18
  const resolve_local_package_dependencies_1 = require("./utils/resolve-local-package-dependencies");
18
- const update_lock_file_1 = require("./utils/update-lock-file");
19
19
  const sort_projects_topologically_1 = require("./utils/sort-projects-topologically");
20
+ const update_lock_file_1 = require("./utils/update-lock-file");
20
21
  async function releaseVersionGenerator(tree, options) {
21
22
  try {
22
23
  const versionData = {};
@@ -65,6 +66,7 @@ Valid values are: ${version_1.validReleaseVersionPrefixes
65
66
  let specifier = options.specifier
66
67
  ? options.specifier
67
68
  : undefined;
69
+ const deleteVersionPlanCallbacks = [];
68
70
  for (const project of projects) {
69
71
  const projectName = project.name;
70
72
  const packageRoot = projectNameToPackageRootMap.get(projectName);
@@ -197,6 +199,8 @@ To fix this you will either need to add a package.json file at that location, or
197
199
  }
198
200
  if (options.specifier) {
199
201
  log(`📄 Using the provided version specifier "${options.specifier}".`);
202
+ // The user is forcibly overriding whatever specifierSource they had otherwise set by imperatively providing a specifier
203
+ options.specifierSource = 'prompt';
200
204
  }
201
205
  /**
202
206
  * If we are versioning independently then we always need to determine the specifier for each project individually, except
@@ -271,8 +275,76 @@ To fix this you will either need to add a package.json file at that location, or
271
275
  }
272
276
  break;
273
277
  }
278
+ case 'version-plans': {
279
+ if (!options.releaseGroup.versionPlans) {
280
+ if (options.releaseGroup.name === config_1.IMPLICIT_DEFAULT_RELEASE_GROUP) {
281
+ throw new Error(`Invalid specifierSource "version-plans" provided. To enable version plans, set the "release.versionPlans" configuration option to "true" in nx.json.`);
282
+ }
283
+ else {
284
+ throw new Error(`Invalid specifierSource "version-plans" provided. To enable version plans for release group "${options.releaseGroup.name}", set the "versionPlans" configuration option to "true" within the release group configuration in nx.json.`);
285
+ }
286
+ }
287
+ if (options.releaseGroup.projectsRelationship === 'independent') {
288
+ specifier = options.releaseGroup.versionPlans.reduce((spec, plan) => {
289
+ if (!spec) {
290
+ return plan.projectVersionBumps[projectName];
291
+ }
292
+ if (plan.projectVersionBumps[projectName]) {
293
+ const prevNewVersion = (0, semver_2.inc)(currentVersion, spec);
294
+ const nextNewVersion = (0, semver_2.inc)(currentVersion, plan.projectVersionBumps[projectName]);
295
+ return (0, semver_2.gt)(nextNewVersion, prevNewVersion)
296
+ ? plan.projectVersionBumps[projectName]
297
+ : spec;
298
+ }
299
+ return spec;
300
+ }, null);
301
+ }
302
+ else {
303
+ specifier = options.releaseGroup.versionPlans.reduce((spec, plan) => {
304
+ if (!spec) {
305
+ return plan.groupVersionBump;
306
+ }
307
+ const prevNewVersion = (0, semver_2.inc)(currentVersion, spec);
308
+ const nextNewVersion = (0, semver_2.inc)(currentVersion, plan.groupVersionBump);
309
+ return (0, semver_2.gt)(nextNewVersion, prevNewVersion)
310
+ ? plan.groupVersionBump
311
+ : spec;
312
+ }, null);
313
+ }
314
+ if (!specifier) {
315
+ if (updateDependents !== 'never' &&
316
+ projectToDependencyBumps.has(projectName)) {
317
+ // No applicable changes to the project directly by the user, but one or more dependencies have been bumped and updateDependents is enabled
318
+ specifier = updateDependentsBump;
319
+ log(`📄 Resolved the specifier as "${specifier}" because "release.version.generatorOptions.updateDependents" is enabled`);
320
+ }
321
+ else {
322
+ specifier = null;
323
+ log(`🚫 No changes were detected within version plans.`);
324
+ }
325
+ }
326
+ else {
327
+ log(`📄 Resolved the specifier as "${specifier}" using version plans.`);
328
+ }
329
+ if (options.deleteVersionPlans) {
330
+ options.releaseGroup.versionPlans.forEach((p) => {
331
+ deleteVersionPlanCallbacks.push(async (dryRun) => {
332
+ if (!dryRun) {
333
+ await (0, fs_extra_1.remove)(p.absolutePath);
334
+ // the relative path is easier to digest, so use that for
335
+ // git operations and logging
336
+ return [p.relativePath];
337
+ }
338
+ else {
339
+ return [];
340
+ }
341
+ });
342
+ });
343
+ }
344
+ break;
345
+ }
274
346
  default:
275
- throw new Error(`Invalid specifierSource "${specifierSource}" provided. Must be one of "prompt" or "conventional-commits"`);
347
+ throw new Error(`Invalid specifierSource "${specifierSource}" provided. Must be one of "prompt", "conventional-commits" or "version-plans".`);
276
348
  }
277
349
  }
278
350
  // Resolve any local package dependencies for this project (before applying the new version or updating the versionData)
@@ -306,7 +378,16 @@ To fix this you will either need to add a package.json file at that location, or
306
378
  circularDependencies.add(`${dependentProject.source}:${dependentProject.target}`);
307
379
  circularDependencies.add(`${dependentProject.target}:${dependentProject.source}`);
308
380
  }
309
- const isInCurrentBatch = options.projects.some((project) => project.name === dependentProject.source);
381
+ let isInCurrentBatch = options.projects.some((project) => project.name === dependentProject.source);
382
+ // For version-plans, we don't just need to consider the current batch of projects, but also the ones that are actually being updated as part of the plan file(s)
383
+ if (isInCurrentBatch && options.specifierSource === 'version-plans') {
384
+ isInCurrentBatch = (options.releaseGroup.versionPlans || []).some((plan) => {
385
+ if ('projectVersionBumps' in plan) {
386
+ return plan.projectVersionBumps[dependentProject.source];
387
+ }
388
+ return true;
389
+ });
390
+ }
310
391
  if (!isInCurrentBatch) {
311
392
  dependentProjectsOutsideCurrentBatch.push(dependentProject);
312
393
  }
@@ -318,11 +399,14 @@ To fix this you will either need to add a package.json file at that location, or
318
399
  if (updateDependents === 'never') {
319
400
  if (dependentProjectsOutsideCurrentBatch.length > 0) {
320
401
  let logMsg = `⚠️ Warning, the following packages depend on "${project.name}"`;
402
+ const reason = options.specifierSource === 'version-plans'
403
+ ? 'because they are not referenced in any version plans'
404
+ : 'via --projects';
321
405
  if (options.releaseGroup.name === config_1.IMPLICIT_DEFAULT_RELEASE_GROUP) {
322
- logMsg += ` but have been filtered out via --projects, and therefore will not be updated:`;
406
+ logMsg += ` but have been filtered out ${reason}, and therefore will not be updated:`;
323
407
  }
324
408
  else {
325
- logMsg += ` but are either not part of the current release group "${options.releaseGroup.name}", or have been filtered out via --projects, and therefore will not be updated:`;
409
+ logMsg += ` but are either not part of the current release group "${options.releaseGroup.name}", or have been filtered out ${reason}, and therefore will not be updated:`;
326
410
  }
327
411
  const indent = Array.from(new Array(projectName.length + 4))
328
412
  .map(() => ' ')
@@ -425,12 +509,20 @@ To fix this you will either need to add a package.json file at that location, or
425
509
  }
426
510
  if (updateDependents === 'auto') {
427
511
  for (const dependentProject of dependentProjectsOutsideCurrentBatch) {
512
+ if (options.specifierSource === 'version-plans' &&
513
+ !projectToDependencyBumps.has(dependentProject.source)) {
514
+ projectToDependencyBumps.set(dependentProject.source, new Set([projectName]));
515
+ }
428
516
  updateDependentProjectAndAddToVersionData({
429
517
  dependentProject,
430
518
  dependencyPackageName: packageName,
431
519
  newDependencyVersion: newVersion,
432
520
  // For these additional dependents, we need to update their package.json version as well because we know they will not come later in the topologically sorted projects loop
433
- forceVersionBump: updateDependentsBump,
521
+ // (Unless using version plans and the dependent is not filtered out by --projects)
522
+ forceVersionBump: options.specifierSource === 'version-plans' &&
523
+ projects.find((p) => p.name === dependentProject.source)
524
+ ? false
525
+ : updateDependentsBump,
434
526
  });
435
527
  }
436
528
  }
@@ -468,9 +560,14 @@ To fix this you will either need to add a package.json file at that location, or
468
560
  return {
469
561
  data: versionData,
470
562
  callback: async (tree, opts) => {
563
+ const changedFiles = [];
564
+ const deletedFiles = [];
565
+ for (const cb of deleteVersionPlanCallbacks) {
566
+ deletedFiles.push(...(await cb(opts.dryRun)));
567
+ }
471
568
  const cwd = tree.root;
472
- const updatedFiles = await (0, update_lock_file_1.updateLockFile)(cwd, opts);
473
- return updatedFiles;
569
+ changedFiles.push(...(await (0, update_lock_file_1.updateLockFile)(cwd, opts)));
570
+ return { changedFiles, deletedFiles };
474
571
  },
475
572
  };
476
573
  }
@@ -29,7 +29,7 @@
29
29
  "type": "string",
30
30
  "default": "prompt",
31
31
  "description": "Which approach to use to determine the semver specifier used to bump the version of the project.",
32
- "enum": ["prompt", "conventional-commits"]
32
+ "enum": ["prompt", "conventional-commits", "version-plans"]
33
33
  },
34
34
  "preid": {
35
35
  "type": "string",
@@ -11,7 +11,7 @@ const minimatch_1 = require("minimatch");
11
11
  const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
12
12
  const cache_directory_1 = require("nx/src/utils/cache-directory");
13
13
  const ts_config_1 = require("../../utils/typescript/ts-config");
14
- const cachePath = (0, node_path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'tsc.hash');
14
+ const cachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, 'tsc.hash');
15
15
  const targetsCache = readTargetsCache();
16
16
  function readTargetsCache() {
17
17
  return (0, node_fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};