fix(@angular/cli): add message update updating from non LTS versions of the CLI

This commit is contained in:
Alan Agius 2021-04-14 20:31:45 +02:00 committed by Charles
parent 36a8882ab3
commit d68cb92dc2

View File

@ -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<UpdateCommandSchema> {
}
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<UpdateCommandSchema> {
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<number, number> = {
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;