Skip to content

Commit 6d3de7e

Browse files
committed
WIP
1 parent fc3f549 commit 6d3de7e

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

source-map-support.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,16 @@ function hasGlobalProcessEventEmitter() {
132132
function tryFileURLToPath(v) {
133133
// TODO technically, file URL can omit /s.
134134
// Copy the isFileURL util from resolve-uri?
135-
if(v.startsWith('file:/')) {
135+
if(isFileUrl(v)) {
136136
return fileURLToPath(v);
137137
}
138138
return v;
139139
}
140140

141141
// 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+
}
142145
function isAbsoluteUrl(input) {
143146
return schemeRegex.test(input);
144147
}
@@ -148,7 +151,6 @@ function isSchemeRelativeUrl(input) {
148151
return input.startsWith('//');
149152
}
150153

151-
152154
// #region Caches
153155
/** @param {string} pathOrFileUrl */
154156
function getCacheKey(pathOrFileUrl) {
@@ -252,9 +254,14 @@ function supportRelativeURL(file, url) {
252254
// We want to preserve path style.
253255
// resolveUri cannot handle windows paths.
254256
// 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+
// }
258265
}
259266
return resolveUri(url, file);
260267
}
@@ -335,14 +342,17 @@ function mapSourcePosition(position) {
335342
map: new AnyMap(urlAndMap.map, urlAndMap.url)
336343
});
337344

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+
338349
// Load all sources stored inline with the source map into the file cache
339350
// to pretend like they are already loaded. They may not exist on disk.
340351
if (sourceMap.map.sourcesContent) {
341-
sourceMap.map.sources.forEach(function(source, i) {
352+
sourceMap.map.resolvedSources.forEach(function(resolvedSource, i) {
342353
var contents = sourceMap.map.sourcesContent[i];
343354
if (contents) {
344-
var url = supportRelativeURL(sourceMap.url, source);
345-
setFileContentsCache(url, contents);
355+
setFileContentsCache(resolvedSource, contents);
346356
}
347357
});
348358
}

0 commit comments

Comments
 (0)