monocart-coverage-reports 2.7.1 → 2.7.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.
@@ -0,0 +1,58 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const Util = require('../utils/util.js');
4
+ const { convertSourceMap } = require('../packages/monocart-coverage-vendor.js');
5
+
6
+ function saveFile(url, source, dir) {
7
+ if (!fs.existsSync(dir)) {
8
+ fs.mkdirSync(dir, {
9
+ recursive: true
10
+ });
11
+ }
12
+
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
+ }
21
+
22
+ }
23
+
24
+ function saveSource(url, loaded, dir) {
25
+
26
+ // filter node modules
27
+ if (url.startsWith('node:')) {
28
+ return;
29
+ }
30
+
31
+ const { source, format } = loaded;
32
+ if (typeof source !== 'string' || !['module', 'commonjs'].includes(format)) {
33
+ // no source or wrong format
34
+ return;
35
+ }
36
+
37
+ if (!convertSourceMap.mapFileCommentRegex.test(source)) {
38
+ // no sourcemap
39
+ return;
40
+ }
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
+ }
53
+ return loaded;
54
+ }
55
+
56
+ module.exports = {
57
+ load
58
+ };
@@ -0,0 +1,3 @@
1
+ import { load } from './hooks.js';
2
+
3
+ export { load };
@@ -0,0 +1,4 @@
1
+ const { register } = require('module');
2
+ const { pathToFileURL } = require('url');
3
+
4
+ register('./hooks.js', pathToFileURL(__filename));
@@ -0,0 +1,3 @@
1
+ import { register } from 'module';
2
+
3
+ register('./hooks.mjs', import.meta.url);
@@ -141,27 +141,43 @@ const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) =>
141
141
 
142
142
  // ========================================================================================================
143
143
 
144
- const mergeSourceRoot = (sourceRoot, sourceName) => {
145
- if (sourceName.startsWith(sourceRoot)) {
146
- return sourceName;
144
+ const resolveSourceUrl = (sourceName, sourceRoot) => {
145
+
146
+ // could be absolute path
147
+ // c:\\workspace\test\\selenium.spec.js
148
+ // a.js false
149
+ // c://a.js true
150
+ // ws://a.js false
151
+
152
+ if (path.isAbsolute(sourceName)) {
153
+ return pathToFileURL(sourceName).toString();
154
+ }
155
+
156
+ // webpack://coverage-v8/./test/mock/src/branch/branch.js
157
+ // webpack://monocart-v8/../starfall-cli/node_modules/css-loader/dist/runtime/api.js
158
+
159
+ // as url
160
+ const urlObj = Util.resolveUrl(sourceName);
161
+ if (urlObj) {
162
+ return urlObj.toString();
147
163
  }
148
- return sourceRoot + sourceName;
164
+
165
+ // as relative path, join sourceRoot
166
+ if (sourceRoot && !sourceName.startsWith(sourceRoot)) {
167
+ sourceName = path.join(sourceRoot, sourceName);
168
+ }
169
+
170
+ sourceName = path.normalize(sourceName);
171
+ const sourceUrl = pathToFileURL(sourceName).toString();
172
+
173
+ return sourceUrl;
149
174
  };
150
175
 
151
176
  const initSourceMapSourcePath = (sourceMap, fileUrls, distFile, sourcePathHandler) => {
152
- // reset sourceRoot
153
- const sourceRoot = sourceMap.sourceRoot || '';
154
- sourceMap.sourceRoot = '';
155
177
 
156
178
  sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
157
179
 
158
- // the sourceName could be absolute path
159
- // c:\\workspace\test\\selenium.spec.js
160
- // console.log(sourceName);
161
- sourceName = Util.formatPath(sourceName);
162
- // console.log(sourceName);
163
-
164
- const sourceUrl = mergeSourceRoot(sourceRoot, sourceName);
180
+ const sourceUrl = resolveSourceUrl(sourceName, sourceMap.sourceRoot);
165
181
 
166
182
  let sourcePath = getSourcePath(sourceUrl, i + 1);
167
183
  if (sourcePathHandler) {
package/package.json CHANGED
@@ -1,83 +1,97 @@
1
- {
2
- "name": "monocart-coverage-reports",
3
- "version": "2.7.1",
4
- "description": "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
- "./package.json": "./package.json"
17
- },
18
- "types": "./lib/index.d.ts",
19
- "scripts": {
20
- "build-docs": "node ./scripts/build-docs.js",
21
- "build-test": "node ./scripts/build-test.js",
22
- "build": "sf lint && sf b -p && npm run build-test",
23
- "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",
24
- "test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",
25
- "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
26
- "test-node-fgc": "node ./test/test-node-fgc.js",
27
- "test-node-ins": "node ./test/test-node-ins.js",
28
- "test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
29
- "test-node-koa": "node ./test/test-node-koa.js",
30
- "test-node-vm": "node ./test/test-node-vm.js",
31
- "test-istanbul": "node ./test/test-istanbul.js",
32
- "test-v8": "node ./test/test-v8.js",
33
- "test-puppeteer": "node ./test/test-puppeteer.js",
34
- "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",
35
- "test-anonymous": "node ./test/test-anonymous.js",
36
- "test-css": "node ./test/test-css.js",
37
- "test-client": "node ./test/test-client.js",
38
- "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
39
- "test-merge": "node ./test/test-merge.js",
40
- "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
41
- "test-all": "npm run test-browser && npm run test-node && npm run test-cli && npm run test-merge && npm run build-docs",
42
- "test": "npx mcr npm run test-all -c test/mcr.config.mcr.js",
43
- "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
44
- "dev": "sf d v8",
45
- "open": "node ./scripts/open.js",
46
- "patch": "npm run build && npm run test && sf publish patch -r"
47
- },
48
- "workspaces": [
49
- "packages/*",
50
- "test"
51
- ],
52
- "files": [
53
- "lib"
54
- ],
55
- "license": "MIT",
56
- "repository": {
57
- "type": "git",
58
- "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
59
- },
60
- "dependencies": {
61
- "console-grid": "^2.2.2",
62
- "eight-colors": "^1.3.0",
63
- "istanbul-lib-coverage": "^3.2.2",
64
- "istanbul-lib-report": "^3.0.1",
65
- "istanbul-reports": "^3.1.7",
66
- "lz-utils": "^2.0.2",
67
- "monocart-code-viewer": "^1.1.2",
68
- "monocart-formatter": "^2.3.2",
69
- "turbogrid": "^3.0.13"
70
- },
71
- "devDependencies": {
72
- "commander": "^12.0.0",
73
- "eslint": "^8.57.0",
74
- "eslint-config-plus": "^1.0.6",
75
- "eslint-plugin-html": "^8.0.0",
76
- "eslint-plugin-vue": "^9.23.0",
77
- "minimatch": "^9.0.3",
78
- "stylelint": "^16.2.1",
79
- "stylelint-config-plus": "^1.1.0",
80
- "supports-color": "^9.4.0",
81
- "ws": "^8.16.0"
82
- }
83
- }
1
+ {
2
+ "name": "monocart-coverage-reports",
3
+ "version": "2.7.3",
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-docs": "node ./scripts/build-docs.js",
28
+ "build-test": "node ./scripts/build-test.js",
29
+ "build": "sf lint && sf b -p && npm run build-test",
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": "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
+ "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-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",
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",
50
+ "test-merge": "node ./test/test-merge.js",
51
+ "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
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",
54
+ "test": "npx mcr npm run test-all -c test/mcr.config.mcr.js",
55
+ "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
56
+ "dev": "sf d v8",
57
+ "open": "node ./scripts/open.js",
58
+ "patch": "npm run build && npm run test && sf publish patch -r"
59
+ },
60
+ "workspaces": [
61
+ "packages/*",
62
+ "test"
63
+ ],
64
+ "files": [
65
+ "lib"
66
+ ],
67
+ "license": "MIT",
68
+ "repository": {
69
+ "type": "git",
70
+ "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
71
+ },
72
+ "dependencies": {
73
+ "console-grid": "^2.2.2",
74
+ "eight-colors": "^1.3.0",
75
+ "istanbul-lib-coverage": "^3.2.2",
76
+ "istanbul-lib-report": "^3.0.1",
77
+ "istanbul-reports": "^3.1.7",
78
+ "lz-utils": "^2.0.2",
79
+ "monocart-code-viewer": "^1.1.2",
80
+ "monocart-formatter": "^2.3.2",
81
+ "turbogrid": "^3.0.13"
82
+ },
83
+ "devDependencies": {
84
+ "commander": "^12.0.0",
85
+ "esbuild": "^0.20.2",
86
+ "eslint": "^8.57.0",
87
+ "eslint-config-plus": "^1.0.6",
88
+ "eslint-plugin-html": "^8.0.0",
89
+ "eslint-plugin-vue": "^9.23.0",
90
+ "minimatch": "^9.0.3",
91
+ "stylelint": "^16.2.1",
92
+ "stylelint-config-plus": "^1.1.0",
93
+ "supports-color": "^9.4.0",
94
+ "tsx": "^4.7.1",
95
+ "ws": "^8.16.0"
96
+ }
97
+ }