@@ -33,7 +33,6 @@ import {readFileSync} from 'fs';
33
33
import { dirname , join , relative } from 'path' ;
34
34
import * as ts from 'typescript' ;
35
35
36
- import { getProjectFromProgram } from './cli-workspace' ;
37
36
import { findHammerScriptImportElements } from './find-hammer-script-tags' ;
38
37
import { findMainModuleExpression } from './find-main-module' ;
39
38
import { isHammerJsUsedInTemplate } from './hammer-template-check' ;
@@ -242,8 +241,7 @@ export class HammerGesturesRule extends MigrationRule<null> {
242
241
* 4) Setup the "HammerModule" in the root app module (if not done already).
243
242
*/
244
243
private _setupHammerWithCustomEvents ( ) {
245
- const project = this . _getProjectOrThrow ( ) ;
246
- const sourceRoot = devkitNormalize ( project . sourceRoot || project . root ) ;
244
+ const sourceRoot = devkitNormalize ( this . project . sourceRoot || this . project . root ) ;
247
245
const newConfigPath =
248
246
devkitJoin ( sourceRoot , this . _getAvailableGestureConfigFileName ( sourceRoot ) ) ;
249
247
@@ -261,20 +259,18 @@ export class HammerGesturesRule extends MigrationRule<null> {
261
259
// Setup the gesture config provider and the "HammerModule" in the root module
262
260
// if not done already. The "HammerModule" is needed in v9 since it enables the
263
261
// Hammer event plugin that was previously enabled by default in v8.
264
- this . _setupNewGestureConfigInRootModule ( project , newConfigPath ) ;
265
- this . _setupHammerModuleInRootModule ( project ) ;
262
+ this . _setupNewGestureConfigInRootModule ( newConfigPath ) ;
263
+ this . _setupHammerModuleInRootModule ( ) ;
266
264
}
267
265
268
266
/**
269
267
* Sets up the standard hammer module in the project and removes all
270
268
* references to the deprecated Angular Material gesture config.
271
269
*/
272
270
private _setupHammerWithStandardEvents ( ) {
273
- const project = this . _getProjectOrThrow ( ) ;
274
-
275
271
// Setup the HammerModule. The HammerModule enables support for
276
272
// the standard HammerJS events.
277
- this . _setupHammerModuleInRootModule ( project ) ;
273
+ this . _setupHammerModuleInRootModule ( ) ;
278
274
this . _removeMaterialGestureConfigSetup ( ) ;
279
275
}
280
276
@@ -285,13 +281,11 @@ export class HammerGesturesRule extends MigrationRule<null> {
285
281
* 3) Remove "hammerjs" from all index HTML files of the current project.
286
282
*/
287
283
private _removeHammerSetup ( ) {
288
- const project = this . _getProjectOrThrow ( ) ;
289
-
290
284
this . _installImports . forEach ( i => this . _importManager . deleteImportByDeclaration ( i ) ) ;
291
285
292
286
this . _removeMaterialGestureConfigSetup ( ) ;
293
287
this . _removeHammerModuleReferences ( ) ;
294
- this . _removeHammerFromIndexFile ( project ) ;
288
+ this . _removeHammerFromIndexFile ( this . project ) ;
295
289
}
296
290
297
291
/**
@@ -645,8 +639,8 @@ export class HammerGesturesRule extends MigrationRule<null> {
645
639
}
646
640
647
641
/** 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 ) ) ;
642
+ private _setupNewGestureConfigInRootModule ( gestureConfigPath : string ) {
643
+ const mainFilePath = join ( this . basePath , getProjectMainFile ( this . project ) ) ;
650
644
const rootModuleSymbol = this . _getRootModuleSymbol ( mainFilePath ) ;
651
645
652
646
if ( rootModuleSymbol === null ) {
@@ -722,8 +716,8 @@ export class HammerGesturesRule extends MigrationRule<null> {
722
716
}
723
717
724
718
/** Sets up the "HammerModule" in the root module of the project. */
725
- private _setupHammerModuleInRootModule ( project : WorkspaceProject ) {
726
- const mainFilePath = join ( this . basePath , getProjectMainFile ( project ) ) ;
719
+ private _setupHammerModuleInRootModule ( ) {
720
+ const mainFilePath = join ( this . basePath , getProjectMainFile ( this . project ) ) ;
727
721
const rootModuleSymbol = this . _getRootModuleSymbol ( mainFilePath ) ;
728
722
729
723
if ( rootModuleSymbol === null ) {
@@ -820,23 +814,6 @@ export class HammerGesturesRule extends MigrationRule<null> {
820
814
} ) ;
821
815
}
822
816
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
817
/** Global state of whether Hammer is used in any analyzed project target. */
841
818
static globalUsesHammer = false ;
842
819
0 commit comments