|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import { |
10 | | - join, |
11 | | - Path, |
12 | | - relative, |
13 | | - dirname |
14 | | -} from '@angular-devkit/core'; |
| 9 | +import {dirname, join, Path, relative} from '@angular-devkit/core'; |
15 | 10 | import {SchematicContext, Tree} from '@angular-devkit/schematics'; |
16 | 11 | import { |
17 | 12 | addSymbolToNgModuleMetadata, |
@@ -64,11 +59,11 @@ interface PackageJson { |
64 | 59 | } |
65 | 60 |
|
66 | 61 | export class HammerGesturesMigration extends DevkitMigration<null> { |
67 | | - // Only enable this rule if the migration targets v9 or v10 and is running for a non-test |
68 | | - // target. We cannot migrate test targets since they have a limited scope |
69 | | - // (in regards to source files) and therefore the HammerJS usage detection can be incorrect. |
70 | | - enabled = |
71 | | - (this.targetVersion === TargetVersion.V9 || this.targetVersion === TargetVersion.V10) && |
| 62 | + // The migration is enabled when v9 or v10 are targeted, but actual targets are only |
| 63 | + // migrated if they are not test targets. We cannot migrate test targets since they have |
| 64 | + // a limited scope, in regards to their source files, and therefore the HammerJS usage |
| 65 | + // detection could be incorrect. |
| 66 | + enabled = HammerGesturesMigration._isMigrationEnabled(this.targetVersion) && |
72 | 67 | !this.context.isTestTarget; |
73 | 68 |
|
74 | 69 | private _printer = ts.createPrinter(); |
@@ -828,7 +823,13 @@ export class HammerGesturesMigration extends DevkitMigration<null> { |
828 | 823 | * on the analysis of the individual targets. For example: we only remove Hammer |
829 | 824 | * from the "package.json" if it is not used in *any* project target. |
830 | 825 | */ |
831 | | - static override globalPostMigration(tree: Tree, context: SchematicContext): PostMigrationAction { |
| 826 | + static override globalPostMigration(tree: Tree, target: TargetVersion, |
| 827 | + context: SchematicContext): PostMigrationAction { |
| 828 | + // Skip printing any global messages when the migration rule is disabled. |
| 829 | + if (!this._isMigrationEnabled(target)) { |
| 830 | + return; |
| 831 | + } |
| 832 | + |
832 | 833 | // Always notify the developer that the Hammer v9 migration does not migrate tests. |
833 | 834 | context.logger.info( |
834 | 835 | '\n⚠ General notice: The HammerJS v9 migration for Angular Components is not able to ' + |
@@ -867,6 +868,12 @@ export class HammerGesturesMigration extends DevkitMigration<null> { |
867 | 868 | } |
868 | 869 | return false; |
869 | 870 | } |
| 871 | + |
| 872 | + /** Gets whether the migration is enabled or not. */ |
| 873 | + private static _isMigrationEnabled(target: TargetVersion) { |
| 874 | + // Only enable this rule if the migration targets v9 or v10. |
| 875 | + return (target === TargetVersion.V9 || target === TargetVersion.V10); |
| 876 | + } |
870 | 877 | } |
871 | 878 |
|
872 | 879 | /** |
|
0 commit comments