@@ -270,7 +270,7 @@ export function fileUrlToNetworkPath(urlOrPath: string): string {
270
270
271
271
// TODO: this does not escape/unescape special characters, but it should.
272
272
export function absolutePathToFileUrl ( absolutePath : string ) : string {
273
- if ( process . platform === 'win32' ) {
273
+ if ( platform === 'win32' ) {
274
274
return 'file:///' + platformPathToUrlPath ( absolutePath ) ;
275
275
}
276
276
return 'file://' + platformPathToUrlPath ( absolutePath ) ;
@@ -422,8 +422,18 @@ export function maybeAbsolutePathToFileUrl(
422
422
return sourceUrl ;
423
423
}
424
424
425
+ let platform = process . platform ;
426
+
427
+ export const overridePlatform = ( newPlatform : NodeJS . Platform ) => {
428
+ platform = newPlatform ;
429
+ } ;
430
+
431
+ export const resetPlatform = ( ) => {
432
+ platform = process . platform ;
433
+ } ;
434
+
425
435
export function urlPathToPlatformPath ( p : string ) : string {
426
- if ( process . platform === 'win32' ) {
436
+ if ( platform === 'win32' ) {
427
437
p = p . replace ( / \/ / g, '\\' ) ;
428
438
}
429
439
@@ -433,7 +443,7 @@ export function urlPathToPlatformPath(p: string): string {
433
443
export function platformPathToUrlPath ( p : string ) : string {
434
444
p = platformPathToPreferredCase ( p ) ;
435
445
436
- if ( process . platform === 'win32' ) {
446
+ if ( platform === 'win32' ) {
437
447
return p
438
448
. split ( / [ \\ / / ] / g)
439
449
. map ( ( p , i ) => ( i > 0 ? encodeURIComponent ( p ) : p ) )
@@ -446,7 +456,7 @@ export function platformPathToUrlPath(p: string): string {
446
456
export function platformPathToPreferredCase ( p : string ) : string ;
447
457
export function platformPathToPreferredCase ( p : string | undefined ) : string | undefined ;
448
458
export function platformPathToPreferredCase ( p : string | undefined ) : string | undefined {
449
- if ( p && process . platform === 'win32' && p [ 1 ] === ':' ) return p [ 0 ] . toUpperCase ( ) + p . substring ( 1 ) ;
459
+ if ( p && platform === 'win32' && p [ 1 ] === ':' ) return p [ 0 ] . toUpperCase ( ) + p . substring ( 1 ) ;
450
460
return p ;
451
461
}
452
462
0 commit comments