Skip to content

Commit f456b09

Browse files
committed
fix(@angular/cli): error when updating Angular packages across multi-major migrations
With this change we show an error message when users try to update `@angular/` and `@nguniversal/` packages across multiple major versions. (cherry picked from commit d60d374)
1 parent 776d121 commit f456b09

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

packages/angular/cli/commands/update-impl.ts

+29
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,35 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
623623
continue;
624624
}
625625

626+
if (node.package && /^@(?:angular|nguniversal)\//.test(node.package.name)) {
627+
const { name, version } = node.package;
628+
const toBeInstalledMajorVersion = +manifest.version.split('.')[0];
629+
const currentMajorVersion = +version.split('.')[0];
630+
631+
if (toBeInstalledMajorVersion - currentMajorVersion > 1) {
632+
// Only allow updating a single version at a time.
633+
if (currentMajorVersion < 6) {
634+
// Before version 6, the major versions were not always sequential.
635+
// Example @angular/core skipped version 3, @angular/cli skipped versions 2-5.
636+
this.logger.error(
637+
`Updating multiple major versions of '${name}' at once is not supported. Please migrate each major version individually.\n` +
638+
`For more information about the update process, see https://update.angular.io/.`,
639+
);
640+
} else {
641+
const nextMajorVersionFromCurrent = currentMajorVersion + 1;
642+
643+
this.logger.error(
644+
`Updating multiple major versions of '${name}' at once is not supported. Please migrate each major version individually.\n` +
645+
`Run 'ng update ${name}@${nextMajorVersionFromCurrent}' in your workspace directory ` +
646+
`to update to latest '${nextMajorVersionFromCurrent}.x' version of '${name}'.\n\n` +
647+
`For more information about the update process, see https://update.angular.io/?v=${currentMajorVersion}.0-${nextMajorVersionFromCurrent}.0`,
648+
);
649+
}
650+
651+
return 1;
652+
}
653+
}
654+
626655
packagesToUpdate.push(requestIdentifier.toString());
627656
}
628657

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { createProjectFromAsset } from '../../utils/assets';
2+
import { installWorkspacePackages, setRegistry } from '../../utils/packages';
3+
import { ng } from '../../utils/process';
4+
import { isPrereleaseCli } from '../../utils/project';
5+
import { expectToFail } from '../../utils/utils';
6+
7+
export default async function () {
8+
try {
9+
await createProjectFromAsset('8.0-project', true, true);
10+
await setRegistry(false);
11+
await installWorkspacePackages();
12+
13+
await setRegistry(true);
14+
const extraArgs = ['--force'];
15+
if (isPrereleaseCli()) {
16+
extraArgs.push('--next');
17+
}
18+
19+
const { message } = await expectToFail(() =>
20+
ng('update', '@angular/cli', '--force', ...extraArgs),
21+
);
22+
if (
23+
!message.includes(
24+
`Updating multiple major versions of '@angular/cli' at once is not supported`,
25+
)
26+
) {
27+
console.error(message);
28+
throw new Error(
29+
`Expected error message to include "Updating multiple major versions of '@angular/cli' at once is not supported" but didn't.`,
30+
);
31+
}
32+
} finally {
33+
await setRegistry(true);
34+
}
35+
}

0 commit comments

Comments
 (0)