11import { dirname , join , relative } from 'path' ;
22import { Logger } from '../logger/logger' ;
33import * as Constants from '../util/constants' ;
4- import { changeExtension , convertFilePathToNgFactoryPath , escapeStringForRegex } from '../util/helpers' ;
4+ import { changeExtension , convertFilePathToNgFactoryPath , escapeStringForRegex , toUnixPath } from '../util/helpers' ;
55import { TreeShakeCalcResults } from '../util/interfaces' ;
66
77export function calculateUnusedComponents ( dependencyMap : Map < string , Set < string > > ) : TreeShakeCalcResults {
@@ -145,7 +145,8 @@ export function purgeUnusedImportsAndExportsFromIndex(indexFilePath: string, ind
145145 // I cannot get the './' prefix to show up when using path api
146146 Logger . debug ( `[treeshake] purgeUnusedImportsFromIndex: Removing ${ modulePath } from ${ indexFilePath } ` ) ;
147147 const extensionless = changeExtension ( modulePath , '' ) ;
148- const importPath = './' + relative ( dirname ( indexFilePath ) , extensionless ) ;
148+ const relativeImportPath = './' + relative ( dirname ( indexFilePath ) , extensionless ) ;
149+ const importPath = toUnixPath ( relativeImportPath ) ;
149150 const importRegex = generateImportRegex ( importPath ) ;
150151 // replace the import if it's found
151152 let results : RegExpExecArray = null ;
@@ -175,7 +176,8 @@ function generateExportRegex(relativeExportPath: string) {
175176export function purgeComponentNgFactoryImportAndUsage ( appModuleNgFactoryPath : string , appModuleNgFactoryContent : string , componentFactoryPath : string ) {
176177 const extensionlessComponentFactoryPath = changeExtension ( componentFactoryPath , '' ) ;
177178 const relativeImportPath = relative ( dirname ( appModuleNgFactoryPath ) , extensionlessComponentFactoryPath ) ;
178- const importRegex = generateWildCardImportRegex ( relativeImportPath ) ;
179+ const importPath = toUnixPath ( relativeImportPath ) ;
180+ const importRegex = generateWildCardImportRegex ( importPath ) ;
179181 const results = importRegex . exec ( appModuleNgFactoryContent ) ;
180182 if ( results && results . length >= 2 ) {
181183 appModuleNgFactoryContent = appModuleNgFactoryContent . replace ( importRegex , '' ) ;
@@ -189,7 +191,8 @@ export function purgeComponentNgFactoryImportAndUsage(appModuleNgFactoryPath: st
189191export function purgeProviderControllerImportAndUsage ( appModuleNgFactoryPath : string , appModuleNgFactoryContent : string , providerPath : string ) {
190192 const extensionlessComponentFactoryPath = changeExtension ( providerPath , '' ) ;
191193 const relativeImportPath = relative ( dirname ( process . env [ Constants . ENV_VAR_IONIC_ANGULAR_DIR ] ) , extensionlessComponentFactoryPath ) ;
192- const importRegex = generateWildCardImportRegex ( relativeImportPath ) ;
194+ const importPath = toUnixPath ( relativeImportPath ) ;
195+ const importRegex = generateWildCardImportRegex ( importPath ) ;
193196 const results = importRegex . exec ( appModuleNgFactoryContent ) ;
194197 if ( results && results . length >= 2 ) {
195198 appModuleNgFactoryContent = appModuleNgFactoryContent . replace ( importRegex , '' ) ;
0 commit comments