|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {join, Path, relative, dirname} from '@angular-devkit/core'; |
| 9 | +import {dirname, join, Path, relative} from '@angular-devkit/core'; |
10 | 10 | import {SchematicContext, Tree} from '@angular-devkit/schematics';
|
11 | 11 | import {
|
12 | 12 | addSymbolToNgModuleMetadata,
|
@@ -58,12 +58,12 @@ interface PackageJson {
|
58 | 58 | }
|
59 | 59 |
|
60 | 60 | export class HammerGesturesMigration extends DevkitMigration<null> {
|
61 |
| - // Only enable this rule if the migration targets v9 or v10 and is running for a non-test |
62 |
| - // target. We cannot migrate test targets since they have a limited scope |
63 |
| - // (in regards to source files) and therefore the HammerJS usage detection can be incorrect. |
| 61 | + // The migration is enabled when v9 or v10 are targeted, but actual targets are only |
| 62 | + // migrated if they are not test targets. We cannot migrate test targets since they have |
| 63 | + // a limited scope, in regards to their source files, and therefore the HammerJS usage |
| 64 | + // detection could be incorrect. |
64 | 65 | enabled =
|
65 |
| - (this.targetVersion === TargetVersion.V9 || this.targetVersion === TargetVersion.V10) && |
66 |
| - !this.context.isTestTarget; |
| 66 | + HammerGesturesMigration._isAllowedVersion(this.targetVersion) && !this.context.isTestTarget; |
67 | 67 |
|
68 | 68 | private _printer = ts.createPrinter();
|
69 | 69 | private _importManager = new ImportManager(this.fileSystem, this._printer);
|
@@ -938,7 +938,16 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
|
938 | 938 | * on the analysis of the individual targets. For example: we only remove Hammer
|
939 | 939 | * from the "package.json" if it is not used in *any* project target.
|
940 | 940 | */
|
941 |
| - static override globalPostMigration(tree: Tree, context: SchematicContext): PostMigrationAction { |
| 941 | + static override globalPostMigration( |
| 942 | + tree: Tree, |
| 943 | + target: TargetVersion, |
| 944 | + context: SchematicContext, |
| 945 | + ): PostMigrationAction { |
| 946 | + // Skip printing any global messages when the target version is not allowed. |
| 947 | + if (!this._isAllowedVersion(target)) { |
| 948 | + return; |
| 949 | + } |
| 950 | + |
942 | 951 | // Always notify the developer that the Hammer v9 migration does not migrate tests.
|
943 | 952 | context.logger.info(
|
944 | 953 | '\n⚠ General notice: The HammerJS v9 migration for Angular Components is not able to ' +
|
@@ -979,6 +988,12 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
|
979 | 988 | }
|
980 | 989 | return false;
|
981 | 990 | }
|
| 991 | + |
| 992 | + /** Gets whether the migration is allowed to run for specified target version. */ |
| 993 | + private static _isAllowedVersion(target: TargetVersion) { |
| 994 | + // This migration is only allowed to run for v9 or v10 target versions. |
| 995 | + return target === TargetVersion.V9 || target === TargetVersion.V10; |
| 996 | + } |
982 | 997 | }
|
983 | 998 |
|
984 | 999 | /**
|
|
0 commit comments