monocart-coverage-reports 2.7.10 → 2.8.1

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.
@@ -1,9 +1,5 @@
1
1
  const Util = {
2
2
 
3
- // definition
4
- tagPattern: /(\s*)@([^@\s]+)(\s*)/g,
5
- lineBreakPattern: /\r\n|[\r\n\u2028\u2029]/gu,
6
-
7
3
  hasOwn: function(obj, key) {
8
4
  return Object.prototype.hasOwnProperty.call(obj, key);
9
5
  },
@@ -21,7 +21,8 @@ const filterPath = (str) => {
21
21
  return ls.join('/');
22
22
  };
23
23
 
24
- const getSourcePath = (url, index = '', type = '') => {
24
+ // eslint-disable-next-line complexity
25
+ const normalizeSourcePath = (url, baseDir, index = '', type = '') => {
25
26
 
26
27
  // no url for anonymous
27
28
  if (!url) {
@@ -32,7 +33,7 @@ const getSourcePath = (url, index = '', type = '') => {
32
33
 
33
34
  // already is file url
34
35
  if (url.startsWith('file:')) {
35
- const relPath = Util.relativePath(fileURLToPath(url));
36
+ const relPath = Util.relativePath(fileURLToPath(url), baseDir);
36
37
  return filterPath(relPath);
37
38
  }
38
39
 
@@ -54,7 +55,7 @@ const getSourcePath = (url, index = '', type = '') => {
54
55
 
55
56
  // could be path
56
57
  const fileUrl = pathToFileURL(url).toString();
57
- const relPath = Util.relativePath(fileURLToPath(fileUrl));
58
+ const relPath = Util.relativePath(fileURLToPath(fileUrl), baseDir);
58
59
  return filterPath(relPath);
59
60
 
60
61
  };
@@ -75,7 +76,7 @@ const getSourceType = (sourcePath) => {
75
76
 
76
77
  // ========================================================================================================
77
78
 
78
- const getSourcePathHandler = (options) => {
79
+ const getSourcePathReplacer = (options) => {
79
80
  const input = options.sourcePath;
80
81
  if (typeof input === 'function') {
81
82
  return input;
@@ -96,8 +97,10 @@ const getSourcePathHandler = (options) => {
96
97
 
97
98
  // ========================================================================================================
98
99
 
99
- const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) => {
100
- if (!sourcePathHandler) {
100
+ const initIstanbulSourcePath = (coverageData, fileSources, options) => {
101
+
102
+ const sourcePathReplacer = getSourcePathReplacer(options);
103
+ if (!sourcePathReplacer) {
101
104
  return coverageData;
102
105
  }
103
106
 
@@ -119,7 +122,7 @@ const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) =>
119
122
  }
120
123
 
121
124
  // new source path, second is source url
122
- const newSourcePath = sourcePathHandler(sourcePath, item);
125
+ const newSourcePath = sourcePathReplacer(sourcePath, item);
123
126
  if (typeof newSourcePath === 'string' && newSourcePath) {
124
127
  sourcePath = newSourcePath;
125
128
  }
@@ -180,16 +183,21 @@ const resolveSourceUrl = (sourceName, sourceRoot) => {
180
183
  return sourceUrl;
181
184
  };
182
185
 
183
- const initSourceMapSourcePath = (sourceMap, fileUrls, distFile, sourcePathHandler) => {
186
+ const initSourceMapSourcesPath = (fileUrls, sourceMap, distFile, options) => {
187
+
188
+ const baseDir = options.baseDir;
189
+ const sourcePathReplacer = getSourcePathReplacer(options);
184
190
 
185
191
  sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
186
192
 
187
193
  const sourceUrl = resolveSourceUrl(sourceName, sourceMap.sourceRoot);
188
194
 
189
- let sourcePath = getSourcePath(sourceUrl, i + 1);
190
- if (sourcePathHandler) {
195
+ let sourcePath = normalizeSourcePath(sourceUrl, baseDir, i + 1);
196
+ // console.log(sourceUrl, sourcePath);
197
+
198
+ if (sourcePathReplacer) {
191
199
  // sourcePath could be a filename only, may using distFile to get full path
192
- const newSourcePath = sourcePathHandler(sourcePath, {
200
+ const newSourcePath = sourcePathReplacer(sourcePath, {
193
201
  url: sourceUrl,
194
202
  distFile
195
203
  });
@@ -208,9 +216,9 @@ module.exports = {
208
216
  // for unit test
209
217
  resolveSourceUrl,
210
218
 
211
- getSourcePath,
219
+ normalizeSourcePath,
212
220
  getSourceType,
213
- getSourcePathHandler,
221
+ getSourcePathReplacer,
214
222
  initIstanbulSourcePath,
215
- initSourceMapSourcePath
223
+ initSourceMapSourcesPath
216
224
  };
package/lib/utils/util.js CHANGED
@@ -10,7 +10,9 @@ const Share = require('../platform/share.js');
10
10
  const request = require('./request.js');
11
11
  const { deflateSync } = require('lz-utils');
12
12
 
13
- const { acornWalk, supportsColor } = require('../packages/monocart-coverage-vendor.js');
13
+ const {
14
+ acornWalk, findUpSync, supportsColor
15
+ } = require('../packages/monocart-coverage-vendor.js');
14
16
 
15
17
  // https://github.com/chalk/supports-color
16
18
  // disabled color if Terminal stdout does not support color
@@ -60,6 +62,27 @@ const Util = {
60
62
  return str;
61
63
  },
62
64
 
65
+ strToObj: (str) => {
66
+ if (typeof str === 'string') {
67
+ str = str.trim();
68
+ if (str.startsWith('{') && str.endsWith('}')) {
69
+ let fun;
70
+ let err;
71
+ try {
72
+ fun = new Function(`return ${str}`);
73
+ } catch (e) {
74
+ err = e;
75
+ }
76
+ if (!err) {
77
+ const obj = fun();
78
+ if (obj && typeof obj === 'object') {
79
+ return obj;
80
+ }
81
+ }
82
+ }
83
+ }
84
+ },
85
+
63
86
  calculateSha1: (buffer) => {
64
87
  const hash = crypto.createHash('sha1');
65
88
  hash.update(buffer);
@@ -81,9 +104,13 @@ const Util = {
81
104
 
82
105
  resolveUrl: (input, base) => {
83
106
  let url;
107
+ let err;
84
108
  try {
85
109
  url = new URL(input, base);
86
110
  } catch (e) {
111
+ err = e;
112
+ }
113
+ if (err) {
87
114
  // console.error('error url', input);
88
115
  return;
89
116
  }
@@ -164,6 +191,31 @@ const Util = {
164
191
  return path.resolve(__dirname, '../packages', p);
165
192
  },
166
193
 
194
+ findUpConfig: (customConfigFile) => {
195
+ if (customConfigFile) {
196
+ if (fs.existsSync(customConfigFile)) {
197
+ return customConfigFile;
198
+ }
199
+ // custom config not found
200
+ return;
201
+ }
202
+
203
+ const defaultConfigList = [
204
+ 'mcr.config.js',
205
+ 'mcr.config.cjs',
206
+ 'mcr.config.mjs',
207
+ 'mcr.config.json',
208
+ 'mcr.config.ts'
209
+ ];
210
+
211
+ const configPath = findUpSync(defaultConfigList);
212
+ if (configPath) {
213
+ return configPath;
214
+ }
215
+
216
+ // default config not found
217
+ },
218
+
167
219
  saveHtmlReport: async (options) => {
168
220
 
169
221
  const {
@@ -472,6 +524,7 @@ const Util = {
472
524
  info: 20,
473
525
  debug: 30
474
526
  },
527
+ loggingLevel: 20,
475
528
 
476
529
  isDebug: () => {
477
530
  return Util.loggingType === 'debug';
package/lib/v8/v8.js CHANGED
@@ -3,7 +3,7 @@ const EC = require('eight-colors');
3
3
  const Util = require('../utils/util.js');
4
4
  const { getV8Summary } = require('./v8-summary.js');
5
5
  const { dedupeFlatRanges } = require('../utils/dedupe.js');
6
- const { getSourcePath, getSourcePathHandler } = require('../utils/source-path.js');
6
+ const { normalizeSourcePath, getSourcePathReplacer } = require('../utils/source-path.js');
7
7
  const { mergeScriptCovs, minimatch } = require('../packages/monocart-coverage-vendor.js');
8
8
  const { collectSourceMaps } = require('../converter/collect-source-maps.js');
9
9
  const version = require('../../package.json').version;
@@ -23,7 +23,7 @@ const getWrapperSource = (offset, source) => {
23
23
  };
24
24
 
25
25
  const getEntryFilter = (options) => {
26
- const input = options.entryFilter;
26
+ let input = options.entryFilter || options.filter;
27
27
 
28
28
  // for function handler
29
29
  if (typeof input === 'function') {
@@ -32,9 +32,17 @@ const getEntryFilter = (options) => {
32
32
 
33
33
  // for single minimatch pattern
34
34
  if (input && typeof input === 'string') {
35
- return (entry) => {
36
- return minimatch(entry.url, input);
37
- };
35
+ // string to multiple patterns "{...}"
36
+ // mcr npx mocha --entryFilter {'**/node_modules/**':false,'**/src/*.js':true}
37
+ // mcr npx mocha --entryFilter "{'**/node_modules/**': false, '**/src/*.js': true}"
38
+ const obj = Util.strToObj(input);
39
+ if (obj) {
40
+ input = obj;
41
+ } else {
42
+ return (entry) => {
43
+ return minimatch(entry.url, input);
44
+ };
45
+ }
38
46
  }
39
47
 
40
48
  // for patterns
@@ -101,7 +109,9 @@ const initV8ListAndSourcemap = async (v8list, options) => {
101
109
  }
102
110
  }
103
111
 
104
- const sourcePathHandler = getSourcePathHandler(options);
112
+ const sourcePathReplacer = getSourcePathReplacer(options);
113
+
114
+ const baseDir = options.baseDir;
105
115
 
106
116
  // init id, sourcePath
107
117
  v8list = v8list.map((entry, i) => {
@@ -141,9 +151,9 @@ const initV8ListAndSourcemap = async (v8list, options) => {
141
151
  }
142
152
 
143
153
  // resolve source path
144
- let sourcePath = getSourcePath(data.url, i + 1, data.type);
145
- if (sourcePathHandler) {
146
- const newSourcePath = sourcePathHandler(sourcePath, data);
154
+ let sourcePath = normalizeSourcePath(data.url, baseDir, i + 1, data.type);
155
+ if (sourcePathReplacer) {
156
+ const newSourcePath = sourcePathReplacer(sourcePath, data);
147
157
  if (typeof newSourcePath === 'string' && newSourcePath) {
148
158
  sourcePath = newSourcePath;
149
159
  }
package/package.json CHANGED
@@ -1,100 +1,101 @@
1
- {
2
- "name": "monocart-coverage-reports",
3
- "version": "2.7.10",
4
- "description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
5
- "main": "./lib/index.js",
6
- "bin": {
7
- "mcr": "./lib/cli.js"
8
- },
9
- "exports": {
10
- ".": {
11
- "types": "./lib/index.d.ts",
12
- "import": "./lib/index.mjs",
13
- "require": "./lib/index.js",
14
- "default": "./lib/index.js"
15
- },
16
- "./register": {
17
- "import": "./lib/register/register.mjs",
18
- "require": "./lib/register/register.js",
19
- "default": "./lib/register/register.js"
20
- },
21
- "./converter": "./lib/converter/converter.js",
22
- "./util": "./lib/utils/util.js",
23
- "./package.json": "./package.json"
24
- },
25
- "types": "./lib/index.d.ts",
26
- "scripts": {
27
- "build-test": "node ./test/build/build-test.js",
28
- "build": "sf lint && sf b -p && npm run build-test",
29
- "test-unit": "mocha --parallel test/unit/*.test.js",
30
- "test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",
31
- "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
32
- "test-node-ins": "node ./test/test-node-ins.js",
33
- "test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
34
- "test-node-vm": "node ./test/test-node-vm.js",
35
- "test-node-koa": "node ./test/test-node-koa.js",
36
- "test-node-fgc": "node ./test/test-node-fgc.js",
37
- "test-node": "node ./test/test.js --node",
38
- "test-istanbul": "node ./test/test-istanbul.js",
39
- "test-v8": "node ./test/test-v8.js",
40
- "test-puppeteer": "node ./test/test-puppeteer.js",
41
- "test-anonymous": "node ./test/test-anonymous.js",
42
- "test-css": "node ./test/test-css.js",
43
- "test-minify": "node ./test/test-minify.js",
44
- "test-esbuild": "node ./test/test-esbuild.js",
45
- "test-rollup": "node ./test/test-rollup.js",
46
- "test-swc": "node ./test/test-swc.js",
47
- "test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
48
- "test-browser": "node ./test/test.js --browser",
49
- "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
50
- "test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
51
- "test-demo": "node ./test/test-demo.js",
52
- "test-merge": "node ./test/test-merge.js",
53
- "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
54
- "test-client": "node ./test/test-client.js",
55
- "test-all": "node ./test/test.js && node ./scripts/docs.js",
56
- "test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js",
57
- "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
58
- "dev": "sf d v8",
59
- "open": "node ./scripts/open.js",
60
- "patch": "npm run build && npm run test && sf publish patch -r"
61
- },
62
- "workspaces": [
63
- "packages/*",
64
- "test"
65
- ],
66
- "files": [
67
- "lib"
68
- ],
69
- "license": "MIT",
70
- "repository": {
71
- "type": "git",
72
- "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
73
- },
74
- "dependencies": {
75
- "console-grid": "^2.2.2",
76
- "eight-colors": "^1.3.0",
77
- "istanbul-lib-coverage": "^3.2.2",
78
- "istanbul-lib-report": "^3.0.1",
79
- "istanbul-reports": "^3.1.7",
80
- "lz-utils": "^2.0.2",
81
- "monocart-code-viewer": "^1.1.3",
82
- "monocart-formatter": "^3.0.0",
83
- "monocart-locator": "^1.0.0",
84
- "turbogrid": "^3.0.13"
85
- },
86
- "devDependencies": {
87
- "commander": "^12.0.0",
88
- "esbuild": "^0.20.2",
89
- "eslint": "~9.1.1",
90
- "eslint-config-plus": "^2.0.0",
91
- "eslint-plugin-html": "^8.1.1",
92
- "eslint-plugin-vue": "^9.25.0",
93
- "minimatch": "^9.0.4",
94
- "stylelint": "^16.4.0",
95
- "stylelint-config-plus": "^1.1.0",
96
- "supports-color": "^9.4.0",
97
- "tsx": "^4.8.2",
98
- "ws": "^8.17.0"
99
- }
100
- }
1
+ {
2
+ "name": "monocart-coverage-reports",
3
+ "version": "2.8.1",
4
+ "description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
5
+ "main": "./lib/index.js",
6
+ "bin": {
7
+ "mcr": "./lib/cli.js"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/index.d.ts",
12
+ "import": "./lib/index.mjs",
13
+ "require": "./lib/index.js",
14
+ "default": "./lib/index.js"
15
+ },
16
+ "./register": {
17
+ "import": "./lib/register/register.mjs",
18
+ "require": "./lib/register/register.js",
19
+ "default": "./lib/register/register.js"
20
+ },
21
+ "./converter": "./lib/converter/converter.js",
22
+ "./util": "./lib/utils/util.js",
23
+ "./package.json": "./package.json"
24
+ },
25
+ "types": "./lib/index.d.ts",
26
+ "scripts": {
27
+ "build-test": "node ./test/build/build-test.js",
28
+ "build": "sf lint && sf b -p && npm run build-test",
29
+ "test-unit": "mocha --parallel test/unit/*.test.js",
30
+ "test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",
31
+ "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
32
+ "test-node-ins": "node ./test/test-node-ins.js",
33
+ "test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
34
+ "test-node-vm": "node ./test/test-node-vm.js",
35
+ "test-node-koa": "node ./test/test-node-koa.js",
36
+ "test-node-fgc": "node ./test/test-node-fgc.js",
37
+ "test-node": "node ./test/test.js --node",
38
+ "test-istanbul": "node ./test/test-istanbul.js",
39
+ "test-v8": "node ./test/test-v8.js",
40
+ "test-puppeteer": "node ./test/test-puppeteer.js",
41
+ "test-anonymous": "node ./test/test-anonymous.js",
42
+ "test-css": "node ./test/test-css.js",
43
+ "test-minify": "node ./test/test-minify.js",
44
+ "test-esbuild": "node ./test/test-esbuild.js",
45
+ "test-rollup": "node ./test/test-rollup.js",
46
+ "test-swc": "node ./test/test-swc.js",
47
+ "test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
48
+ "test-browser": "node ./test/test.js --browser",
49
+ "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
50
+ "test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
51
+ "test-demo": "node ./test/test-demo.js",
52
+ "test-merge": "node ./test/test-merge.js",
53
+ "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
54
+ "test-client": "node ./test/test-client.js",
55
+ "test-all": "node ./test/test.js && node ./scripts/docs.js",
56
+ "test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js",
57
+ "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
58
+ "dev": "sf d v8",
59
+ "open": "node ./scripts/open.js",
60
+ "patch": "npm run build && npm run test && sf publish patch -r"
61
+ },
62
+ "workspaces": [
63
+ "packages/*",
64
+ "test"
65
+ ],
66
+ "files": [
67
+ "lib",
68
+ "README.zh-Hans.md"
69
+ ],
70
+ "license": "MIT",
71
+ "repository": {
72
+ "type": "git",
73
+ "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
74
+ },
75
+ "dependencies": {
76
+ "console-grid": "^2.2.2",
77
+ "eight-colors": "^1.3.0",
78
+ "istanbul-lib-coverage": "^3.2.2",
79
+ "istanbul-lib-report": "^3.0.1",
80
+ "istanbul-reports": "^3.1.7",
81
+ "lz-utils": "^2.0.2",
82
+ "monocart-code-viewer": "^1.1.3",
83
+ "monocart-formatter": "^3.0.0",
84
+ "monocart-locator": "^1.0.0",
85
+ "turbogrid": "^3.0.13"
86
+ },
87
+ "devDependencies": {
88
+ "commander": "^12.0.0",
89
+ "esbuild": "^0.21.1",
90
+ "eslint": "~9.2.0",
91
+ "eslint-config-plus": "^2.0.0",
92
+ "eslint-plugin-html": "^8.1.1",
93
+ "eslint-plugin-vue": "^9.26.0",
94
+ "minimatch": "^9.0.4",
95
+ "stylelint": "^16.5.0",
96
+ "stylelint-config-plus": "^1.1.2",
97
+ "supports-color": "^9.4.0",
98
+ "tsx": "^4.9.3",
99
+ "ws": "^8.17.0"
100
+ }
101
+ }