Skip to content

Commit

Permalink
fix(@angular/cli): ensure all available package migrations are executed
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
clydin committed May 18, 2022
1 parent 160cb07 commit 4b22593
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/angular/cli/src/commands/update/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,9 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
options.createCommits,
);

if (!result) {
return 0;
// A non-zero value is a failure for the package's migrations
if (result !== 0) {
return result;
}
}
}
Expand Down
21 changes: 18 additions & 3 deletions tests/legacy-cli/e2e/tests/update/update-10.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { appendFile } from 'fs/promises';
import { SemVer } from 'semver';
import { createProjectFromAsset } from '../../utils/assets';
import { expectFileMatchToExist, readFile } from '../../utils/fs';
import { setRegistry } from '../../utils/packages';
import { getActivePackageManager, setRegistry } from '../../utils/packages';
import { ng, noSilentNg } from '../../utils/process';
import { isPrereleaseCli, useCIChrome, useCIDefaults, NgCLIVersion } from '../../utils/project';

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

// CLI proiject version
// If using npm, enable legacy peer deps mode to avoid defects in npm 7+'s peer dependency resolution
// Example error where 11.2.14 satisfies the SemVer range ^11.0.0 but still fails:
// npm ERR! Conflicting peer dependency: @angular/[email protected]
// npm ERR! node_modules/@angular/compiler-cli
// npm ERR! peer @angular/compiler-cli@"^11.0.0 || ^11.2.0-next" from @angular-devkit/[email protected]
// npm ERR! node_modules/@angular-devkit/build-angular
// npm ERR! dev @angular-devkit/build-angular@"~0.1102.19" from the root project
if (getActivePackageManager() === 'npm') {
await appendFile('.npmrc', '\nlegacy-peer-deps=true');
}

// CLI project version
const { version: cliVersion } = JSON.parse(
await readFile('./node_modules/@angular/cli/package.json'),
);
Expand All @@ -30,7 +42,10 @@ export default async function () {
// - 12 -> 13
const { stdout } = await ng('update', `@angular/cli@${version}`, `@angular/core@${version}`);
if (!stdout.includes("Executing migrations of package '@angular/cli'")) {
throw new Error('Update did not execute migrations. OUTPUT: \n' + stdout);
throw new Error('Update did not execute migrations for @angular/cli. OUTPUT: \n' + stdout);
}
if (!stdout.includes("Executing migrations of package '@angular/core'")) {
throw new Error('Update did not execute migrations for @angular/core. OUTPUT: \n' + stdout);
}
}
} finally {
Expand Down

0 comments on commit 4b22593

Please sign in to comment.