Skip to content

Commit 4b22593

Browse files
committed
fix(@angular/cli): ensure all available package migrations are executed
For v14, the update command migration execution logic was incorrectly exiting after the success of the first package's migrations. This prevented any other updated packages from executing migrations automatically. The success check is now a failure check and will allow the migration execution process to continue to execute migrations until complete or a failure occurs. (cherry picked from commit 5ad5bda)
1 parent 160cb07 commit 4b22593

File tree

2 files changed

+21
-5
lines changed
  • packages/angular/cli/src/commands/update
  • tests/legacy-cli/e2e/tests/update

2 files changed

+21
-5
lines changed

packages/angular/cli/src/commands/update/cli.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,9 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
787787
options.createCommits,
788788
);
789789

790-
if (!result) {
791-
return 0;
790+
// A non-zero value is a failure for the package's migrations
791+
if (result !== 0) {
792+
return result;
792793
}
793794
}
794795
}

tests/legacy-cli/e2e/tests/update/update-10.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { appendFile } from 'fs/promises';
12
import { SemVer } from 'semver';
23
import { createProjectFromAsset } from '../../utils/assets';
34
import { expectFileMatchToExist, readFile } from '../../utils/fs';
4-
import { setRegistry } from '../../utils/packages';
5+
import { getActivePackageManager, setRegistry } from '../../utils/packages';
56
import { ng, noSilentNg } from '../../utils/process';
67
import { isPrereleaseCli, useCIChrome, useCIDefaults, NgCLIVersion } from '../../utils/project';
78

@@ -12,7 +13,18 @@ export default async function () {
1213
await setRegistry(false);
1314
await createProjectFromAsset('10.0-project', true);
1415

15-
// CLI proiject version
16+
// If using npm, enable legacy peer deps mode to avoid defects in npm 7+'s peer dependency resolution
17+
// Example error where 11.2.14 satisfies the SemVer range ^11.0.0 but still fails:
18+
// npm ERR! Conflicting peer dependency: @angular/[email protected]
19+
// npm ERR! node_modules/@angular/compiler-cli
20+
// npm ERR! peer @angular/compiler-cli@"^11.0.0 || ^11.2.0-next" from @angular-devkit/[email protected]
21+
// npm ERR! node_modules/@angular-devkit/build-angular
22+
// npm ERR! dev @angular-devkit/build-angular@"~0.1102.19" from the root project
23+
if (getActivePackageManager() === 'npm') {
24+
await appendFile('.npmrc', '\nlegacy-peer-deps=true');
25+
}
26+
27+
// CLI project version
1628
const { version: cliVersion } = JSON.parse(
1729
await readFile('./node_modules/@angular/cli/package.json'),
1830
);
@@ -30,7 +42,10 @@ export default async function () {
3042
// - 12 -> 13
3143
const { stdout } = await ng('update', `@angular/cli@${version}`, `@angular/core@${version}`);
3244
if (!stdout.includes("Executing migrations of package '@angular/cli'")) {
33-
throw new Error('Update did not execute migrations. OUTPUT: \n' + stdout);
45+
throw new Error('Update did not execute migrations for @angular/cli. OUTPUT: \n' + stdout);
46+
}
47+
if (!stdout.includes("Executing migrations of package '@angular/core'")) {
48+
throw new Error('Update did not execute migrations for @angular/core. OUTPUT: \n' + stdout);
3449
}
3550
}
3651
} finally {

0 commit comments

Comments
 (0)