@@ -11,7 +11,7 @@ import {
11
11
normalize as devkitNormalize ,
12
12
Path as DevkitPath
13
13
} from '@angular-devkit/core' ;
14
- import { SchematicContext , SchematicsException , Tree } from '@angular-devkit/schematics' ;
14
+ import { SchematicContext , Tree } from '@angular-devkit/schematics' ;
15
15
import {
16
16
getImportOfIdentifier ,
17
17
getProjectIndexFiles ,
@@ -27,13 +27,11 @@ import {
27
27
getMetadataField
28
28
} from '@angular/cdk/schematics' ;
29
29
import { InsertChange } from '@schematics/angular/utility/change' ;
30
- import { getWorkspace } from '@schematics/angular/utility/config' ;
31
30
import { WorkspaceProject } from '@schematics/angular/utility/workspace-models' ;
32
31
import { readFileSync } from 'fs' ;
33
32
import { dirname , join , relative } from 'path' ;
34
33
import * as ts from 'typescript' ;
35
34
36
- import { getProjectFromProgram } from './cli-workspace' ;
37
35
import { findHammerScriptImportElements } from './find-hammer-script-tags' ;
38
36
import { findMainModuleExpression } from './find-main-module' ;
39
37
import { isHammerJsUsedInTemplate } from './hammer-template-check' ;
@@ -242,8 +240,7 @@ export class HammerGesturesRule extends MigrationRule<null> {
242
240
* 4) Setup the "HammerModule" in the root app module (if not done already).
243
241
*/
244
242
private _setupHammerWithCustomEvents ( ) {
245
- const project = this . _getProjectOrThrow ( ) ;
246
- const sourceRoot = devkitNormalize ( project . sourceRoot || project . root ) ;
243
+ const sourceRoot = devkitNormalize ( this . project . sourceRoot || this . project . root ) ;
247
244
const newConfigPath =
248
245
devkitJoin ( sourceRoot , this . _getAvailableGestureConfigFileName ( sourceRoot ) ) ;
249
246
@@ -261,20 +258,18 @@ export class HammerGesturesRule extends MigrationRule<null> {
261
258
// Setup the gesture config provider and the "HammerModule" in the root module
262
259
// if not done already. The "HammerModule" is needed in v9 since it enables the
263
260
// Hammer event plugin that was previously enabled by default in v8.
264
- this . _setupNewGestureConfigInRootModule ( project , newConfigPath ) ;
265
- this . _setupHammerModuleInRootModule ( project ) ;
261
+ this . _setupNewGestureConfigInRootModule ( newConfigPath ) ;
262
+ this . _setupHammerModuleInRootModule ( ) ;
266
263
}
267
264
268
265
/**
269
266
* Sets up the standard hammer module in the project and removes all
270
267
* references to the deprecated Angular Material gesture config.
271
268
*/
272
269
private _setupHammerWithStandardEvents ( ) {
273
- const project = this . _getProjectOrThrow ( ) ;
274
-
275
270
// Setup the HammerModule. The HammerModule enables support for
276
271
// the standard HammerJS events.
277
- this . _setupHammerModuleInRootModule ( project ) ;
272
+ this . _setupHammerModuleInRootModule ( ) ;
278
273
this . _removeMaterialGestureConfigSetup ( ) ;
279
274
}
280
275
@@ -285,13 +280,11 @@ export class HammerGesturesRule extends MigrationRule<null> {
285
280
* 3) Remove "hammerjs" from all index HTML files of the current project.
286
281
*/
287
282
private _removeHammerSetup ( ) {
288
- const project = this . _getProjectOrThrow ( ) ;
289
-
290
283
this . _installImports . forEach ( i => this . _importManager . deleteImportByDeclaration ( i ) ) ;
291
284
292
285
this . _removeMaterialGestureConfigSetup ( ) ;
293
286
this . _removeHammerModuleReferences ( ) ;
294
- this . _removeHammerFromIndexFile ( project ) ;
287
+ this . _removeHammerFromIndexFile ( this . project ) ;
295
288
}
296
289
297
290
/**
@@ -645,8 +638,8 @@ export class HammerGesturesRule extends MigrationRule<null> {
645
638
}
646
639
647
640
/** Sets up the Hammer gesture config in the root module if needed. */
648
- private _setupNewGestureConfigInRootModule ( project : WorkspaceProject , gestureConfigPath : string ) {
649
- const mainFilePath = join ( this . basePath , getProjectMainFile ( project ) ) ;
641
+ private _setupNewGestureConfigInRootModule ( gestureConfigPath : string ) {
642
+ const mainFilePath = join ( this . basePath , getProjectMainFile ( this . project ) ) ;
650
643
const rootModuleSymbol = this . _getRootModuleSymbol ( mainFilePath ) ;
651
644
652
645
if ( rootModuleSymbol === null ) {
@@ -722,8 +715,8 @@ export class HammerGesturesRule extends MigrationRule<null> {
722
715
}
723
716
724
717
/** Sets up the "HammerModule" in the root module of the project. */
725
- private _setupHammerModuleInRootModule ( project : WorkspaceProject ) {
726
- const mainFilePath = join ( this . basePath , getProjectMainFile ( project ) ) ;
718
+ private _setupHammerModuleInRootModule ( ) {
719
+ const mainFilePath = join ( this . basePath , getProjectMainFile ( this . project ) ) ;
727
720
const rootModuleSymbol = this . _getRootModuleSymbol ( mainFilePath ) ;
728
721
729
722
if ( rootModuleSymbol === null ) {
@@ -820,23 +813,6 @@ export class HammerGesturesRule extends MigrationRule<null> {
820
813
} ) ;
821
814
}
822
815
823
- /**
824
- * Gets the project from the current program or throws if no project
825
- * could be found.
826
- */
827
- private _getProjectOrThrow ( ) : WorkspaceProject {
828
- const workspace = getWorkspace ( this . tree ) ;
829
- const project = getProjectFromProgram ( workspace , this . program ) ;
830
-
831
- if ( ! project ) {
832
- throw new SchematicsException (
833
- 'Could not find project to perform HammerJS v9 migration. ' +
834
- 'Please ensure your workspace configuration defines a project.' ) ;
835
- }
836
-
837
- return project ;
838
- }
839
-
840
816
/** Global state of whether Hammer is used in any analyzed project target. */
841
817
static globalUsesHammer = false ;
842
818
0 commit comments