diff-cover-js 0.1.0 → 0.2.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/README.md +62 -3
- package/dist/calculator.d.ts.map +1 -1
- package/dist/calculator.js +12 -1
- package/dist/calculator.js.map +1 -1
- package/dist/cli.js +7 -1
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/git-diff.d.ts +51 -4
- package/dist/git-diff.d.ts.map +1 -1
- package/dist/git-diff.js +340 -38
- package/dist/git-diff.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/lcov-parser.d.ts +13 -0
- package/dist/lcov-parser.d.ts.map +1 -1
- package/dist/lcov-parser.js +35 -3
- package/dist/lcov-parser.js.map +1 -1
- package/dist/path-utils.d.ts +11 -3
- package/dist/path-utils.d.ts.map +1 -1
- package/dist/path-utils.js +17 -8
- package/dist/path-utils.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -29,6 +29,8 @@ diff-cover-js \
|
|
|
29
29
|
--fail-under 80
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
By default this counts committed, staged **and** unstaged changes, like Python diff-cover. See [Uncommitted changes](#uncommitted-changes).
|
|
33
|
+
|
|
32
34
|
### Generate HTML + JSON reports
|
|
33
35
|
|
|
34
36
|
```bash
|
|
@@ -48,7 +50,10 @@ Create `.diff-cover-js.json` in your project root:
|
|
|
48
50
|
"lcov": "coverage/lcov.info",
|
|
49
51
|
"compareBranch": "origin/main",
|
|
50
52
|
"failUnder": 80,
|
|
51
|
-
"format": "html:reports/diff-cover.html,json"
|
|
53
|
+
"format": "html:reports/diff-cover.html,json",
|
|
54
|
+
"ignoreStaged": false,
|
|
55
|
+
"ignoreUnstaged": false,
|
|
56
|
+
"includeUntracked": false
|
|
52
57
|
}
|
|
53
58
|
```
|
|
54
59
|
|
|
@@ -58,6 +63,22 @@ Then just run:
|
|
|
58
63
|
diff-cover-js
|
|
59
64
|
```
|
|
60
65
|
|
|
66
|
+
### Use it as a library
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { getGitDiff, parseLcov, calculateDiffCoverage } from 'diff-cover-js';
|
|
70
|
+
|
|
71
|
+
const diffs = getGitDiff('origin/main', '...', {
|
|
72
|
+
ignoreStaged: false, // optional, same as --ignore-staged
|
|
73
|
+
ignoreUnstaged: false, // optional, same as --ignore-unstaged
|
|
74
|
+
includeUntracked: false, // optional, same as --include-untracked
|
|
75
|
+
});
|
|
76
|
+
const result = calculateDiffCoverage(diffs, parseLcov('coverage/lcov.info'));
|
|
77
|
+
console.log(result.overallPercent);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`mergeLcovCoverage(into, from)` is also exported for combining coverage records for the same file.
|
|
81
|
+
|
|
61
82
|
## CLI flags
|
|
62
83
|
|
|
63
84
|
| Flag | Default | Description |
|
|
@@ -70,6 +91,9 @@ diff-cover-js
|
|
|
70
91
|
| `--no-default-excludes` | off | Skip the built-in test/spec/`.d.ts` file exclusions entirely |
|
|
71
92
|
| `--strict` | off | Treat files missing from coverage data as 0% covered |
|
|
72
93
|
| `--diff-range-notation <...∣..>` | `...` | Git diff range notation (symmetric `...` or simple `..`) |
|
|
94
|
+
| `--ignore-staged` | off | Don't count staged changes |
|
|
95
|
+
| `--ignore-unstaged` | off | Don't count unstaged changes in the working tree |
|
|
96
|
+
| `--include-untracked` | off | Also count untracked files (not ignored by `.gitignore`); every line counts as added |
|
|
73
97
|
| `-q, --quiet` | off | Only print the final percentage, suppress the full report |
|
|
74
98
|
| `-c, --config-file <path>` | auto | Path to config file (auto-discovered if omitted) |
|
|
75
99
|
|
|
@@ -102,12 +126,34 @@ module.exports = {
|
|
|
102
126
|
|
|
103
127
|
## How it works
|
|
104
128
|
|
|
105
|
-
1.
|
|
106
|
-
2. Reads `lcov.info` to get per-line hit counts for instrumented files
|
|
129
|
+
1. Finds the base commit (`git merge-base <compare-branch> HEAD`, or the compare branch itself with `--diff-range-notation ..`) and runs `git diff <base> --unified=0` to get the exact lines you added, including staged and unstaged changes
|
|
130
|
+
2. Reads `lcov.info` to get per-line hit counts for instrumented files. If the same source file appears in several `SF:` blocks (Jest multi-project setups, concatenated or sharded reports), or under different paths that resolve to the same file, the blocks are merged by adding hit counts, as `lcov` does
|
|
107
131
|
3. Cross-references: for each added line, is it in the coverage data and was it executed?
|
|
108
132
|
4. Non-executable lines (blank lines, comments, type declarations) are automatically skipped — they don't count for or against coverage
|
|
109
133
|
5. Reports the percentage of your added executable lines that were covered
|
|
110
134
|
|
|
135
|
+
## Uncommitted changes
|
|
136
|
+
|
|
137
|
+
> **Changed in 0.2.0:** staged and unstaged changes are now counted by default, matching Python diff-cover. 0.1.x only counted committed changes (`git diff <compare-branch>...HEAD`). In CI with a clean checkout the result is the same as before. If a CI step modifies tracked files before diff-cover-js runs (code generation, `npm install` rewriting `package-lock.json`, version stamping), those edits are now counted as changed lines; with `--strict`, files missing from coverage count as 0%. To get the 0.1.x behaviour, pass `--ignore-staged --ignore-unstaged`.
|
|
138
|
+
|
|
139
|
+
Line numbers in the report always refer to the file **as it is on disk now**, because that is what your tests ran against when they produced `lcov.info`. To keep them right, each mode uses a single diff against the base instead of combining separate committed/staged/unstaged diffs:
|
|
140
|
+
|
|
141
|
+
| Mode | Lines counted | How |
|
|
142
|
+
|------|---------------|-----|
|
|
143
|
+
| default | committed + staged + unstaged | `git diff <base>` (base vs working tree) |
|
|
144
|
+
| `--ignore-unstaged` | committed + staged | `git diff --cached <base>` (base vs index), line numbers mapped to the working tree through `git diff` |
|
|
145
|
+
| `--ignore-staged --ignore-unstaged` | committed only | `git diff <base> HEAD`, line numbers mapped to the working tree through `git diff HEAD` |
|
|
146
|
+
| `--ignore-staged` | committed + unstaged | `git diff <base>`, minus the lines whose current content came from a staged change (see below) |
|
|
147
|
+
| `--include-untracked` | adds untracked files | `git ls-files --others --exclude-standard`; every line of each text file counts as added. Binary files, symlinks and empty or unreadable files are skipped. Works with any of the modes above |
|
|
148
|
+
|
|
149
|
+
When a mode excludes some changes, a line is counted only if its current content comes from a change that is included. For example, with `--ignore-unstaged`, a staged line that you then edited again without staging is not counted, because what is on disk now is the unstaged edit. Lines that a later, excluded change moved are reported at their new position.
|
|
150
|
+
|
|
151
|
+
**`--ignore-staged` on its own.** No single `git diff` gives "committed + unstaged without staged". Python diff-cover runs the committed and unstaged diffs separately, then for each one removes that diff's deleted line numbers and adds its added ones. It doesn't shift the other line numbers, so they drift when both diffs touch the same file. diff-cover-js instead starts from `git diff <base>` (everything that differs from the base on disk). It then removes the lines added by the staged diff (`git diff --cached HEAD`), after moving them to their working-tree positions with `git diff`. Limitations:
|
|
152
|
+
|
|
153
|
+
- A line added in a commit and then modified by a staged change counts as staged, so it is excluded. Python counts it, at its line number in `HEAD`.
|
|
154
|
+
- A staged line that you edited again without staging counts as an unstaged change, so it is included.
|
|
155
|
+
- If your git config sets `diff.renames=false`, a file renamed with a staged `git mv` is reported in full by `--ignore-staged` (your config treats it as a new file), but only its committed lines by `--ignore-staged --ignore-unstaged`. This errs towards counting more lines, so it can't hide an uncovered line.
|
|
156
|
+
|
|
111
157
|
## Output formats
|
|
112
158
|
|
|
113
159
|
**Console (default)**
|
|
@@ -141,11 +187,24 @@ module.exports = {
|
|
|
141
187
|
| JSON report | ✓ | ✓ |
|
|
142
188
|
| Markdown report | ✓ | ✓ |
|
|
143
189
|
| Config file | TOML (`pyproject.toml`) | JSON (`.diff-cover-js.json`) |
|
|
190
|
+
| `--ignore-staged` / `--ignore-unstaged` / `--include-untracked` | ✓ | ✓ |
|
|
191
|
+
| Line numbers when committed, staged and unstaged changes touch the same file | Can drift: each diff's line numbers are combined without shifting | Always match the file on disk (see [Uncommitted changes](#uncommitted-changes)) |
|
|
144
192
|
| Code snippets in HTML | ✓ (via Pygments) | planned |
|
|
145
193
|
| diff-quality (lint violations) | ✓ | planned |
|
|
146
194
|
| Cobertura XML input | ✓ | not planned (lcov only) |
|
|
147
195
|
| Runtime | Python | Node.js |
|
|
148
196
|
|
|
197
|
+
## Development
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
npm install
|
|
201
|
+
npm run build # compile to dist/
|
|
202
|
+
npm test # vitest
|
|
203
|
+
npm run typecheck # type-check src/ and test/
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The package runs on Node.js >= 16, but the test tooling (vitest/vite) needs Node.js ^20.19 or >= 22.12.
|
|
207
|
+
|
|
149
208
|
## License
|
|
150
209
|
|
|
151
210
|
|
package/dist/calculator.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,EAAqB,MAAM,eAAe,CAAC;AAGpE,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,CAuGpB"}
|
package/dist/calculator.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_EXCLUDES = void 0;
|
|
4
4
|
exports.calculateDiffCoverage = calculateDiffCoverage;
|
|
5
|
+
const lcov_parser_1 = require("./lcov-parser");
|
|
5
6
|
const path_utils_1 = require("./path-utils");
|
|
6
7
|
// Glob → RegExp converter, processed character-by-character.
|
|
7
8
|
// Supports **/ (path prefix), ** (any chars), * (single segment), ? (single char).
|
|
@@ -60,9 +61,19 @@ function calculateDiffCoverage(diffs, lcovData, options = {}) {
|
|
|
60
61
|
: [...exports.DEFAULT_EXCLUDES, ...((_b = options.exclude) !== null && _b !== void 0 ? _b : [])];
|
|
61
62
|
// Pre-compile once — not per file/pattern pair
|
|
62
63
|
const compiledExcludes = rawPatterns.map(globToRegex);
|
|
64
|
+
// Different raw paths (e.g. "/abs/repo/src/a.ts" and "src/a.ts") can normalize to the
|
|
65
|
+
// same file. Merge them instead of letting the last one win. Each entry is copied before
|
|
66
|
+
// merging so the caller's lcovData is never mutated.
|
|
63
67
|
const normalizedLcov = new Map();
|
|
64
68
|
for (const [filePath, coverage] of lcovData) {
|
|
65
|
-
|
|
69
|
+
const key = (0, path_utils_1.toRepoRelativePath)(filePath);
|
|
70
|
+
const existing = normalizedLcov.get(key);
|
|
71
|
+
if (existing === undefined) {
|
|
72
|
+
normalizedLcov.set(key, { filePath: coverage.filePath, lines: new Map(coverage.lines) });
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
(0, lcov_parser_1.mergeLcovCoverage)(existing, coverage);
|
|
76
|
+
}
|
|
66
77
|
}
|
|
67
78
|
const files = [];
|
|
68
79
|
const missingFromLcov = [];
|
package/dist/calculator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculator.js","sourceRoot":"","sources":["../src/calculator.ts"],"names":[],"mappings":";;;AAiGA,
|
|
1
|
+
{"version":3,"file":"calculator.js","sourceRoot":"","sources":["../src/calculator.ts"],"names":[],"mappings":";;;AAiGA,sDA2GC;AA3MD,+CAAoE;AACpE,6CAAkD;AA+BlD,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,CAAC;gBAC3B,MAAM,IAAI,QAAQ,CAAC,CAAC,yCAAyC;gBAC7D,CAAC,IAAI,CAAC,CAAC;YACT,CAAC;iBAAM,C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CAAC;YACrC,CAAC;QACH,CAAC;QAED,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAE3C,yDAAyD;QACzD,oEAAoE;QACpE,MAAM,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.js
CHANGED
|
@@ -33,6 +33,9 @@ program
|
|
|
33
33
|
.option('--exclude <patterns...>', 'Additional glob patterns to exclude (test files excluded by default)')
|
|
34
34
|
.option('--no-default-excludes', 'Do not apply the built-in test/spec/.d.ts file exclusions')
|
|
35
35
|
.option('--strict', 'Count files missing from coverage data as 0% covered')
|
|
36
|
+
.option('--ignore-staged', 'Ignore staged changes')
|
|
37
|
+
.option('--ignore-unstaged', 'Ignore unstaged changes')
|
|
38
|
+
.option('--include-untracked', 'Include untracked files (every line counts as added)')
|
|
36
39
|
// Boolean flags (.option without <value>) are undefined when absent, true when present — safe to use directly.
|
|
37
40
|
.option('-q, --quiet', 'Suppress the console report — only print errors and the final percentage')
|
|
38
41
|
.option('-c, --config-file <path>', 'Path to .diff-cover-js.json config file (auto-discovered if omitted)')
|
|
@@ -74,6 +77,9 @@ program
|
|
|
74
77
|
const formatRaw = (_h = (_g = cliOptions.format) !== null && _g !== void 0 ? _g : fileConfig.format) !== null && _h !== void 0 ? _h : '';
|
|
75
78
|
const quiet = cliOptions.quiet === true || fileConfig.quiet === true;
|
|
76
79
|
const strict = cliOptions.strict === true || fileConfig.strict === true;
|
|
80
|
+
const ignoreStaged = cliOptions.ignoreStaged === true || fileConfig.ignoreStaged === true;
|
|
81
|
+
const ignoreUnstaged = cliOptions.ignoreUnstaged === true || fileConfig.ignoreUnstaged === true;
|
|
82
|
+
const includeUntracked = cliOptions.includeUntracked === true || fileConfig.includeUntracked === true;
|
|
77
83
|
// Commander --no-default-excludes sets cliOptions.defaultExcludes = false when the flag is passed,
|
|
78
84
|
// true when absent. So false means the user explicitly opted out of default exclusions.
|
|
79
85
|
const noDefaultExcludes = cliOptions.defaultExcludes === false || fileConfig.noDefaultExcludes === true;
|
|
@@ -95,7 +101,7 @@ program
|
|
|
95
101
|
// ── Get git diff ───────────────────────────────────────────────────────
|
|
96
102
|
let diffs;
|
|
97
103
|
try {
|
|
98
|
-
diffs = (0, git_diff_1.getGitDiff)(compareRef, rangeNotation);
|
|
104
|
+
diffs = (0, git_diff_1.getGitDiff)(compareRef, rangeNotation, { ignoreStaged, ignoreUnstaged, includeUntracked });
|
|
99
105
|
}
|
|
100
106
|
catch (err) {
|
|
101
107
|
console.error(`❌ ${err instanceof Error ? err.message : String(err)}`);
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +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;
|
|
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,G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sBAAW,EAAC,MAAM,CAAC,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,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"}
|
package/dist/config.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ export interface DiffCoverConfig {
|
|
|
8
8
|
diffRangeNotation?: '...' | '..';
|
|
9
9
|
format?: string;
|
|
10
10
|
noDefaultExcludes?: boolean;
|
|
11
|
+
/** Exclude staged changes (same as --ignore-staged) */
|
|
12
|
+
ignoreStaged?: boolean;
|
|
13
|
+
/** Exclude unstaged changes (same as --ignore-unstaged) */
|
|
14
|
+
ignoreUnstaged?: boolean;
|
|
15
|
+
/** Count untracked files, every line as added (same as --include-untracked) */
|
|
16
|
+
includeUntracked?: boolean;
|
|
11
17
|
}
|
|
12
18
|
/**
|
|
13
19
|
* Load config from the first matching file found, searching upward from cwd.
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;IAC5B,uDAAuD;IACvD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,+EAA+E;IAC/E,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAOD;;;GAGG;AACH,wBAAgB,UAAU,CAAE,QAAQ,SAAgB,GAAG,eAAe,CAwBrE"}
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;AA8BA,gCAwBC;AAtDD,4CAAoB;AACpB,gDAAwB;AAoBxB,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"}
|
package/dist/git-diff.d.ts
CHANGED
|
@@ -7,13 +7,60 @@ export interface FileDiff {
|
|
|
7
7
|
isNew: boolean;
|
|
8
8
|
}
|
|
9
9
|
export type RangeNotation = '...' | '..';
|
|
10
|
+
export interface GitDiffOptions {
|
|
11
|
+
/** Exclude changes that are staged in the index (Python diff-cover: --ignore-staged). */
|
|
12
|
+
ignoreStaged?: boolean;
|
|
13
|
+
/** Exclude changes in the working tree that are not staged (Python diff-cover: --ignore-unstaged). */
|
|
14
|
+
ignoreUnstaged?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Also report untracked files (not ignored by .gitignore), with every line
|
|
17
|
+
* counted as added (Python diff-cover: --include-untracked). Default: false.
|
|
18
|
+
*/
|
|
19
|
+
includeUntracked?: boolean;
|
|
20
|
+
/** Directory to run git in. Defaults to process.cwd(). */
|
|
21
|
+
cwd?: string;
|
|
22
|
+
}
|
|
10
23
|
/**
|
|
11
|
-
*
|
|
24
|
+
* Return the lines added relative to the base, per file. Line numbers always refer to the
|
|
25
|
+
* file as it is on disk now, because lcov is generated from the working tree.
|
|
26
|
+
*
|
|
27
|
+
* The base is `git merge-base <compareRef> HEAD` for "..." notation, or <compareRef> for "..".
|
|
28
|
+
* Rather than running the committed, staged and unstaged diffs separately and merging their line
|
|
29
|
+
* numbers (which gives wrong numbers when several of them touch one file), each mode uses one
|
|
30
|
+
* diff against the base, then translates line numbers to the working tree when needed:
|
|
31
|
+
*
|
|
32
|
+
* default (all changes): git diff <base> (base → working tree)
|
|
33
|
+
* ignoreUnstaged: git diff --cached <base> (base → index), then mapped through
|
|
34
|
+
* `git diff` (index → working tree)
|
|
35
|
+
* ignoreStaged + ignoreUnstaged:
|
|
36
|
+
* git diff <base> HEAD (base → HEAD), then mapped through
|
|
37
|
+
* `git diff HEAD` (HEAD → working tree)
|
|
38
|
+
* ignoreStaged only: no single git diff gives "committed + unstaged". Python diff-cover
|
|
39
|
+
* applies the committed and unstaged diffs one after the other,
|
|
40
|
+
* dropping "deleted" line numbers and adding "added" ones without
|
|
41
|
+
* shifting the rest, so its line numbers drift whenever both touch one
|
|
42
|
+
* file. Instead we take the default result (git diff <base>) and remove
|
|
43
|
+
* the lines whose current content was written by a staged change: the
|
|
44
|
+
* lines added by `git diff --cached HEAD`, mapped to the working tree
|
|
45
|
+
* through `git diff`. Staged lines that were edited again later
|
|
46
|
+
* (unstaged) count as unstaged changes and are kept.
|
|
47
|
+
*
|
|
48
|
+
* In the mapping steps, a line that an excluded change later rewrote or deleted is dropped,
|
|
49
|
+
* because its current content comes from that excluded change. When the working tree is clean,
|
|
50
|
+
* the mapping diffs are empty and every mode returns plain `git diff <base>` results.
|
|
51
|
+
*
|
|
52
|
+
* Known limitations:
|
|
53
|
+
* - ignoreStaged only: a line added by a commit and then modified by a staged change counts as
|
|
54
|
+
* staged and is excluded. Python counts it, at its HEAD line number.
|
|
55
|
+
* - With the user's git config diff.renames=false, the reported diffs follow that config (a
|
|
56
|
+
* renamed file is all new) but the staged and mapping diffs force rename detection. After a
|
|
57
|
+
* staged `git mv`, ignoreStaged alone therefore still reports every line of the renamed file,
|
|
58
|
+
* while ignoreStaged + ignoreUnstaged reports only its committed lines. This over-reports, so
|
|
59
|
+
* it can lower coverage but never hide an uncovered line. Forcing renames on the reported diff
|
|
60
|
+
* instead would make ignoreStaged differ from the default mode even with nothing staged.
|
|
12
61
|
*
|
|
13
62
|
* 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
63
|
* --diff-filter=ACMR skips deleted files.
|
|
17
64
|
*/
|
|
18
|
-
export declare function getGitDiff(compareRef: string, rangeNotation?: RangeNotation): FileDiff[];
|
|
65
|
+
export declare function getGitDiff(compareRef: string, rangeNotation?: RangeNotation, options?: GitDiffOptions): FileDiff[];
|
|
19
66
|
//# sourceMappingURL=git-diff.d.ts.map
|
package/dist/git-diff.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-diff.d.ts","sourceRoot":"","sources":["../src/git-diff.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"git-diff.d.ts","sourceRoot":"","sources":["../src/git-diff.ts"],"names":[],"mappings":"AAKA,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,MAAM,WAAW,cAAc;IAC7B,yFAAyF;IACzF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sGAAsG;IACtG,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,0DAA0D;IAC1D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAkTD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,MAAM,EAClB,aAAa,GAAE,aAAqB,EACpC,OAAO,GAAE,cAAmB,GAC3B,QAAQ,EAAE,CAqCZ"}
|
package/dist/git-diff.js
CHANGED
|
@@ -4,33 +4,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getGitDiff = getGitDiff;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
7
9
|
const child_process_1 = require("child_process");
|
|
8
10
|
const parse_diff_1 = __importDefault(require("parse-diff"));
|
|
9
|
-
const
|
|
11
|
+
const GIT_CONFIG_OVERRIDES = [
|
|
12
|
+
// Suppress prefix and mnemonic-prefix config that could alter path format
|
|
13
|
+
'-c', 'diff.noprefix=no',
|
|
14
|
+
'-c', 'diff.mnemonicprefix=no',
|
|
15
|
+
// Force plain path output so parse-diff sees unquoted paths for non-ASCII filenames
|
|
16
|
+
'-c', 'core.quotePath=false',
|
|
17
|
+
];
|
|
18
|
+
// --no-color and --no-ext-diff prevent ANSI escape codes / external tools from corrupting
|
|
19
|
+
// parse-diff output. --unified=0 gives no context lines so every hunk line is purely + or -,
|
|
20
|
+
// and makes hunk headers describe exactly the changed ranges (needed for line mapping).
|
|
21
|
+
const DIFF_FLAGS = ['--unified=0', '--no-color', '--no-ext-diff'];
|
|
22
|
+
/** Diffs whose added lines we report. --diff-filter=ACMR skips deleted files. */
|
|
23
|
+
function changesDiffArgs(revs) {
|
|
24
|
+
return [...GIT_CONFIG_OVERRIDES, 'diff', ...revs, ...DIFF_FLAGS, '--diff-filter=ACMR'];
|
|
25
|
+
}
|
|
10
26
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* --unified=0 gives no context lines so every hunk line is purely + or -.
|
|
16
|
-
* --diff-filter=ACMR skips deleted files.
|
|
27
|
+
* Diffs used only to translate line numbers into working-tree coordinates.
|
|
28
|
+
* No --diff-filter, because we must see deletions to drop files that no longer exist.
|
|
29
|
+
* diff.renames=true forces rename detection (and turns off copy detection, which would
|
|
30
|
+
* give one source path several destinations) regardless of the user's git config.
|
|
17
31
|
*/
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
'diff',
|
|
27
|
-
`${compareRef}${rangeNotation}HEAD`,
|
|
28
|
-
'--unified=0',
|
|
29
|
-
'--diff-filter=ACMR',
|
|
30
|
-
'--no-color',
|
|
31
|
-
'--no-ext-diff',
|
|
32
|
-
];
|
|
32
|
+
function mappingDiffArgs(revs) {
|
|
33
|
+
return [...GIT_CONFIG_OVERRIDES, '-c', 'diff.renames=true', 'diff', ...revs, ...DIFF_FLAGS];
|
|
34
|
+
}
|
|
35
|
+
function fetchHint(compareRef) {
|
|
36
|
+
return `Make sure "${compareRef}" is fetched before running diff-cover-js.`;
|
|
37
|
+
}
|
|
38
|
+
/** Spawn git without a shell. Throws only if git could not be started. */
|
|
39
|
+
function spawnGit(args, cwd, name, hint) {
|
|
33
40
|
const proc = (0, child_process_1.spawnSync)('git', args, {
|
|
41
|
+
cwd,
|
|
34
42
|
encoding: 'utf8',
|
|
35
43
|
maxBuffer: 50 * 1024 * 1024,
|
|
36
44
|
});
|
|
@@ -38,33 +46,327 @@ function getGitDiff(compareRef, rangeNotation = '...') {
|
|
|
38
46
|
const isNotFound = proc.error.code === 'ENOENT';
|
|
39
47
|
throw new Error(isNotFound
|
|
40
48
|
? 'git not found. Make sure git is installed and available in your PATH.'
|
|
41
|
-
:
|
|
49
|
+
: `${name} failed: ${proc.error.message}${hint ? `\n${hint}` : ''}`);
|
|
42
50
|
}
|
|
51
|
+
return proc;
|
|
52
|
+
}
|
|
53
|
+
/** Run git and return stdout. Throws on a non-zero exit status. */
|
|
54
|
+
function runGit(args, cwd, name, hint) {
|
|
55
|
+
var _a, _b, _c;
|
|
56
|
+
const proc = spawnGit(args, cwd, name, hint);
|
|
43
57
|
if (proc.status !== 0) {
|
|
44
58
|
const stderr = (_b = (_a = proc.stderr) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
|
|
45
|
-
throw new Error(
|
|
59
|
+
throw new Error(`${name} exited with code ${proc.status}: ${stderr}${hint ? `\n${hint}` : ''}`);
|
|
46
60
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
return (_c = proc.stdout) !== null && _c !== void 0 ? _c : '';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolve the commit that changes are measured against:
|
|
65
|
+
* "..." → git merge-base <compareRef> HEAD
|
|
66
|
+
* ".." → <compareRef> itself
|
|
67
|
+
* Returns a full commit hash, so later git commands never see a user-supplied string.
|
|
68
|
+
*/
|
|
69
|
+
function resolveDiffBase(compareRef, rangeNotation, cwd) {
|
|
70
|
+
var _a, _b, _c, _d;
|
|
71
|
+
if (rangeNotation !== '...' && rangeNotation !== '..') {
|
|
72
|
+
throw new Error(`Invalid diff range notation "${String(rangeNotation)}": must be "..." or "..".`);
|
|
73
|
+
}
|
|
74
|
+
if (!compareRef) {
|
|
75
|
+
throw new Error('A compare ref is required (e.g. origin/main).');
|
|
76
|
+
}
|
|
77
|
+
// Without this, a ref like "--output=x" would be parsed by git as an option.
|
|
78
|
+
if (compareRef.startsWith('-')) {
|
|
79
|
+
throw new Error(`Invalid compare ref "${compareRef}": a git ref cannot start with "-".`);
|
|
80
|
+
}
|
|
81
|
+
const hint = fetchHint(compareRef);
|
|
82
|
+
const rev = spawnGit(['rev-parse', '--verify', '--quiet', `${compareRef}^{commit}`], cwd, 'git rev-parse', hint);
|
|
83
|
+
const refSha = rev.status === 0 ? rev.stdout.trim() : '';
|
|
84
|
+
if (!refSha) {
|
|
85
|
+
// --quiet silences only "ref not found". Anything on stderr is a different failure
|
|
86
|
+
// (not a git repository, safe.directory "dubious ownership", corrupt repo), so show git's
|
|
87
|
+
// own message instead of telling the user to fetch.
|
|
88
|
+
const stderr = (_b = (_a = rev.stderr) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
|
|
89
|
+
throw new Error(stderr
|
|
90
|
+
? `git rev-parse exited with code ${rev.status}: ${stderr}`
|
|
91
|
+
: `Could not resolve "${compareRef}" to a commit.\n${hint}`);
|
|
92
|
+
}
|
|
93
|
+
if (rangeNotation === '..')
|
|
94
|
+
return refSha;
|
|
95
|
+
const mb = spawnGit(['merge-base', refSha, 'HEAD'], cwd, 'git merge-base', hint);
|
|
96
|
+
const base = mb.status === 0 ? mb.stdout.trim().split('\n')[0] : '';
|
|
97
|
+
if (base)
|
|
98
|
+
return base;
|
|
99
|
+
const stderr = (_d = (_c = mb.stderr) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : '';
|
|
100
|
+
if (mb.status === 1 && !stderr) {
|
|
101
|
+
// Exit 1 with no output means "no common ancestor".
|
|
102
|
+
const shallow = spawnGit(['rev-parse', '--is-shallow-repository'], cwd, 'git rev-parse');
|
|
103
|
+
const isShallow = shallow.status === 0 && shallow.stdout.trim() === 'true';
|
|
104
|
+
throw new Error(`No merge base found between "${compareRef}" and HEAD.\n` +
|
|
105
|
+
(isShallow
|
|
106
|
+
? 'This is a shallow clone, so their common ancestor is probably outside the fetched history. ' +
|
|
107
|
+
'Fetch more history (e.g. "git fetch --unshallow", or "fetch-depth: 0" with actions/checkout), ' +
|
|
108
|
+
'or use --diff-range-notation "..".\n'
|
|
109
|
+
: `"${compareRef}" and HEAD do not share any history. Use --diff-range-notation ".." to diff against "${compareRef}" directly.\n`) +
|
|
110
|
+
hint);
|
|
111
|
+
}
|
|
112
|
+
throw new Error(`git merge-base exited with code ${mb.status}: ${stderr}\n${hint}`);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* parse-diff has already stripped the a/ b/ prefixes, and git prints repo-relative posix paths,
|
|
116
|
+
* so the path is used as-is. (normalizePath would strip a second "a/" or "b/", mangling files
|
|
117
|
+
* under a real top-level a/ or b/ directory.)
|
|
118
|
+
*/
|
|
119
|
+
function toPath(raw) {
|
|
120
|
+
return raw && raw !== '/dev/null' ? raw : null;
|
|
121
|
+
}
|
|
122
|
+
function parseGitDiff(diffOutput) {
|
|
123
|
+
return (0, parse_diff_1.default)(diffOutput).map(file => {
|
|
57
124
|
const addedLines = new Set();
|
|
58
125
|
for (const chunk of file.chunks) {
|
|
59
126
|
for (const change of chunk.changes) {
|
|
60
|
-
if (change.type === 'add')
|
|
127
|
+
if (change.type === 'add')
|
|
61
128
|
addedLines.add(change.ln);
|
|
62
|
-
}
|
|
63
129
|
}
|
|
64
130
|
}
|
|
65
|
-
|
|
131
|
+
return {
|
|
132
|
+
from: toPath(file.from),
|
|
133
|
+
to: toPath(file.to),
|
|
134
|
+
isNew: file.new === true,
|
|
135
|
+
isDeleted: file.deleted === true || file.to === '/dev/null',
|
|
136
|
+
addedLines,
|
|
137
|
+
hunks: file.chunks.map(({ oldStart, oldLines, newStart, newLines }) => ({ oldStart, oldLines, newStart, newLines })),
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/** Files with at least one added line, in diff order. */
|
|
142
|
+
function toFileDiffs(files) {
|
|
143
|
+
const result = [];
|
|
144
|
+
for (const file of files) {
|
|
145
|
+
if (file.isDeleted || file.to === null || file.addedLines.size === 0)
|
|
66
146
|
continue;
|
|
67
|
-
result.push({ filePath, addedLines, isNew: file.
|
|
147
|
+
result.push({ filePath: file.to, addedLines: file.addedLines, isNew: file.isNew });
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
function runChangesDiff(revs, cwd, hint) {
|
|
152
|
+
return toFileDiffs(parseGitDiff(runGit(changesDiffArgs(revs), cwd, 'git diff', hint)));
|
|
153
|
+
}
|
|
154
|
+
function runMappingDiff(revs, cwd) {
|
|
155
|
+
return parseGitDiff(runGit(mappingDiffArgs(revs), cwd, 'git diff'));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Map a line number on the old side of a --unified=0 diff to the new side.
|
|
159
|
+
* Returns null when the line was deleted or replaced by the diff.
|
|
160
|
+
*/
|
|
161
|
+
function mapOldLineToNew(hunks, line) {
|
|
162
|
+
let offset = 0;
|
|
163
|
+
for (const h of hunks) {
|
|
164
|
+
if (h.oldLines > 0) {
|
|
165
|
+
if (line < h.oldStart)
|
|
166
|
+
break;
|
|
167
|
+
if (line < h.oldStart + h.oldLines)
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
else if (line <= h.oldStart) {
|
|
171
|
+
// Pure insertion after old line h.oldStart: lines up to and including it are unaffected.
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
offset += h.newLines - h.oldLines;
|
|
175
|
+
}
|
|
176
|
+
return line + offset;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Translate line numbers of `files` (taken from some snapshot, e.g. HEAD or the index) into
|
|
180
|
+
* working-tree line numbers, using `mapping` = the diff from that snapshot to the working tree.
|
|
181
|
+
* Lines that the mapping diff deleted or rewrote are dropped: their current content comes from
|
|
182
|
+
* a change that was excluded. Files deleted in the working tree are dropped.
|
|
183
|
+
*/
|
|
184
|
+
function mapToWorktree(files, mapping) {
|
|
185
|
+
const bySource = new Map();
|
|
186
|
+
for (const m of mapping) {
|
|
187
|
+
if (m.from !== null)
|
|
188
|
+
bySource.set(m.from, m);
|
|
189
|
+
}
|
|
190
|
+
const result = [];
|
|
191
|
+
for (const file of files) {
|
|
192
|
+
const m = bySource.get(file.filePath);
|
|
193
|
+
if (m === undefined) {
|
|
194
|
+
result.push(file); // unchanged between the snapshot and the working tree
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (m.isDeleted || m.to === null)
|
|
198
|
+
continue;
|
|
199
|
+
const addedLines = new Set();
|
|
200
|
+
for (const line of file.addedLines) {
|
|
201
|
+
const mapped = mapOldLineToNew(m.hunks, line);
|
|
202
|
+
if (mapped !== null)
|
|
203
|
+
addedLines.add(mapped);
|
|
204
|
+
}
|
|
205
|
+
if (addedLines.size > 0) {
|
|
206
|
+
result.push({ filePath: m.to, addedLines, isNew: file.isNew });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
/** Remove `remove`'s lines from `from`, per file. Files left with no lines are dropped. */
|
|
212
|
+
function subtractLines(from, remove) {
|
|
213
|
+
const removeByPath = new Map(remove.map(f => [f.filePath, f.addedLines]));
|
|
214
|
+
const result = [];
|
|
215
|
+
for (const file of from) {
|
|
216
|
+
const toRemove = removeByPath.get(file.filePath);
|
|
217
|
+
if (toRemove === undefined) {
|
|
218
|
+
result.push(file);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const addedLines = new Set([...file.addedLines].filter(line => !toRemove.has(line)));
|
|
222
|
+
if (addedLines.size > 0)
|
|
223
|
+
result.push({ ...file, addedLines });
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Count the lines of a text file, reading it in fixed-size chunks so that a huge untracked file
|
|
229
|
+
* is never loaded into memory at once. Returns null for binary files, using git's heuristic:
|
|
230
|
+
* a NUL byte in the first 8000 bytes.
|
|
231
|
+
*/
|
|
232
|
+
function countTextLines(filePath) {
|
|
233
|
+
const fd = fs_1.default.openSync(filePath, 'r');
|
|
234
|
+
try {
|
|
235
|
+
const buf = Buffer.alloc(64 * 1024);
|
|
236
|
+
let count = 0;
|
|
237
|
+
let total = 0;
|
|
238
|
+
let lastByte = -1;
|
|
239
|
+
let bytesRead;
|
|
240
|
+
while ((bytesRead = fs_1.default.readSync(fd, buf, 0, buf.length, null)) > 0) {
|
|
241
|
+
if (total === 0 && buf.subarray(0, Math.min(bytesRead, 8000)).includes(0))
|
|
242
|
+
return null;
|
|
243
|
+
for (let i = buf.indexOf(0x0a); i !== -1 && i < bytesRead; i = buf.indexOf(0x0a, i + 1))
|
|
244
|
+
count++;
|
|
245
|
+
lastByte = buf[bytesRead - 1];
|
|
246
|
+
total += bytesRead;
|
|
247
|
+
}
|
|
248
|
+
if (total === 0)
|
|
249
|
+
return 0;
|
|
250
|
+
return lastByte === 0x0a ? count : count + 1;
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
fs_1.default.closeSync(fd);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Untracked, non-ignored files with every line marked as added.
|
|
258
|
+
* Binary files, symlinks, nested repositories and unreadable files are skipped.
|
|
259
|
+
*/
|
|
260
|
+
function getUntrackedFiles(cwd) {
|
|
261
|
+
// ls-files prints paths relative to the directory it runs in, while git diff prints
|
|
262
|
+
// repo-root-relative paths, so list from the root to get matching paths for the whole repo.
|
|
263
|
+
const root = runGit(['rev-parse', '--show-toplevel'], cwd, 'git rev-parse').trim();
|
|
264
|
+
const output = runGit(['ls-files', '--others', '--exclude-standard', '-z'], root, 'git ls-files');
|
|
265
|
+
const result = [];
|
|
266
|
+
for (const relPath of output.split('\0')) {
|
|
267
|
+
if (!relPath)
|
|
268
|
+
continue;
|
|
269
|
+
const fullPath = path_1.default.join(root, relPath);
|
|
270
|
+
let lineCount;
|
|
271
|
+
try {
|
|
272
|
+
if (!fs_1.default.lstatSync(fullPath).isFile())
|
|
273
|
+
continue;
|
|
274
|
+
lineCount = countTextLines(fullPath);
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (lineCount === null || lineCount === 0)
|
|
280
|
+
continue;
|
|
281
|
+
const addedLines = new Set();
|
|
282
|
+
for (let i = 1; i <= lineCount; i++)
|
|
283
|
+
addedLines.add(i);
|
|
284
|
+
// ls-files -z output is repo-relative (we run it from the root) and never quoted.
|
|
285
|
+
result.push({ filePath: relPath, addedLines, isNew: true });
|
|
286
|
+
}
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Return the lines added relative to the base, per file. Line numbers always refer to the
|
|
291
|
+
* file as it is on disk now, because lcov is generated from the working tree.
|
|
292
|
+
*
|
|
293
|
+
* The base is `git merge-base <compareRef> HEAD` for "..." notation, or <compareRef> for "..".
|
|
294
|
+
* Rather than running the committed, staged and unstaged diffs separately and merging their line
|
|
295
|
+
* numbers (which gives wrong numbers when several of them touch one file), each mode uses one
|
|
296
|
+
* diff against the base, then translates line numbers to the working tree when needed:
|
|
297
|
+
*
|
|
298
|
+
* default (all changes): git diff <base> (base → working tree)
|
|
299
|
+
* ignoreUnstaged: git diff --cached <base> (base → index), then mapped through
|
|
300
|
+
* `git diff` (index → working tree)
|
|
301
|
+
* ignoreStaged + ignoreUnstaged:
|
|
302
|
+
* git diff <base> HEAD (base → HEAD), then mapped through
|
|
303
|
+
* `git diff HEAD` (HEAD → working tree)
|
|
304
|
+
* ignoreStaged only: no single git diff gives "committed + unstaged". Python diff-cover
|
|
305
|
+
* applies the committed and unstaged diffs one after the other,
|
|
306
|
+
* dropping "deleted" line numbers and adding "added" ones without
|
|
307
|
+
* shifting the rest, so its line numbers drift whenever both touch one
|
|
308
|
+
* file. Instead we take the default result (git diff <base>) and remove
|
|
309
|
+
* the lines whose current content was written by a staged change: the
|
|
310
|
+
* lines added by `git diff --cached HEAD`, mapped to the working tree
|
|
311
|
+
* through `git diff`. Staged lines that were edited again later
|
|
312
|
+
* (unstaged) count as unstaged changes and are kept.
|
|
313
|
+
*
|
|
314
|
+
* In the mapping steps, a line that an excluded change later rewrote or deleted is dropped,
|
|
315
|
+
* because its current content comes from that excluded change. When the working tree is clean,
|
|
316
|
+
* the mapping diffs are empty and every mode returns plain `git diff <base>` results.
|
|
317
|
+
*
|
|
318
|
+
* Known limitations:
|
|
319
|
+
* - ignoreStaged only: a line added by a commit and then modified by a staged change counts as
|
|
320
|
+
* staged and is excluded. Python counts it, at its HEAD line number.
|
|
321
|
+
* - With the user's git config diff.renames=false, the reported diffs follow that config (a
|
|
322
|
+
* renamed file is all new) but the staged and mapping diffs force rename detection. After a
|
|
323
|
+
* staged `git mv`, ignoreStaged alone therefore still reports every line of the renamed file,
|
|
324
|
+
* while ignoreStaged + ignoreUnstaged reports only its committed lines. This over-reports, so
|
|
325
|
+
* it can lower coverage but never hide an uncovered line. Forcing renames on the reported diff
|
|
326
|
+
* instead would make ignoreStaged differ from the default mode even with nothing staged.
|
|
327
|
+
*
|
|
328
|
+
* Uses spawnSync (no shell) to prevent command injection from user-supplied compareRef.
|
|
329
|
+
* --diff-filter=ACMR skips deleted files.
|
|
330
|
+
*/
|
|
331
|
+
function getGitDiff(compareRef, rangeNotation = '...', options = {}) {
|
|
332
|
+
const { ignoreStaged = false, ignoreUnstaged = false, includeUntracked = false, cwd } = options;
|
|
333
|
+
const hint = fetchHint(compareRef);
|
|
334
|
+
const base = resolveDiffBase(compareRef, rangeNotation, cwd);
|
|
335
|
+
let result;
|
|
336
|
+
if (!ignoreStaged && !ignoreUnstaged) {
|
|
337
|
+
result = runChangesDiff([base], cwd, hint);
|
|
338
|
+
}
|
|
339
|
+
else if (!ignoreStaged && ignoreUnstaged) {
|
|
340
|
+
result = runChangesDiff(['--cached', base], cwd, hint);
|
|
341
|
+
if (result.length > 0)
|
|
342
|
+
result = mapToWorktree(result, runMappingDiff([], cwd));
|
|
343
|
+
}
|
|
344
|
+
else if (ignoreStaged && ignoreUnstaged) {
|
|
345
|
+
result = runChangesDiff([base, 'HEAD'], cwd, hint);
|
|
346
|
+
if (result.length > 0)
|
|
347
|
+
result = mapToWorktree(result, runMappingDiff(['HEAD'], cwd));
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
result = runChangesDiff([base], cwd, hint);
|
|
351
|
+
// diff.renames=true so a staged `git mv` is not treated as a staged rewrite of every line.
|
|
352
|
+
const staged = toFileDiffs(runMappingDiff(['--cached', 'HEAD'], cwd));
|
|
353
|
+
if (result.length > 0 && staged.length > 0) {
|
|
354
|
+
result = subtractLines(result, mapToWorktree(staged, runMappingDiff([], cwd)));
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (includeUntracked) {
|
|
358
|
+
const byPath = new Map(result.map(f => [f.filePath, f]));
|
|
359
|
+
for (const file of getUntrackedFiles(cwd)) {
|
|
360
|
+
const existing = byPath.get(file.filePath);
|
|
361
|
+
if (existing === undefined) {
|
|
362
|
+
result.push(file);
|
|
363
|
+
byPath.set(file.filePath, file);
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
for (const line of file.addedLines)
|
|
367
|
+
existing.addedLines.add(line);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
68
370
|
}
|
|
69
371
|
return result;
|
|
70
372
|
}
|
package/dist/git-diff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-diff.js","sourceRoot":"","sources":["../src/git-diff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A2F;QAC3F,MAAM,MAAM,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QACtE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3C,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QACjF,CAAC;IACH,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACzD,KAAK,MAAM,IAAI,IAAI,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1C,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC3C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAClB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU;oBAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { getGitDiff } from './git-diff';
|
|
2
|
-
export { parseLcov } from './lcov-parser';
|
|
2
|
+
export { parseLcov, mergeLcovCoverage } from './lcov-parser';
|
|
3
3
|
export { calculateDiffCoverage, DEFAULT_EXCLUDES } from './calculator';
|
|
4
4
|
export { printReport } from './reporter';
|
|
5
|
-
export { normalizePath, findRepoRoot, clearRepoRootCache } from './path-utils';
|
|
5
|
+
export { normalizePath, toRepoRelativePath, findRepoRoot, clearRepoRootCache } from './path-utils';
|
|
6
6
|
export { generateJsonReport, generateMarkdownReport, generateHtmlReport, buildReportDict, combineAdjacentLines, parseFormatOption, writeFormats, } from './report-generator';
|
|
7
7
|
export { loadConfig } from './config';
|
|
8
|
-
export type { FileDiff, RangeNotation } from './git-diff';
|
|
8
|
+
export type { FileDiff, RangeNotation, GitDiffOptions } from './git-diff';
|
|
9
9
|
export type { LcovFileCoverage } from './lcov-parser';
|
|
10
10
|
export type { FileStats, DiffCoverageResult, CalculatorOptions } from './calculator';
|
|
11
11
|
export type { ReportDict, SrcStats } from './report-generator';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACnG,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC1E,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACrF,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC/D,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadConfig = exports.writeFormats = exports.parseFormatOption = exports.combineAdjacentLines = exports.buildReportDict = exports.generateHtmlReport = exports.generateMarkdownReport = exports.generateJsonReport = exports.clearRepoRootCache = exports.findRepoRoot = exports.normalizePath = exports.printReport = exports.DEFAULT_EXCLUDES = exports.calculateDiffCoverage = exports.parseLcov = exports.getGitDiff = void 0;
|
|
3
|
+
exports.loadConfig = exports.writeFormats = exports.parseFormatOption = exports.combineAdjacentLines = exports.buildReportDict = exports.generateHtmlReport = exports.generateMarkdownReport = exports.generateJsonReport = exports.clearRepoRootCache = exports.findRepoRoot = exports.toRepoRelativePath = exports.normalizePath = exports.printReport = exports.DEFAULT_EXCLUDES = exports.calculateDiffCoverage = exports.mergeLcovCoverage = exports.parseLcov = exports.getGitDiff = void 0;
|
|
4
4
|
var git_diff_1 = require("./git-diff");
|
|
5
5
|
Object.defineProperty(exports, "getGitDiff", { enumerable: true, get: function () { return git_diff_1.getGitDiff; } });
|
|
6
6
|
var lcov_parser_1 = require("./lcov-parser");
|
|
7
7
|
Object.defineProperty(exports, "parseLcov", { enumerable: true, get: function () { return lcov_parser_1.parseLcov; } });
|
|
8
|
+
Object.defineProperty(exports, "mergeLcovCoverage", { enumerable: true, get: function () { return lcov_parser_1.mergeLcovCoverage; } });
|
|
8
9
|
var calculator_1 = require("./calculator");
|
|
9
10
|
Object.defineProperty(exports, "calculateDiffCoverage", { enumerable: true, get: function () { return calculator_1.calculateDiffCoverage; } });
|
|
10
11
|
Object.defineProperty(exports, "DEFAULT_EXCLUDES", { enumerable: true, get: function () { return calculator_1.DEFAULT_EXCLUDES; } });
|
|
@@ -12,6 +13,7 @@ var reporter_1 = require("./reporter");
|
|
|
12
13
|
Object.defineProperty(exports, "printReport", { enumerable: true, get: function () { return reporter_1.printReport; } });
|
|
13
14
|
var path_utils_1 = require("./path-utils");
|
|
14
15
|
Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return path_utils_1.normalizePath; } });
|
|
16
|
+
Object.defineProperty(exports, "toRepoRelativePath", { enumerable: true, get: function () { return path_utils_1.toRepoRelativePath; } });
|
|
15
17
|
Object.defineProperty(exports, "findRepoRoot", { enumerable: true, get: function () { return path_utils_1.findRepoRoot; } });
|
|
16
18
|
Object.defineProperty(exports, "clearRepoRootCache", { enumerable: true, get: function () { return path_utils_1.clearRepoRootCache; } });
|
|
17
19
|
var report_generator_1 = require("./report-generator");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AAA/B,sGAAA,UAAU,OAAA;AACnB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AAA/B,sGAAA,UAAU,OAAA;AACnB,6CAA6D;AAApD,wGAAA,SAAS,OAAA;AAAE,gHAAA,iBAAiB,OAAA;AACrC,2CAAuE;AAA9D,mHAAA,qBAAqB,OAAA;AAAE,8GAAA,gBAAgB,OAAA;AAChD,uCAAyC;AAAhC,uGAAA,WAAW,OAAA;AACpB,2CAAmG;AAA1F,2GAAA,aAAa,OAAA;AAAE,gHAAA,kBAAkB,OAAA;AAAE,0GAAA,YAAY,OAAA;AAAE,gHAAA,kBAAkB,OAAA;AAC5E,uDAQ4B;AAP1B,sHAAA,kBAAkB,OAAA;AAClB,0HAAA,sBAAsB,OAAA;AACtB,sHAAA,kBAAkB,OAAA;AAClB,mHAAA,eAAe,OAAA;AACf,wHAAA,oBAAoB,OAAA;AACpB,qHAAA,iBAAiB,OAAA;AACjB,gHAAA,YAAY,OAAA;AAEd,mCAAsC;AAA7B,oGAAA,UAAU,OAAA"}
|
package/dist/lcov-parser.d.ts
CHANGED
|
@@ -3,6 +3,16 @@ export interface LcovFileCoverage {
|
|
|
3
3
|
/** lineNumber → hitCount (0 = not covered, >0 = covered) */
|
|
4
4
|
lines: Map<number, number>;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Merge the line data of `from` into `into` (mutates and returns `into`).
|
|
8
|
+
* Hit counts for the same line are added together, as lcov's own merge does, so a
|
|
9
|
+
* line covered in either record stays covered. `into.filePath` is kept.
|
|
10
|
+
*
|
|
11
|
+
* Use this whenever two coverage records describe the same source file: repeated SF:
|
|
12
|
+
* blocks in one lcov file, different raw paths that normalize to the same file, or
|
|
13
|
+
* records from several lcov files.
|
|
14
|
+
*/
|
|
15
|
+
export declare function mergeLcovCoverage(into: LcovFileCoverage, from: LcovFileCoverage): LcovFileCoverage;
|
|
6
16
|
/**
|
|
7
17
|
* Parse an lcov.info file.
|
|
8
18
|
* Only SF: (source file) and DA: (line data) records matter for diff coverage.
|
|
@@ -13,6 +23,9 @@ export interface LcovFileCoverage {
|
|
|
13
23
|
* DA:<line number>,<hit count>
|
|
14
24
|
* ...
|
|
15
25
|
* end_of_record
|
|
26
|
+
*
|
|
27
|
+
* The same SF: path can appear in several blocks (Jest multi-project setups,
|
|
28
|
+
* concatenated or sharded reports); those blocks are merged with mergeLcovCoverage.
|
|
16
29
|
*/
|
|
17
30
|
export declare function parseLcov(lcovPath: string): Map<string, LcovFileCoverage>;
|
|
18
31
|
//# sourceMappingURL=lcov-parser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lcov-parser.d.ts","sourceRoot":"","sources":["../src/lcov-parser.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5B;AAED
|
|
1
|
+
{"version":3,"file":"lcov-parser.d.ts","sourceRoot":"","sources":["../src/lcov-parser.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CAKnG;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAE,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CA0C1E"}
|
package/dist/lcov-parser.js
CHANGED
|
@@ -3,8 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mergeLcovCoverage = mergeLcovCoverage;
|
|
6
7
|
exports.parseLcov = parseLcov;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
/**
|
|
10
|
+
* Merge the line data of `from` into `into` (mutates and returns `into`).
|
|
11
|
+
* Hit counts for the same line are added together, as lcov's own merge does, so a
|
|
12
|
+
* line covered in either record stays covered. `into.filePath` is kept.
|
|
13
|
+
*
|
|
14
|
+
* Use this whenever two coverage records describe the same source file: repeated SF:
|
|
15
|
+
* blocks in one lcov file, different raw paths that normalize to the same file, or
|
|
16
|
+
* records from several lcov files.
|
|
17
|
+
*/
|
|
18
|
+
function mergeLcovCoverage(into, from) {
|
|
19
|
+
var _a;
|
|
20
|
+
for (const [lineNum, hitCount] of from.lines) {
|
|
21
|
+
into.lines.set(lineNum, ((_a = into.lines.get(lineNum)) !== null && _a !== void 0 ? _a : 0) + hitCount);
|
|
22
|
+
}
|
|
23
|
+
return into;
|
|
24
|
+
}
|
|
8
25
|
/**
|
|
9
26
|
* Parse an lcov.info file.
|
|
10
27
|
* Only SF: (source file) and DA: (line data) records matter for diff coverage.
|
|
@@ -15,15 +32,30 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
15
32
|
* DA:<line number>,<hit count>
|
|
16
33
|
* ...
|
|
17
34
|
* end_of_record
|
|
35
|
+
*
|
|
36
|
+
* The same SF: path can appear in several blocks (Jest multi-project setups,
|
|
37
|
+
* concatenated or sharded reports); those blocks are merged with mergeLcovCoverage.
|
|
18
38
|
*/
|
|
19
39
|
function parseLcov(lcovPath) {
|
|
20
40
|
var _a;
|
|
21
41
|
const content = fs_1.default.readFileSync(lcovPath, 'utf8');
|
|
22
42
|
const result = new Map();
|
|
23
43
|
let current = null;
|
|
44
|
+
const flush = (block) => {
|
|
45
|
+
const existing = result.get(block.filePath);
|
|
46
|
+
if (existing === undefined) {
|
|
47
|
+
result.set(block.filePath, block);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
mergeLcovCoverage(existing, block);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
24
53
|
for (const raw of content.split('\n')) {
|
|
25
54
|
const line = raw.trim();
|
|
26
55
|
if (line.startsWith('SF:')) {
|
|
56
|
+
// A new SF: before end_of_record means the previous block was not terminated; keep its data.
|
|
57
|
+
if (current !== null)
|
|
58
|
+
flush(current);
|
|
27
59
|
current = { filePath: line.slice(3), lines: new Map() };
|
|
28
60
|
}
|
|
29
61
|
else if (line.startsWith('DA:') && current !== null) {
|
|
@@ -31,19 +63,19 @@ function parseLcov(lcovPath) {
|
|
|
31
63
|
const lineNum = parseInt(lineNumStr, 10);
|
|
32
64
|
const hitCount = parseInt(hitCountStr, 10);
|
|
33
65
|
if (!isNaN(lineNum) && !isNaN(hitCount)) {
|
|
34
|
-
// If the same line appears multiple times
|
|
66
|
+
// If the same line appears multiple times within one block, keep the max hit count
|
|
35
67
|
const existing = (_a = current.lines.get(lineNum)) !== null && _a !== void 0 ? _a : 0;
|
|
36
68
|
current.lines.set(lineNum, Math.max(existing, hitCount));
|
|
37
69
|
}
|
|
38
70
|
}
|
|
39
71
|
else if (line === 'end_of_record' && current !== null) {
|
|
40
|
-
|
|
72
|
+
flush(current);
|
|
41
73
|
current = null;
|
|
42
74
|
}
|
|
43
75
|
}
|
|
44
76
|
// Flush the last block in case the file is truncated (no trailing end_of_record)
|
|
45
77
|
if (current !== null) {
|
|
46
|
-
|
|
78
|
+
flush(current);
|
|
47
79
|
}
|
|
48
80
|
return result;
|
|
49
81
|
}
|
package/dist/lcov-parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lcov-parser.js","sourceRoot":"","sources":["../src/lcov-parser.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"lcov-parser.js","sourceRoot":"","sources":["../src/lcov-parser.ts"],"names":[],"mappings":";;;;;AAiBA,8CAKC;AAgBD,8BA0CC;AAhFD,4CAAoB;AAQpB;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAAE,IAAsB,EAAE,IAAsB;;IAC/E,KAAK,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,MAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,mCAAI,CA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C,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC3D,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;YACzC,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAC3C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACxC,mFAAmF;gBACnF,MAAM,QAAQ,GAAG,MAAA,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,mCAAI,CAAC,CAAC;gBACjD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;aAAM,IAAI,IAAI,KAAK,eAAe,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACxD,KAAK,CAAC,OAAO,CAAC,CAAC;YACf,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;IACH,CAAC;IAED,iFAAiF;IACjF,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/path-utils.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
export declare function clearRepoRootCache(): void;
|
|
2
2
|
export declare function findRepoRoot(): string;
|
|
3
3
|
/**
|
|
4
|
-
* Normalize a
|
|
4
|
+
* Normalize a raw unified-diff path ("a/src/foo.ts", "b/src/foo.ts") to a relative posix form.
|
|
5
|
+
* Strips one a/ or b/ prefix, then applies toRepoRelativePath.
|
|
6
|
+
*
|
|
7
|
+
* Only use this on paths that still carry a diff prefix. Paths from parse-diff, git ls-files
|
|
8
|
+
* and lcov have none, and a real top-level directory named a/ or b/ would be stripped by mistake
|
|
9
|
+
* ("b/foo.ts" → "foo.ts"); use toRepoRelativePath for those.
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizePath(filePath: string, repoRoot?: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Normalize a file path (e.g. an lcov SF: path) to a consistent repo-relative posix form.
|
|
5
14
|
* Handles:
|
|
6
|
-
* - git diff a/b prefixes ("a/src/foo.ts" → "src/foo.ts")
|
|
7
15
|
* - absolute paths ("/vd/src/foo.ts" → "src/foo.ts")
|
|
8
16
|
* - leading ./ ("./src/foo.ts" → "src/foo.ts")
|
|
9
17
|
* - Windows backslashes ("src\\foo.ts" → "src/foo.ts")
|
|
10
18
|
*/
|
|
11
|
-
export declare function
|
|
19
|
+
export declare function toRepoRelativePath(filePath: string, repoRoot?: string): string;
|
|
12
20
|
//# sourceMappingURL=path-utils.d.ts.map
|
package/dist/path-utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-utils.d.ts","sourceRoot":"","sources":["../src/path-utils.ts"],"names":[],"mappings":"AAOA,wBAAgB,kBAAkB,IAAK,IAAI,CAE1C;AAED,wBAAgB,YAAY,IAAK,MAAM,CAStC;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"path-utils.d.ts","sourceRoot":"","sources":["../src/path-utils.ts"],"names":[],"mappings":"AAOA,wBAAgB,kBAAkB,IAAK,IAAI,CAE1C;AAED,wBAAgB,YAAY,IAAK,MAAM,CAStC;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAI1E;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAkB/E"}
|
package/dist/path-utils.js
CHANGED
|
@@ -6,9 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.clearRepoRootCache = clearRepoRootCache;
|
|
7
7
|
exports.findRepoRoot = findRepoRoot;
|
|
8
8
|
exports.normalizePath = normalizePath;
|
|
9
|
+
exports.toRepoRelativePath = toRepoRelativePath;
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
10
11
|
const child_process_1 = require("child_process");
|
|
11
|
-
// Module-level cache — findRepoRoot() is called once per
|
|
12
|
+
// Module-level cache — findRepoRoot() is called once per toRepoRelativePath() call,
|
|
12
13
|
// which happens for every LCOV entry. Cache avoids spawning hundreds of subprocesses.
|
|
13
14
|
let _repoRoot = null;
|
|
14
15
|
function clearRepoRootCache() {
|
|
@@ -24,19 +25,27 @@ function findRepoRoot() {
|
|
|
24
25
|
return _repoRoot;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
|
-
* Normalize a
|
|
28
|
+
* Normalize a raw unified-diff path ("a/src/foo.ts", "b/src/foo.ts") to a relative posix form.
|
|
29
|
+
* Strips one a/ or b/ prefix, then applies toRepoRelativePath.
|
|
30
|
+
*
|
|
31
|
+
* Only use this on paths that still carry a diff prefix. Paths from parse-diff, git ls-files
|
|
32
|
+
* and lcov have none, and a real top-level directory named a/ or b/ would be stripped by mistake
|
|
33
|
+
* ("b/foo.ts" → "foo.ts"); use toRepoRelativePath for those.
|
|
34
|
+
*/
|
|
35
|
+
function normalizePath(filePath, repoRoot) {
|
|
36
|
+
// Strip a/ or b/ prefix from unified diff paths
|
|
37
|
+
const p = /^[ab]\//.test(filePath) ? filePath.slice(2) : filePath;
|
|
38
|
+
return toRepoRelativePath(p, repoRoot);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Normalize a file path (e.g. an lcov SF: path) to a consistent repo-relative posix form.
|
|
28
42
|
* Handles:
|
|
29
|
-
* - git diff a/b prefixes ("a/src/foo.ts" → "src/foo.ts")
|
|
30
43
|
* - absolute paths ("/vd/src/foo.ts" → "src/foo.ts")
|
|
31
44
|
* - leading ./ ("./src/foo.ts" → "src/foo.ts")
|
|
32
45
|
* - Windows backslashes ("src\\foo.ts" → "src/foo.ts")
|
|
33
46
|
*/
|
|
34
|
-
function
|
|
47
|
+
function toRepoRelativePath(filePath, repoRoot) {
|
|
35
48
|
let p = filePath;
|
|
36
|
-
// Strip a/ or b/ prefix from unified diff paths
|
|
37
|
-
if (/^[ab]\//.test(p)) {
|
|
38
|
-
p = p.slice(2);
|
|
39
|
-
}
|
|
40
49
|
// Strip absolute path to relative
|
|
41
50
|
if (path_1.default.isAbsolute(p)) {
|
|
42
51
|
const root = repoRoot !== null && repoRoot !== void 0 ? repoRoot : findRepoRoot();
|
package/dist/path-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-utils.js","sourceRoot":"","sources":["../src/path-utils.ts"],"names":[],"mappings":";;;;;AAOA,gDAEC;AAED,oCASC;AAUD,
|
|
1
|
+
{"version":3,"file":"path-utils.js","sourceRoot":"","sources":["../src/path-utils.ts"],"names":[],"mappings":";;;;;AAOA,gDAEC;AAED,oCASC;AAUD,sCAIC;AASD,gDAkBC;AA7DD,gDAAwB;AACxB,iDAA0C;AAE1C,oFAAoF;AACpF,sFAAsF;AACtF,IAAI,SAAS,GAAkB,IAAI,CAAC;AAEpC,SAAgB,kBAAkB;IAChC,SAAS,GAAG,IAAI,CAAC;AACnB,CAAC;AAED,SAAgB,YAAY;IAC1B,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAEzC,MAAM,IAAI,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,WAAW,EAAE,iBAAiB,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IACtF,SAAS,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM;QAC1C,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;QACpB,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IAElB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,aAAa,CAAE,QAAgB,EAAE,QAAiB;IAChE,gDAAgD;IAChD,MAAM,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAClE,OAAO,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAE,QAAgB,EAAE,QAAiB;IACrE,IAAI,CAAC,GAAG,QAAQ,CAAC;IAEjB,kCAAkC;IAClC,IAAI,cAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,YAAY,EAAE,CAAC;QACxC,CAAC,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC;IAED,mBAAmB;IACnB,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACvB,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IAED,mDAAmD;IACnD,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE1B,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diff-cover-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Diff-aware test coverage checker — JS/TS equivalent of Python diff-cover. Reports coverage only for lines you changed, not the whole file.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsc",
|
|
39
39
|
"dev": "ts-node src/cli.ts",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"typecheck": "tsc -p tsconfig.test.json",
|
|
40
42
|
"prepublishOnly": "npm run build"
|
|
41
43
|
},
|
|
42
44
|
"dependencies": {
|
|
@@ -46,7 +48,8 @@
|
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@types/node": "^20.0.0",
|
|
48
50
|
"ts-node": "^10.9.0",
|
|
49
|
-
"typescript": "^5.0.0"
|
|
51
|
+
"typescript": "^5.0.0",
|
|
52
|
+
"vitest": "^3.2.7"
|
|
50
53
|
},
|
|
51
54
|
"engines": {
|
|
52
55
|
"node": ">=16.0.0"
|