Skip to content

Commit

Permalink
fix(@angular/cli): run all migrations when updating from or between p…
Browse files Browse the repository at this point in the history
…rereleases

With this change we consider the update schematics are idempotent. When updating from or between prereleases we will execute all migrations for the version.

(cherry picked from commit 131379f)
  • Loading branch information
alan-agius4 committed Apr 19, 2021
1 parent 5f25616 commit cd198d5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/angular/cli/commands/update-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,14 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
private async executeMigrations(
packageName: string,
collectionPath: string,
range: semver.Range,
from: string,
to: string,
commit?: boolean,
): Promise<boolean> {
const collection = this.workflow.engine.createCollection(collectionPath);
const migrationRange = new semver.Range(
'>' + (semver.prerelease(from) ? from.split('-')[0] + '-0' : from) + ' <=' + to,
);
const migrations = [];

for (const name of collection.listSchematicNames()) {
Expand All @@ -207,7 +211,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
continue;
}

if (semver.satisfies(description.version, range, { includePrerelease: true })) {
if (semver.satisfies(description.version, migrationRange, { includePrerelease: true })) {
migrations.push(description as typeof schematic.description & { version: string });
}
}
Expand Down Expand Up @@ -492,14 +496,11 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
return 1;
}

const migrationRange = new semver.Range(
'>' + from + ' <=' + (options.to || packageNode.version),
);

success = await this.executeMigrations(
packageName,
migrations,
migrationRange,
from,
options.to || packageNode.version,
options.createCommits,
);
}
Expand Down Expand Up @@ -647,7 +648,6 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
next: !!options.next,
packageManager: this.packageManager,
packages: packagesToUpdate,
migrateExternal: true,
});

if (success && options.createCommits) {
Expand Down Expand Up @@ -733,7 +733,8 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
const result = await this.executeMigrations(
migration.package,
migrations,
new semver.Range('>' + migration.from + ' <=' + migration.to),
migration.from,
migration.to,
options.createCommits,
);

Expand Down

0 comments on commit cd198d5

Please sign in to comment.