monocart-coverage-reports 2.7.2 → 2.7.4

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.
@@ -3,35 +3,53 @@ const path = require('path');
3
3
  const Util = require('../utils/util.js');
4
4
  const { convertSourceMap } = require('../packages/monocart-coverage-vendor.js');
5
5
 
6
- async function load(url, context, nextLoad) {
7
-
8
- const loaded = await nextLoad(url, context);
9
- const { source, format } = loaded;
10
- const dir = process.env.NODE_V8_COVERAGE;
6
+ function saveFile(url, source, dir) {
7
+ if (!fs.existsSync(dir)) {
8
+ fs.mkdirSync(dir, {
9
+ recursive: true
10
+ });
11
+ }
11
12
 
12
- if (dir && typeof source === 'string' && (format === 'module' || format === 'commonjs')) {
13
+ const id = Util.calculateSha1(url + source);
14
+ const filePath = path.resolve(dir, `source-${id}.json`);
15
+ if (!fs.existsSync(filePath)) {
16
+ fs.writeFileSync(filePath, JSON.stringify({
17
+ url,
18
+ source
19
+ }));
20
+ }
13
21
 
14
- if (convertSourceMap.mapFileCommentRegex.test(source)) {
22
+ }
15
23
 
16
- if (!fs.existsSync(dir)) {
17
- fs.mkdirSync(dir, {
18
- recursive: true
19
- });
20
- }
24
+ function saveSource(url, loaded, dir) {
21
25
 
22
- const id = Util.calculateSha1(url + source);
23
- const filePath = path.resolve(dir, `source-${id}.json`);
24
- if (!fs.existsSync(filePath)) {
25
- fs.writeFileSync(filePath, JSON.stringify({
26
- url,
27
- source
28
- }));
29
- }
26
+ // filter node modules
27
+ if (url.startsWith('node:')) {
28
+ return;
29
+ }
30
30
 
31
- }
31
+ const { source, format } = loaded;
32
+ if (typeof source !== 'string' || !['module', 'commonjs'].includes(format)) {
33
+ // no source or wrong format
34
+ return;
35
+ }
32
36
 
37
+ if (!convertSourceMap.mapFileCommentRegex.test(source)) {
38
+ // no sourcemap
39
+ return;
33
40
  }
34
41
 
42
+ saveFile(url, source, dir);
43
+
44
+ }
45
+
46
+ async function load(url, context, nextLoad) {
47
+ const loaded = await nextLoad(url, context);
48
+ const dir = process.env.NODE_V8_COVERAGE;
49
+ if (dir) {
50
+ // only for coverage enabled
51
+ saveSource(url, loaded, dir);
52
+ }
35
53
  return loaded;
36
54
  }
37
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.7.2",
3
+ "version": "2.7.4",
4
4
  "description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -27,25 +27,30 @@
27
27
  "build-docs": "node ./scripts/build-docs.js",
28
28
  "build-test": "node ./scripts/build-test.js",
29
29
  "build": "sf lint && sf b -p && npm run build-test",
30
- "test-node": "npm run test-node-env && npm run test-node-api && npm run test-node-ins && npm run test-node-cdp && npm run test-node-koa && npm run test-node-vm",
31
30
  "test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",
32
31
  "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
33
- "test-node-fgc": "node ./test/test-node-fgc.js",
34
32
  "test-node-ins": "node ./test/test-node-ins.js",
35
33
  "test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
36
- "test-node-koa": "node ./test/test-node-koa.js",
37
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": "npm run test-node-env && npm run test-node-api && npm run test-node-ins && npm run test-node-cdp && npm run test-node-vm && npm run test-node-koa",
38
38
  "test-istanbul": "node ./test/test-istanbul.js",
39
39
  "test-v8": "node ./test/test-v8.js",
40
40
  "test-puppeteer": "node ./test/test-puppeteer.js",
41
- "test-browser": "node ./test/test-browser.js && npm run test-istanbul && npm run test-v8 && npm run test-puppeteer && npm run test-anonymous && npm run test-css",
42
41
  "test-anonymous": "node ./test/test-anonymous.js",
43
42
  "test-css": "node ./test/test-css.js",
44
- "test-client": "node ./test/test-client.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-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
47
+ "test-browser": "npm run test-istanbul && npm run test-v8 && npm run test-puppeteer && npm run test-anonymous && npm run test-css && npm run test-minify && npm run test-esbuild && npm run test-rollup && npm run test-v8-and-istanbul",
45
48
  "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
49
+ "test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
46
50
  "test-merge": "node ./test/test-merge.js",
47
51
  "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
48
- "test-all": "npm run test-browser && npm run test-node && npm run test-cli && npm run test-merge && npm run build-docs",
52
+ "test-client": "node ./test/test-client.js",
53
+ "test-all": "npm run test-node && npm run test-browser && npm run test-cli && npm run test-tsx && npm run test-merge && npm run build-docs",
49
54
  "test": "npx mcr npm run test-all -c test/mcr.config.mcr.js",
50
55
  "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
51
56
  "dev": "sf d v8",
@@ -77,6 +82,7 @@
77
82
  },
78
83
  "devDependencies": {
79
84
  "commander": "^12.0.0",
85
+ "esbuild": "^0.20.2",
80
86
  "eslint": "^8.57.0",
81
87
  "eslint-config-plus": "^1.0.6",
82
88
  "eslint-plugin-html": "^8.0.0",