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