diff-cover-js 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Samriddhi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # diff-cover-js
2
+
3
+ Diff-aware test coverage for JavaScript/TypeScript projects. Reports coverage **only for lines you changed**, not the entire file.
4
+
5
+ The JS/TS equivalent of the Python [diff-cover](https://github.com/Bachmann1234/diff_cover) tool — same algorithm, same CLI flags, no Python required.
6
+
7
+ ## The problem it solves
8
+
9
+ Standard coverage tools measure the whole file. If you add 10 lines to a 500-line file and cover all 10, Jest reports ~2% coverage. **diff-cover-js reports 100%** — because all your changed lines are covered.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install -g diff-cover-js
15
+ ```
16
+
17
+ ## Requirements
18
+
19
+ - Node.js >= 16
20
+ - A `lcov.info` file generated by your test runner (Jest produces one with the `lcov` reporter)
21
+ - A git repository with the base branch available locally
22
+
23
+ ## Usage
24
+
25
+ ```bash
26
+ diff-cover-js \
27
+ --lcov coverage/lcov.info \
28
+ --compare-branch origin/main \
29
+ --fail-under 80
30
+ ```
31
+
32
+ ### Generate HTML + JSON reports
33
+
34
+ ```bash
35
+ diff-cover-js \
36
+ --lcov coverage/lcov.info \
37
+ --compare-branch origin/main \
38
+ --fail-under 80 \
39
+ --format html:reports/diff-cover.html,json:reports/diff-cover.json,markdown
40
+ ```
41
+
42
+ ### Use a config file instead of flags
43
+
44
+ Create `.diff-cover-js.json` in your project root:
45
+
46
+ ```json
47
+ {
48
+ "lcov": "coverage/lcov.info",
49
+ "compareBranch": "origin/main",
50
+ "failUnder": 80,
51
+ "format": "html:reports/diff-cover.html,json"
52
+ }
53
+ ```
54
+
55
+ Then just run:
56
+
57
+ ```bash
58
+ diff-cover-js
59
+ ```
60
+
61
+ ## CLI flags
62
+
63
+ | Flag | Default | Description |
64
+ |------|---------|-------------|
65
+ | `--lcov <path>` | — | Path to `lcov.info` coverage file |
66
+ | `--compare-branch <ref>` | — | Git branch or ref to compare against (e.g. `origin/main`, `FETCH_HEAD`) |
67
+ | `--fail-under <percent>` | `0` | Exit code 1 if diff coverage is below this |
68
+ | `--format <formats>` | — | Output formats: `html`, `json`, `markdown` — with optional paths |
69
+ | `--exclude <globs...>` | — | Additional glob patterns to exclude on top of the built-in defaults |
70
+ | `--no-default-excludes` | off | Skip the built-in test/spec/`.d.ts` file exclusions entirely |
71
+ | `--strict` | off | Treat files missing from coverage data as 0% covered |
72
+ | `--diff-range-notation <...∣..>` | `...` | Git diff range notation (symmetric `...` or simple `..`) |
73
+ | `-q, --quiet` | off | Only print the final percentage, suppress the full report |
74
+ | `-c, --config-file <path>` | auto | Path to config file (auto-discovered if omitted) |
75
+
76
+ ### Default excluded patterns
77
+
78
+ These file patterns are excluded from diff coverage by default (test/spec files and type declarations). Use `--no-default-excludes` to opt out entirely, or just use `--exclude` to add more patterns on top.
79
+
80
+ ```
81
+ **/*.test.ts **/*.test.tsx **/*.test.js **/*.test.jsx
82
+ **/*.spec.ts **/*.spec.tsx **/*.spec.js **/*.spec.jsx
83
+ **/__tests__/**
84
+ **/__mocks__/**
85
+ **/*.d.ts
86
+ ```
87
+
88
+ > **Note:** The Python diff-cover tool has no built-in default exclusions — it relies on explicit `--exclude` flags. The default exclusions here are a JS-ecosystem convenience. Pass `--no-default-excludes` to match the Python tool's behavior exactly.
89
+
90
+ ## Jest setup
91
+
92
+ Add `lcov` to your Jest coverage reporters:
93
+
94
+ ```js
95
+ // jest.config.js
96
+ module.exports = {
97
+ collectCoverage: true,
98
+ coverageDirectory: 'coverage',
99
+ coverageReporters: ['lcov', 'text'],
100
+ };
101
+ ```
102
+
103
+ ## How it works
104
+
105
+ 1. Runs `git diff <compare-branch>...HEAD --unified=0` to get the exact lines you added
106
+ 2. Reads `lcov.info` to get per-line hit counts for instrumented files
107
+ 3. Cross-references: for each added line, is it in the coverage data and was it executed?
108
+ 4. Non-executable lines (blank lines, comments, type declarations) are automatically skipped — they don't count for or against coverage
109
+ 5. Reports the percentage of your added executable lines that were covered
110
+
111
+ ## Output formats
112
+
113
+ **Console (default)**
114
+ ```
115
+ ────────────────────────────────────────────────────────────────
116
+ diff-cover-js · Diff Coverage Report
117
+
118
+ ✓ src/utils/foo.ts
119
+ 100% diff coverage (5/5 coverable changed lines)
120
+
121
+ ✗ src/services/bar.ts
122
+ 60% diff coverage (3/5 coverable changed lines)
123
+ Missing lines: 42, 45
124
+
125
+ ────────────────────────────────────────────────────────────────
126
+ Overall diff coverage: 72%
127
+ 8/10 coverable changed lines covered
128
+ ────────────────────────────────────────────────────────────────
129
+ ```
130
+
131
+ **HTML** — table with per-file coverage % and missing line ranges
132
+ **JSON** — structured output for CI dashboards and PR comment bots
133
+ **Markdown** — for posting in PR descriptions
134
+
135
+ ## Differences from Python diff-cover
136
+
137
+ | Feature | diff-cover (Python) | diff-cover-js |
138
+ |---------|---------------------|---------------|
139
+ | lcov support | ✓ | ✓ |
140
+ | HTML report | ✓ | ✓ |
141
+ | JSON report | ✓ | ✓ |
142
+ | Markdown report | ✓ | ✓ |
143
+ | Config file | TOML (`pyproject.toml`) | JSON (`.diff-cover-js.json`) |
144
+ | Code snippets in HTML | ✓ (via Pygments) | planned |
145
+ | diff-quality (lint violations) | ✓ | planned |
146
+ | Cobertura XML input | ✓ | not planned (lcov only) |
147
+ | Runtime | Python | Node.js |
148
+
149
+ ## License
150
+
151
+
152
+ MIT
@@ -0,0 +1,46 @@
1
+ import { FileDiff } from './git-diff';
2
+ import { LcovFileCoverage } from './lcov-parser';
3
+ export interface FileStats {
4
+ filePath: string;
5
+ /** Total added lines in the diff (includes non-executable lines) */
6
+ addedLines: number;
7
+ /** Added lines that appear as executable in lcov (blank/comment lines excluded) */
8
+ coverableAddedLines: number;
9
+ /** Count of covered executable changed lines */
10
+ coveredLines: number;
11
+ /** Actual covered line numbers (for JSON report consumers) */
12
+ coveredLineNumbers: number[];
13
+ /** Line numbers that are executable but not covered */
14
+ uncoveredLineNumbers: number[];
15
+ /** Integer percent, floored to match diff-cover's int() behavior */
16
+ coveragePercent: number;
17
+ /** False when the file was in the diff but had no entry in lcov */
18
+ inLcov: boolean;
19
+ }
20
+ export interface DiffCoverageResult {
21
+ files: FileStats[];
22
+ /** Files that appeared in the diff but had no lcov entry at all */
23
+ missingFromLcov: string[];
24
+ totalAdded: number;
25
+ totalCoverable: number;
26
+ totalCovered: number;
27
+ /** Integer percent, floored (matches diff-cover's int() truncation) */
28
+ overallPercent: number;
29
+ }
30
+ export declare const DEFAULT_EXCLUDES: string[];
31
+ export interface CalculatorOptions {
32
+ /**
33
+ * When true, files in the diff but absent from lcov are counted as 0% covered.
34
+ * Default (false): those files are listed as warnings but excluded from the %.
35
+ */
36
+ strict?: boolean;
37
+ /** Additional glob patterns to exclude from the diff analysis */
38
+ exclude?: string[];
39
+ /**
40
+ * When true, the built-in DEFAULT_EXCLUDES (test/spec/.d.ts files) are not applied.
41
+ * Only the patterns in `exclude` are used.
42
+ */
43
+ noDefaultExcludes?: boolean;
44
+ }
45
+ export declare function calculateDiffCoverage(diffs: FileDiff[], lcovData: Map<string, LcovFileCoverage>, options?: CalculatorOptions): DiffCoverageResult;
46
+ //# sourceMappingURL=calculator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculator.d.ts","sourceRoot":"","sources":["../src/calculator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjD,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IACnB,mFAAmF;IACnF,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,YAAY,EAAE,MAAM,CAAC;IACrB,8DAA8D;IAC9D,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,uDAAuD;IACvD,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,oEAAoE;IACpE,eAAe,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,mEAAmE;IACnE,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,cAAc,EAAE,MAAM,CAAC;CACxB;AAqCD,eAAO,MAAM,gBAAgB,UAY5B,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,QAAQ,EAAE,EACjB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACvC,OAAO,GAAE,iBAAsB,GAC9B,kBAAkB,CA8FpB"}
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_EXCLUDES = void 0;
4
+ exports.calculateDiffCoverage = calculateDiffCoverage;
5
+ const path_utils_1 = require("./path-utils");
6
+ // Glob → RegExp converter, processed character-by-character.
7
+ // Supports **/ (path prefix), ** (any chars), * (single segment), ? (single char).
8
+ function globToRegex(pattern) {
9
+ let result = '^';
10
+ let i = 0;
11
+ while (i < pattern.length) {
12
+ const ch = pattern[i];
13
+ if (ch === '*' && pattern[i + 1] === '*') {
14
+ if (pattern[i + 2] === '/') {
15
+ result += '(.+/)?'; // **/ → match zero or more path segments
16
+ i += 3;
17
+ }
18
+ else {
19
+ result += '.*'; // ** → match anything
20
+ i += 2;
21
+ }
22
+ }
23
+ else if (ch === '*') {
24
+ result += '[^/]*'; // * → match within a single segment
25
+ i++;
26
+ }
27
+ else if (ch === '?') {
28
+ result += '[^/]'; // ? → single non-slash char
29
+ i++;
30
+ }
31
+ else {
32
+ // Escape all regex special characters in literal parts
33
+ result += ch.replace(/[.+^${}()|[\]\\]/g, '\\$&');
34
+ i++;
35
+ }
36
+ }
37
+ result += '$';
38
+ return new RegExp(result);
39
+ }
40
+ function isExcluded(filePath, compiled) {
41
+ return compiled.some(re => re.test(filePath));
42
+ }
43
+ exports.DEFAULT_EXCLUDES = [
44
+ '**/*.test.ts',
45
+ '**/*.test.tsx',
46
+ '**/*.test.js',
47
+ '**/*.spec.ts',
48
+ '**/*.spec.tsx',
49
+ '**/*.spec.js',
50
+ '**/*.test.jsx',
51
+ '**/*.spec.jsx',
52
+ '**/__tests__/**',
53
+ '**/__mocks__/**',
54
+ '**/*.d.ts',
55
+ ];
56
+ function calculateDiffCoverage(diffs, lcovData, options = {}) {
57
+ var _a, _b;
58
+ const rawPatterns = options.noDefaultExcludes
59
+ ? [...((_a = options.exclude) !== null && _a !== void 0 ? _a : [])]
60
+ : [...exports.DEFAULT_EXCLUDES, ...((_b = options.exclude) !== null && _b !== void 0 ? _b : [])];
61
+ // Pre-compile once — not per file/pattern pair
62
+ const compiledExcludes = rawPatterns.map(globToRegex);
63
+ const normalizedLcov = new Map();
64
+ for (const [filePath, coverage] of lcovData) {
65
+ normalizedLcov.set((0, path_utils_1.normalizePath)(filePath), coverage);
66
+ }
67
+ const files = [];
68
+ const missingFromLcov = [];
69
+ let totalAdded = 0;
70
+ let totalCoverable = 0;
71
+ let totalCovered = 0;
72
+ for (const diff of diffs) {
73
+ if (isExcluded(diff.filePath, compiledExcludes))
74
+ continue;
75
+ const coverage = normalizedLcov.get(diff.filePath);
76
+ if (coverage === undefined) {
77
+ missingFromLcov.push(diff.filePath);
78
+ if (options.strict === true) {
79
+ const lines = Array.from(diff.addedLines).sort((a, b) => a - b);
80
+ files.push({
81
+ filePath: diff.filePath,
82
+ addedLines: diff.addedLines.size,
83
+ coverableAddedLines: diff.addedLines.size,
84
+ coveredLines: 0,
85
+ coveredLineNumbers: [],
86
+ uncoveredLineNumbers: lines,
87
+ coveragePercent: 0,
88
+ inLcov: false,
89
+ });
90
+ totalAdded += diff.addedLines.size;
91
+ totalCoverable += diff.addedLines.size;
92
+ }
93
+ continue;
94
+ }
95
+ let covered = 0;
96
+ let coverable = 0;
97
+ const coveredLineNumbers = [];
98
+ const uncoveredLineNumbers = [];
99
+ for (const lineNum of diff.addedLines) {
100
+ const hitCount = coverage.lines.get(lineNum);
101
+ if (hitCount === undefined) {
102
+ // Not in lcov = blank line / comment / import istanbul skips → not executable
103
+ continue;
104
+ }
105
+ coverable++;
106
+ if (hitCount > 0) {
107
+ covered++;
108
+ coveredLineNumbers.push(lineNum);
109
+ }
110
+ else {
111
+ uncoveredLineNumbers.push(lineNum);
112
+ }
113
+ }
114
+ coveredLineNumbers.sort((a, b) => a - b);
115
+ uncoveredLineNumbers.sort((a, b) => a - b);
116
+ // Floor to match diff-cover's int() truncation behavior.
117
+ // Example: 79.9% → 79 (not 80), so --fail-under 80 correctly fails.
118
+ const coveragePercent = coverable === 0
119
+ ? 100
120
+ : Math.floor((covered / coverable) * 100);
121
+ files.push({
122
+ filePath: diff.filePath,
123
+ addedLines: diff.addedLines.size,
124
+ coverableAddedLines: coverable,
125
+ coveredLines: covered,
126
+ coveredLineNumbers,
127
+ uncoveredLineNumbers,
128
+ coveragePercent,
129
+ inLcov: true,
130
+ });
131
+ totalAdded += diff.addedLines.size;
132
+ totalCoverable += coverable;
133
+ totalCovered += covered;
134
+ }
135
+ const overallPercent = totalCoverable === 0
136
+ ? 100
137
+ : Math.floor((totalCovered / totalCoverable) * 100);
138
+ return { files, missingFromLcov, totalAdded, totalCoverable, totalCovered, overallPercent };
139
+ }
140
+ //# sourceMappingURL=calculator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculator.js","sourceRoot":"","sources":["../src/calculator.ts"],"names":[],"mappings":";;;AAiGA,sDAkGC;AAjMD,6CAA6C;AA+B7C,6DAA6D;AAC7D,mFAAmF;AACnF,SAAS,WAAW,CAAE,OAAe;IACnC,IAAI,MAAM,GAAG,GAAG,CAAC;IACjB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,EAAE,KAAK,GAAG,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YACzC,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE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eAAe,GAAG,SAAS,KAAK,CAAC;YACrC,CAAC,CAAC,GAAG;YACL,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC,GAAG,GAAG,CAAC,CAAC;QAE5C,KAAK,CAAC,IAAI,CAAC;YACT,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI;YAChC,mBAAmB,EAAE,SAAS;YAC9B,YAAY,EAAE,OAAO;YACrB,kBAAkB;YAClB,oBAAoB;YACpB,eAAe;YACf,MAAM,EAAE,IAAI;SACb,CAAC,CAAC;QAEH,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QACnC,cAAc,IAAI,SAAS,CAAC;QAC5B,YAAY,IAAI,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM,cAAc,GAAG,cAAc,KAAK,CAAC;QACzC,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,YAAY,GAAG,cAAc,CAAC,GAAG,GAAG,CAAC,CAAC;IAEtD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAC9F,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const commander_1 = require("commander");
10
+ const git_diff_1 = require("./git-diff");
11
+ const lcov_parser_1 = require("./lcov-parser");
12
+ const calculator_1 = require("./calculator");
13
+ const reporter_1 = require("./reporter");
14
+ const report_generator_1 = require("./report-generator");
15
+ const config_1 = require("./config");
16
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
17
+ const { version } = require('../package.json');
18
+ const program = new commander_1.Command();
19
+ program
20
+ .name('diff-cover-js')
21
+ .description('Diff-aware test coverage: reports coverage only for lines you changed,\n' +
22
+ 'not the entire file. JS/TS equivalent of Python diff-cover.')
23
+ .version(version)
24
+ // Both use .option (not .requiredOption) so config-file values can satisfy them.
25
+ // Manual validation after config merge replaces Commander's built-in enforcement.
26
+ .option('--lcov <path>', 'Path to lcov.info coverage file')
27
+ .option('--compare-branch <ref>', 'Git branch or ref to compare against (e.g. origin/main, FETCH_HEAD)')
28
+ // No defaults here — defaults would silently shadow config-file values.
29
+ // Defaults are applied after config merge below.
30
+ .option('--format <formats>', 'Output formats: html, json, markdown — with optional paths')
31
+ .option('--fail-under <percent>', 'Exit with code 1 if diff coverage is below this percentage')
32
+ .option('--diff-range-notation <notation>', 'Git diff range notation: "..." (symmetric) or ".." (simple)')
33
+ .option('--exclude <patterns...>', 'Additional glob patterns to exclude (test files excluded by default)')
34
+ .option('--no-default-excludes', 'Do not apply the built-in test/spec/.d.ts file exclusions')
35
+ .option('--strict', 'Count files missing from coverage data as 0% covered')
36
+ // Boolean flags (.option without <value>) are undefined when absent, true when present — safe to use directly.
37
+ .option('-q, --quiet', 'Suppress the console report — only print errors and the final percentage')
38
+ .option('-c, --config-file <path>', 'Path to .diff-cover-js.json config file (auto-discovered if omitted)')
39
+ .action((cliOptions) => {
40
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
41
+ // ── Load config file ───────────────────────────────────────────────────
42
+ let fileConfig = {};
43
+ if (cliOptions.configFile) {
44
+ if (!fs_1.default.existsSync(cliOptions.configFile)) {
45
+ console.error(`❌ Config file not found: ${cliOptions.configFile}`);
46
+ process.exit(1);
47
+ }
48
+ try {
49
+ fileConfig = JSON.parse(fs_1.default.readFileSync(cliOptions.configFile, 'utf8'));
50
+ }
51
+ catch (err) {
52
+ console.error(`❌ Could not parse config file: ${err instanceof Error ? err.message : String(err)}`);
53
+ process.exit(1);
54
+ }
55
+ }
56
+ else {
57
+ fileConfig = (0, config_1.loadConfig)();
58
+ }
59
+ // ── Merge: config file provides defaults, CLI always wins ──────────────
60
+ // For string options, Commander leaves them undefined when not passed, so
61
+ // ?? correctly falls through to the config file value then the hardcoded default.
62
+ //
63
+ // For boolean flags (.option without <value>), Commander sets true when
64
+ // passed and leaves undefined when absent — so cliOptions.quiet === true
65
+ // is a reliable "was this flag passed?" check, no argv.includes() needed.
66
+ const lcovPath = (_a = cliOptions.lcov) !== null && _a !== void 0 ? _a : fileConfig.lcov;
67
+ const compareRef = (_b = cliOptions.compareBranch) !== null && _b !== void 0 ? _b : fileConfig.compareBranch;
68
+ const failUnder = parseFloat(String((_d = (_c = cliOptions.failUnder) !== null && _c !== void 0 ? _c : fileConfig.failUnder) !== null && _d !== void 0 ? _d : 0));
69
+ if (isNaN(failUnder)) {
70
+ console.error('❌ --fail-under must be a number (e.g. 80 or 80.5)');
71
+ process.exit(1);
72
+ }
73
+ const rangeNotation = ((_f = (_e = cliOptions.diffRangeNotation) !== null && _e !== void 0 ? _e : fileConfig.diffRangeNotation) !== null && _f !== void 0 ? _f : '...');
74
+ const formatRaw = (_h = (_g = cliOptions.format) !== null && _g !== void 0 ? _g : fileConfig.format) !== null && _h !== void 0 ? _h : '';
75
+ const quiet = cliOptions.quiet === true || fileConfig.quiet === true;
76
+ const strict = cliOptions.strict === true || fileConfig.strict === true;
77
+ // Commander --no-default-excludes sets cliOptions.defaultExcludes = false when the flag is passed,
78
+ // true when absent. So false means the user explicitly opted out of default exclusions.
79
+ const noDefaultExcludes = cliOptions.defaultExcludes === false || fileConfig.noDefaultExcludes === true;
80
+ const extraExcludes = [...((_j = cliOptions.exclude) !== null && _j !== void 0 ? _j : []), ...((_k = fileConfig.exclude) !== null && _k !== void 0 ? _k : [])];
81
+ const formats = (0, report_generator_1.parseFormatOption)(formatRaw);
82
+ // ── Validate required values ───────────────────────────────────────────
83
+ if (!lcovPath) {
84
+ console.error('❌ --lcov is required (or set "lcov" in .diff-cover-js.json)');
85
+ process.exit(1);
86
+ }
87
+ if (!compareRef) {
88
+ console.error('❌ --compare-branch is required (or set "compareBranch" in .diff-cover-js.json)');
89
+ process.exit(1);
90
+ }
91
+ if (!['...', '..'].includes(rangeNotation)) {
92
+ console.error('❌ --diff-range-notation must be "..." or ".."');
93
+ process.exit(1);
94
+ }
95
+ // ── Get git diff ───────────────────────────────────────────────────────
96
+ let diffs;
97
+ try {
98
+ diffs = (0, git_diff_1.getGitDiff)(compareRef, rangeNotation);
99
+ }
100
+ catch (err) {
101
+ console.error(`❌ ${err instanceof Error ? err.message : String(err)}`);
102
+ process.exit(1);
103
+ }
104
+ // ── Parse lcov ────────────────────────────────────────────────────────
105
+ const resolvedLcov = path_1.default.resolve(lcovPath);
106
+ let lcovData;
107
+ try {
108
+ lcovData = (0, lcov_parser_1.parseLcov)(resolvedLcov);
109
+ }
110
+ catch (err) {
111
+ console.error(`❌ Could not read lcov file at ${resolvedLcov}: ${err instanceof Error ? err.message : String(err)}`);
112
+ process.exit(1);
113
+ }
114
+ // ── Calculate ──────────────────────────────────────────────────────────
115
+ const result = (0, calculator_1.calculateDiffCoverage)(diffs, lcovData, { strict, exclude: extraExcludes, noDefaultExcludes });
116
+ // ── Console report ────────────────────────────────────────────────────
117
+ if (!quiet) {
118
+ (0, reporter_1.printReport)(result);
119
+ }
120
+ else {
121
+ console.log(`Diff coverage: ${result.overallPercent}%`);
122
+ }
123
+ // ── Write file reports (pass failUnder so HTML colours match threshold) ─
124
+ if (Object.keys(formats).length > 0) {
125
+ (0, report_generator_1.writeFormats)(formats, result, compareRef, failUnder);
126
+ }
127
+ // ── Fail-under check ──────────────────────────────────────────────────
128
+ if (failUnder > 0 && result.overallPercent < failUnder) {
129
+ console.error(`❌ Failure. Diff coverage ${result.overallPercent}% is below ${failUnder}%`);
130
+ process.exit(1);
131
+ }
132
+ });
133
+ program.parse(process.argv);
134
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AACA,4CAAoB;AACpB,gDAAwB;AACxB,yCAAoC;AACpC,yCAAuD;AACvD,+CAA0C;AAC1C,6CAAqD;AACrD,yCAAyC;AACzC,yDAAqE;AACrE,qCAAuD;AAEvD,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAwB,CAAC;AAEtE,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,eAAe,CAAC;KACrB,WAAW,CACV,0EAA0E;IAC1E,6DAA6D,CAC9D;KACA,OAAO,CAAC,OAAO,CAAC;IAEjB,iFAAiF;IACjF,kFAAkF;KACjF,MAAM,CAAC,eAAe,EAAE,iCAAiC,CAAC;KAC1D,MAAM,CAAC,wBAAwB,EAAE,qEAAqE,CAAC;IAExG,wEAAwE;IACxE,iDAAiD;KAChD,MAAM,CAAC,oBAAoB,EAAE,4DAA4D,CAAC;KAC1F,MAAM,CAAC,wBAAwB,EAAE,4DAA4D,CAAC;KAC9F,MAAM,CAAC,kCAAkC,EAAE,6DAA6D,CAAC;KAEzG,MAAM,CAAC,yBAAyB,EAAE,sEAAsE,CAAC;KACzG,MAAM,CAAC,uBAAuB,EAAE,2DAA2D,CAAC;KAC5F,MAAM,CAAC,UAAU,EAAE,sDAAsD,CAAC;IAC3E,+GAA+G;KAC9G,MAAM,CAAC,aAAa,EAAE,0EAA0E,CAAC;KACjG,MAAM,CAAC,0BAA0B,EAAE,sEAAsE,CAAC;KAE1G,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;;IAC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ACN,OAAO,CAAC,GAAG,CAAC,kBAAkB,MAAM,CAAC,cAAc,GAAG,CAAC,CAAC;IAC1D,CAAC;IAED,2EAA2E;IAC3E,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpC,IAAA,+BAAY,EAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,yEAAyE;IACzE,IAAI,SAAS,GAAG,CAAC,IAAI,MAAM,CAAC,cAAc,GAAG,SAAS,EAAE,CAAC;QACvD,OAAO,CAAC,KAAK,CAAC,4BAA4B,MAAM,CAAC,cAAc,cAAc,SAAS,GAAG,CAAC,CAAC;QAC3F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ export interface DiffCoverConfig {
2
+ lcov?: string;
3
+ compareBranch?: string;
4
+ failUnder?: number;
5
+ exclude?: string[];
6
+ strict?: boolean;
7
+ quiet?: boolean;
8
+ diffRangeNotation?: '...' | '..';
9
+ format?: string;
10
+ noDefaultExcludes?: boolean;
11
+ }
12
+ /**
13
+ * Load config from the first matching file found, searching upward from cwd.
14
+ * Mirrors diff-cover's config_parser.py — CLI args always override config file values.
15
+ */
16
+ export declare function loadConfig(startDir?: string): DiffCoverConfig;
17
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iBAAiB,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAOD;;;GAGG;AACH,wBAAgB,UAAU,CAAE,QAAQ,SAAgB,GAAG,eAAe,CAwBrE"}
package/dist/config.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadConfig = loadConfig;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const CONFIG_FILE_NAMES = [
10
+ '.diff-cover-js.json',
11
+ 'diff-cover-js.json',
12
+ ];
13
+ /**
14
+ * Load config from the first matching file found, searching upward from cwd.
15
+ * Mirrors diff-cover's config_parser.py — CLI args always override config file values.
16
+ */
17
+ function loadConfig(startDir = process.cwd()) {
18
+ let dir = startDir;
19
+ while (true) {
20
+ for (const name of CONFIG_FILE_NAMES) {
21
+ const filePath = path_1.default.join(dir, name);
22
+ if (fs_1.default.existsSync(filePath)) {
23
+ try {
24
+ return JSON.parse(fs_1.default.readFileSync(filePath, 'utf8'));
25
+ }
26
+ catch (err) {
27
+ console.warn(`⚠ Could not parse config file ${filePath}: ${err instanceof Error ? err.message : String(err)}`);
28
+ return {};
29
+ }
30
+ }
31
+ }
32
+ const parent = path_1.default.dirname(dir);
33
+ if (parent === dir)
34
+ break;
35
+ dir = parent;
36
+ }
37
+ return {};
38
+ }
39
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;AAwBA,gCAwBC;AAhDD,4CAAoB;AACpB,gDAAwB;AAcxB,MAAM,iBAAiB,GAAG;IACxB,qBAAqB;IACrB,oBAAoB;CACrB,CAAC;AAEF;;;GAGG;AACH,SAAgB,UAAU,CAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE;IAClD,IAAI,GAAG,GAAG,QAAQ,CAAC;IAEnB,OAAO,IAAI,EAAE,CAAC;QACZ,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE,CAAC;YACrC,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACtC,IAAI,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC5B,IAAI,CAAC;oBACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAoB,CAAC;gBAC1E,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,CAAC,IAAI,CACV,kCAAkC,QAAQ,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAClG,CAAC;oBACF,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,MAAM,KAAK,GAAG;YAAE,MAAM;QAC1B,GAAG,GAAG,MAAM,CAAC;IACf,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,19 @@
1
+ export interface FileDiff {
2
+ /** Normalized relative path of the file in the new version */
3
+ filePath: string;
4
+ /** Line numbers (in the new file) that were added in this diff */
5
+ addedLines: Set<number>;
6
+ /** True if this is a brand-new file (all lines are additions) */
7
+ isNew: boolean;
8
+ }
9
+ export type RangeNotation = '...' | '..';
10
+ /**
11
+ * Run `git diff <compareRef><rangeNotation>HEAD` and return added line numbers per file.
12
+ *
13
+ * Uses spawnSync (no shell) to prevent command injection from user-supplied compareRef.
14
+ * --no-color and --no-ext-diff prevent ANSI escape codes from corrupting parse-diff output.
15
+ * --unified=0 gives no context lines so every hunk line is purely + or -.
16
+ * --diff-filter=ACMR skips deleted files.
17
+ */
18
+ export declare function getGitDiff(compareRef: string, rangeNotation?: RangeNotation): FileDiff[];
19
+ //# sourceMappingURL=git-diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-diff.d.ts","sourceRoot":"","sources":["../src/git-diff.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,QAAQ;IACvB,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,iEAAiE;IACjE,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,IAAI,CAAC;AAEzC;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAE,UAAU,EAAE,MAAM,EAAE,aAAa,GAAE,aAAqB,GAAG,QAAQ,EAAE,CA8DhG"}