@@ -132,13 +132,16 @@ function hasGlobalProcessEventEmitter() {
132
132
function tryFileURLToPath ( v ) {
133
133
// TODO technically, file URL can omit /s.
134
134
// Copy the isFileURL util from resolve-uri?
135
- if ( v . startsWith ( 'file:/' ) ) {
135
+ if ( isFileUrl ( v ) ) {
136
136
return fileURLToPath ( v ) ;
137
137
}
138
138
return v ;
139
139
}
140
140
141
141
// TODO un-copy these from resolve-uri; see if they can be exported from that lib
142
+ function isFileUrl ( input ) {
143
+ return input . startsWith ( 'file:' ) ;
144
+ }
142
145
function isAbsoluteUrl ( input ) {
143
146
return schemeRegex . test ( input ) ;
144
147
}
@@ -148,7 +151,6 @@ function isSchemeRelativeUrl(input) {
148
151
return input . startsWith ( '//' ) ;
149
152
}
150
153
151
-
152
154
// #region Caches
153
155
/** @param {string } pathOrFileUrl */
154
156
function getCacheKey ( pathOrFileUrl ) {
@@ -252,9 +254,14 @@ function supportRelativeURL(file, url) {
252
254
// We want to preserve path style.
253
255
// resolveUri cannot handle windows paths.
254
256
// Therefore, special-case when output will be a windows path
255
- if ( process . platform === 'win32' && path . isAbsolute ( file ) && ! isAbsoluteUrl ( url ) && ! isSchemeRelativeUrl ( url ) ) {
256
- const dir = path . dirname ( file ) ;
257
- return path . resolve ( dir , url ) ;
257
+ if ( process . platform === 'win32' ) {
258
+ if ( path . isAbsolute ( file ) && ! isAbsoluteUrl ( url ) && ! isSchemeRelativeUrl ( url ) ) {
259
+ const dir = path . dirname ( file ) ;
260
+ return path . resolve ( dir , url ) ;
261
+ }
262
+ // if(isFileUrl(file) && path.isAbsolute(url)) {
263
+ // url = pathToFileURL(url).toString();
264
+ // }
258
265
}
259
266
return resolveUri ( url , file ) ;
260
267
}
@@ -335,14 +342,17 @@ function mapSourcePosition(position) {
335
342
map : new AnyMap ( urlAndMap . map , urlAndMap . url )
336
343
} ) ;
337
344
345
+ // Overwrite trace-mapping's resolutions, because they do not handle
346
+ // Windows paths the way we want.
347
+ sourceMap . map . resolvedSources = sourceMap . map . sources . map ( s => supportRelativeURL ( sourceMap . url , s ) ) ;
348
+
338
349
// Load all sources stored inline with the source map into the file cache
339
350
// to pretend like they are already loaded. They may not exist on disk.
340
351
if ( sourceMap . map . sourcesContent ) {
341
- sourceMap . map . sources . forEach ( function ( source , i ) {
352
+ sourceMap . map . resolvedSources . forEach ( function ( resolvedSource , i ) {
342
353
var contents = sourceMap . map . sourcesContent [ i ] ;
343
354
if ( contents ) {
344
- var url = supportRelativeURL ( sourceMap . url , source ) ;
345
- setFileContentsCache ( url , contents ) ;
355
+ setFileContentsCache ( resolvedSource , contents ) ;
346
356
}
347
357
} ) ;
348
358
}
0 commit comments