File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 11import * as nodePath from 'path' ;
22
3+ const PATH_REGEXP = new RegExp ( '\\' + nodePath . win32 . sep , 'g' ) ;
4+ const ensureUnixPathCache = new Map < string , string > ( ) ;
5+
36export const ensureUnixPath = ( path ?: string ) : string | null => {
47 if ( ! path ) {
58 return null ;
69 }
710
11+ const cachePath = ensureUnixPathCache . get ( path ) ;
12+ if ( cachePath ) {
13+ return cachePath ;
14+ }
15+
816 // we use a regex instead of the character literal due to a bug in some versions of node.js
917 // 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 ;
1221} ;
You can’t perform that action at this time.
0 commit comments