File tree 1 file changed +17
-7
lines changed
1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -86,18 +86,28 @@ export function valueError(message: string, name?: string): Error {
86
86
return Error ( name ? `$${ name } : ${ message } .` : `${ message } .` ) ;
87
87
}
88
88
89
+ // Node changed its implementation of pathToFileURL:
90
+ // https://github.com/nodejs/node/pull/54545
91
+ const unsafePathToFileURL = url . pathToFileURL ( '~' ) . pathname . endsWith ( '~' ) ;
92
+
89
93
/** Converts a (possibly relative) path on the local filesystem to a URL. */
90
94
export function pathToUrlString ( path : string ) : string {
91
95
if ( p . isAbsolute ( path ) ) return url . pathToFileURL ( path ) . toString ( ) ;
92
96
93
97
// percent encode relative path like `pathToFileURL`
94
- return encodeURI ( path )
95
- . replace ( / [ # ? ] / g, encodeURIComponent )
96
- . replace (
97
- process . platform === 'win32' ? / % ( 5 B | 5 C | 5 D | 5 E | 7 C ) / g : / % ( 5 B | 5 D | 5 E | 7 C ) / g,
98
- decodeURIComponent ,
99
- )
100
- . replace ( / \\ / g, '/' ) ;
98
+ let fileUrl = encodeURI ( path ) . replace ( / [ # ? ] / g, encodeURIComponent ) ;
99
+
100
+ if ( unsafePathToFileURL ) {
101
+ fileUrl = fileUrl . replace ( / % ( 5 B | 5 D | 5 E | 7 C ) / g, decodeURIComponent ) ;
102
+ } else {
103
+ fileUrl = fileUrl . replace ( / ~ / g, '%7E' ) ;
104
+ }
105
+
106
+ if ( process . platform === 'win32' ) {
107
+ fileUrl = fileUrl . replace ( / % 5 C / g, '/' ) ;
108
+ }
109
+
110
+ return fileUrl ;
101
111
}
102
112
103
113
/**
You can’t perform that action at this time.
0 commit comments