Skip to content

Commit

Permalink
use resolve-uri for handling relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Apr 23, 2022
1 parent 62cb778 commit ce5e122
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"/source-map-support.js"
],
"dependencies": {
"@jridgewell/resolve-uri": "^3.0.6",
"@jridgewell/trace-mapping": "0.3.9"
},
"devDependencies": {
Expand Down
19 changes: 2 additions & 17 deletions source-map-support.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { TraceMap, originalPositionFor, AnyMap } = require('@jridgewell/trace-mapping');
const resolveUri = require('@jridgewell/resolve-uri');
var path = require('path');
const { fileURLToPath } = require('url');
var util = require('util');
Expand Down Expand Up @@ -187,23 +188,7 @@ sharedData.internalRetrieveFileHandlers.push(function(path) {
// Support URLs relative to a directory, but be careful about a protocol prefix
// in case we are in the browser (i.e. directories may start with "http://" or "file:///")
function supportRelativeURL(file, url) {
if (!file) return url;
let targetPath = url;
try {
const urlParsed = new URL(url);
if(urlParsed.protocol !== 'file:') return url;
targetPath = fileURLToPath(urlParsed);
} catch(e) {}
var dir = path.dirname(file);
var match = /^\w+:\/\/[^\/]*/.exec(dir);
var protocol = match ? match[0] : '';
var startPath = dir.slice(protocol.length);
if (protocol && /^\/\w\:/.test(startPath)) {
// handle file:///C:/ paths
protocol += '/';
return protocol + path.resolve(dir.slice(protocol.length), targetPath).replace(/\\/g, '/');
}
return protocol + path.resolve(dir.slice(protocol.length), targetPath);
return resolveUri(url, file);
}

function retrieveSourceMapURL(source) {
Expand Down

0 comments on commit ce5e122

Please sign in to comment.