1
- import { basename , dirname , join , relative } from 'path' ;
1
+ import { dirname , join , relative } from 'path' ;
2
2
import { Logger } from '../logger/logger' ;
3
3
import * as Constants from '../util/constants' ;
4
- import { changeExtension , escapeStringForRegex } from '../util/helpers' ;
4
+ import { changeExtension , convertFilePathToNgFactoryPath , escapeStringForRegex } from '../util/helpers' ;
5
5
import { TreeShakeCalcResults } from '../util/interfaces' ;
6
6
7
7
export function calculateUnusedComponents ( dependencyMap : Map < string , Set < string > > ) : TreeShakeCalcResults {
@@ -71,43 +71,24 @@ function processImportTree(dependencyMap: Map<string, Set<string>>, importee: st
71
71
}
72
72
73
73
function calculateUnusedIonicProviders ( dependencyMap : Map < string , Set < string > > ) {
74
- const ACTION_SHEET_CONTROLLER = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'action-sheet' , 'action-sheet-controller.js' ) ;
75
- const ACTION_SHEET_COMPONENT_FACTORY = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'action-sheet' , 'action-sheet-component.ngfactory.js' ) ;
76
74
77
- const ALERT_CONTROLLER = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'alert' , 'alert-controller.js' ) ;
78
- const ALERT_COMPONENT_FACTORY = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'alert' , 'alert-component.ngfactory.js' ) ;
79
75
80
- const LOADING_CONTROLLER = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'loading' , 'loading-controller.js' ) ;
81
- const LOADING_COMPONENT_FACTORY = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'loading' , 'loading-component.ngfactory.js' ) ;
82
-
83
- const MODAL_CONTROLLER = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'modal' , 'modal-controller.js' ) ;
84
- const MODAL_COMPONENT_FACTORY = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'modal' , 'modal-component.ngfactory.js' ) ;
85
-
86
- const PICKER_CONTROLLER = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'picker' , 'picker-controller.js' ) ;
87
- const PICKER_COMPONENT_FACTORY = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'picker' , 'picker-component.ngfactory.js' ) ;
88
-
89
- const POPOVER_CONTROLLER = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'popover' , 'popover-controller.js' ) ;
90
- const POPOVER_COMPONENT_FACTORY = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'popover' , 'popover-component.ngfactory.js' ) ;
91
-
92
- const TOAST_CONTROLLER = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'toast' , 'toast-controller.js' ) ;
93
- const TOAST_COMPONENT_FACTORY = join ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] , 'components' , 'toast' , 'toast-component.ngfactory.js' ) ;
94
-
95
- processIonicProviders ( dependencyMap , ACTION_SHEET_CONTROLLER ) ;
96
- processIonicProviders ( dependencyMap , ALERT_CONTROLLER ) ;
97
- processIonicProviders ( dependencyMap , LOADING_CONTROLLER ) ;
98
- processIonicProviders ( dependencyMap , MODAL_CONTROLLER ) ;
99
- processIonicProviders ( dependencyMap , PICKER_CONTROLLER ) ;
100
- processIonicProviders ( dependencyMap , POPOVER_CONTROLLER ) ;
101
- processIonicProviders ( dependencyMap , TOAST_CONTROLLER ) ;
76
+ processIonicProviders ( dependencyMap , process . env [ Constants . ENV_ACTION_SHEET_CONTROLLER_PATH ] ) ;
77
+ processIonicProviders ( dependencyMap , process . env [ Constants . ENV_ALERT_CONTROLLER_PATH ] ) ;
78
+ processIonicProviders ( dependencyMap , process . env [ Constants . ENV_LOADING_CONTROLLER_PATH ] ) ;
79
+ processIonicProviders ( dependencyMap , process . env [ Constants . ENV_MODAL_CONTROLLER_PATH ] ) ;
80
+ processIonicProviders ( dependencyMap , process . env [ Constants . ENV_PICKER_CONTROLLER_PATH ] ) ;
81
+ processIonicProviders ( dependencyMap , process . env [ Constants . ENV_POPOVER_CONTROLLER_PATH ] ) ;
82
+ processIonicProviders ( dependencyMap , process . env [ Constants . ENV_TOAST_CONTROLLER_PATH ] ) ;
102
83
103
84
// check if the controllers were deleted, if so, purge the component too
104
- processIonicProviderComponents ( dependencyMap , ACTION_SHEET_CONTROLLER , ACTION_SHEET_COMPONENT_FACTORY ) ;
105
- processIonicProviderComponents ( dependencyMap , ALERT_CONTROLLER , ALERT_COMPONENT_FACTORY ) ;
106
- processIonicProviderComponents ( dependencyMap , LOADING_CONTROLLER , LOADING_COMPONENT_FACTORY ) ;
107
- processIonicProviderComponents ( dependencyMap , MODAL_CONTROLLER , MODAL_COMPONENT_FACTORY ) ;
108
- processIonicProviderComponents ( dependencyMap , PICKER_CONTROLLER , PICKER_COMPONENT_FACTORY ) ;
109
- processIonicProviderComponents ( dependencyMap , POPOVER_CONTROLLER , POPOVER_COMPONENT_FACTORY ) ;
110
- processIonicProviderComponents ( dependencyMap , TOAST_CONTROLLER , TOAST_COMPONENT_FACTORY ) ;
85
+ processIonicProviderComponents ( dependencyMap , process . env [ Constants . ENV_ACTION_SHEET_CONTROLLER_PATH ] , process . env [ Constants . ENV_ACTION_SHEET_COMPONENT_FACTORY_PATH ] ) ;
86
+ processIonicProviderComponents ( dependencyMap , process . env [ Constants . ENV_ALERT_CONTROLLER_PATH ] , process . env [ Constants . ENV_ALERT_COMPONENT_FACTORY_PATH ] ) ;
87
+ processIonicProviderComponents ( dependencyMap , process . env [ Constants . ENV_LOADING_CONTROLLER_PATH ] , process . env [ Constants . ENV_LOADING_COMPONENT_FACTORY_PATH ] ) ;
88
+ processIonicProviderComponents ( dependencyMap , process . env [ Constants . ENV_MODAL_CONTROLLER_PATH ] , process . env [ Constants . ENV_MODAL_COMPONENT_FACTORY_PATH ] ) ;
89
+ processIonicProviderComponents ( dependencyMap , process . env [ Constants . ENV_PICKER_CONTROLLER_PATH ] , process . env [ Constants . ENV_PICKER_COMPONENT_FACTORY_PATH ] ) ;
90
+ processIonicProviderComponents ( dependencyMap , process . env [ Constants . ENV_POPOVER_CONTROLLER_PATH ] , process . env [ Constants . ENV_POPOVER_COMPONENT_FACTORY_PATH ] ) ;
91
+ processIonicProviderComponents ( dependencyMap , process . env [ Constants . ENV_TOAST_CONTROLLER_PATH ] , process . env [ Constants . ENV_TOAST_COMPONENT_FACTORY_PATH ] ) ;
111
92
}
112
93
113
94
function processIonicProviderComponents ( dependencyMap : Map < string , Set < string > > , providerPath : string , componentPath : string ) {
@@ -119,10 +100,7 @@ function processIonicProviderComponents(dependencyMap: Map<string, Set<string>>,
119
100
120
101
function getAppModuleNgFactoryPath ( ) {
121
102
const appNgModulePath = process . env [ Constants . ENV_APP_NG_MODULE_PATH ] ;
122
- const directory = dirname ( appNgModulePath ) ;
123
- const extensionlessFileName = basename ( appNgModulePath , '.js' ) ;
124
- const ngFactoryFileName = extensionlessFileName + '.ngfactory.js' ;
125
- return join ( directory , ngFactoryFileName ) ;
103
+ return convertFilePathToNgFactoryPath ( appNgModulePath ) ;
126
104
}
127
105
128
106
function processIonicProviders ( dependencyMap : Map < string , Set < string > > , providerPath : string ) {
0 commit comments