From ce5e122f6251adf20e86b54be6679f60f3a1e46c Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Sat, 23 Apr 2022 20:14:21 +0000 Subject: [PATCH] use resolve-uri for handling relative paths --- package-lock.json | 13 +++++++------ package.json | 1 + source-map-support.js | 19 ++----------------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index c4ea1c4..717506a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.7.0", "license": "MIT", "dependencies": { + "@jridgewell/resolve-uri": "^3.0.6", "@jridgewell/trace-mapping": "0.3.9" }, "devDependencies": { @@ -24,9 +25,9 @@ } }, "node_modules/@jridgewell/resolve-uri": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.0.5.tgz", - "integrity": "sha512-VPeQ7+wH0itvQxnG+lIzWgkysKIr3L9sslimFW55rHMdGu/qCQ5z5h9zq4gI8uBtqkpHhsF4Z/OwExufUCThew==", + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.0.6.tgz", + "integrity": "sha512-R7xHtBSNm+9SyvpJkdQl+qrM3Hm2fea3Ef197M3mUug+v+yR+Rhfbs7PBtcBUVnIWJ4JcAdjvij+c8hXS9p5aw==", "engines": { "node": ">=6.0.0" } @@ -5267,9 +5268,9 @@ }, "dependencies": { "@jridgewell/resolve-uri": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.0.5.tgz", - "integrity": "sha512-VPeQ7+wH0itvQxnG+lIzWgkysKIr3L9sslimFW55rHMdGu/qCQ5z5h9zq4gI8uBtqkpHhsF4Z/OwExufUCThew==" + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.0.6.tgz", + "integrity": "sha512-R7xHtBSNm+9SyvpJkdQl+qrM3Hm2fea3Ef197M3mUug+v+yR+Rhfbs7PBtcBUVnIWJ4JcAdjvij+c8hXS9p5aw==" }, "@jridgewell/sourcemap-codec": { "version": "1.4.11", diff --git a/package.json b/package.json index a14687b..4e6d3af 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "/source-map-support.js" ], "dependencies": { + "@jridgewell/resolve-uri": "^3.0.6", "@jridgewell/trace-mapping": "0.3.9" }, "devDependencies": { diff --git a/source-map-support.js b/source-map-support.js index 16388c1..1b8c2d4 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -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'); @@ -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) {