monocart-coverage-reports 2.5.1 → 2.5.3

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.
@@ -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, ./ ../
@@ -34,22 +23,21 @@ const filterPath = (str) => {
34
23
 
35
24
  const getSourcePath = (url, index = '', type = '') => {
36
25
 
26
+ // no url for anonymous
37
27
  if (!url) {
38
28
  // anonymous scripts will have __playwright_evaluation_script__ as their URL.
39
- url = pathToFileURL(['anonymous', index ? `-${index}` : '', type ? `.${type}` : ''].join('')).toString();
40
- }
41
-
42
- // url could be a path
43
- if (!URL.canParse(url)) {
44
- url = pathToFileURL(url).toString();
29
+ url = ['anonymous', index ? `-${index}` : '', type ? `.${type}` : ''].join('');
30
+ return filterPath(url);
45
31
  }
46
32
 
33
+ // already is file url
47
34
  if (url.startsWith('file:')) {
48
35
  const relPath = Util.relativePath(fileURLToPath(url));
49
36
  return filterPath(relPath);
50
37
  }
51
38
 
52
- const urlObj = resolveUrl(url);
39
+ // http/https url, other url
40
+ const urlObj = Util.resolveUrl(url);
53
41
  if (urlObj) {
54
42
  const host = [urlObj.hostname, urlObj.port].filter((it) => it).join('-');
55
43
  // always start with '/'
@@ -64,7 +52,11 @@ const getSourcePath = (url, index = '', type = '') => {
64
52
  return filterPath(p);
65
53
  }
66
54
 
67
- return filterPath(url);
55
+ // could be path
56
+ const fileUrl = pathToFileURL(url).toString();
57
+ const relPath = Util.relativePath(fileURLToPath(fileUrl));
58
+ return filterPath(relPath);
59
+
68
60
  };
69
61
 
70
62
  const getSourceType = (sourcePath) => {
package/lib/utils/util.js CHANGED
@@ -9,7 +9,13 @@ const CG = require('console-grid');
9
9
  const Share = require('../platform/share.js');
10
10
  const { deflateSync } = require('lz-utils');
11
11
 
12
- const { acornWalk } = require('../packages/monocart-coverage-vendor.js');
12
+ const { acornWalk, supportsColor } = require('../packages/monocart-coverage-vendor.js');
13
+
14
+ // https://github.com/chalk/supports-color
15
+ // disabled color if Terminal stdout does not support color
16
+ if (!supportsColor.stdout) {
17
+ EC.disabled = true;
18
+ }
13
19
 
14
20
  const Util = {
15
21
  ... Share,
@@ -70,6 +76,17 @@ const Util = {
70
76
  return false;
71
77
  },
72
78
 
79
+ resolveUrl: (input, base) => {
80
+ let url;
81
+ try {
82
+ url = new URL(input, base);
83
+ } catch (e) {
84
+ // console.error('error url', input);
85
+ return;
86
+ }
87
+ return url;
88
+ },
89
+
73
90
  resolveCacheSourcePath: (cacheDir, id) => {
74
91
  const filename = `source-${id}.json`;
75
92
  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.3",
4
4
  "description": "Monocart coverage reports",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -55,10 +55,10 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "console-grid": "~2.2.1",
58
- "eight-colors": "~1.2.1",
58
+ "eight-colors": "~1.3.0",
59
59
  "istanbul-lib-coverage": "~3.2.2",
60
60
  "istanbul-lib-report": "~3.0.1",
61
- "istanbul-reports": "~3.1.6",
61
+ "istanbul-reports": "~3.1.7",
62
62
  "lz-utils": "~2.0.2",
63
63
  "monocart-code-viewer": "~1.1.0",
64
64
  "monocart-formatter": "~2.3.1",
@@ -71,6 +71,7 @@
71
71
  "eslint-plugin-html": "^8.0.0",
72
72
  "eslint-plugin-vue": "^9.21.1",
73
73
  "stylelint": "^15.11.0",
74
- "stylelint-config-plus": "^1.0.4"
74
+ "stylelint-config-plus": "^1.0.4",
75
+ "supports-color": "^9.4.0"
75
76
  }
76
77
  }