repometry 0.10.0 → 0.11.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 +5 -3
- package/package.json +1 -1
- package/target/main/resources/config/process-plugins-v1.schema.json +22 -0
- package/target/main/resources/report/json/config-v1.schema.json +125 -2
- package/target/main/resources/report/json/file-metrics-v1.schema.json +23 -1
- package/target/main/resources/report/json/pull-review-v2.schema.json +100 -0
- package/target/main/ts/api/cache/root.d.ts +3 -0
- package/target/main/ts/api/cache/root.js +21 -0
- package/target/main/ts/api/gh/github.d.ts +0 -4
- package/target/main/ts/api/gh/github.js +3 -33
- package/target/main/ts/api/git/blob-batch.js +2 -1
- package/target/main/ts/api/git/blob-history.d.ts +20 -0
- package/target/main/ts/api/git/blob-history.js +54 -0
- package/target/main/ts/api/git/commit-metadata.d.ts +0 -1
- package/target/main/ts/api/git/commit-metadata.js +1 -10
- package/target/main/ts/api/git/git-executable.d.ts +1 -0
- package/target/main/ts/api/git/git-executable.js +31 -0
- package/target/main/ts/api/git/git.d.ts +8 -1
- package/target/main/ts/api/git/git.js +58 -61
- package/target/main/ts/api/git/inspection-source.d.ts +2 -1
- package/target/main/ts/api/git/inspection-source.js +3 -2
- package/target/main/ts/api/git/local-sources.js +3 -2
- package/target/main/ts/api/git/source-cache.d.ts +0 -2
- package/target/main/ts/api/git/source-cache.js +1 -16
- package/target/main/ts/api/import/cobertura.d.ts +2 -0
- package/target/main/ts/api/import/cobertura.js +160 -0
- package/target/main/ts/api/import/coverage-xml.d.ts +7 -0
- package/target/main/ts/api/import/coverage-xml.js +135 -0
- package/target/main/ts/api/import/lcov-files.d.ts +3 -1
- package/target/main/ts/api/import/lcov-files.js +23 -4
- package/target/main/ts/api/process/go-parser-cache.d.ts +1 -0
- package/target/main/ts/api/process/go-parser-cache.js +71 -0
- package/target/main/ts/api/process/go-parser-files.d.ts +5 -0
- package/target/main/ts/api/process/go-parser-files.js +65 -0
- package/target/main/ts/api/process/host-language-runner.d.ts +3 -5
- package/target/main/ts/api/process/host-language-runner.js +21 -66
- package/target/main/ts/api/process/host-tool.d.ts +22 -0
- package/target/main/ts/api/process/host-tool.js +87 -0
- package/target/main/ts/cli/arguments.js +2 -4
- package/target/main/ts/cli/config.d.ts +20 -3
- package/target/main/ts/cli/config.js +43 -10
- package/target/main/ts/cli/imports.d.ts +1 -0
- package/target/main/ts/cli/imports.js +6 -2
- package/target/main/ts/cli/main.js +66 -215
- package/target/main/ts/cli/range-inspection.d.ts +25 -0
- package/target/main/ts/cli/range-inspection.js +29 -0
- package/target/main/ts/cli/range-jobs.d.ts +22 -0
- package/target/main/ts/cli/range-jobs.js +150 -0
- package/target/main/ts/cli/range-worker.d.ts +1 -0
- package/target/main/ts/cli/range-worker.js +36 -0
- package/target/main/ts/cli/reporting.d.ts +2 -7
- package/target/main/ts/cli/reporting.js +23 -37
- package/target/main/ts/compose/analysis-report.d.ts +1 -1
- package/target/main/ts/compose/analysis-report.js +8 -8
- package/target/main/ts/compose/analysis-results.d.ts +1 -1
- package/target/main/ts/compose/analysis-results.js +4 -6
- package/target/main/ts/compose/analysis-steps.d.ts +23 -0
- package/target/main/ts/compose/analysis-steps.js +215 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
- package/target/main/ts/compose/analyze-snapshot.js +8 -12
- package/target/main/ts/compose/built-ins.d.ts +3 -0
- package/target/main/ts/compose/built-ins.js +5 -0
- package/target/main/ts/compose/diff-coverage.d.ts +2 -4
- package/target/main/ts/compose/diff-coverage.js +16 -13
- package/target/main/ts/compose/history-cache.d.ts +3 -1
- package/target/main/ts/compose/history-cache.js +2 -0
- package/target/main/ts/compose/inspect.d.ts +6 -9
- package/target/main/ts/compose/inspect.js +11 -12
- package/target/main/ts/compose/languages.d.ts +4 -1
- package/target/main/ts/compose/languages.js +9 -6
- package/target/main/ts/compose/native-language-plugins.d.ts +0 -1
- package/target/main/ts/compose/native-language-plugins.js +11 -17
- package/target/main/ts/compose/phases.d.ts +126 -0
- package/target/main/ts/compose/phases.js +154 -0
- package/target/main/ts/compose/plugin-list.d.ts +8 -2
- package/target/main/ts/compose/plugin-list.js +4 -13
- package/target/main/ts/compose/process-plugins.js +1 -1
- package/target/main/ts/compose/review.d.ts +2 -4
- package/target/main/ts/compose/review.js +10 -9
- package/target/main/ts/compose/sources.d.ts +1 -2
- package/target/main/ts/compose/sources.js +7 -7
- package/target/main/ts/core/engine/execute.d.ts +4 -1
- package/target/main/ts/core/engine/execute.js +1 -1
- package/target/main/ts/core/engine/manifest.d.ts +0 -1
- package/target/main/ts/core/engine/manifest.js +9 -13
- package/target/main/ts/core/engine/plugin.d.ts +1 -1
- package/target/main/ts/core/engine/report-products.js +3 -2
- package/target/main/ts/core/model/changes.d.ts +2 -0
- package/target/main/ts/core/model/changes.js +5 -1
- package/target/main/ts/core/model/clone-source.d.ts +2 -0
- package/target/main/ts/core/model/clone-source.js +4 -0
- package/target/main/ts/core/model/code-structure.d.ts +4 -1
- package/target/main/ts/core/model/code-structure.js +3 -1
- package/target/main/ts/core/model/coverage-input.d.ts +12 -0
- package/target/main/ts/core/model/coverage-input.js +11 -0
- package/target/main/ts/core/model/diff-coverage.d.ts +2 -0
- package/target/main/ts/core/model/diff-coverage.js +9 -1
- package/target/main/ts/core/model/language.d.ts +28 -0
- package/target/main/ts/core/model/language.js +25 -1
- package/target/main/ts/core/model/quality-summary.js +1 -1
- package/target/main/ts/core/model/report.d.ts +0 -2
- package/target/main/ts/core/model/report.js +0 -20
- package/target/main/ts/core/ports/tool-runner.d.ts +13 -0
- package/target/main/ts/core/usecases/inspect.d.ts +1 -2
- package/target/main/ts/core/usecases/review.js +11 -3
- package/target/main/ts/index.d.ts +6 -33
- package/target/main/ts/index.js +3 -18
- package/target/main/ts/plugin.d.ts +7 -3
- package/target/main/ts/plugin.js +3 -0
- package/target/main/ts/plugins/built-in.d.ts +6 -0
- package/target/main/ts/plugins/built-in.js +39 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +3 -24
- package/target/main/ts/plugins/coverage/coverage.js +8 -11
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +1 -5
- package/target/main/ts/plugins/coverage/diff-coverage.js +5 -14
- package/target/main/ts/plugins/duplication/duplication.d.ts +1 -3
- package/target/main/ts/plugins/duplication/duplication.js +2 -6
- package/target/main/ts/plugins/language-js/babel-provider.js +3 -2
- package/target/main/ts/plugins/language-js/structural-observations.js +1 -1
- package/target/main/ts/plugins/language-js/syntax.d.ts +2 -0
- package/target/main/ts/plugins/language-js/syntax.js +11 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -8
- package/target/main/ts/plugins/maintainability/maintainability.js +4 -10
- package/target/main/ts/plugins/source/forges.js +1 -1
- package/target/main/ts/report/html/app/viewer-languages.d.ts +3 -1
- package/target/main/ts/report/html/app/viewer-languages.js +11 -1
- package/target/main/ts/report/html/app/viewer-metrics-view.js +1 -1
- package/target/main/ts/report/html/app/viewer-source-view.js +2 -2
- package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +7 -6
- package/target/main/ts/report/html/app/viewer-tokenizer.js +72 -71
- package/target/main/ts/report/html/site/export-site.d.ts +1 -5
- package/target/main/ts/report/html/site/export-site.js +2 -6
- package/target/main/ts/report/html/site/projects.d.ts +1 -3
- package/target/main/ts/report/html/site/projects.js +2 -4
- package/target/main/ts/report/json/projections/commit-summary.js +5 -7
- package/target/main/ts/report/json/projections/file-metrics.js +1 -1
- package/target/main/ts/report/json/projections/inspection-context.d.ts +1 -0
- package/target/main/ts/report/json/projections/inspection-context.js +19 -1
- package/target/main/ts/report/json/projections/inspection-details.js +7 -2
- package/target/main/ts/report/json/projections/metric-values.d.ts +5 -0
- package/target/main/ts/report/json/projections/metric-values.js +9 -6
- package/target/main/ts/report/json/store/local-store.js +2 -0
- package/target/main/ts/report/json/store/replace-file.d.ts +1 -1
- package/target/main/ts/report/json/store/replace-file.js +24 -3
- package/target/main/ts/report/json/store/store-check.js +10 -1
- package/target/main/ts/report/json/validation/metabranch.d.ts +1 -1
- package/target/main/ts/report/json/validation/metabranch.js +6 -3
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +3 -1
- package/target/main/ts/report.d.ts +13 -1
- package/target/main/ts/report.js +7 -1
- package/target/main/ts/api/git/metabranch-worktree.d.ts +0 -1
- package/target/main/ts/api/git/metabranch-worktree.js +0 -35
- package/target/main/ts/api/worker/remote-executor.d.ts +0 -2
- package/target/main/ts/api/worker/remote-executor.js +0 -46
- package/target/main/ts/api/worker/worker-protocol.d.ts +0 -7
- package/target/main/ts/api/worker/worker-protocol.js +0 -127
- package/target/main/ts/api/worker/worker.d.ts +0 -5
- package/target/main/ts/api/worker/worker.js +0 -86
- package/target/main/ts/compose/analysis-files.d.ts +0 -15
- package/target/main/ts/compose/analysis-files.js +0 -129
- package/target/main/ts/compose/analysis-imports.d.ts +0 -7
- package/target/main/ts/compose/analysis-imports.js +0 -36
- package/target/main/ts/compose/analysis-repository.d.ts +0 -7
- package/target/main/ts/compose/analysis-repository.js +0 -99
- package/target/main/ts/compose/analysis-sources.d.ts +0 -48
- package/target/main/ts/compose/analysis-sources.js +0 -54
- package/target/main/ts/compose/prepare-metabranch.d.ts +0 -9
- package/target/main/ts/compose/prepare-metabranch.js +0 -17
- package/target/main/ts/compose/security-plugins.d.ts +0 -1
- package/target/main/ts/compose/security-plugins.js +0 -7
- package/target/main/ts/core/usecases/compare.d.ts +0 -6
- package/target/main/ts/core/usecases/compare.js +0 -189
- package/target/main/ts/report/json/store/components.d.ts +0 -2
- package/target/main/ts/report/json/store/components.js +0 -32
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { realpath } from 'node:fs/promises';
|
|
2
|
-
import { execFile, spawn
|
|
2
|
+
import { execFile, spawn } from 'node:child_process';
|
|
3
3
|
import { promisify } from 'node:util';
|
|
4
|
-
import { comparePaths, isExcludedDirectory,
|
|
4
|
+
import { comparePaths, isExcludedDirectory, utf8 } from '../../core/model/snapshot.js';
|
|
5
5
|
import { isClaimedText, maxClaimedFileBytes } from '../../core/model/source.js';
|
|
6
6
|
import { isGeneratedSource } from '../../core/profile/exclusions.js';
|
|
7
|
+
import { gitExecutable } from './git-executable.js';
|
|
8
|
+
import { GitBlobHistory, gitBlobBatchBytes } from './blob-history.js';
|
|
7
9
|
const git = promisify(execFile);
|
|
8
|
-
const maxBuffer =
|
|
10
|
+
const maxBuffer = gitBlobBatchBytes;
|
|
9
11
|
const oidPattern = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
|
|
10
|
-
const
|
|
12
|
+
const baseEnv = { ...process.env, GIT_NO_LAZY_FETCH: '1' };
|
|
13
|
+
function gitEnvironment() {
|
|
14
|
+
return { ...baseEnv, PATH: process.env.PATH };
|
|
15
|
+
}
|
|
11
16
|
export async function gitRoot(directory) {
|
|
12
17
|
try {
|
|
13
18
|
return (await gitText(directory, ['rev-parse', '--show-toplevel'])).replace(/\r?\n$/, '');
|
|
@@ -22,16 +27,16 @@ export async function physicalGitRoot(directory) {
|
|
|
22
27
|
return realpath(await gitRoot(directory));
|
|
23
28
|
}
|
|
24
29
|
export async function gitText(directory, args, timeout) {
|
|
25
|
-
const { stdout } = await git(
|
|
30
|
+
const { stdout } = await git(gitExecutable(), ['--no-replace-objects', ...args], { cwd: directory, env: gitEnvironment(), maxBuffer, timeout });
|
|
26
31
|
return stdout;
|
|
27
32
|
}
|
|
28
33
|
export async function gitUtf8(directory, args, timeout) {
|
|
29
|
-
const result = await git(
|
|
34
|
+
const result = await git(gitExecutable(), ['--no-replace-objects', ...args], { cwd: directory, env: gitEnvironment(), encoding: 'buffer', maxBuffer, timeout });
|
|
30
35
|
return utf8(result.stdout);
|
|
31
36
|
}
|
|
32
37
|
export async function gitWorkingTreePaths(directory) {
|
|
33
38
|
try {
|
|
34
|
-
const { stdout } = await git(
|
|
39
|
+
const { stdout } = await git(gitExecutable(), ['--no-replace-objects', 'ls-files', '--cached', '--others', '--exclude-standard', '-z', '--', '.'], { cwd: directory, env: { ...gitEnvironment(), LC_ALL: 'C' }, encoding: 'buffer', maxBuffer });
|
|
35
40
|
return [...new Set(utf8(stdout).split('\0').filter(Boolean))];
|
|
36
41
|
}
|
|
37
42
|
catch (error) {
|
|
@@ -73,7 +78,7 @@ export async function gitTreeFiles(directory, commit, prefix, includeSize = fals
|
|
|
73
78
|
args.push(commit);
|
|
74
79
|
if (prefix !== undefined)
|
|
75
80
|
args.push('--', prefix);
|
|
76
|
-
const tree = await git(
|
|
81
|
+
const tree = await git(gitExecutable(), args, { cwd: directory, env: gitEnvironment(), encoding: 'buffer', maxBuffer });
|
|
77
82
|
const entries = [];
|
|
78
83
|
for (const entry of utf8(tree.stdout).split('\0')) {
|
|
79
84
|
if (!entry)
|
|
@@ -120,7 +125,7 @@ export class GitBlobReader {
|
|
|
120
125
|
});
|
|
121
126
|
}
|
|
122
127
|
start() {
|
|
123
|
-
const child = spawn(
|
|
128
|
+
const child = spawn(gitExecutable(), ['--no-replace-objects', 'cat-file', '--batch'], { cwd: this.directory, env: gitEnvironment() });
|
|
124
129
|
const errors = [];
|
|
125
130
|
child.stdout.on('data', (chunk) => this.receive(chunk));
|
|
126
131
|
child.stderr.on('data', (chunk) => errors.push(chunk));
|
|
@@ -184,86 +189,78 @@ function setHeld(child, held) {
|
|
|
184
189
|
handle.unref();
|
|
185
190
|
}
|
|
186
191
|
}
|
|
187
|
-
export async function readGitCommit(directory, revision, excludes, isSource, claims) {
|
|
192
|
+
export async function readGitCommit(directory, revision, { excludes, isSource, claims, history }) {
|
|
188
193
|
const id = await resolveGitCommit(directory, revision);
|
|
189
194
|
const tracked = (await gitTreeFiles(directory, id, undefined, true)).filter(({ path }) => !path.split('/').slice(0, -1).some(isExcludedDirectory) && !excludes(path));
|
|
190
|
-
const entries = tracked.filter(
|
|
191
|
-
const
|
|
195
|
+
const entries = tracked.filter(({ path }) => isSource(path));
|
|
196
|
+
const claimed = tracked.filter(({ path }) => !isSource(path) && claims?.(path));
|
|
197
|
+
const oversized = new Set(claimed.filter(({ size }) => size !== undefined && size > maxClaimedFileBytes).map(({ path }) => path));
|
|
198
|
+
const requested = claimed.filter(({ path }) => !oversized.has(path));
|
|
199
|
+
const blobs = await (history ?? new GitBlobHistory()).read(blobRequests(tracked.filter(({ path }) => !oversized.has(path)), entries, requested), ids => readBlobs(directory, ids));
|
|
192
200
|
const generated = new Set();
|
|
193
201
|
const files = entries.flatMap(({ path, oid }) => {
|
|
194
|
-
const bytes = blobs.get(oid);
|
|
202
|
+
const bytes = blobs.get(oid)?.bytes;
|
|
195
203
|
if (!bytes)
|
|
196
204
|
throw new Error(`Git blob unavailable: ${oid}`);
|
|
197
205
|
if (!isGeneratedSource(bytes))
|
|
198
|
-
return [{ path, bytes }];
|
|
206
|
+
return [{ path, bytes: snapshotBytes(bytes, history) }];
|
|
199
207
|
generated.add(path);
|
|
200
208
|
return [];
|
|
201
209
|
});
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const counts = inventoryLineCounts(directory, tracked.filter(({ path }) => !oversized.has(path)), blobs, (oid, bytes) => { if (requested.has(oid) && isClaimedText(bytes))
|
|
207
|
-
claimedBlobs.set(oid, bytes); });
|
|
208
|
-
for (const { path, oid } of claimed) {
|
|
209
|
-
const bytes = claimedBlobs.get(oid);
|
|
210
|
-
if (bytes && !oversized.has(path))
|
|
211
|
-
files.push({ path, bytes });
|
|
210
|
+
for (const { path, oid } of requested) {
|
|
211
|
+
const bytes = blobs.get(oid)?.bytes;
|
|
212
|
+
if (bytes && isClaimedText(bytes))
|
|
213
|
+
files.push({ path, bytes: snapshotBytes(bytes, history) });
|
|
212
214
|
}
|
|
213
215
|
files.sort((left, right) => comparePaths(left.path, right.path));
|
|
214
|
-
const inventory = tracked.filter(({ path }) => !generated.has(path)).map(({ path, oid, size }) => ({ path, lines:
|
|
216
|
+
const inventory = tracked.filter(({ path }) => !generated.has(path)).map(({ path, oid, size }) => ({ path, lines: blobs.get(oid)?.lines ?? null, ...(size === undefined ? {} : { bytes: size }) }));
|
|
215
217
|
const blobIds = new Map(tracked.map(({ path, oid }) => [path, oid]));
|
|
216
218
|
return { subject: { kind: 'commit', id }, files, blobIds, inventory, generatedExcluded: [...generated].sort(comparePaths),
|
|
217
219
|
...(oversized.size ? { oversizedClaims: [...oversized].sort(comparePaths) } : {}) };
|
|
218
220
|
}
|
|
219
|
-
function
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
flush();
|
|
236
|
-
return lines;
|
|
237
|
-
function flush() {
|
|
238
|
-
for (const [oid, value] of readBlobs(directory, batch)) {
|
|
239
|
-
lines.set(oid, textLineCount(value));
|
|
240
|
-
capture(oid, value);
|
|
221
|
+
function snapshotBytes(bytes, history) {
|
|
222
|
+
// Inspectors receive mutable byte arrays. Keep retained Git data independent of those inputs.
|
|
223
|
+
return history === undefined ? bytes : Buffer.from(bytes);
|
|
224
|
+
}
|
|
225
|
+
function blobRequests(tracked, sources, claimed) {
|
|
226
|
+
const required = new Set(sources.map(({ oid }) => oid));
|
|
227
|
+
const contents = new Set([...required, ...claimed.map(({ oid }) => oid)]);
|
|
228
|
+
const byId = new Map(tracked.map(({ oid, size }) => [oid, size]));
|
|
229
|
+
const requests = [];
|
|
230
|
+
for (const [id, size] of byId) {
|
|
231
|
+
if (size !== undefined && size + 128 <= maxBuffer) {
|
|
232
|
+
requests.push({ id, estimatedBytes: size + 128, contents: contents.has(id) });
|
|
233
|
+
}
|
|
234
|
+
else if (required.has(id)) {
|
|
235
|
+
requests.push({ id, estimatedBytes: maxBuffer, contents: true });
|
|
241
236
|
}
|
|
242
|
-
batch = [];
|
|
243
|
-
bytes = 0;
|
|
244
237
|
}
|
|
238
|
+
return requests;
|
|
245
239
|
}
|
|
246
|
-
function readBlobs(directory, ids) {
|
|
240
|
+
async function readBlobs(directory, ids) {
|
|
241
|
+
const command = git(gitExecutable(), ['--no-replace-objects', 'cat-file', '--batch'], { cwd: directory, env: gitEnvironment(), encoding: 'buffer', maxBuffer });
|
|
242
|
+
command.child.stdin?.on('error', () => { });
|
|
243
|
+
command.child.stdin?.end(`${ids.join('\n')}\n`);
|
|
244
|
+
const { stdout } = await command.catch((error) => {
|
|
245
|
+
if (error instanceof Error && 'code' in error && typeof error.code === 'number'
|
|
246
|
+
&& 'stderr' in error && Buffer.isBuffer(error.stderr)) {
|
|
247
|
+
throw new Error(`git cat-file failed: ${error.stderr.toString('utf8').trim()}`, { cause: error });
|
|
248
|
+
}
|
|
249
|
+
throw error;
|
|
250
|
+
});
|
|
247
251
|
const blobs = new Map();
|
|
248
|
-
if (ids.length === 0)
|
|
249
|
-
return blobs;
|
|
250
|
-
const result = spawnSync('git', ['--no-replace-objects', 'cat-file', '--batch'], { cwd: directory, env, input: `${ids.join('\n')}\n`, maxBuffer });
|
|
251
|
-
if (result.error)
|
|
252
|
-
throw result.error;
|
|
253
|
-
if (result.status !== 0)
|
|
254
|
-
throw new Error(`git cat-file failed: ${result.stderr.toString('utf8').trim()}`);
|
|
255
252
|
let cursor = 0;
|
|
256
253
|
for (const oid of ids) {
|
|
257
|
-
const end =
|
|
254
|
+
const end = stdout.indexOf(10, cursor);
|
|
258
255
|
if (end < 0)
|
|
259
256
|
throw new Error(`Missing Git blob header: ${oid}`);
|
|
260
|
-
const match = /^([a-f0-9]+) blob (\d+)$/.exec(
|
|
257
|
+
const match = /^([a-f0-9]+) blob (\d+)$/.exec(stdout.toString('ascii', cursor, end));
|
|
261
258
|
const size = Number(match?.[2]);
|
|
262
259
|
const from = end + 1;
|
|
263
260
|
const to = from + size;
|
|
264
|
-
if (match?.[1] !== oid || !Number.isSafeInteger(size) ||
|
|
261
|
+
if (match?.[1] !== oid || !Number.isSafeInteger(size) || stdout[to] !== 10)
|
|
265
262
|
throw new Error(`Invalid Git blob: ${oid}`);
|
|
266
|
-
blobs.set(oid,
|
|
263
|
+
blobs.set(oid, stdout.subarray(from, to));
|
|
267
264
|
cursor = to + 1;
|
|
268
265
|
}
|
|
269
266
|
return blobs;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GitSelection } from './git.js';
|
|
1
2
|
export interface SourceSelection {
|
|
2
3
|
readonly directory: string;
|
|
3
4
|
readonly output: string;
|
|
@@ -7,7 +8,7 @@ export interface SourceSelection {
|
|
|
7
8
|
readonly revision: string;
|
|
8
9
|
};
|
|
9
10
|
}
|
|
10
|
-
export declare function readInspectionSource(request: SourceSelection,
|
|
11
|
+
export declare function readInspectionSource(request: SourceSelection, selection: GitSelection): Promise<{
|
|
11
12
|
root: string;
|
|
12
13
|
snapshot: import("../../plugin.js").SourceSnapshot;
|
|
13
14
|
excludedOutput: string | null;
|
|
@@ -2,7 +2,8 @@ import { realpath } from 'node:fs/promises';
|
|
|
2
2
|
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
3
3
|
import { gitRoot, gitWorkingTreePaths, readGitCommit } from './git.js';
|
|
4
4
|
import { containsPath, readWorkingTree } from './local.js';
|
|
5
|
-
export async function readInspectionSource(request,
|
|
5
|
+
export async function readInspectionSource(request, selection) {
|
|
6
|
+
const { excludes, isSource, claims } = selection;
|
|
6
7
|
const root = await realpath('workingTree' in request.source ? request.directory : await gitRoot(request.directory));
|
|
7
8
|
const output = await physicalPath(resolve(request.output));
|
|
8
9
|
if (containsPath(output, root) || output.split(sep).includes('.git')) {
|
|
@@ -10,7 +11,7 @@ export async function readInspectionSource(request, excludes, isSource, claims)
|
|
|
10
11
|
}
|
|
11
12
|
const snapshot = 'workingTree' in request.source
|
|
12
13
|
? await readWorkingTree(root, output, excludes, isSource, claims, await gitWorkingTreePaths(root))
|
|
13
|
-
: await readGitCommit(root, request.source.revision,
|
|
14
|
+
: await readGitCommit(root, request.source.revision, selection);
|
|
14
15
|
const excludedOutput = snapshot.subject.kind === 'working-tree' && containsPath(root, output)
|
|
15
16
|
? relative(root, output).split(sep).join('/') : null;
|
|
16
17
|
return { root, snapshot, excludedOutput, output };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { utf8 } from '../../core/model/snapshot.js';
|
|
2
2
|
import { validSubjectId } from '../../core/model/report.js';
|
|
3
3
|
import { isSourcePathname } from '../../core/ports/source-provider.js';
|
|
4
|
+
import { cacheRoot } from '../cache/root.js';
|
|
4
5
|
import { GitBlobBatch } from './blob-batch.js';
|
|
5
6
|
import { gitText, gitTreeFiles } from './git.js';
|
|
6
|
-
import { cachedBlob
|
|
7
|
-
export function readLocalSources(repository, cache =
|
|
7
|
+
import { cachedBlob } from './source-cache.js';
|
|
8
|
+
export function readLocalSources(repository, cache = cacheRoot()) {
|
|
8
9
|
const git = new GitBlobBatch(repository);
|
|
9
10
|
const known = new Map();
|
|
10
11
|
return {
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export declare function sourceCacheRoot(env?: NodeJS.ProcessEnv, system?: NodeJS.Platform, home?: string): string;
|
|
2
|
-
export declare function clearSourceCache(root?: string): Promise<void>;
|
|
3
1
|
export declare function cachedBlob(root: string, oid: string, load: () => Promise<Buffer | undefined>): Promise<Buffer | undefined>;
|
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
2
|
import { lstat, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
4
|
-
import { join, resolve } from 'node:path';
|
|
3
|
+
import { join } from 'node:path';
|
|
5
4
|
import { validSubjectId } from '../../core/model/report.js';
|
|
6
|
-
export function sourceCacheRoot(env = process.env, system = process.platform, home = homedir()) {
|
|
7
|
-
if (env.REPOMETRY_CACHE_DIR)
|
|
8
|
-
return resolve(env.REPOMETRY_CACHE_DIR);
|
|
9
|
-
if (env.XDG_CACHE_HOME)
|
|
10
|
-
return resolve(env.XDG_CACHE_HOME, 'repometry');
|
|
11
|
-
if (system === 'darwin')
|
|
12
|
-
return join(home, 'Library', 'Caches', 'repometry');
|
|
13
|
-
if (system === 'win32' && env.LOCALAPPDATA)
|
|
14
|
-
return resolve(env.LOCALAPPDATA, 'repometry', 'cache');
|
|
15
|
-
return join(home, '.cache', 'repometry');
|
|
16
|
-
}
|
|
17
|
-
export async function clearSourceCache(root = sourceCacheRoot()) {
|
|
18
|
-
await rm(join(root, 'sources'), { recursive: true, force: true });
|
|
19
|
-
}
|
|
20
5
|
export async function cachedBlob(root, oid, load) {
|
|
21
6
|
if (!validSubjectId('commit', oid))
|
|
22
7
|
throw new Error('Invalid source blob ID');
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { posix, win32 } from 'node:path';
|
|
2
|
+
import { comparePaths } from '../../core/model/snapshot.js';
|
|
3
|
+
import { readCoverageXml } from './coverage-xml.js';
|
|
4
|
+
export function coberturaToLcov(text, input, source) {
|
|
5
|
+
const invalid = (line, reason) => { throw new Error('Invalid Cobertura report ' + input + ' at line ' + line + ': ' + reason); };
|
|
6
|
+
const { classes, sources } = parse(text, invalid);
|
|
7
|
+
const resolve = coveragePaths(source, sources);
|
|
8
|
+
const files = new Map();
|
|
9
|
+
for (const item of classes) {
|
|
10
|
+
const path = resolve(item.filename);
|
|
11
|
+
if (/[\r\n\0]/.test(path))
|
|
12
|
+
invalid(item.xmlLine, 'filename contains a line break or NUL');
|
|
13
|
+
const file = files.get(path) ?? { lines: new Map(), methods: [] };
|
|
14
|
+
files.set(path, file);
|
|
15
|
+
for (const line of item.lines.values())
|
|
16
|
+
mergeLine(file, line);
|
|
17
|
+
for (const method of item.methods)
|
|
18
|
+
file.methods.push(method);
|
|
19
|
+
}
|
|
20
|
+
return render(files);
|
|
21
|
+
}
|
|
22
|
+
const [sourcesPath, classesPath] = ['coverage/sources', 'coverage/packages/package/classes'];
|
|
23
|
+
const methodsPath = classesPath + '/class/methods';
|
|
24
|
+
const maxBranches = 2 ** 24; // Each branch becomes an entry of one Map, which holds at most 2^24.
|
|
25
|
+
function parse(input, invalid) {
|
|
26
|
+
const classes = [];
|
|
27
|
+
let branches = 0;
|
|
28
|
+
const sources = [];
|
|
29
|
+
let current;
|
|
30
|
+
let method;
|
|
31
|
+
let sourceText;
|
|
32
|
+
readCoverageXml(input, invalid, {
|
|
33
|
+
open(name, attributes, parents, line) {
|
|
34
|
+
const path = parents.join('/');
|
|
35
|
+
if (name === 'source' && path === sourcesPath)
|
|
36
|
+
sourceText = [];
|
|
37
|
+
if (name === 'class' && path === classesPath) {
|
|
38
|
+
const filename = attributes.get('filename');
|
|
39
|
+
if (!filename?.trim())
|
|
40
|
+
return invalid(line, '<class> has no filename');
|
|
41
|
+
current = { filename, name: attributes.get('name') ?? '', lines: new Map(), methods: [], xmlLine: line };
|
|
42
|
+
classes.push(current);
|
|
43
|
+
}
|
|
44
|
+
if (!current)
|
|
45
|
+
return;
|
|
46
|
+
if (name === 'method' && path === methodsPath) {
|
|
47
|
+
const key = current.name + '.' + (attributes.get('name') ?? '') + (attributes.get('signature') ?? '');
|
|
48
|
+
if (/[\r\n\0]/.test(key))
|
|
49
|
+
invalid(line, 'method name contains a line break or NUL');
|
|
50
|
+
method = { key };
|
|
51
|
+
current.methods.push(method);
|
|
52
|
+
}
|
|
53
|
+
if (name !== 'line')
|
|
54
|
+
return;
|
|
55
|
+
if (path === classesPath + '/class/lines') {
|
|
56
|
+
const entry = readLine(attributes, line, invalid, true);
|
|
57
|
+
branches += entry.branches?.total ?? 0;
|
|
58
|
+
if (branches > maxBranches)
|
|
59
|
+
invalid(line, 'too many branches');
|
|
60
|
+
mergeLine(current, entry);
|
|
61
|
+
}
|
|
62
|
+
if (method && path === methodsPath + '/method/lines') {
|
|
63
|
+
const entry = readLine(attributes, line, invalid, false);
|
|
64
|
+
if (!method.first || entry.number < method.first.number)
|
|
65
|
+
method.first = entry;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
close(name, parents) {
|
|
69
|
+
const path = parents.join('/');
|
|
70
|
+
if (name === 'source' && path === sourcesPath && sourceText) {
|
|
71
|
+
const value = sourceText.join('').trim();
|
|
72
|
+
if (value)
|
|
73
|
+
sources.push(value);
|
|
74
|
+
sourceText = undefined;
|
|
75
|
+
}
|
|
76
|
+
if (name === 'class' && path === classesPath)
|
|
77
|
+
current = undefined;
|
|
78
|
+
if (name === 'method' && path === methodsPath)
|
|
79
|
+
method = undefined;
|
|
80
|
+
},
|
|
81
|
+
text(value, parents) {
|
|
82
|
+
if (sourceText && parents.join('/') === sourcesPath + '/source')
|
|
83
|
+
sourceText.push(value);
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
return { classes, sources };
|
|
87
|
+
}
|
|
88
|
+
function readLine(attributes, xmlLine, invalid, classLine) {
|
|
89
|
+
const rawLine = attributes.get('number') ?? '';
|
|
90
|
+
const rawHits = attributes.get('hits') ?? '';
|
|
91
|
+
const number = Number(rawLine);
|
|
92
|
+
const hits = Number(rawHits);
|
|
93
|
+
if (!/^\d+$/.test(rawLine) || !Number.isSafeInteger(number) || number === 0)
|
|
94
|
+
invalid(xmlLine, 'line number must be a positive integer');
|
|
95
|
+
if (!/^\d+$/.test(rawHits))
|
|
96
|
+
invalid(xmlLine, 'hits must be a non-negative integer');
|
|
97
|
+
if (!Number.isSafeInteger(hits))
|
|
98
|
+
invalid(xmlLine, 'hit count exceeds the supported integer range');
|
|
99
|
+
return { number, hits, branches: classLine ? readBranches(attributes.get('condition-coverage'), xmlLine, invalid) : undefined };
|
|
100
|
+
}
|
|
101
|
+
function readBranches(value, xmlLine, invalid) {
|
|
102
|
+
const match = value === undefined ? null : /^\d+(?:\.\d+)?%\s*\((\d+)\/(\d+)\)$/.exec(value);
|
|
103
|
+
if (!match)
|
|
104
|
+
return undefined;
|
|
105
|
+
const covered = Number(match[1]);
|
|
106
|
+
const total = Number(match[2]);
|
|
107
|
+
if (!Number.isSafeInteger(total) || !Number.isSafeInteger(covered) || total === 0 || covered > total) {
|
|
108
|
+
invalid(xmlLine, 'invalid condition-coverage ' + JSON.stringify(value));
|
|
109
|
+
}
|
|
110
|
+
return { covered, total };
|
|
111
|
+
}
|
|
112
|
+
function mergeLine(file, line) {
|
|
113
|
+
const previous = file.lines.get(line.number);
|
|
114
|
+
const before = previous?.branches;
|
|
115
|
+
const next = line.branches;
|
|
116
|
+
const branches = next && (!before || next.total > before.total || (next.total === before.total && next.covered > before.covered))
|
|
117
|
+
? next : before;
|
|
118
|
+
file.lines.set(line.number, { number: line.number, hits: Math.max(line.hits, previous?.hits ?? 0), branches });
|
|
119
|
+
}
|
|
120
|
+
function coveragePaths({ root, snapshot }, sources) {
|
|
121
|
+
const platform = win32.isAbsolute(root) && !posix.isAbsolute(root) ? win32 : posix;
|
|
122
|
+
const slash = (path) => platform === win32 ? path.replaceAll('\\', '/') : path;
|
|
123
|
+
const known = new Set([...snapshot.files.map(file => file.path), ...(snapshot.generatedExcluded ?? []),
|
|
124
|
+
...(snapshot.inventory?.map(file => file.path) ?? [])]);
|
|
125
|
+
const normalize = (path) => slash(platform.isAbsolute(path) ? platform.relative(root, path) || '.' : platform.normalize(path));
|
|
126
|
+
const paths = new Map();
|
|
127
|
+
return (filename) => {
|
|
128
|
+
const prior = paths.get(filename);
|
|
129
|
+
if (prior !== undefined)
|
|
130
|
+
return prior;
|
|
131
|
+
const candidates = platform.isAbsolute(filename) ? [normalize(filename)]
|
|
132
|
+
: [...sources.map(source => normalize(platform.join(source, filename))), normalize(filename)];
|
|
133
|
+
const matches = [...new Set(candidates)].filter(path => known.has(path));
|
|
134
|
+
if (matches.length > 1)
|
|
135
|
+
throw new Error('Ambiguous Cobertura source ' + JSON.stringify(filename) + ': ' + matches.sort(comparePaths).join(', '));
|
|
136
|
+
const selected = matches[0] ?? candidates.at(-1); // An unknown relative filename stays relative to the root.
|
|
137
|
+
paths.set(filename, selected);
|
|
138
|
+
return selected;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function render(files) {
|
|
142
|
+
const output = [];
|
|
143
|
+
for (const [path, { lines, methods }] of [...files].sort(([left], [right]) => comparePaths(left, right))) {
|
|
144
|
+
output.push('SF:' + path);
|
|
145
|
+
for (const { key, first } of methods)
|
|
146
|
+
if (first)
|
|
147
|
+
output.push('FN:' + first.number + ',' + key, 'FNDA:' + first.hits + ',' + key);
|
|
148
|
+
for (const { number, hits, branches } of [...lines.values()].sort((a, b) => a.number - b.number)) {
|
|
149
|
+
output.push('DA:' + number + ',' + hits);
|
|
150
|
+
if (!branches)
|
|
151
|
+
continue;
|
|
152
|
+
const prefix = 'BRDA:' + number + ',0,';
|
|
153
|
+
for (let index = 0; index < branches.total; index++)
|
|
154
|
+
output.push(prefix + index + ',' + Number(index < branches.covered));
|
|
155
|
+
}
|
|
156
|
+
output.push('end_of_record');
|
|
157
|
+
}
|
|
158
|
+
return output.join('\n');
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=cobertura.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface XmlVisitor {
|
|
2
|
+
open(name: string, attributes: ReadonlyMap<string, string>, parents: readonly string[], line: number): void;
|
|
3
|
+
close(name: string, parents: readonly string[]): void;
|
|
4
|
+
text(value: string, parents: readonly string[]): void;
|
|
5
|
+
}
|
|
6
|
+
export declare function readCoverageXml(input: string, invalid: (line: number, reason: string) => never, visitor: XmlVisitor): void;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
const entities = new Map([['lt', '<'], ['gt', '>'], ['amp', '&'], ['quot', '"'], ['apos', "'"]]);
|
|
2
|
+
export function readCoverageXml(input, invalid, visitor) {
|
|
3
|
+
const text = input.replace(/^\uFEFF/, '').replace(/\r\n?/g, '\n');
|
|
4
|
+
const parents = [];
|
|
5
|
+
let root = false;
|
|
6
|
+
let line = 1;
|
|
7
|
+
let offset = 0;
|
|
8
|
+
const fail = (reason, position = offset) => invalid(line + text.slice(offset, position).split('\n').length - 1, reason);
|
|
9
|
+
while (offset < text.length) {
|
|
10
|
+
const token = readToken(text, offset, fail);
|
|
11
|
+
if (token.kind === 'open') {
|
|
12
|
+
if (parents.length === 0) {
|
|
13
|
+
if (root || token.name !== 'coverage')
|
|
14
|
+
invalid(line, 'expected a <coverage> root element');
|
|
15
|
+
root = true;
|
|
16
|
+
}
|
|
17
|
+
visitor.open(token.name, token.attributes, parents, line);
|
|
18
|
+
if (token.empty)
|
|
19
|
+
visitor.close(token.name, parents);
|
|
20
|
+
else
|
|
21
|
+
parents.push(token.name);
|
|
22
|
+
}
|
|
23
|
+
else if (token.kind === 'close') {
|
|
24
|
+
if (parents.pop() !== token.name)
|
|
25
|
+
invalid(line, 'unexpected </' + token.name + '>');
|
|
26
|
+
visitor.close(token.name, parents);
|
|
27
|
+
}
|
|
28
|
+
else if (token.kind === 'text') {
|
|
29
|
+
if (!parents.length && token.value.trim())
|
|
30
|
+
fail('expected a <coverage> root element', offset + text.slice(offset).search(/\S/));
|
|
31
|
+
visitor.text(token.value, parents);
|
|
32
|
+
}
|
|
33
|
+
for (; offset < token.end; offset++)
|
|
34
|
+
if (text.charCodeAt(offset) === 10)
|
|
35
|
+
line++;
|
|
36
|
+
}
|
|
37
|
+
if (parents.length)
|
|
38
|
+
invalid(line, 'unclosed <' + parents.at(-1) + '>');
|
|
39
|
+
if (!root)
|
|
40
|
+
invalid(1, 'expected a <coverage> root element');
|
|
41
|
+
}
|
|
42
|
+
function readToken(text, offset, fail) {
|
|
43
|
+
if (text[offset] !== '<') {
|
|
44
|
+
const next = text.indexOf('<', offset);
|
|
45
|
+
const end = next === -1 ? text.length : next;
|
|
46
|
+
return { kind: 'text', end, value: decode(text.slice(offset, end), offset, fail) };
|
|
47
|
+
}
|
|
48
|
+
if (text.startsWith('<![CDATA[', offset)) {
|
|
49
|
+
const end = sectionEnd(text, offset + 9, ']]>', fail);
|
|
50
|
+
return { kind: 'text', end, value: text.slice(offset + 9, end - 3) };
|
|
51
|
+
}
|
|
52
|
+
if (text.startsWith('<!--', offset))
|
|
53
|
+
return { kind: 'skip', end: sectionEnd(text, offset + 4, '-->', fail) };
|
|
54
|
+
if (text.startsWith('<?', offset))
|
|
55
|
+
return { kind: 'skip', end: sectionEnd(text, offset + 2, '?>', fail) };
|
|
56
|
+
if (text.startsWith('<!DOCTYPE', offset))
|
|
57
|
+
return { kind: 'skip', end: doctypeEnd(text, offset, fail) };
|
|
58
|
+
return readTag(text, offset, fail);
|
|
59
|
+
}
|
|
60
|
+
function sectionEnd(text, start, separator, fail) {
|
|
61
|
+
const end = text.indexOf(separator, start);
|
|
62
|
+
if (end === -1)
|
|
63
|
+
fail('malformed tag');
|
|
64
|
+
return end + separator.length;
|
|
65
|
+
}
|
|
66
|
+
function doctypeEnd(text, offset, fail) {
|
|
67
|
+
const name = /<!DOCTYPE\s+[A-Za-z_:][\w:.-]*/y;
|
|
68
|
+
name.lastIndex = offset;
|
|
69
|
+
if (!name.test(text))
|
|
70
|
+
fail('malformed tag');
|
|
71
|
+
// Quoted identifiers can contain brackets. Stop before reading any unquoted internal subset.
|
|
72
|
+
for (let index = name.lastIndex; index < text.length; index++) {
|
|
73
|
+
const char = text[index];
|
|
74
|
+
if (char === '>')
|
|
75
|
+
return index + 1;
|
|
76
|
+
if (char === '[')
|
|
77
|
+
fail('DOCTYPE with an internal subset is not supported', index);
|
|
78
|
+
if (char === '"' || char === "'")
|
|
79
|
+
index = text.indexOf(char, index + 1);
|
|
80
|
+
if (index === -1)
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
return fail('malformed tag');
|
|
84
|
+
}
|
|
85
|
+
function readTag(text, offset, fail) {
|
|
86
|
+
const tag = /<(\/?)([A-Za-z_:][\w:.-]*)/y;
|
|
87
|
+
tag.lastIndex = offset;
|
|
88
|
+
const match = tag.exec(text);
|
|
89
|
+
if (!match)
|
|
90
|
+
fail('malformed tag');
|
|
91
|
+
const name = match[2];
|
|
92
|
+
const ending = /\s*(\/?)>/y;
|
|
93
|
+
if (match[1]) {
|
|
94
|
+
ending.lastIndex = tag.lastIndex;
|
|
95
|
+
const close = ending.exec(text);
|
|
96
|
+
if (!close || close[1])
|
|
97
|
+
fail('malformed tag');
|
|
98
|
+
return { kind: 'close', end: ending.lastIndex, name };
|
|
99
|
+
}
|
|
100
|
+
const attributes = new Map();
|
|
101
|
+
const attr = /\s+([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"<]*)"|'([^'<]*)')/y;
|
|
102
|
+
for (let end = tag.lastIndex;; end = attr.lastIndex) {
|
|
103
|
+
ending.lastIndex = end;
|
|
104
|
+
const edge = ending.exec(text);
|
|
105
|
+
if (edge)
|
|
106
|
+
return { kind: 'open', end: ending.lastIndex, name, attributes, empty: edge[1] === '/' };
|
|
107
|
+
attr.lastIndex = end;
|
|
108
|
+
const value = attr.exec(text);
|
|
109
|
+
if (!value)
|
|
110
|
+
fail('malformed attribute', end + text.slice(end).search(/\S/));
|
|
111
|
+
const key = value[1];
|
|
112
|
+
const raw = value[2] ?? value[3];
|
|
113
|
+
if (attributes.has(key))
|
|
114
|
+
fail('duplicate attribute ' + key, end + value[0].search(/\S/));
|
|
115
|
+
attributes.set(key, decode(raw, attr.lastIndex - raw.length - 1, fail));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function decode(value, start, fail) {
|
|
119
|
+
return value.replace(/&(?:[^&;<\s]*;)?/g, (reference, index) => {
|
|
120
|
+
const entity = reference.slice(1, -1);
|
|
121
|
+
const named = entities.get(entity);
|
|
122
|
+
if (named !== undefined)
|
|
123
|
+
return named;
|
|
124
|
+
const code = /^#x[\da-f]+$/i.test(entity) ? Number.parseInt(entity.slice(2), 16)
|
|
125
|
+
: /^#\d+$/.test(entity) ? Number(entity.slice(1)) : NaN;
|
|
126
|
+
if (!xmlCharacter(code))
|
|
127
|
+
fail('unknown entity ' + reference, start + index);
|
|
128
|
+
return String.fromCodePoint(code);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function xmlCharacter(code) {
|
|
132
|
+
return code === 9 || code === 10 || code === 13 || (code >= 32 && code <= 0xd7ff)
|
|
133
|
+
|| (code >= 0xe000 && code <= 0xfffd) || (code >= 0x10000 && code <= 0x10ffff);
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=coverage-xml.js.map
|
|
@@ -3,8 +3,10 @@ export type LcovFiles = string | readonly string[];
|
|
|
3
3
|
export interface CoverageInputs {
|
|
4
4
|
readonly lcov?: LcovFiles;
|
|
5
5
|
readonly goCover?: LcovFiles;
|
|
6
|
+
readonly cobertura?: LcovFiles;
|
|
6
7
|
}
|
|
7
|
-
export declare function
|
|
8
|
+
export declare function hasCoverageInputs({ lcov, goCover, cobertura }: CoverageInputs): boolean;
|
|
9
|
+
export declare function readCoverageFiles({ lcov, goCover, cobertura }: CoverageInputs, source: CoverageSource): Promise<{
|
|
8
10
|
text: string;
|
|
9
11
|
inputDigests: string[];
|
|
10
12
|
}>;
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { comparePaths, digest, utf8 } from '../../core/model/snapshot.js';
|
|
3
|
+
import { coberturaToLcov } from './cobertura.js';
|
|
3
4
|
import { goCoverSource, goCoverToLcov } from './go-cover.js';
|
|
4
|
-
export
|
|
5
|
+
export function hasCoverageInputs({ lcov, goCover, cobertura }) {
|
|
6
|
+
return lcov !== undefined || goCover !== undefined || cobertura !== undefined;
|
|
7
|
+
}
|
|
8
|
+
export async function readCoverageFiles({ lcov, goCover, cobertura }, source) {
|
|
5
9
|
const lcovPaths = paths(lcov);
|
|
6
10
|
const goPaths = paths(goCover);
|
|
11
|
+
const coberturaPaths = paths(cobertura);
|
|
7
12
|
if (lcov !== undefined && lcovPaths.length === 0)
|
|
8
13
|
throw new Error('Provide at least one LCOV file');
|
|
9
14
|
if (goCover !== undefined && goPaths.length === 0)
|
|
10
15
|
throw new Error('Provide at least one Go coverprofile');
|
|
11
|
-
if (
|
|
16
|
+
if (cobertura !== undefined && coberturaPaths.length === 0)
|
|
17
|
+
throw new Error('Provide at least one Cobertura file');
|
|
18
|
+
if (lcovPaths.length === 0 && goPaths.length === 0 && coberturaPaths.length === 0)
|
|
12
19
|
throw new Error('Provide at least one coverage input');
|
|
13
|
-
const [lcovSources, goSources] = await Promise.all([
|
|
20
|
+
const [lcovSources, goSources, coberturaSources] = await Promise.all([
|
|
14
21
|
Promise.all(lcovPaths.map(readInput)),
|
|
15
22
|
readGoCoverFiles(goPaths, source),
|
|
23
|
+
Promise.all(coberturaPaths.map(file => readCobertura(file, source))),
|
|
16
24
|
]);
|
|
17
|
-
const sources = [...lcovSources, ...goSources];
|
|
25
|
+
const sources = [...lcovSources, ...goSources, ...coberturaSources];
|
|
18
26
|
sources.sort((a, b) => comparePaths(a.digest, b.digest));
|
|
19
27
|
return { text: sources.map(source => source.text).join('\n'), inputDigests: sources.map(source => source.digest) };
|
|
20
28
|
}
|
|
@@ -27,6 +35,17 @@ async function readGoCoverFiles(files, source) {
|
|
|
27
35
|
const [goSource, inputs] = await Promise.all([goCoverSource(source), Promise.all(files.map(readInput))]);
|
|
28
36
|
return inputs.map((input, index) => ({ ...input, text: goCoverToLcov(input.text, files[index], goSource) }));
|
|
29
37
|
}
|
|
38
|
+
async function readCobertura(path, source) {
|
|
39
|
+
const bytes = await readFile(path);
|
|
40
|
+
let text;
|
|
41
|
+
try {
|
|
42
|
+
text = utf8(bytes);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new Error('Invalid Cobertura report ' + path + ' at line 1: invalid UTF-8', { cause: error });
|
|
46
|
+
}
|
|
47
|
+
return { text: coberturaToLcov(text, path, source), digest: digest(text) };
|
|
48
|
+
}
|
|
30
49
|
async function readInput(path) {
|
|
31
50
|
const text = utf8(await readFile(path));
|
|
32
51
|
return { text, digest: digest(text) };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cachedGoParser(key: string, deadline: number, compile: () => Promise<string>, root?: string): Promise<string>;
|