escover 1.3.0 → 1.3.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.
package/ChangeLog CHANGED
@@ -1,3 +1,30 @@
1
+ 2022.01.15, v1.3.4
2
+
3
+ fix:
4
+ - escover: rm useless import
5
+
6
+
7
+ 2022.01.15, v1.3.3
8
+
9
+ feature:
10
+ - escover: exclude not from current path
11
+
12
+
13
+ 2022.01.15, v1.3.2
14
+
15
+ fix:
16
+ - escover: rm console.log
17
+
18
+
19
+ 2022.01.15, v1.3.1
20
+
21
+ fix:
22
+ - escover: do not write coverage when empty
23
+
24
+ feature:
25
+ - escover: add ability to get coverage of itself
26
+
27
+
1
28
  2022.01.15, v1.3.0
2
29
 
3
30
  feature:
package/lib/c4.js CHANGED
@@ -1,8 +1,8 @@
1
- const files = new Map();
1
+ export const __fileEntries = new Map();
2
2
 
3
3
  export const createFileEntry = (url) => {
4
- const lines = files.get(url) || new Map();
5
- files.set(url, lines);
4
+ const lines = __fileEntries.get(url) || new Map();
5
+ __fileEntries.set(url, lines);
6
6
 
7
7
  return {
8
8
  '🧨': (line, column) => {
@@ -14,4 +14,4 @@ export const createFileEntry = (url) => {
14
14
  };
15
15
  };
16
16
 
17
- export const getFiles = () => files;
17
+ export const getFileEntries = () => __fileEntries;
@@ -0,0 +1,47 @@
1
+ import tryCatch from 'try-catch';
2
+ import {
3
+ writeFileSync,
4
+ readFileSync,
5
+ } from 'fs';
6
+ import {getFileEntries} from './c4.js';
7
+ import {transform} from './transform.js';
8
+ import {merge} from './merge.js';
9
+ import findCacheDir from 'find-cache-dir';
10
+
11
+ const {
12
+ stringify,
13
+ parse,
14
+ } = JSON;
15
+
16
+ const NAME = 'escover';
17
+ const buildName = (a) => `${a}/${NAME}.json`;
18
+
19
+ export const write = () => {
20
+ const files = getFileEntries();
21
+
22
+ if (!files.size)
23
+ return;
24
+
25
+ const parsed = transform(files);
26
+ const merged = merge(parsed);
27
+ const name = findCacheDir({
28
+ name: NAME,
29
+ create: true,
30
+ });
31
+
32
+ writeFileSync(buildName(name), stringify(merged, null, 4));
33
+ };
34
+
35
+ export const read = () => {
36
+ const name = findCacheDir({
37
+ name: NAME,
38
+ });
39
+
40
+ const [error, data] = tryCatch(readFileSync, buildName(name), 'utf8');
41
+
42
+ if (error)
43
+ return [];
44
+
45
+ return parse(data);
46
+ };
47
+
package/lib/escover.js CHANGED
@@ -9,8 +9,15 @@ import {createFileEntry} from './c4.js';
9
9
  global.__createC4 = createFileEntry;
10
10
 
11
11
  process.once('exit', exit);
12
+ const CWD = process.cwd();
12
13
 
13
- const EXCLUDE = ['.spec.', 'node_modules', '/fixture/', '.madrun.', '/test/'];
14
+ const EXCLUDE = [
15
+ '.spec.',
16
+ 'node_modules',
17
+ '/fixture/',
18
+ '.madrun.',
19
+ '/test/',
20
+ ];
14
21
 
15
22
  export async function load(url, context, defaultLoad) {
16
23
  const {format, source: rawSource} = await defaultLoad(url, context, defaultLoad);
@@ -20,6 +27,12 @@ export async function load(url, context, defaultLoad) {
20
27
  format,
21
28
  };
22
29
 
30
+ if (!url.includes(CWD))
31
+ return {
32
+ format,
33
+ source: rawSource,
34
+ };
35
+
23
36
  if (exclude(url, EXCLUDE))
24
37
  return {
25
38
  format,
@@ -1,13 +1,13 @@
1
- import putout, {} from 'putout';
1
+ import putout from 'putout';
2
2
 
3
3
  import * as mark from './plugin-mark/index.js';
4
4
 
5
5
  export const instrument = (url, source) => {
6
- const __c4 = global.__createC4(url);
6
+ const c4 = global.__createC4(url);
7
7
  const options = {
8
8
  rules: {
9
9
  mark: ['on', {
10
- __c4,
10
+ c4,
11
11
  }],
12
12
  },
13
13
  plugins: [
@@ -23,8 +23,8 @@ const buildLineNode = template(LINE, {
23
23
  placeholderPattern: /^__[a-z]$/,
24
24
  });
25
25
 
26
- function getLineNode(__c4, {line, column}) {
27
- __c4.init(line, column);
26
+ function getLineNode(c4, {line, column}) {
27
+ c4.init(line, column);
28
28
 
29
29
  return buildLineNode({
30
30
  __l: NumericLiteral(line),
@@ -35,24 +35,18 @@ function getLineNode(__c4, {line, column}) {
35
35
  export const report = () => 'Mark line';
36
36
 
37
37
  export const fix = (path, {options}) => {
38
- const {
39
- parentPath,
40
- node,
41
- } = path;
38
+ const {node} = path;
42
39
 
43
- const {start} = path.node.loc || parentPath.node.loc || {};
44
-
45
- if (!start)
46
- return;
40
+ const {start} = path.node.loc;
47
41
 
48
42
  const {
49
- __c4 = {
43
+ c4 = {
50
44
  mark: () => {},
51
45
  init: () => {},
52
46
  },
53
47
  } = options;
54
48
 
55
- const lineNode = getLineNode(__c4, start);
49
+ const lineNode = getLineNode(c4, start);
56
50
 
57
51
  if (path.isBlockStatement()) {
58
52
  path.node.body.unshift(lineNode);
@@ -74,7 +68,7 @@ export const fix = (path, {options}) => {
74
68
  path.node.left,
75
69
  ]));
76
70
  replaceWith(path.get('right'), SequenceExpression([
77
- getLineNode(__c4, path.node.right.loc.start).expression,
71
+ getLineNode(c4, path.node.right.loc.start).expression,
78
72
  path.node.right,
79
73
  ]));
80
74
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "1.3.0",
3
+ "version": "1.3.4",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
5
  "description": "Coverage for EcmaScript Modules",
6
6
  "main": "lib/escover.js",
@@ -54,7 +54,7 @@
54
54
  "devDependencies": {
55
55
  "@putout/test": "^4.1.0",
56
56
  "c8": "^7.8.0",
57
- "escover": ".",
57
+ "escover": "^1.0.0",
58
58
  "eslint": "^8.3.0",
59
59
  "eslint-plugin-node": "^11.1.0",
60
60
  "eslint-plugin-putout": "^13.0.1",