1
1
import * as fs from "fs" ;
2
- import * as path from "path" ;
2
+ import { join , dirname , basename , resolve as pathResolve , extname , normalize } from "path" ;
3
3
import * as minimatch from "minimatch" ;
4
4
import * as injector from "./yok" ;
5
5
import * as crypto from "crypto" ;
@@ -74,7 +74,7 @@ export class FileSystem implements IFileSystem {
74
74
75
75
let proc : string ;
76
76
if ( $hostInfo . isWindows ) {
77
- proc = path . join ( __dirname , "resources/platform-tools/unzip/win32/unzip" ) ;
77
+ proc = join ( __dirname , "resources/platform-tools/unzip/win32/unzip" ) ;
78
78
} else if ( $hostInfo . isDarwin ) {
79
79
proc = "unzip" ; // darwin unzip is info-zip
80
80
} else if ( $hostInfo . isLinux ) {
@@ -98,11 +98,11 @@ export class FileSystem implements IFileSystem {
98
98
}
99
99
100
100
private findFileCaseInsensitive ( file : string ) : string {
101
- const dir = path . dirname ( file ) ;
102
- const basename = path . basename ( file ) ;
101
+ const dir = dirname ( file ) ;
102
+ const baseName = basename ( file ) ;
103
103
const entries = this . readDirectory ( dir ) ;
104
- const match = minimatch . match ( entries , basename , { nocase : true , nonegate : true , nonull : true } ) [ 0 ] ;
105
- const result = path . join ( dir , match ) ;
104
+ const match = minimatch . match ( entries , baseName , { nocase : true , nonegate : true , nonull : true } ) [ 0 ] ;
105
+ const result = join ( dir , match ) ;
106
106
return result ;
107
107
}
108
108
@@ -204,7 +204,7 @@ export class FileSystem implements IFileSystem {
204
204
}
205
205
206
206
public writeFile ( filename : string , data : string | NodeBuffer , encoding ?: string ) : void {
207
- this . createDirectory ( path . dirname ( filename ) ) ;
207
+ this . createDirectory ( dirname ( filename ) ) ;
208
208
fs . writeFileSync ( filename , data , { encoding : encoding } ) ;
209
209
}
210
210
@@ -218,7 +218,7 @@ export class FileSystem implements IFileSystem {
218
218
}
219
219
220
220
let stringifiedData ;
221
- if ( path . basename ( filename ) === PACKAGE_JSON_FILE_NAME ) {
221
+ if ( basename ( filename ) === PACKAGE_JSON_FILE_NAME ) {
222
222
let newline = EOL ;
223
223
if ( fs . existsSync ( filename ) ) {
224
224
const existingFile = this . readText ( filename ) ;
@@ -233,11 +233,11 @@ export class FileSystem implements IFileSystem {
233
233
}
234
234
235
235
public copyFile ( sourceFileName : string , destinationFileName : string ) : void {
236
- if ( path . resolve ( sourceFileName ) === path . resolve ( destinationFileName ) ) {
236
+ if ( pathResolve ( sourceFileName ) === pathResolve ( destinationFileName ) ) {
237
237
return ;
238
238
}
239
239
240
- this . createDirectory ( path . dirname ( destinationFileName ) ) ;
240
+ this . createDirectory ( dirname ( destinationFileName ) ) ;
241
241
242
242
// MobileApplication.app is resolved as a directory on Mac,
243
243
// therefore we need to copy it recursively as it's not a single file.
@@ -284,8 +284,8 @@ export class FileSystem implements IFileSystem {
284
284
if ( ! this . exists ( baseName ) ) {
285
285
return baseName ;
286
286
}
287
- const extension = path . extname ( baseName ) ;
288
- const prefix = path . basename ( baseName , extension ) ;
287
+ const extension = extname ( baseName ) ;
288
+ const prefix = basename ( baseName , extension ) ;
289
289
290
290
for ( let i = 2 ; ; ++ i ) {
291
291
const numberedName = prefix + i + extension ;
@@ -301,8 +301,8 @@ export class FileSystem implements IFileSystem {
301
301
}
302
302
303
303
public isRelativePath ( p : string ) : boolean {
304
- const normal = path . normalize ( p ) ;
305
- const absolute = path . resolve ( p ) ;
304
+ const normal = normalize ( p ) ;
305
+ const absolute = pathResolve ( p ) ;
306
306
return normal !== absolute ;
307
307
}
308
308
@@ -357,7 +357,7 @@ export class FileSystem implements IFileSystem {
357
357
358
358
const contents = this . readDirectory ( directoryPath ) ;
359
359
for ( let i = 0 ; i < contents . length ; ++ i ) {
360
- const file = path . join ( directoryPath , contents [ i ] ) ;
360
+ const file = join ( directoryPath , contents [ i ] ) ;
361
361
let stat : fs . Stats = null ;
362
362
if ( this . exists ( file ) ) {
363
363
stat = this . getFsStats ( file ) ;
@@ -420,11 +420,11 @@ export class FileSystem implements IFileSystem {
420
420
}
421
421
422
422
public deleteEmptyParents ( directory : string ) : void {
423
- let parent = this . exists ( directory ) ? directory : path . dirname ( directory ) ;
423
+ let parent = this . exists ( directory ) ? directory : dirname ( directory ) ;
424
424
425
425
while ( this . isEmptyDir ( parent ) ) {
426
426
this . deleteDirectory ( parent ) ;
427
- parent = path . dirname ( parent ) ;
427
+ parent = dirname ( parent ) ;
428
428
}
429
429
}
430
430
0 commit comments