oxc-coverage-instrument 0.2.14 → 0.2.16

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.
Files changed (3) hide show
  1. package/package.json +8 -8
  2. package/vitest.d.ts +20 -12
  3. package/vitest.js +17 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxc-coverage-instrument",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "Istanbul-compatible JavaScript/TypeScript coverage instrumentation using the Oxc AST. 8-48x faster than istanbul-lib-instrument.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -61,12 +61,12 @@
61
61
  "test": "node test.mjs"
62
62
  },
63
63
  "optionalDependencies": {
64
- "@oxc-coverage-instrument/binding-darwin-arm64": "0.2.14",
65
- "@oxc-coverage-instrument/binding-darwin-x64": "0.2.14",
66
- "@oxc-coverage-instrument/binding-linux-x64-gnu": "0.2.14",
67
- "@oxc-coverage-instrument/binding-linux-arm64-gnu": "0.2.14",
68
- "@oxc-coverage-instrument/binding-linux-x64-musl": "0.2.14",
69
- "@oxc-coverage-instrument/binding-win32-x64-msvc": "0.2.14",
70
- "@oxc-coverage-instrument/binding-win32-arm64-msvc": "0.2.14"
64
+ "@oxc-coverage-instrument/binding-darwin-arm64": "0.2.16",
65
+ "@oxc-coverage-instrument/binding-darwin-x64": "0.2.16",
66
+ "@oxc-coverage-instrument/binding-linux-x64-gnu": "0.2.16",
67
+ "@oxc-coverage-instrument/binding-linux-arm64-gnu": "0.2.16",
68
+ "@oxc-coverage-instrument/binding-linux-x64-musl": "0.2.16",
69
+ "@oxc-coverage-instrument/binding-win32-x64-msvc": "0.2.16",
70
+ "@oxc-coverage-instrument/binding-win32-arm64-msvc": "0.2.16"
71
71
  }
72
72
  }
package/vitest.d.ts CHANGED
@@ -1,10 +1,23 @@
1
+ /**
2
+ * Options for creating an Oxc-based coverage instrumenter.
3
+ *
4
+ * When used with Vitest's `coverage.instrumenter` option, the factory receives
5
+ * `InstrumenterOptions` with `coverageVariable` and `ignoreClassMethods`.
6
+ */
7
+ export interface OxcInstrumenterOptions {
8
+ /** Global variable name for coverage data (Vitest passes `__VITEST_COVERAGE__`). */
9
+ coverageVariable?: string
10
+ /** Class method names to exclude from function coverage. */
11
+ ignoreClassMethods?: string[]
12
+ /** When true, adds truthy-value tracking (bT) for logical expressions. */
13
+ reportLogic?: boolean
14
+ }
15
+
1
16
  /**
2
17
  * Creates an instrumenter that implements the istanbul-lib-instrument
3
18
  * Instrumenter interface, backed by oxc-coverage-instrument.
4
19
  *
5
- * Use with Vitest's `coverage.instrumenter` option (requires vitest with
6
- * custom instrumenter support):
7
- *
20
+ * @example
8
21
  * ```ts
9
22
  * import { defineConfig } from 'vitest/config'
10
23
  * import { createOxcInstrumenter } from 'oxc-coverage-instrument/vitest'
@@ -13,21 +26,16 @@
13
26
  * test: {
14
27
  * coverage: {
15
28
  * provider: 'istanbul',
16
- * instrumenter: () => createOxcInstrumenter(),
29
+ * instrumenter: (options) => createOxcInstrumenter(options),
17
30
  * }
18
31
  * }
19
32
  * })
20
33
  * ```
21
34
  */
22
- export declare function createOxcInstrumenter(options?: {
23
- /** Name of the global coverage variable (default: "__coverage__"). */
24
- coverageVariable?: string
25
- /** Class method names to exclude from function coverage. */
26
- ignoreClassMethods?: string[]
27
- /** When true, adds truthy-value tracking (bT) for logical expressions. */
28
- reportLogic?: boolean
29
- }): {
35
+ export declare function createOxcInstrumenter(options?: OxcInstrumenterOptions): {
30
36
  instrumentSync(code: string, filename: string, inputSourceMap?: any): string
31
37
  lastSourceMap(): any
32
38
  lastFileCoverage(): any
39
+ /** Property alias for compatibility with vite-plugin-istanbul. */
40
+ readonly fileCoverage: any
33
41
  }
package/vitest.js CHANGED
@@ -12,7 +12,7 @@
12
12
  // test: {
13
13
  // coverage: {
14
14
  // provider: 'istanbul',
15
- // instrumenter: createOxcInstrumenter(),
15
+ // instrumenter: (options) => createOxcInstrumenter(options),
16
16
  // }
17
17
  // }
18
18
  // })
@@ -23,13 +23,19 @@ const { instrument } = require('./index.js');
23
23
  * Creates an instrumenter that implements the istanbul-lib-instrument
24
24
  * Instrumenter interface, backed by oxc-coverage-instrument.
25
25
  *
26
+ * When used with Vitest's `coverage.instrumenter` option, the factory receives
27
+ * `InstrumenterOptions` with `coverageVariable` and `ignoreClassMethods`.
28
+ * These are forwarded to the native instrumenter automatically.
29
+ *
26
30
  * @param {object} [options]
27
- * @param {string} [options.coverageVariable='__coverage__']
28
- * @param {string[]} [options.ignoreClassMethods=[]]
29
- * @param {boolean} [options.reportLogic=false]
30
- * @returns {Instrumenter}
31
+ * @param {string} [options.coverageVariable] - Global variable for coverage data.
32
+ * Vitest passes its internal `__VITEST_COVERAGE__`; defaults to `__coverage__`.
33
+ * @param {string[]} [options.ignoreClassMethods] - Class methods to skip.
34
+ * @param {boolean} [options.reportLogic] - Enable truthy-value tracking (bT).
35
+ * @returns {{ instrumentSync, lastSourceMap, lastFileCoverage }}
31
36
  */
32
- function createOxcInstrumenter(options = {}) {
37
+ function createOxcInstrumenter(options) {
38
+ options = options || {};
33
39
  const coverageVariable = options.coverageVariable || '__coverage__';
34
40
  const ignoreClassMethods = options.ignoreClassMethods || [];
35
41
  const reportLogic = options.reportLogic || false;
@@ -38,13 +44,6 @@ function createOxcInstrumenter(options = {}) {
38
44
  let _lastFileCoverage = null;
39
45
 
40
46
  return {
41
- /**
42
- * Instrument source code synchronously.
43
- * @param {string} code - Source code to instrument.
44
- * @param {string} filename - File path for coverage map.
45
- * @param {object} [inputSourceMap] - Input source map from prior transform.
46
- * @returns {string} Instrumented source code.
47
- */
48
47
  instrumentSync(code, filename, inputSourceMap) {
49
48
  const result = instrument(code, filename, {
50
49
  coverageVariable,
@@ -60,21 +59,18 @@ function createOxcInstrumenter(options = {}) {
60
59
  return result.code;
61
60
  },
62
61
 
63
- /**
64
- * Get the source map of the last instrumented file.
65
- * @returns {object|null}
66
- */
67
62
  lastSourceMap() {
68
63
  return _lastSourceMap;
69
64
  },
70
65
 
71
- /**
72
- * Get the coverage object of the last instrumented file.
73
- * @returns {object}
74
- */
75
66
  lastFileCoverage() {
76
67
  return _lastFileCoverage;
77
68
  },
69
+
70
+ // Property alias used by vite-plugin-istanbul (vs lastFileCoverage() method used by Vitest)
71
+ get fileCoverage() {
72
+ return _lastFileCoverage;
73
+ },
78
74
  };
79
75
  }
80
76