File tree 1 file changed +11
-2
lines changed
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 1
1
import * as nodePath from 'path' ;
2
2
3
+ const PATH_REGEXP = new RegExp ( '\\' + nodePath . win32 . sep , 'g' ) ;
4
+ const ensureUnixPathCache = new Map < string , string > ( ) ;
5
+
3
6
export const ensureUnixPath = ( path ?: string ) : string | null => {
4
7
if ( ! path ) {
5
8
return null ;
6
9
}
7
10
11
+ const cachePath = ensureUnixPathCache . get ( path ) ;
12
+ if ( cachePath ) {
13
+ return cachePath ;
14
+ }
15
+
8
16
// we use a regex instead of the character literal due to a bug in some versions of node.js
9
17
// the path separator needs to be preceded by an escape character
10
- const regex = new RegExp ( '\\' + nodePath . win32 . sep , 'g' ) ;
11
- return path . replace ( regex , nodePath . posix . sep ) ;
18
+ const normalizedPath = path . replace ( PATH_REGEXP , nodePath . posix . sep ) ;
19
+ ensureUnixPathCache . set ( path , normalizedPath ) ;
20
+ return normalizedPath ;
12
21
} ;
You can’t perform that action at this time.
0 commit comments