|
1 | 1 | const { TraceMap, originalPositionFor, AnyMap } = require('@jridgewell/trace-mapping');
|
2 | 2 | var path = require('path');
|
| 3 | +const { fileURLToPath } = require('url'); |
3 | 4 | var util = require('util');
|
4 | 5 |
|
5 | 6 | var fs;
|
@@ -187,16 +188,22 @@ sharedData.internalRetrieveFileHandlers.push(function(path) {
|
187 | 188 | // in case we are in the browser (i.e. directories may start with "http://" or "file:///")
|
188 | 189 | function supportRelativeURL(file, url) {
|
189 | 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) {} |
190 | 197 | var dir = path.dirname(file);
|
191 | 198 | var match = /^\w+:\/\/[^\/]*/.exec(dir);
|
192 | 199 | var protocol = match ? match[0] : '';
|
193 | 200 | var startPath = dir.slice(protocol.length);
|
194 | 201 | if (protocol && /^\/\w\:/.test(startPath)) {
|
195 | 202 | // handle file:///C:/ paths
|
196 | 203 | protocol += '/';
|
197 |
| - return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, '/'); |
| 204 | + return protocol + path.resolve(dir.slice(protocol.length), targetPath).replace(/\\/g, '/'); |
198 | 205 | }
|
199 |
| - return protocol + path.resolve(dir.slice(protocol.length), url); |
| 206 | + return protocol + path.resolve(dir.slice(protocol.length), targetPath); |
200 | 207 | }
|
201 | 208 |
|
202 | 209 | function retrieveSourceMapURL(source) {
|
|
0 commit comments