Skip to content

refactor(material/schematics): do not print hammer migration message when updating to v13 #23752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cdk/schematics/ng-update/devkit-migration-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function createMigrationSchematicRule(
migrations.forEach(m => {
const actionResult =
isDevkitMigration(m) && m.globalPostMigration !== undefined
? m.globalPostMigration(tree, context)
? m.globalPostMigration(tree, targetVersion, context)
: null;
if (actionResult) {
runPackageManager = runPackageManager || actionResult.runPackageManager;
Expand Down
7 changes: 6 additions & 1 deletion src/cdk/schematics/ng-update/devkit-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {SchematicContext, Tree} from '@angular-devkit/schematics';
import {ProjectDefinition} from '@angular-devkit/core/src/workspace';
import {Constructor, Migration, PostMigrationAction} from '../update-tool/migration';
import {TargetVersion} from '../update-tool/target-version';

export type DevkitContext = {
/** Devkit tree for the current migrations. Can be used to insert/remove files. */
Expand All @@ -34,7 +35,11 @@ export abstract class DevkitMigration<Data> extends Migration<Data, DevkitContex
* migration result of all individual targets. e.g. removing HammerJS if it
* is not needed in any project target.
*/
static globalPostMigration?(tree: Tree, context: SchematicContext): PostMigrationAction;
static globalPostMigration?(
tree: Tree,
targetVersion: TargetVersion,
context: SchematicContext,
): PostMigrationAction;
}

export type DevkitMigrationCtor<Data> = Constructor<DevkitMigration<Data>> &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {join, Path, relative, dirname} from '@angular-devkit/core';
import {dirname, join, Path, relative} from '@angular-devkit/core';
import {SchematicContext, Tree} from '@angular-devkit/schematics';
import {
addSymbolToNgModuleMetadata,
Expand Down Expand Up @@ -58,12 +58,12 @@ interface PackageJson {
}

export class HammerGesturesMigration extends DevkitMigration<null> {
// Only enable this rule if the migration targets v9 or v10 and is running for a non-test
// target. We cannot migrate test targets since they have a limited scope
// (in regards to source files) and therefore the HammerJS usage detection can be incorrect.
// The migration is enabled when v9 or v10 are targeted, but actual targets are only
// migrated if they are not test targets. We cannot migrate test targets since they have
// a limited scope, in regards to their source files, and therefore the HammerJS usage
// detection could be incorrect.
enabled =
(this.targetVersion === TargetVersion.V9 || this.targetVersion === TargetVersion.V10) &&
!this.context.isTestTarget;
HammerGesturesMigration._isAllowedVersion(this.targetVersion) && !this.context.isTestTarget;

private _printer = ts.createPrinter();
private _importManager = new ImportManager(this.fileSystem, this._printer);
Expand Down Expand Up @@ -938,7 +938,16 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
* on the analysis of the individual targets. For example: we only remove Hammer
* from the "package.json" if it is not used in *any* project target.
*/
static override globalPostMigration(tree: Tree, context: SchematicContext): PostMigrationAction {
static override globalPostMigration(
tree: Tree,
target: TargetVersion,
context: SchematicContext,
): PostMigrationAction {
// Skip printing any global messages when the target version is not allowed.
if (!this._isAllowedVersion(target)) {
return;
}

// Always notify the developer that the Hammer v9 migration does not migrate tests.
context.logger.info(
'\n⚠ General notice: The HammerJS v9 migration for Angular Components is not able to ' +
Expand Down Expand Up @@ -979,6 +988,12 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
}
return false;
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export class ThemingApiMigration extends DevkitMigration<null> {
}

/** Logs out the number of migrated files at the end of the migration. */
static override globalPostMigration(_tree: unknown, context: SchematicContext): void {
static override globalPostMigration(
_tree: unknown,
_targetVersion: TargetVersion,
context: SchematicContext,
): void {
const count = ThemingApiMigration.migratedFileCount;

if (count > 0) {
Expand Down