Skip to content

Commit 35462ba

Browse files
devversionmmalerba
authored andcommitted
refactor: update-tool should support migrations without target version
Updates the update-tool to support migrations without a target version. Consider the MDC update script relying on the update-tool but it being always manually invoked. In those cases there is no actual target version.
1 parent f981ee9 commit 35462ba

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

src/cdk/schematics/ng-update/upgrade-data.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export function getVersionUpgradeData<
7171
T extends keyof UpgradeData,
7272
U = ValueOfChanges<UpgradeData[T]>,
7373
>(migration: Migration<UpgradeData>, dataName: T): U[] {
74+
if (migration.targetVersion === null) {
75+
return [];
76+
}
77+
7478
// Note that below we need to cast to `unknown` first TS doesn't infer the type of T correctly.
7579
return getChangesForTarget<U>(
7680
migration.targetVersion,

src/cdk/schematics/update-tool/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ export class UpdateProject<Context> {
4545
/**
4646
* Migrates the project to the specified target version.
4747
* @param migrationTypes Migrations that should be run.
48-
* @param target Version the project should be updated to.
48+
* @param target Version the project should be updated to. Can be `null` if the set of
49+
* specified migrations runs regardless of a target version.
4950
* @param data Upgrade data that is passed to all migration rules.
5051
* @param additionalStylesheetPaths Additional stylesheets that should be migrated, if not
5152
* referenced in an Angular component. This is helpful for global stylesheets in a project.
5253
*/
5354
migrate<Data>(
5455
migrationTypes: MigrationCtor<Data, Context>[],
55-
target: TargetVersion,
56+
target: TargetVersion | null,
5657
data: Data,
5758
additionalStylesheetPaths?: string[],
5859
): {hasFailures: boolean} {
@@ -157,7 +158,7 @@ export class UpdateProject<Context> {
157158
*/
158159
private _createMigrations<Data>(
159160
types: MigrationCtor<Data, Context>[],
160-
target: TargetVersion,
161+
target: TargetVersion | null,
161162
data: Data,
162163
): Migration<Data, Context>[] {
163164
const result: Migration<Data, Context>[] = [];

src/cdk/schematics/update-tool/migration.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ export abstract class Migration<Data, Context = any> {
4141
public program: ts.Program,
4242
/** TypeChecker instance for the analysis program. */
4343
public typeChecker: ts.TypeChecker,
44-
/** Version for which the migration rule should run. */
45-
public targetVersion: TargetVersion,
44+
/**
45+
* Version for which the migration rule should run. Null if the migration
46+
* is invoked manually.
47+
*/
48+
public targetVersion: TargetVersion | null,
4649
/** Context data for the migration. */
4750
public context: Context,
4851
/** Upgrade data passed to the migration. */

src/material/schematics/ng-update/migrations/hammer-gestures-v9/hammer-gestures-migration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
990990
}
991991

992992
/** Gets whether the migration is allowed to run for specified target version. */
993-
private static _isAllowedVersion(target: TargetVersion) {
993+
private static _isAllowedVersion(target: TargetVersion | null) {
994994
// This migration is only allowed to run for v9 or v10 target versions.
995995
return target === TargetVersion.V9 || target === TargetVersion.V10;
996996
}

0 commit comments

Comments
 (0)