|
1 | 1 | const { TraceMap, originalPositionFor, AnyMap } = require('@jridgewell/trace-mapping');
|
2 |
| -const resolveUri = require('@jridgewell/resolve-uri'); |
3 | 2 | var path = require('path');
|
4 | 3 | const { fileURLToPath, pathToFileURL } = require('url');
|
5 | 4 | var util = require('util');
|
@@ -251,19 +250,51 @@ sharedData.internalRetrieveFileHandlers.push(function(path) {
|
251 | 250 | // Support URLs relative to a directory, but be careful about a protocol prefix
|
252 | 251 | // in case we are in the browser (i.e. directories may start with "http://" or "file:///")
|
253 | 252 | 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)); |
261 | 287 | }
|
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; |
264 | 293 | }
|
| 294 | + return path.join(file, '..', url); |
| 295 | + } catch(e) { |
| 296 | + return url; |
265 | 297 | }
|
266 |
| - return resolveUri(url, file); |
267 | 298 | }
|
268 | 299 |
|
269 | 300 | function retrieveSourceMapURL(source) {
|
|
0 commit comments