Skip to content

Commit e150661

Browse files
committed
fix
1 parent 69893db commit e150661

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"/source-map-support.js"
1919
],
2020
"dependencies": {
21-
"@jridgewell/resolve-uri": "^3.0.6",
2221
"@jridgewell/trace-mapping": "0.3.9"
2322
},
2423
"devDependencies": {

source-map-support.js

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const { TraceMap, originalPositionFor, AnyMap } = require('@jridgewell/trace-mapping');
2-
const resolveUri = require('@jridgewell/resolve-uri');
32
var path = require('path');
43
const { fileURLToPath, pathToFileURL } = require('url');
54
var util = require('util');
@@ -251,19 +250,51 @@ sharedData.internalRetrieveFileHandlers.push(function(path) {
251250
// Support URLs relative to a directory, but be careful about a protocol prefix
252251
// in case we are in the browser (i.e. directories may start with "http://" or "file:///")
253252
function supportRelativeURL(file, url) {
254-
// We want to preserve path style.
255-
// resolveUri cannot handle windows paths.
256-
// Therefore, special-case when output will be a windows path
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);
253+
if(!file) return url;
254+
// given that this happens within error formatting codepath, probably best to
255+
// fallback instead of throwing if anything goes wrong
256+
try {
257+
// if should output a URL
258+
if(isAbsoluteUrl(file) || isSchemeRelativeUrl(file)) {
259+
if(isAbsoluteUrl(url) || isSchemeRelativeUrl(url)) {
260+
return new URL(url, file).toString();
261+
}
262+
if(path.isAbsolute(url)) {
263+
return new URL(pathToFileURL(url), file).toString();
264+
}
265+
// url is relative path or URL
266+
return new URL(url.replace(/\\/g, '/'), file).toString();
267+
}
268+
// if should output a path (unless URL is something like https://)
269+
if(path.isAbsolute(file)) {
270+
if(isFileUrl(url)) {
271+
return fileURLToPath(url);
272+
}
273+
if(isSchemeRelativeUrl(url)) {
274+
return fileURLToPath(new URL(url, 'file://'));
275+
}
276+
if(isAbsoluteUrl(url)) {
277+
// url is a non-file URL
278+
// Go with the URL
279+
return url;
280+
}
281+
if(path.isAbsolute(url)) {
282+
return url;
283+
// Normalize at all? decodeURI or normalize slashes?
284+
}
285+
// url is relative path or URL
286+
return path.join(file, '..', decodeURI(url));
261287
}
262-
if(isFileUrl(file) && path.isAbsolute(url)) {
263-
url = pathToFileURL(url).toString();
288+
// If we get here, file is relative.
289+
// Shouldn't happen since node identifies modules with absolute paths or URLs.
290+
// But we can take a stab at returning something meaningful anyway.
291+
if(isAbsoluteUrl(url) || isSchemeRelativeUrl(url)) {
292+
return url;
264293
}
294+
return path.join(file, '..', url);
295+
} catch(e) {
296+
return url;
265297
}
266-
return resolveUri(url, file);
267298
}
268299

269300
function retrieveSourceMapURL(source) {

test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,3 +1072,6 @@ describe('uninstall', function() {
10721072
assert(peInvocations >= 1);
10731073
});
10741074
});
1075+
// Without this, the code under test sees stuff in the test cases above and tries to load source-maps
1076+
// This causes confusing red herrings while debugging.
1077+
//#sourceMappingURL=test.js.map-intentionally-does-not-exist

0 commit comments

Comments
 (0)