@angular/cli 12.2.10 → 12.2.14

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.
@@ -30,8 +30,9 @@ export declare class UpdateCommand extends Command<UpdateCommandSchema> {
30
30
  private commit;
31
31
  private checkCleanGit;
32
32
  /**
33
- * Checks if the current installed CLI version is older than the latest version.
34
- * @returns `true` when the installed version is older.
33
+ * Checks if the current installed CLI version is older or newer than a compatible version.
34
+ * @returns the version to install or null when there is no update to install.
35
35
  */
36
- private checkCLILatestVersion;
36
+ private checkCLIVersion;
37
+ private getCLIUpdateRunnerVersion;
37
38
  }
@@ -48,8 +48,6 @@ const package_manager_1 = require("../utilities/package-manager");
48
48
  const package_metadata_1 = require("../utilities/package-metadata");
49
49
  const package_tree_1 = require("../utilities/package-tree");
50
50
  const pickManifest = require('npm-pick-manifest');
51
- const NG_VERSION_9_POST_MSG = color_1.colors.cyan('\nYour project has been updated to Angular version 9!\n' +
52
- 'For more info, please see: https://v9.angular.io/guide/updating-to-version-9');
53
51
  const UPDATE_SCHEMATIC_COLLECTION = path.join(__dirname, '../src/commands/update/schematic/collection.json');
54
52
  /**
55
53
  * Disable CLI version mismatch checks and forces usage of the invoked CLI
@@ -59,6 +57,7 @@ const disableVersionCheckEnv = process.env['NG_DISABLE_VERSION_CHECK'];
59
57
  const disableVersionCheck = disableVersionCheckEnv !== undefined &&
60
58
  disableVersionCheckEnv !== '0' &&
61
59
  disableVersionCheckEnv.toLowerCase() !== 'false';
60
+ const ANGULAR_PACKAGES_REGEXP = /^@(?:angular|nguniversal)\//;
62
61
  class UpdateCommand extends command_1.Command {
63
62
  constructor() {
64
63
  super(...arguments);
@@ -163,7 +162,7 @@ class UpdateCommand extends command_1.Command {
163
162
  */
164
163
  async executeMigrations(packageName, collectionPath, from, to, commit) {
165
164
  const collection = this.workflow.engine.createCollection(collectionPath);
166
- const migrationRange = new semver.Range('>' + (semver.prerelease(from) ? from.split('-')[0] + '-0' : from) + ' <=' + to);
165
+ const migrationRange = new semver.Range('>' + (semver.prerelease(from) ? from.split('-')[0] + '-0' : from) + ' <=' + to.split('-')[0]);
167
166
  const migrations = [];
168
167
  for (const name of collection.listSchematicNames()) {
169
168
  const schematic = this.workflow.engine.createSchematic(name, collection);
@@ -215,12 +214,16 @@ class UpdateCommand extends command_1.Command {
215
214
  }
216
215
  // eslint-disable-next-line max-lines-per-function
217
216
  async run(options) {
218
- var _a, _b;
217
+ var _a;
219
218
  await package_manager_1.ensureCompatibleNpm(this.context.root);
220
- // Check if the current installed CLI version is older than the latest version.
221
- if (!disableVersionCheck && (await this.checkCLILatestVersion(options.verbose, options.next))) {
222
- this.logger.warn(`The installed local Angular CLI version is older than the latest ${options.next ? 'pre-release' : 'stable'} version.\n` + 'Installing a temporary version to perform the update.');
223
- return install_package_1.runTempPackageBin(`@angular/cli@${options.next ? 'next' : 'latest'}`, this.packageManager, process.argv.slice(2));
219
+ // Check if the current installed CLI version is older than the latest compatible version.
220
+ if (!disableVersionCheck) {
221
+ const cliVersionToInstall = await this.checkCLIVersion(options['--'], options.verbose, options.next);
222
+ if (cliVersionToInstall) {
223
+ this.logger.warn('The installed Angular CLI version is outdated.\n' +
224
+ `Installing a temporary Angular CLI versioned ${cliVersionToInstall} to perform the update.`);
225
+ return install_package_1.runTempPackageBin(`@angular/cli@${cliVersionToInstall}`, this.packageManager, process.argv.slice(2));
226
+ }
224
227
  }
225
228
  const logVerbose = (message) => {
226
229
  if (options.verbose) {
@@ -346,8 +349,7 @@ class UpdateCommand extends command_1.Command {
346
349
  // Normalize slashes
347
350
  migrations = migrations.replace(/\\/g, '/');
348
351
  if (migrations.startsWith('../')) {
349
- this.logger.error('Package contains an invalid migrations field. ' +
350
- 'Paths outside the package root are not permitted.');
352
+ this.logger.error('Package contains an invalid migrations field. Paths outside the package root are not permitted.');
351
353
  return 1;
352
354
  }
353
355
  // Check if it is a package-local location
@@ -371,9 +373,9 @@ class UpdateCommand extends command_1.Command {
371
373
  return 1;
372
374
  }
373
375
  }
374
- let success = false;
376
+ let result;
375
377
  if (typeof options.migrateOnly == 'string') {
376
- success = await this.executeMigration(packageName, migrations, options.migrateOnly, options.createCommits);
378
+ result = await this.executeMigration(packageName, migrations, options.migrateOnly, options.createCommits);
377
379
  }
378
380
  else {
379
381
  const from = coerceVersionNumber(options.from);
@@ -381,18 +383,9 @@ class UpdateCommand extends command_1.Command {
381
383
  this.logger.error(`"from" value [${options.from}] is not a valid version.`);
382
384
  return 1;
383
385
  }
384
- success = await this.executeMigrations(packageName, migrations, from, options.to || packageNode.version, options.createCommits);
385
- }
386
- if (success) {
387
- if (packageName === '@angular/core' &&
388
- options.from &&
389
- +options.from.split('.')[0] < 9 &&
390
- (options.to || packageNode.version).split('.')[0] === '9') {
391
- this.logger.info(NG_VERSION_9_POST_MSG);
392
- }
393
- return 0;
386
+ result = await this.executeMigrations(packageName, migrations, from, options.to || packageNode.version, options.createCommits);
394
387
  }
395
- return 1;
388
+ return result ? 0 : 1;
396
389
  }
397
390
  const requests = [];
398
391
  // Validate packages actually are part of the workspace
@@ -463,29 +456,32 @@ class UpdateCommand extends command_1.Command {
463
456
  this.logger.error(`Package specified by '${requestIdentifier.raw}' does not exist within the registry.`);
464
457
  return 1;
465
458
  }
466
- if (((_a = node.package) === null || _a === void 0 ? void 0 : _a.name) === '@angular/cli') {
467
- // Migrations for non LTS versions of Angular CLI are no longer included in @schematics/angular v12.
459
+ if (manifest.version === ((_a = node.package) === null || _a === void 0 ? void 0 : _a.version)) {
460
+ this.logger.info(`Package '${packageName}' is already up to date.`);
461
+ continue;
462
+ }
463
+ if (node.package && ANGULAR_PACKAGES_REGEXP.test(node.package.name)) {
464
+ const { name, version } = node.package;
468
465
  const toBeInstalledMajorVersion = +manifest.version.split('.')[0];
469
- const currentMajorVersion = +node.package.version.split('.')[0];
470
- if (currentMajorVersion < 9 && toBeInstalledMajorVersion >= 12) {
471
- const updateVersions = {
472
- 1: 6,
473
- 6: 7,
474
- 7: 8,
475
- 8: 9,
476
- };
477
- const updateTo = updateVersions[currentMajorVersion];
478
- this.logger.error('Updating multiple major versions at once is not recommended. ' +
479
- `Run 'ng update @angular/cli@${updateTo}' in your workspace directory ` +
480
- `to update to latest '${updateTo}.x' version of '@angular/cli'.\n\n` +
481
- 'For more information about the update process, see https://update.angular.io/.');
466
+ const currentMajorVersion = +version.split('.')[0];
467
+ if (toBeInstalledMajorVersion - currentMajorVersion > 1) {
468
+ // Only allow updating a single version at a time.
469
+ if (currentMajorVersion < 6) {
470
+ // Before version 6, the major versions were not always sequential.
471
+ // Example @angular/core skipped version 3, @angular/cli skipped versions 2-5.
472
+ this.logger.error(`Updating multiple major versions of '${name}' at once is not supported. Please migrate each major version individually.\n` +
473
+ `For more information about the update process, see https://update.angular.io/.`);
474
+ }
475
+ else {
476
+ const nextMajorVersionFromCurrent = currentMajorVersion + 1;
477
+ this.logger.error(`Updating multiple major versions of '${name}' at once is not supported. Please migrate each major version individually.\n` +
478
+ `Run 'ng update ${name}@${nextMajorVersionFromCurrent}' in your workspace directory ` +
479
+ `to update to latest '${nextMajorVersionFromCurrent}.x' version of '${name}'.\n\n` +
480
+ `For more information about the update process, see https://update.angular.io/?v=${currentMajorVersion}.0-${nextMajorVersionFromCurrent}.0`);
481
+ }
482
482
  return 1;
483
483
  }
484
484
  }
485
- if (manifest.version === ((_b = node.package) === null || _b === void 0 ? void 0 : _b.version)) {
486
- this.logger.info(`Package '${packageName}' is already up to date.`);
487
- continue;
488
- }
489
485
  packagesToUpdate.push(requestIdentifier.toString());
490
486
  }
491
487
  if (packagesToUpdate.length === 0) {
@@ -584,11 +580,6 @@ class UpdateCommand extends command_1.Command {
584
580
  return 0;
585
581
  }
586
582
  }
587
- if (migrations.some((m) => m.package === '@angular/core' &&
588
- m.to.split('.')[0] === '9' &&
589
- +m.from.split('.')[0] < 9)) {
590
- this.logger.info(NG_VERSION_9_POST_MSG);
591
- }
592
583
  }
593
584
  return success ? 0 : 1;
594
585
  }
@@ -653,16 +644,38 @@ class UpdateCommand extends command_1.Command {
653
644
  return true;
654
645
  }
655
646
  /**
656
- * Checks if the current installed CLI version is older than the latest version.
657
- * @returns `true` when the installed version is older.
647
+ * Checks if the current installed CLI version is older or newer than a compatible version.
648
+ * @returns the version to install or null when there is no update to install.
658
649
  */
659
- async checkCLILatestVersion(verbose = false, next = false) {
660
- const installedCLIVersion = version_1.VERSION.full;
661
- const LatestCLIManifest = await package_metadata_1.fetchPackageManifest(`@angular/cli@${next ? 'next' : 'latest'}`, this.logger, {
650
+ async checkCLIVersion(packagesToUpdate, verbose = false, next = false) {
651
+ const { version } = await package_metadata_1.fetchPackageManifest(`@angular/cli@${this.getCLIUpdateRunnerVersion(packagesToUpdate, next)}`, this.logger, {
662
652
  verbose,
663
653
  usingYarn: this.packageManager === workspace_schema_1.PackageManager.Yarn,
664
654
  });
665
- return semver.lt(installedCLIVersion, LatestCLIManifest.version);
655
+ return version_1.VERSION.full === version ? null : version;
656
+ }
657
+ getCLIUpdateRunnerVersion(packagesToUpdate, next) {
658
+ var _a, _b;
659
+ if (next) {
660
+ return 'next';
661
+ }
662
+ const updatingAngularPackage = packagesToUpdate === null || packagesToUpdate === void 0 ? void 0 : packagesToUpdate.find((r) => ANGULAR_PACKAGES_REGEXP.test(r));
663
+ if (updatingAngularPackage) {
664
+ // If we are updating any Angular package we can update the CLI to the target version because
665
+ // migrations for @angular/core@13 can be executed using Angular/cli@13.
666
+ // This is same behaviour as `npx @angular/cli@13 update @angular/core@13`.
667
+ // `@angular/cli@13` -> ['', 'angular/cli', '13']
668
+ // `@angular/cli` -> ['', 'angular/cli']
669
+ const tempVersion = coerceVersionNumber(updatingAngularPackage.split('@')[2]);
670
+ return (_b = (_a = semver.parse(tempVersion)) === null || _a === void 0 ? void 0 : _a.major) !== null && _b !== void 0 ? _b : 'latest';
671
+ }
672
+ // When not updating an Angular package we cannot determine which schematic runtime the migration should to be executed in.
673
+ // Typically, we can assume that the `@angular/cli` was updated previously.
674
+ // Example: Angular official packages are typically updated prior to NGRX etc...
675
+ // Therefore, we only update to the latest patch version of the installed major version of the Angular CLI.
676
+ // This is important because we might end up in a scenario where locally Angular v12 is installed, updating NGRX from 11 to 12.
677
+ // We end up using Angular ClI v13 to run the migrations if we run the migrations using the CLI installed major version + 1 logic.
678
+ return version_1.VERSION.major;
666
679
  }
667
680
  }
668
681
  exports.UpdateCommand = UpdateCommand;
package/lib/init.js CHANGED
@@ -84,7 +84,9 @@ const config_1 = require("../utilities/config");
84
84
  if (isGlobalGreater) {
85
85
  // If using the update command and the global version is greater, use the newer update command
86
86
  // This allows improvements in update to be used in older versions that do not have bootstrapping
87
- if (process.argv[2] === 'update') {
87
+ if (process.argv[2] === 'update' &&
88
+ cli.VERSION &&
89
+ cli.VERSION.major - globalVersion.major <= 1) {
88
90
  cli = await Promise.resolve().then(() => __importStar(require('./cli')));
89
91
  }
90
92
  else if (await config_1.isWarningEnabled('versionMismatch')) {
@@ -182,7 +182,7 @@ async function promptProjectAnalytics(force = false) {
182
182
  if (answers.analytics) {
183
183
  console.log('');
184
184
  console.log(core_1.tags.stripIndent `
185
- Thank you for sharing anonymous usage data. Would you change your mind, the following
185
+ Thank you for sharing anonymous usage data. Should you change your mind, the following
186
186
  command will disable this feature entirely:
187
187
 
188
188
  ${color_1.colors.yellow('ng analytics project off')}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular/cli",
3
- "version": "12.2.10",
3
+ "version": "12.2.14",
4
4
  "description": "CLI tool for Angular",
5
5
  "main": "lib/cli/index.js",
6
6
  "bin": {
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "homepage": "https://github.com/angular/angular-cli",
30
30
  "dependencies": {
31
- "@angular-devkit/architect": "0.1202.10",
32
- "@angular-devkit/core": "12.2.10",
33
- "@angular-devkit/schematics": "12.2.10",
34
- "@schematics/angular": "12.2.10",
31
+ "@angular-devkit/architect": "0.1202.14",
32
+ "@angular-devkit/core": "12.2.14",
33
+ "@angular-devkit/schematics": "12.2.14",
34
+ "@schematics/angular": "12.2.14",
35
35
  "@yarnpkg/lockfile": "1.1.0",
36
36
  "ansi-colors": "4.1.1",
37
37
  "debug": "4.3.2",
@@ -42,7 +42,7 @@
42
42
  "npm-pick-manifest": "6.1.1",
43
43
  "open": "8.2.1",
44
44
  "ora": "5.4.1",
45
- "pacote": "11.3.5",
45
+ "pacote": "12.0.2",
46
46
  "resolve": "1.20.0",
47
47
  "semver": "7.3.5",
48
48
  "symbol-observable": "4.0.0",
@@ -51,17 +51,17 @@
51
51
  "ng-update": {
52
52
  "migrations": "@schematics/angular/migrations/migration-collection.json",
53
53
  "packageGroup": {
54
- "@angular/cli": "12.2.10",
55
- "@angular-devkit/architect": "0.1202.10",
56
- "@angular-devkit/build-angular": "12.2.10",
57
- "@angular-devkit/build-webpack": "0.1202.10",
58
- "@angular-devkit/core": "12.2.10",
59
- "@angular-devkit/schematics": "12.2.10"
54
+ "@angular/cli": "12.2.14",
55
+ "@angular-devkit/architect": "0.1202.14",
56
+ "@angular-devkit/build-angular": "12.2.14",
57
+ "@angular-devkit/build-webpack": "0.1202.14",
58
+ "@angular-devkit/core": "12.2.14",
59
+ "@angular-devkit/schematics": "12.2.14"
60
60
  }
61
61
  },
62
62
  "engines": {
63
63
  "node": "^12.14.1 || >=14.0.0",
64
- "npm": "^6.11.0 || ^7.5.6",
64
+ "npm": "^6.11.0 || ^7.5.6 || >=8.0.0",
65
65
  "yarn": ">= 1.13.0"
66
66
  }
67
67
  }
@@ -322,13 +322,34 @@ function _usageMessage(options, infoMap, logger) {
322
322
  const packageGroups = new Map();
323
323
  const packagesToUpdate = [...infoMap.entries()]
324
324
  .map(([name, info]) => {
325
- const tag = options.next
325
+ var _a, _b;
326
+ let tag = options.next
326
327
  ? info.npmPackageJson['dist-tags']['next']
327
328
  ? 'next'
328
329
  : 'latest'
329
330
  : 'latest';
330
- const version = info.npmPackageJson['dist-tags'][tag];
331
- const target = info.npmPackageJson.versions[version];
331
+ let version = info.npmPackageJson['dist-tags'][tag];
332
+ let target = info.npmPackageJson.versions[version];
333
+ const versionDiff = semver.diff(info.installed.version, version);
334
+ if (versionDiff !== 'patch' &&
335
+ versionDiff !== 'minor' &&
336
+ /^@(?:angular|nguniversal)\//.test(name)) {
337
+ const installedMajorVersion = (_a = semver.parse(info.installed.version)) === null || _a === void 0 ? void 0 : _a.major;
338
+ const toInstallMajorVersion = (_b = semver.parse(version)) === null || _b === void 0 ? void 0 : _b.major;
339
+ if (installedMajorVersion !== undefined &&
340
+ toInstallMajorVersion !== undefined &&
341
+ installedMajorVersion < toInstallMajorVersion - 1) {
342
+ const nextMajorVersion = `${installedMajorVersion + 1}.`;
343
+ const nextMajorVersions = Object.keys(info.npmPackageJson.versions)
344
+ .filter((v) => v.startsWith(nextMajorVersion))
345
+ .sort((a, b) => (a > b ? -1 : 1));
346
+ if (nextMajorVersions.length) {
347
+ version = nextMajorVersions[0];
348
+ target = info.npmPackageJson.versions[version];
349
+ tag = '';
350
+ }
351
+ }
352
+ }
332
353
  return {
333
354
  name,
334
355
  info,
@@ -344,6 +365,7 @@ function _usageMessage(options, infoMap, logger) {
344
365
  return target['ng-update'];
345
366
  })
346
367
  .map(({ name, info, version, tag, target }) => {
368
+ var _a;
347
369
  // Look for packageGroup.
348
370
  if (target['ng-update'] && target['ng-update']['packageGroup']) {
349
371
  const packageGroup = target['ng-update']['packageGroup'];
@@ -358,7 +380,10 @@ function _usageMessage(options, infoMap, logger) {
358
380
  }
359
381
  }
360
382
  let command = `ng update ${name}`;
361
- if (tag == 'next') {
383
+ if (!tag) {
384
+ command += `@${((_a = semver.parse(version)) === null || _a === void 0 ? void 0 : _a.major) || version}`;
385
+ }
386
+ else if (tag == 'next') {
362
387
  command += ' --next';
363
388
  }
364
389
  return [name, `${info.installed.version} -> ${version} `, command];