monocart-coverage-reports 2.5.1 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,17 +55,12 @@ const getSourceMapUrl = (content, url) => {
55
55
  // for some odd reason //# .. captures in 1 and /* .. */ in 2
56
56
  const filename = r[1] || r[2];
57
57
 
58
- if (!URL.canParse(filename, url)) {
59
- url = pathToFileURL(url).toString();
58
+ const urlObj = Util.resolveUrl(filename, url);
59
+ if (urlObj) {
60
+ return urlObj.toString();
60
61
  }
61
62
 
62
- let mapUrl;
63
-
64
- try {
65
- mapUrl = new URL(filename, url);
66
- } catch (e) {
67
- Util.logDebug(EC.red(`${e.message} ${filename} ${url}`));
68
- }
63
+ const mapUrl = Util.resolveUrl(filename, pathToFileURL(url).toString());
69
64
  if (mapUrl) {
70
65
  return mapUrl.toString();
71
66
  }
@@ -2,17 +2,6 @@ const path = require('path');
2
2
  const { fileURLToPath, pathToFileURL } = require('url');
3
3
  const Util = require('./util.js');
4
4
 
5
- const resolveUrl = (input) => {
6
- let url;
7
- try {
8
- url = new URL(input);
9
- } catch (e) {
10
- // console.error('error url', input);
11
- return;
12
- }
13
- return url;
14
- };
15
-
16
5
  const filterPath = (str) => {
17
6
  str = decodeURI(str);
18
7
  // remove / of start, end or double, ./ ../
@@ -40,16 +29,12 @@ const getSourcePath = (url, index = '', type = '') => {
40
29
  }
41
30
 
42
31
  // url could be a path
43
- if (!URL.canParse(url)) {
44
- url = pathToFileURL(url).toString();
45
- }
46
-
47
32
  if (url.startsWith('file:')) {
48
33
  const relPath = Util.relativePath(fileURLToPath(url));
49
34
  return filterPath(relPath);
50
35
  }
51
36
 
52
- const urlObj = resolveUrl(url);
37
+ const urlObj = Util.resolveUrl(url);
53
38
  if (urlObj) {
54
39
  const host = [urlObj.hostname, urlObj.port].filter((it) => it).join('-');
55
40
  // always start with '/'
@@ -64,7 +49,9 @@ const getSourcePath = (url, index = '', type = '') => {
64
49
  return filterPath(p);
65
50
  }
66
51
 
52
+ url = pathToFileURL(url).toString();
67
53
  return filterPath(url);
54
+
68
55
  };
69
56
 
70
57
  const getSourceType = (sourcePath) => {
package/lib/utils/util.js CHANGED
@@ -70,6 +70,17 @@ const Util = {
70
70
  return false;
71
71
  },
72
72
 
73
+ resolveUrl: (input, base) => {
74
+ let url;
75
+ try {
76
+ url = new URL(input, base);
77
+ } catch (e) {
78
+ // console.error('error url', input);
79
+ return;
80
+ }
81
+ return url;
82
+ },
83
+
73
84
  resolveCacheSourcePath: (cacheDir, id) => {
74
85
  const filename = `source-${id}.json`;
75
86
  const sourcePath = path.resolve(cacheDir, filename);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "description": "Monocart coverage reports",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {