1
- import { join } from 'path' ;
1
+ import { join , relative } from 'path' ;
2
2
import * as treeshake from './treeshake' ;
3
3
import * as Constants from '../util/constants' ;
4
+ import * as helpers from '../util/helpers' ;
4
5
5
6
6
7
let originalEnv : any = null ;
@@ -1207,15 +1208,26 @@ export const AppModuleNgFactory = new import0.NgModuleFactory(AppModuleInjector,
1207
1208
const componentFactoryPath2 = `/Users/dan/Dev/myApp3/node_modules/ionic-angular/components/alert/alert-component.ngfactory.js` ;
1208
1209
1209
1210
// act
1210
- let updatedContent = treeshake . purgeComponentNgFactoryImportAndUsage ( appModuleNgFactoryPath , knownContent , componentFactoryPath ) ;
1211
- updatedContent = treeshake . purgeComponentNgFactoryImportAndUsage ( appModuleNgFactoryPath , updatedContent , componentFactoryPath2 ) ;
1211
+ const updatedContent = treeshake . purgeComponentNgFactoryImportAndUsage ( appModuleNgFactoryPath , knownContent , componentFactoryPath ) ;
1212
+ const updatedContentAgain = treeshake . purgeComponentNgFactoryImportAndUsage ( appModuleNgFactoryPath , updatedContent , componentFactoryPath2 ) ;
1212
1213
1213
1214
// assert
1214
- expect ( updatedContent ) . not . toEqual ( knownContent ) ;
1215
- expect ( updatedContent . indexOf ( knownImport ) ) . toEqual ( - 1 ) ;
1216
- expect ( updatedContent . indexOf ( knownImport2 ) ) . toEqual ( - 1 ) ;
1217
- expect ( updatedContent . indexOf ( knownImportUsage ) ) . toEqual ( - 1 ) ;
1218
- expect ( updatedContent . indexOf ( knownImportUsage2 ) ) . toEqual ( - 1 ) ;
1215
+ expect ( updatedContentAgain ) . not . toEqual ( knownContent ) ;
1216
+ const knownImportOneRegex = treeshake . generateWildCardImportRegex ( '../../node_modules/ionic-angular/components/action-sheet/action-sheet-component.ngfactory' ) ;
1217
+ const knownImportTwoRegex = treeshake . generateWildCardImportRegex ( '../../node_modules/ionic-angular/components/alert/alert-component.ngfactory' ) ;
1218
+ const knownImportOneResults = knownImportOneRegex . exec ( updatedContentAgain ) ;
1219
+ const knownImportTwoResults = knownImportTwoRegex . exec ( updatedContentAgain ) ;
1220
+ const knownNamedImportOne = knownImportOneResults [ 1 ] . trim ( ) ;
1221
+ const knownNamedImportTwo = knownImportTwoResults [ 1 ] . trim ( ) ;
1222
+ expect ( updatedContentAgain . indexOf ( `/*${ knownImportOneResults [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
1223
+ expect ( updatedContentAgain . indexOf ( `/*${ knownImportTwoResults [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
1224
+
1225
+ const removeFromConstructorRegexOne = treeshake . generateRemoveComponentFromConstructorRegex ( knownNamedImportOne ) ;
1226
+ const removeFromConstructorRegexTwo = treeshake . generateRemoveComponentFromConstructorRegex ( knownNamedImportTwo ) ;
1227
+ const removeFromConstructorOneResults = removeFromConstructorRegexOne . exec ( updatedContentAgain ) ;
1228
+ const removeFromConstructorTwoResults = removeFromConstructorRegexTwo . exec ( updatedContentAgain ) ;
1229
+ expect ( updatedContentAgain . indexOf ( `/*${ removeFromConstructorOneResults [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
1230
+ expect ( updatedContentAgain . indexOf ( `/*${ removeFromConstructorTwoResults [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
1219
1231
} ) ;
1220
1232
} ) ;
1221
1233
@@ -1235,32 +1247,32 @@ export const AppModuleNgFactory = new import0.NgModuleFactory(AppModuleInjector,
1235
1247
// arrange
1236
1248
1237
1249
const ifStatementOne = `
1238
- if ((token === import32.ActionSheetController)) {
1239
- return this._ActionSheetController_54;
1240
- }
1250
+ if ((token === import32.ActionSheetController)) {
1251
+ return this._ActionSheetController_54;
1252
+ }
1241
1253
` ;
1242
1254
const ifStatementTwo = `
1243
- if ((token === import33.AlertController)) {
1244
- return this._AlertController_55;
1245
- }
1255
+ if ((token === import33.AlertController)) {
1256
+ return this._AlertController_55;
1257
+ }
1246
1258
` ;
1247
1259
1248
1260
const getterOne = `
1249
- get _ActionSheetController_54() {
1250
- if ((this.__ActionSheetController_54 == null)) {
1251
- (this.__ActionSheetController_54 = new import32.ActionSheetController(this._App_19, this._Config_16));
1252
- }
1253
- return this.__ActionSheetController_54;
1254
- }
1261
+ get _ActionSheetController_54() {
1262
+ if ((this.__ActionSheetController_54 == null)) {
1263
+ (this.__ActionSheetController_54 = new import32.ActionSheetController(this._App_19, this._Config_16));
1264
+ }
1265
+ return this.__ActionSheetController_54;
1266
+ }
1255
1267
` ;
1256
1268
1257
1269
const getterTwo = `
1258
- get _AlertController_55() {
1259
- if ((this.__AlertController_55 == null)) {
1260
- (this.__AlertController_55 = new import33.AlertController(this._App_19, this._Config_16));
1261
- }
1262
- return this.__AlertController_55;
1263
- }
1270
+ get _AlertController_55() {
1271
+ if ((this.__AlertController_55 == null)) {
1272
+ (this.__AlertController_55 = new import33.AlertController(this._App_19, this._Config_16));
1273
+ }
1274
+ return this.__AlertController_55;
1275
+ }
1264
1276
` ;
1265
1277
1266
1278
const knownContent = `
@@ -1916,22 +1928,47 @@ export const AppModuleNgFactory = new import0.NgModuleFactory(AppModuleInjector,
1916
1928
//# sourceMappingURL=app.module.ngfactory.js.map
1917
1929
` ;
1918
1930
1931
+ const nodeModulesPath = '/Users/dan/Dev/myApp3/node_modules' ;
1932
+
1919
1933
const appModuleNgFactoryPath = `/Users/dan/Dev/myApp3/src/app/app.module.ngfactory.js` ;
1920
- const controllerPath = `/Users/dan/Dev/myApp3/node_modules/ ionic-angular/ components/ action-sheet/ action-sheet-controller.js` ;
1921
- const controllerPath2 = `/Users/dan/Dev/myApp3/node_modules/ ionic-angular/ components/ alert/ alert-controller.js` ;
1934
+ const controllerPath = join ( nodeModulesPath , ' ionic-angular' , ' components' , ' action-sheet' , ' action-sheet-controller.js' ) ;
1935
+ const controllerPath2 = join ( nodeModulesPath , ' ionic-angular' , ' components' , ' alert' , ' alert-controller.js' ) ;
1922
1936
1923
1937
// act
1924
1938
1925
1939
let updatedContent = treeshake . purgeProviderControllerImportAndUsage ( appModuleNgFactoryPath , knownContent , controllerPath ) ;
1926
- updatedContent = treeshake . purgeProviderControllerImportAndUsage ( appModuleNgFactoryPath , knownContent , controllerPath2 ) ;
1940
+ updatedContent = treeshake . purgeProviderControllerImportAndUsage ( appModuleNgFactoryPath , updatedContent , controllerPath2 ) ;
1927
1941
1928
1942
// assert
1929
1943
expect ( updatedContent ) . not . toEqual ( knownContent ) ;
1930
- /*expect(updatedContent.indexOf(ifStatementOne)).toEqual(-1);
1931
- expect(updatedContent.indexOf(ifStatementTwo)).toEqual(-1);
1932
- expect(updatedContent.indexOf(getterOne)).toEqual(-1);
1933
- expect(updatedContent.indexOf(getterTwo)).toEqual(-1);
1934
- */
1944
+ const relativeImportPathOne = helpers . changeExtension ( relative ( nodeModulesPath , controllerPath ) , '' ) ;
1945
+ const relativeImportPathTwo = helpers . changeExtension ( relative ( nodeModulesPath , controllerPath2 ) , '' ) ;
1946
+
1947
+ const importRegexOne = treeshake . generateWildCardImportRegex ( relativeImportPathOne ) ;
1948
+ const importRegexTwo = treeshake . generateWildCardImportRegex ( relativeImportPathTwo ) ;
1949
+ const importResultOne = importRegexOne . exec ( updatedContent ) ;
1950
+ const importResultTwo = importRegexTwo . exec ( updatedContent ) ;
1951
+ expect ( updatedContent . indexOf ( `/*${ importResultOne [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
1952
+ expect ( updatedContent . indexOf ( `/*${ importResultTwo [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
1953
+
1954
+ const namedImportOne = importResultOne [ 1 ] . trim ( ) ;
1955
+ const namedImportTwo = importResultTwo [ 1 ] . trim ( ) ;
1956
+
1957
+ const purgeGetterRegExOne = treeshake . generateRemoveGetterFromImportRegex ( namedImportOne ) ;
1958
+ const purgeGetterResultsOne = purgeGetterRegExOne . exec ( updatedContent ) ;
1959
+ const purgeIfRegExOne = treeshake . generateRemoveIfStatementRegex ( namedImportOne ) ;
1960
+ const purgeIfResultsOne = purgeIfRegExOne . exec ( updatedContent ) ;
1961
+
1962
+ const purgeGetterRegExTwo = treeshake . generateRemoveGetterFromImportRegex ( namedImportTwo ) ;
1963
+
1964
+ const purgeGetterResultsTwo = purgeGetterRegExTwo . exec ( updatedContent ) ;
1965
+ const purgeIfRegExTwo = treeshake . generateRemoveIfStatementRegex ( namedImportTwo ) ;
1966
+ const purgeIfResultsTwo = purgeIfRegExTwo . exec ( updatedContent ) ;
1967
+
1968
+ expect ( updatedContent . indexOf ( `/*${ purgeGetterResultsOne [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
1969
+ expect ( updatedContent . indexOf ( `/*${ purgeIfResultsOne [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
1970
+ expect ( updatedContent . indexOf ( `/*${ purgeGetterResultsTwo [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
1971
+ expect ( updatedContent . indexOf ( `/*${ purgeIfResultsTwo [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
1935
1972
} ) ;
1936
1973
} ) ;
1937
1974
@@ -1999,8 +2036,12 @@ export const AppModuleNgFactory = new import0.NgModuleFactory(AppModuleInjector,
1999
2036
2000
2037
// assert
2001
2038
expect ( updatedContent ) . not . toEqual ( knownContent ) ;
2002
- expect ( updatedContent . indexOf ( classOne ) ) . toEqual ( - 1 ) ;
2003
- expect ( updatedContent . indexOf ( classTwo ) ) . toEqual ( - 1 ) ;
2039
+ const regexOne = treeshake . generateIonicModulePurgeProviderRegex ( classOne ) ;
2040
+ const regexTwo = treeshake . generateIonicModulePurgeProviderRegex ( classTwo ) ;
2041
+ const resultsOne = regexOne . exec ( updatedContent ) ;
2042
+ const resultsTwo = regexTwo . exec ( updatedContent ) ;
2043
+ expect ( updatedContent . indexOf ( `/*${ resultsOne [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
2044
+ expect ( updatedContent . indexOf ( `/*${ resultsTwo [ 0 ] } */` ) ) . toBeGreaterThanOrEqual ( 0 ) ;
2004
2045
} ) ;
2005
2046
} ) ;
2006
2047
} ) ;
0 commit comments