@@ -47,7 +47,13 @@ function requiredModule(modulePath: string) {
47
47
const appModule = changeExtension ( getStringPropertyValue ( Constants . ENV_APP_NG_MODULE_PATH ) , '.js' ) ;
48
48
const appModuleNgFactory = getAppModuleNgFactoryPath ( ) ;
49
49
const moduleFile = getIonicModuleFilePath ( ) ;
50
- return modulePath === mainJsFile || modulePath === mainTsFile || modulePath === appModule || modulePath === appModuleNgFactory || modulePath === moduleFile ;
50
+ const menuTypes = join ( dirname ( getStringPropertyValue ( Constants . ENV_VAR_IONIC_ANGULAR_ENTRY_POINT ) ) , 'components' , 'menu' , 'menu-types.js' ) ;
51
+ return modulePath === mainJsFile
52
+ || modulePath === mainTsFile
53
+ || modulePath === appModule
54
+ || modulePath === appModuleNgFactory
55
+ || modulePath === moduleFile
56
+ || modulePath === menuTypes ;
51
57
}
52
58
53
59
function filterMap ( dependencyMap : Map < string , Set < string > > ) {
@@ -103,45 +109,35 @@ function calculateUnusedIonicProviders(dependencyMap: Map<string, Set<string>>)
103
109
104
110
// check if the controllers were deleted, if so, purge the component too
105
111
Logger . debug ( `[treeshake] calculateUnusedIonicProviders: attempting to action sheet component` ) ;
106
- processIonicProviderComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_ACTION_SHEET_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_ACTION_SHEET_COMPONENT_FACTORY_PATH ) ) ;
112
+ processIonicOverlayComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_ACTION_SHEET_VIEW_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_ACTION_SHEET_COMPONENT_PATH ) , getStringPropertyValue ( Constants . ENV_ACTION_SHEET_COMPONENT_FACTORY_PATH ) ) ;
107
113
Logger . debug ( `[treeshake] calculateUnusedIonicProviders: attempting to alert component` ) ;
108
- processIonicProviderComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_ALERT_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_ALERT_COMPONENT_FACTORY_PATH ) ) ;
114
+ processIonicOverlayComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_ALERT_VIEW_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_ALERT_COMPONENT_PATH ) , getStringPropertyValue ( Constants . ENV_ALERT_COMPONENT_FACTORY_PATH ) ) ;
109
115
Logger . debug ( `[treeshake] calculateUnusedIonicProviders: attempting to loading component` ) ;
110
- processIonicProviderComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_LOADING_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_LOADING_COMPONENT_FACTORY_PATH ) ) ;
116
+ processIonicOverlayComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_LOADING_VIEW_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_LOADING_COMPONENT_PATH ) , getStringPropertyValue ( Constants . ENV_LOADING_COMPONENT_FACTORY_PATH ) ) ;
111
117
Logger . debug ( `[treeshake] calculateUnusedIonicProviders: attempting to modal component` ) ;
112
- processIonicProviderComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_MODAL_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_MODAL_COMPONENT_FACTORY_PATH ) ) ;
118
+ processIonicOverlayComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_MODAL_VIEW_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_MODAL_COMPONENT_PATH ) , getStringPropertyValue ( Constants . ENV_MODAL_COMPONENT_FACTORY_PATH ) ) ;
113
119
Logger . debug ( `[treeshake] calculateUnusedIonicProviders: attempting to picker component` ) ;
114
- processIonicProviderComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_PICKER_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_PICKER_COMPONENT_FACTORY_PATH ) ) ;
120
+ processIonicOverlayComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_PICKER_VIEW_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_PICKER_COMPONENT_PATH ) , getStringPropertyValue ( Constants . ENV_PICKER_COMPONENT_FACTORY_PATH ) ) ;
115
121
Logger . debug ( `[treeshake] calculateUnusedIonicProviders: attempting to popover component` ) ;
116
- processIonicProviderComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_POPOVER_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_POPOVER_COMPONENT_FACTORY_PATH ) ) ;
122
+ processIonicOverlayComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_POPOVER_VIEW_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_POPOVER_COMPONENT_PATH ) , getStringPropertyValue ( Constants . ENV_POPOVER_COMPONENT_FACTORY_PATH ) ) ;
117
123
Logger . debug ( `[treeshake] calculateUnusedIonicProviders: attempting to toast component` ) ;
118
- processIonicProviderComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_TOAST_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_TOAST_COMPONENT_FACTORY_PATH ) ) ;
124
+ processIonicOverlayComponents ( dependencyMap , getStringPropertyValue ( Constants . ENV_TOAST_VIEW_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_TOAST_COMPONENT_PATH ) , getStringPropertyValue ( Constants . ENV_TOAST_COMPONENT_FACTORY_PATH ) ) ;
119
125
120
126
// in this case, it's actually an entry component, not a provider
121
127
processIonicProviders ( dependencyMap , getStringPropertyValue ( Constants . ENV_SELECT_POPOVER_COMPONENT_FACTORY_PATH ) ) ;
122
-
123
- restoreOverlayViewControllers ( dependencyMap , getStringPropertyValue ( Constants . ENV_ACTION_SHEET_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_ACTION_SHEET_VIEW_CONTROLLER_PATH ) ) ;
124
- restoreOverlayViewControllers ( dependencyMap , getStringPropertyValue ( Constants . ENV_ALERT_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_ALERT_VIEW_CONTROLLER_PATH ) ) ;
125
- restoreOverlayViewControllers ( dependencyMap , getStringPropertyValue ( Constants . ENV_LOADING_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_LOADING_VIEW_CONTROLLER_PATH ) ) ;
126
- restoreOverlayViewControllers ( dependencyMap , getStringPropertyValue ( Constants . ENV_MODAL_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_MODAL_VIEW_CONTROLLER_PATH ) ) ;
127
- restoreOverlayViewControllers ( dependencyMap , getStringPropertyValue ( Constants . ENV_PICKER_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_PICKER_VIEW_CONTROLLER_PATH ) ) ;
128
- restoreOverlayViewControllers ( dependencyMap , getStringPropertyValue ( Constants . ENV_POPOVER_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_POPOVER_VIEW_CONTROLLER_PATH ) ) ;
129
- restoreOverlayViewControllers ( dependencyMap , getStringPropertyValue ( Constants . ENV_TOAST_CONTROLLER_PATH ) , getStringPropertyValue ( Constants . ENV_TOAST_VIEW_CONTROLLER_PATH ) ) ;
130
- }
131
-
132
- function processIonicProviderComponents ( dependencyMap : Map < string , Set < string > > , providerPath : string , componentPath : string ) {
133
- const importeeSet = dependencyMap . get ( providerPath ) ;
134
- if ( importeeSet && importeeSet . size === 0 ) {
135
- processIonicProviders ( dependencyMap , componentPath ) ;
136
- }
137
128
}
138
129
139
- function restoreOverlayViewControllers ( dependencyMap : Map < string , Set < string > > , providerPath : string , viewControllerPath : string ) {
140
- const providerImporteeSet = dependencyMap . get ( providerPath ) ;
141
- if ( providerImporteeSet && providerImporteeSet . size > 0 ) {
142
- const viewControllerImportees = dependencyMap . get ( viewControllerPath ) || new Set < string > ( ) ;
143
- viewControllerImportees . add ( providerPath ) ;
144
- dependencyMap . set ( viewControllerPath , viewControllerImportees ) ;
130
+ function processIonicOverlayComponents ( dependencyMap : Map < string , Set < string > > , viewControllerPath : string , componentPath : string , componentFactoryPath : string ) {
131
+ const viewControllerImportees = dependencyMap . get ( viewControllerPath ) ;
132
+ const componentImportees = dependencyMap . get ( componentPath ) ;
133
+ if ( viewControllerImportees && viewControllerImportees . size === 0 && componentImportees && componentImportees . size === 1 && componentImportees . has ( componentFactoryPath ) ) {
134
+ const componentFactoryImportees = dependencyMap . get ( componentFactoryPath ) ;
135
+ const onlyNgModuleFactoryImportees = onlyNgModuleFactories ( componentFactoryImportees ) ;
136
+ if ( onlyNgModuleFactoryImportees ) {
137
+ // sweet, we can remove this bad boy
138
+ dependencyMap . set ( componentFactoryPath , new Set < string > ( ) ) ;
139
+ componentImportees . delete ( componentFactoryPath ) ;
140
+ }
145
141
}
146
142
}
147
143
@@ -154,15 +150,29 @@ export function getAppModuleNgFactoryPath() {
154
150
function processIonicProviders ( dependencyMap : Map < string , Set < string > > , providerPath : string ) {
155
151
const importeeSet = dependencyMap . get ( providerPath ) ;
156
152
const appModuleNgFactoryPath = getAppModuleNgFactoryPath ( ) ;
157
- // we can only purge an ionic provider if it is imported from one module, which is the AppModuleNgFactory
158
- if ( importeeSet && importeeSet . has ( appModuleNgFactoryPath ) ) {
153
+
154
+ // we can only purge providers that are only referenced in .module.ngfactory.js files
155
+ const onlyNgModuleFactoryImportees = onlyNgModuleFactories ( importeeSet ) ;
156
+ if ( onlyNgModuleFactoryImportees && importeeSet && importeeSet . has ( appModuleNgFactoryPath ) ) {
159
157
Logger . debug ( `[treeshake] processIonicProviders: Purging ${ providerPath } ` ) ;
160
158
importeeSet . delete ( appModuleNgFactoryPath ) ;
161
159
// loop over the dependency map and remove this provider from importee sets
162
160
processImportTreeForProviders ( dependencyMap , providerPath ) ;
163
161
}
164
162
}
165
163
164
+ function onlyNgModuleFactories ( importeeSet : Set < string > ) {
165
+ const moduleNgFactoryTs = changeExtension ( getStringPropertyValue ( Constants . ENV_NG_MODULE_FILE_NAME_SUFFIX ) , '.ngfactory.ts' ) ;
166
+ const moduleNgFactoryJs = changeExtension ( getStringPropertyValue ( Constants . ENV_NG_MODULE_FILE_NAME_SUFFIX ) , '.ngfactory.js' ) ;
167
+ let onlyNgModuleFactories = true ;
168
+ importeeSet . forEach ( importee => {
169
+ if ( onlyNgModuleFactories && ! ( importee . endsWith ( moduleNgFactoryTs ) || importee . endsWith ( moduleNgFactoryJs ) ) ) {
170
+ onlyNgModuleFactories = false ;
171
+ }
172
+ } ) ;
173
+ return onlyNgModuleFactories ;
174
+ }
175
+
166
176
function processImportTreeForProviders ( dependencyMap : Map < string , Set < string > > , importee : string ) {
167
177
const importees : string [ ] = [ ] ;
168
178
dependencyMap . forEach ( ( importeeSet : Set < string > , modulePath : string ) => {
0 commit comments