1
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 , convertFilePathToNgFactoryPath , escapeStringForRegex } from '../util/helpers' ;
4
+ import { changeExtension , convertFilePathToNgFactoryPath , escapeStringForRegex , toUnixPath } from '../util/helpers' ;
5
5
import { TreeShakeCalcResults } from '../util/interfaces' ;
6
6
7
7
export function calculateUnusedComponents ( dependencyMap : Map < string , Set < string > > ) : TreeShakeCalcResults {
@@ -145,7 +145,8 @@ export function purgeUnusedImportsAndExportsFromIndex(indexFilePath: string, ind
145
145
// I cannot get the './' prefix to show up when using path api
146
146
Logger . debug ( `[treeshake] purgeUnusedImportsFromIndex: Removing ${ modulePath } from ${ indexFilePath } ` ) ;
147
147
const extensionless = changeExtension ( modulePath , '' ) ;
148
- const importPath = './' + relative ( dirname ( indexFilePath ) , extensionless ) ;
148
+ const relativeImportPath = './' + relative ( dirname ( indexFilePath ) , extensionless ) ;
149
+ const importPath = toUnixPath ( relativeImportPath ) ;
149
150
const importRegex = generateImportRegex ( importPath ) ;
150
151
// replace the import if it's found
151
152
let results : RegExpExecArray = null ;
@@ -175,7 +176,8 @@ function generateExportRegex(relativeExportPath: string) {
175
176
export function purgeComponentNgFactoryImportAndUsage ( appModuleNgFactoryPath : string , appModuleNgFactoryContent : string , componentFactoryPath : string ) {
176
177
const extensionlessComponentFactoryPath = changeExtension ( componentFactoryPath , '' ) ;
177
178
const relativeImportPath = relative ( dirname ( appModuleNgFactoryPath ) , extensionlessComponentFactoryPath ) ;
178
- const importRegex = generateWildCardImportRegex ( relativeImportPath ) ;
179
+ const importPath = toUnixPath ( relativeImportPath ) ;
180
+ const importRegex = generateWildCardImportRegex ( importPath ) ;
179
181
const results = importRegex . exec ( appModuleNgFactoryContent ) ;
180
182
if ( results && results . length >= 2 ) {
181
183
appModuleNgFactoryContent = appModuleNgFactoryContent . replace ( importRegex , '' ) ;
@@ -189,7 +191,8 @@ export function purgeComponentNgFactoryImportAndUsage(appModuleNgFactoryPath: st
189
191
export function purgeProviderControllerImportAndUsage ( appModuleNgFactoryPath : string , appModuleNgFactoryContent : string , providerPath : string ) {
190
192
const extensionlessComponentFactoryPath = changeExtension ( providerPath , '' ) ;
191
193
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 ) ;
193
196
const results = importRegex . exec ( appModuleNgFactoryContent ) ;
194
197
if ( results && results . length >= 2 ) {
195
198
appModuleNgFactoryContent = appModuleNgFactoryContent . replace ( importRegex , '' ) ;
0 commit comments