Skip to content

Commit ce5e122

Browse files
committed
use resolve-uri for handling relative paths
1 parent 62cb778 commit ce5e122

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

package-lock.json

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

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

source-map-support.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { TraceMap, originalPositionFor, AnyMap } = require('@jridgewell/trace-mapping');
2+
const resolveUri = require('@jridgewell/resolve-uri');
23
var path = require('path');
34
const { fileURLToPath } = require('url');
45
var util = require('util');
@@ -187,23 +188,7 @@ sharedData.internalRetrieveFileHandlers.push(function(path) {
187188
// Support URLs relative to a directory, but be careful about a protocol prefix
188189
// in case we are in the browser (i.e. directories may start with "http://" or "file:///")
189190
function supportRelativeURL(file, url) {
190-
if (!file) return url;
191-
let targetPath = url;
192-
try {
193-
const urlParsed = new URL(url);
194-
if(urlParsed.protocol !== 'file:') return url;
195-
targetPath = fileURLToPath(urlParsed);
196-
} catch(e) {}
197-
var dir = path.dirname(file);
198-
var match = /^\w+:\/\/[^\/]*/.exec(dir);
199-
var protocol = match ? match[0] : '';
200-
var startPath = dir.slice(protocol.length);
201-
if (protocol && /^\/\w\:/.test(startPath)) {
202-
// handle file:///C:/ paths
203-
protocol += '/';
204-
return protocol + path.resolve(dir.slice(protocol.length), targetPath).replace(/\\/g, '/');
205-
}
206-
return protocol + path.resolve(dir.slice(protocol.length), targetPath);
191+
return resolveUri(url, file);
207192
}
208193

209194
function retrieveSourceMapURL(source) {

0 commit comments

Comments
 (0)