From d68cb92dc2113753e7eefb91e54b70a60c1acd94 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 14 Apr 2021 20:31:45 +0200 Subject: [PATCH] fix(@angular/cli): add message update updating from non LTS versions of the CLI --- packages/angular/cli/commands/update-impl.ts | 38 +++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/angular/cli/commands/update-impl.ts b/packages/angular/cli/commands/update-impl.ts index ef09d4d89c52..f4f1f724254e 100644 --- a/packages/angular/cli/commands/update-impl.ts +++ b/packages/angular/cli/commands/update-impl.ts @@ -40,8 +40,6 @@ const pickManifest = require('npm-pick-manifest') as ( selector: string, ) => PackageManifest; -const oldConfigFileNames = ['.angular-cli.json', 'angular-cli.json']; - const NG_VERSION_9_POST_MSG = colors.cyan( '\nYour project has been updated to Angular version 9!\n' + 'For more info, please see: https://v9.angular.io/guide/updating-to-version-9', @@ -367,20 +365,6 @@ export class UpdateCommand extends Command { } this.logger.info(`Using package manager: '${this.packageManager}'`); - - // Special handling for Angular CLI 1.x migrations - if ( - options.migrateOnly === undefined && - options.from === undefined && - packages.length === 1 && - packages[0].name === '@angular/cli' && - this.workspace && - oldConfigFileNames.includes(path.basename(this.workspace.filePath)) - ) { - options.migrateOnly = true; - options.from = '1.0.0'; - } - this.logger.info('Collecting installed dependencies...'); const rootDependencies = await getProjectDependencies(this.context.root); @@ -623,6 +607,28 @@ export class UpdateCommand extends Command { return 1; } + if (node.package?.name === '@angular/cli') { + // Migrations for non LTS versions of Angular CLI are no longer included in @schematics/angular v12. + const toBeInstalledMajorVersion = +manifest.version.split('.')[0]; + const currentMajorVersion = +node.package.version.split('.')[0]; + if (currentMajorVersion < 9 && toBeInstalledMajorVersion >= 12) { + const updateVersions: Record = { + 1: 6, + 6: 7, + 7: 8, + 8: 9, + }; + + const updateTo = updateVersions[currentMajorVersion]; + this.logger.error('Updating multiple major versions at once is not recommended. ' + + `Run 'ng update @angular/cli@${updateTo}' in your workspace directory ` + + `to update to latest '${updateTo}.x' version of '@angular/cli'.\n\n` + + 'For more information about the update process, see https://update.angular.io/.'); + + return 1; + } + } + if (manifest.version === node.package?.version) { this.logger.info(`Package '${packageName}' is already up to date.`); continue;