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
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { fork } from 'node:child_process';
|
|
2
|
+
import { lstat, realpath } from 'node:fs/promises';
|
|
3
|
+
import { availableParallelism } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { LocalReportStore } from '../report/json/store/local-store.js';
|
|
6
|
+
import { inspectCommits, rangeInspector } from './range-inspection.js';
|
|
7
|
+
const minimumChunkSize = 25;
|
|
8
|
+
const workerMemoryBytes = 512 * 1024 * 1024;
|
|
9
|
+
export function historyChunks(commits, concurrency, memory) {
|
|
10
|
+
if (commits.length === 0)
|
|
11
|
+
return [];
|
|
12
|
+
const workers = Math.max(1, Math.min(concurrency, Math.floor(memory / workerMemoryBytes), Math.floor(commits.length / minimumChunkSize)));
|
|
13
|
+
const size = Math.floor(commits.length / workers);
|
|
14
|
+
const remainder = commits.length % workers;
|
|
15
|
+
return Array.from({ length: workers }, (_, index) => {
|
|
16
|
+
const start = index * size + Math.min(index, remainder);
|
|
17
|
+
return commits.slice(start, start + size + Number(index < remainder));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export async function analyzeCommits(commits, options) {
|
|
21
|
+
const { inspection, config, configValue, concurrency, skipSaved } = options;
|
|
22
|
+
const inspectCommit = rangeInspector(inspection, config);
|
|
23
|
+
const outcomes = new Map();
|
|
24
|
+
const control = new AbortController();
|
|
25
|
+
const { signal } = control;
|
|
26
|
+
const stop = () => {
|
|
27
|
+
if (signal.aborted)
|
|
28
|
+
return;
|
|
29
|
+
control.abort();
|
|
30
|
+
process.stderr.write('Stopping after the current commit in each worker.\n');
|
|
31
|
+
};
|
|
32
|
+
process.on('SIGINT', stop);
|
|
33
|
+
const width = String(commits.length).length;
|
|
34
|
+
const record = (outcome) => {
|
|
35
|
+
outcomes.set(outcome.commit, outcome);
|
|
36
|
+
const state = outcome.state === 'failed' ? `failed: ${outcome.error}` : outcome.state;
|
|
37
|
+
process.stderr.write(`[${String(outcomes.size).padStart(width)}/${commits.length}] ${outcome.commit.slice(0, 7)} ${state}\n`);
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
const pending = await pendingCommits(commits, inspection.output, skipSaved, signal, record);
|
|
41
|
+
const chunks = historyChunks(pending, concurrency ?? availableParallelism(), process.availableMemory());
|
|
42
|
+
if (!signal.aborted && chunks.length === 1) {
|
|
43
|
+
await inspectCommits(chunks[0], inspectCommit, () => signal.aborted, record);
|
|
44
|
+
}
|
|
45
|
+
else if (!signal.aborted) {
|
|
46
|
+
await Promise.all(chunks.map(chunk => runChunk(chunk, inspection, configValue, signal, record)));
|
|
47
|
+
}
|
|
48
|
+
const results = collectOutcomes(commits, outcomes);
|
|
49
|
+
if (results.analyzed.length || results.skipped.length) {
|
|
50
|
+
await new LocalReportStore(await realpath(inspection.output)).refreshSummary();
|
|
51
|
+
}
|
|
52
|
+
return { ...results, interrupted: signal.aborted };
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
process.removeListener('SIGINT', stop);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function pendingCommits(commits, store, skipSaved, signal, record) {
|
|
59
|
+
if (!skipSaved)
|
|
60
|
+
return commits;
|
|
61
|
+
const pending = [];
|
|
62
|
+
for (const commit of commits) {
|
|
63
|
+
if (signal.aborted)
|
|
64
|
+
break;
|
|
65
|
+
if (await isSaved(store, commit))
|
|
66
|
+
record({ commit, state: 'skipped' });
|
|
67
|
+
else
|
|
68
|
+
pending.push(commit);
|
|
69
|
+
}
|
|
70
|
+
return pending;
|
|
71
|
+
}
|
|
72
|
+
export async function isSaved(store, id) {
|
|
73
|
+
try {
|
|
74
|
+
return (await lstat(join(store, 'commits', id, 'report.json'))).isFile();
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR'))
|
|
78
|
+
return false;
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function collectOutcomes(commits, outcomes) {
|
|
83
|
+
const analyzed = [], partial = [], skipped = [];
|
|
84
|
+
const failed = [];
|
|
85
|
+
for (const commit of commits) {
|
|
86
|
+
const outcome = outcomes.get(commit);
|
|
87
|
+
switch (outcome?.state) {
|
|
88
|
+
case 'partial': partial.push(commit);
|
|
89
|
+
// Partial analysis still leaves a saved report.
|
|
90
|
+
case 'analyzed':
|
|
91
|
+
analyzed.push(commit);
|
|
92
|
+
break;
|
|
93
|
+
case 'skipped':
|
|
94
|
+
skipped.push(commit);
|
|
95
|
+
break;
|
|
96
|
+
case 'failed':
|
|
97
|
+
failed.push({ commit, error: outcome.error });
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { analyzed, partial, skipped, failed };
|
|
102
|
+
}
|
|
103
|
+
async function runChunk(commits, inspection, config, signal, record) {
|
|
104
|
+
const pending = new Set(commits);
|
|
105
|
+
try {
|
|
106
|
+
// A terminal interrupt reaches the coordinator. Workers finish their current Git and analyzer subprocesses.
|
|
107
|
+
const worker = fork(new URL('./range-worker.js', import.meta.url), [], {
|
|
108
|
+
detached: process.platform !== 'win32', execArgv: [], stdio: ['ignore', 'ignore', 'inherit', 'ipc'],
|
|
109
|
+
});
|
|
110
|
+
const message = { kind: 'start', commits, inspection, config };
|
|
111
|
+
await runWorker(worker, message, signal, outcome => {
|
|
112
|
+
if (pending.delete(outcome.commit))
|
|
113
|
+
record(outcome);
|
|
114
|
+
});
|
|
115
|
+
failPending('Range worker exited before reporting the remaining commits');
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
failPending(error instanceof Error ? error.message : String(error));
|
|
119
|
+
}
|
|
120
|
+
function failPending(error) {
|
|
121
|
+
if (!signal.aborted)
|
|
122
|
+
for (const commit of pending)
|
|
123
|
+
record({ commit, state: 'failed', error });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function runWorker(worker, message, signal, record) {
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
const stop = () => {
|
|
129
|
+
const interrupt = { kind: 'stop' };
|
|
130
|
+
if (worker.connected)
|
|
131
|
+
worker.send(interrupt, () => { });
|
|
132
|
+
};
|
|
133
|
+
worker.on('message', record);
|
|
134
|
+
worker.once('error', reject);
|
|
135
|
+
worker.once('close', (code, cause) => {
|
|
136
|
+
signal.removeEventListener('abort', stop);
|
|
137
|
+
if (code === 0 || signal.aborted)
|
|
138
|
+
resolve();
|
|
139
|
+
else
|
|
140
|
+
reject(new Error(`Range worker exited with ${cause ?? code}`));
|
|
141
|
+
});
|
|
142
|
+
worker.send(message, error => { if (error && !signal.aborted)
|
|
143
|
+
reject(error); });
|
|
144
|
+
if (signal.aborted)
|
|
145
|
+
stop();
|
|
146
|
+
else
|
|
147
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=range-jobs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { parseConfig } from './config.js';
|
|
2
|
+
import { inspectCommits, rangeInspector } from './range-inspection.js';
|
|
3
|
+
let stopped = false;
|
|
4
|
+
let started = false;
|
|
5
|
+
const stop = () => { stopped = true; };
|
|
6
|
+
process.on('SIGINT', stop);
|
|
7
|
+
process.on('disconnect', stop);
|
|
8
|
+
process.on('message', (message) => {
|
|
9
|
+
if (message.kind === 'stop')
|
|
10
|
+
stop();
|
|
11
|
+
else if (!started) {
|
|
12
|
+
started = true;
|
|
13
|
+
void run(message);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
async function run({ commits, inspection, config }) {
|
|
17
|
+
try {
|
|
18
|
+
await inspectCommits(commits, rangeInspector(inspection, parseConfig(config)), () => stopped, send);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
if (process.connected)
|
|
26
|
+
process.disconnect();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function send(outcome) {
|
|
30
|
+
if (!process.connected)
|
|
31
|
+
return Promise.resolve();
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
process.send(outcome, error => error ? reject(error) : resolve());
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=range-worker.js.map
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { readConfig } from './config.js';
|
|
2
2
|
import type { Invocation } from './arguments.js';
|
|
3
3
|
import type { Store } from './store.js';
|
|
4
|
-
declare const reporters: {
|
|
5
|
-
readonly html: '.repometry/report/html';
|
|
6
|
-
readonly json: '.repometry/report/summary.json';
|
|
7
|
-
};
|
|
8
4
|
export declare const reporterIds: string[];
|
|
9
|
-
export declare function outputReports(root: string, store: Store,
|
|
10
|
-
format:
|
|
5
|
+
export declare function outputReports(root: string, store: Store, input: Invocation, config: Awaited<ReturnType<typeof readConfig>>): Promise<{
|
|
6
|
+
format: "html" | "json";
|
|
11
7
|
path: string;
|
|
12
8
|
}[]>;
|
|
13
9
|
export declare function viewTarget(input: Invocation, port: number): Promise<{
|
|
@@ -15,4 +11,3 @@ export declare function viewTarget(input: Invocation, port: number): Promise<{
|
|
|
15
11
|
close: () => void;
|
|
16
12
|
label: string;
|
|
17
13
|
}>;
|
|
18
|
-
export {};
|
|
@@ -9,42 +9,37 @@ import { commitSummary, withCommitMetadata } from '../report/json/projections/co
|
|
|
9
9
|
import { exportSite, siteSummary } from '../report/html/site/export-site.js';
|
|
10
10
|
import { readExportedSummary, serveExportedSite } from '../report/html/site/exported-server.js';
|
|
11
11
|
import { serveSite } from '../report/html/site/local-server.js';
|
|
12
|
-
import { readComponents } from '../report/json/store/components.js';
|
|
13
12
|
import { listPullReviews } from '../report/json/store/pull-review-store.js';
|
|
14
13
|
import { readConfig } from './config.js';
|
|
15
14
|
import { findRepository, invocationDirectory, isDirectory, selectStore } from './store.js';
|
|
16
15
|
const reporters = { html: '.repometry/report/html', json: '.repometry/report/summary.json' };
|
|
17
16
|
export const reporterIds = Object.keys(reporters);
|
|
18
|
-
export async function outputReports(root, store,
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
export async function outputReports(root, store, input, config) {
|
|
18
|
+
const typed = input.args.length > 0;
|
|
19
|
+
const base = typed ? invocationDirectory(input) : root;
|
|
20
|
+
const configured = config.reports.length ? config.reports : ['html'];
|
|
21
|
+
const requested = typed ? input.args : configured;
|
|
22
22
|
const requests = requested.map(spec => {
|
|
23
23
|
const equal = spec.indexOf('=');
|
|
24
24
|
const format = equal < 0 ? spec : spec.slice(0, equal);
|
|
25
25
|
const path = equal < 0 ? undefined : spec.slice(equal + 1);
|
|
26
26
|
if (!Object.hasOwn(reporters, format))
|
|
27
27
|
throw new Error(`Unknown reporter: ${format}. Choose ${reporterIds.join(', ')}.`);
|
|
28
|
-
if (path === ''
|
|
29
|
-
throw new Error('
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
if (path === '')
|
|
29
|
+
throw new Error('Expected an output path after FORMAT=');
|
|
30
|
+
const name = format;
|
|
31
|
+
return { format: name, path: path === undefined ? resolve(root, reporters[name]) : resolve(base, path) };
|
|
32
32
|
});
|
|
33
33
|
if (new Set(requests.map(request => request.path)).size !== requests.length)
|
|
34
34
|
throw new Error('Each report requires a separate output');
|
|
35
|
-
if (requests.length === 0)
|
|
36
|
-
return requests;
|
|
37
35
|
const repository = await findRepository(root);
|
|
38
36
|
const readCommitMetadata = repository === undefined ? undefined : commitMetadataReader(repository);
|
|
39
37
|
const sourceOption = input.text('sources') ?? config.sources;
|
|
40
38
|
const sources = resolveSourceLocator(sourceOption, { remotes: await sourceRemotes(root), env: process.env });
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const options = { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, sources, components, pulls, readCommitMetadata, branch: input.text('branch') ?? config.branch,
|
|
46
|
-
title: input.text('title') ?? (input.text('repo') ? basename(root) : undefined),
|
|
47
|
-
footer: !input.flag('no-footer') };
|
|
39
|
+
const pulls = store.path ? await listPullReviews(store.path) : [];
|
|
40
|
+
const options = { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, sources,
|
|
41
|
+
components: config.components, pulls, readCommitMetadata, branch: input.text('branch') ?? config.branch,
|
|
42
|
+
title: input.text('title') ?? basename(root) };
|
|
48
43
|
for (const request of requests) {
|
|
49
44
|
if (request.format === 'html')
|
|
50
45
|
await exportSite(store.reader, request.path, options);
|
|
@@ -68,10 +63,9 @@ async function writeSummary(path, data) {
|
|
|
68
63
|
}
|
|
69
64
|
}
|
|
70
65
|
export async function viewTarget(input, port) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const exported = await readExportedSummary(target);
|
|
66
|
+
const target = resolve(input.args[0] ?? '.');
|
|
67
|
+
const storeOption = input.text('store');
|
|
68
|
+
const exported = storeOption === undefined ? await readExportedSummary(target) : undefined;
|
|
75
69
|
const repository = await findRepository(target);
|
|
76
70
|
if (exported) {
|
|
77
71
|
const local = exported.sources?.provider === 'local' && repository ? readLocalSources(repository) : undefined;
|
|
@@ -80,26 +74,18 @@ export async function viewTarget(input, port) {
|
|
|
80
74
|
const data = resolve(target, 'data');
|
|
81
75
|
const dataStore = basename(target) === '.repometry' && await isDirectory(data);
|
|
82
76
|
const directStore = await isDirectory(resolve(target, 'commits'));
|
|
83
|
-
if (!repository && !dataStore && !directStore) {
|
|
77
|
+
if (!repository && !dataStore && !directStore && storeOption === undefined) {
|
|
84
78
|
throw new Error(`No report at ${target}: expected a repository, a .repometry folder or an exported report`);
|
|
85
79
|
}
|
|
86
80
|
const root = repository ?? target;
|
|
87
|
-
const store = selectStore(root,
|
|
81
|
+
const store = selectStore(root, storeOption ?? (dataStore ? data : directStore ? target : undefined), invocationDirectory(input));
|
|
88
82
|
if ((await store.reader.listSummaries?.() ?? []).length === 0)
|
|
89
|
-
throw new Error(`No saved inspections in ${store.path ??
|
|
90
|
-
const [
|
|
91
|
-
readComponents(componentsPath(root, input), input.text('components') === undefined),
|
|
92
|
-
store.path ? listPullReviews(store.path) : [],
|
|
93
|
-
readConfig(root, input),
|
|
94
|
-
]);
|
|
83
|
+
throw new Error(`No saved inspections in ${store.path ?? storeOption}. Run repometry analyze first.`);
|
|
84
|
+
const [pulls, config] = await Promise.all([store.path ? listPullReviews(store.path) : [], readConfig(root, input)]);
|
|
95
85
|
const local = repository ? readLocalSources(repository) : undefined;
|
|
96
|
-
const server = await serveSite(store.reader, port, { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, title: input.text('title') ?? basename(root), components, pulls,
|
|
86
|
+
const server = await serveSite(store.reader, port, { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, title: input.text('title') ?? basename(root), components: config.components, pulls,
|
|
97
87
|
branch: input.text('branch') ?? config.branch, readCommitMetadata: repository ? commitMetadataReader(repository) : undefined,
|
|
98
|
-
sources: local ? resolveSourceLocator('local', { remotes: [], env: {} }) : undefined
|
|
99
|
-
return { ...server, label: `${basename(root)} (live from ${store.path ??
|
|
100
|
-
}
|
|
101
|
-
function componentsPath(root, input) {
|
|
102
|
-
const explicit = input.text('components');
|
|
103
|
-
return explicit === undefined ? resolve(root, '.repometry/components.json') : resolve(invocationDirectory(input), explicit);
|
|
88
|
+
sources: local ? resolveSourceLocator('local', { remotes: [], env: {} }) : undefined }, local);
|
|
89
|
+
return { ...server, label: `${basename(root)} (live from ${store.path ?? storeOption})` };
|
|
104
90
|
}
|
|
105
91
|
//# sourceMappingURL=reporting.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Report } from '../core/model/report.js';
|
|
2
2
|
import type { AnalysisInput } from '../core/usecases/inspect.js';
|
|
3
3
|
import type { AnalysisResults } from './analysis-results.js';
|
|
4
|
-
import type { AnalysisSources } from './
|
|
4
|
+
import type { AnalysisSources } from './phases.js';
|
|
5
5
|
export declare const analysisProfile = "repository/v3";
|
|
6
6
|
export declare function assembleAnalysisReport(input: AnalysisInput, sources: AnalysisSources, results: AnalysisResults): Report;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { structureMeasures } from '../core/model/code-structure.js';
|
|
1
2
|
import { definitions } from '../core/model/measurement.js';
|
|
2
3
|
import { debtModel } from '../core/model/quality-summary.js';
|
|
3
4
|
import { reportSchema } from '../core/model/report.js';
|
|
4
5
|
import { comparePaths, digest, sourceDirectoriesExcluded, textLineCount } from '../core/model/snapshot.js';
|
|
5
6
|
import { defaultSourceExclusions, generatedSourcePolicy } from '../core/profile/exclusions.js';
|
|
6
7
|
import { duplicationSettings, structuralRules } from '../core/profile/maintainability.js';
|
|
7
|
-
import { defaultProvider } from './analysis-sources.js';
|
|
8
8
|
import { fileTypeId } from '../core/model/file-types.js';
|
|
9
9
|
export const analysisProfile = 'repository/v3';
|
|
10
10
|
const measurementDefinitions = {
|
|
@@ -21,7 +21,7 @@ const measurementDefinitions = {
|
|
|
21
21
|
export function assembleAnalysisReport(input, sources, results) {
|
|
22
22
|
const pluginData = results.pluginData();
|
|
23
23
|
const { snapshot } = input;
|
|
24
|
-
const fileCount = sources.sourceFiles.length;
|
|
24
|
+
const fileCount = sources.sourceFiles.length + sources.unavailableFiles.size;
|
|
25
25
|
return {
|
|
26
26
|
schema: reportSchema,
|
|
27
27
|
subject: snapshot.subject,
|
|
@@ -30,7 +30,7 @@ export function assembleAnalysisReport(input, sources, results) {
|
|
|
30
30
|
definitions: { ...Object.fromEntries((pluginData?.metrics ?? []).map(metric => [metric.id, metric.description ?? metric.label])),
|
|
31
31
|
...measurementDefinitions },
|
|
32
32
|
scope: { files: fileCount, parsed: results.parsed.size },
|
|
33
|
-
status: inspectionStatus(fileCount > 0
|
|
33
|
+
status: inspectionStatus(fileCount > 0, results),
|
|
34
34
|
measurements: results.measurements,
|
|
35
35
|
diagnostics: results.diagnostics,
|
|
36
36
|
findings: results.findings,
|
|
@@ -39,14 +39,14 @@ export function assembleAnalysisReport(input, sources, results) {
|
|
|
39
39
|
inventory: reportInventory(snapshot, sources, results) } }),
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], coverage }, { languages,
|
|
43
|
-
const securityScanners = results.securityScanners(
|
|
42
|
+
function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], coverage }, { languages, plugins }, results) {
|
|
43
|
+
const securityScanners = results.securityScanners(plugins);
|
|
44
44
|
return {
|
|
45
45
|
profile: analysisProfile, mode: snapshot.subject.kind,
|
|
46
46
|
source: { extensions: languages.extensions, ...(languages.globs.length ? { globs: languages.globs } : {}),
|
|
47
47
|
excludedDirectories: sourceDirectoriesExcluded, excludedOutput, excludedPaths,
|
|
48
48
|
defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
|
|
49
|
-
parser:
|
|
49
|
+
parser: languages.providers[0].plugin.settings,
|
|
50
50
|
maintainability: { structuralRules, duplication: duplicationSettings, debtModel, remediation: 'nonoverlapping-complexity/v1' },
|
|
51
51
|
coverage: coverage === undefined ? null : { inputDigest: digest(coverage.text), pathBase: coverage.sourceRoot,
|
|
52
52
|
merge: 'any-hit', hitCounts: 'sum',
|
|
@@ -59,7 +59,7 @@ function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], co
|
|
|
59
59
|
function pluginProvenance({ id, version, api, tools, kinds, claims, settings, providesLanguages, unavailableReason }) {
|
|
60
60
|
return { id, version, api, tools: tools ?? {}, kinds,
|
|
61
61
|
...(claims === undefined ? {} : { claims }), ...(settings === undefined ? {} : { settings }),
|
|
62
|
-
...(providesLanguages === undefined ? {} : { providesLanguages }), ...(unavailableReason === undefined ? {} : { unavailableReason }) };
|
|
62
|
+
...(providesLanguages === undefined ? {} : { providesLanguages: providesLanguages.map(({ syntax, ...language }) => language) }), ...(unavailableReason === undefined ? {} : { unavailableReason }) };
|
|
63
63
|
}
|
|
64
64
|
function inspectionStatus(hasSources, results) {
|
|
65
65
|
if (results.diagnostics.length > 0)
|
|
@@ -74,7 +74,7 @@ function reportInventory(snapshot, sources, results) {
|
|
|
74
74
|
}
|
|
75
75
|
return [...inventory].sort(([left], [right]) => comparePaths(left, right)).map(([path, { lines, bytes }]) => {
|
|
76
76
|
const provider = sources.providersByPath.get(path);
|
|
77
|
-
const unmeasured = results.unmeasured.get(path);
|
|
77
|
+
const unmeasured = sources.unavailableFiles.has(path) ? structureMeasures : results.unmeasured.get(path);
|
|
78
78
|
return { path, lines, ...(bytes === undefined ? {} : { bytes }), language: provider?.language(path) ?? fileTypeId(path),
|
|
79
79
|
analysed: results.parsed.has(path) || results.inspected.has(path), ...(provider === undefined ? {} : { provider: provider.key }),
|
|
80
80
|
...(unmeasured === undefined ? {} : { unmeasured }) };
|
|
@@ -18,7 +18,7 @@ export declare class AnalysisResults {
|
|
|
18
18
|
private readonly scanOnly;
|
|
19
19
|
private readonly securityOperations;
|
|
20
20
|
private readonly usedPlans;
|
|
21
|
-
constructor(plugins: readonly Plugin[],
|
|
21
|
+
constructor(plugins: readonly Plugin[], oversized: readonly string[]);
|
|
22
22
|
remember(task: PlannedOperation, syntaxProvider?: string): void;
|
|
23
23
|
operationRecords(): readonly ReturnType<typeof operationProvenance>[];
|
|
24
24
|
pluginData(): import("../core/model/plugin-data.js").PluginData | undefined;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ReportProducts } from '../core/engine/report-products.js';
|
|
2
|
-
import { inspectionKeys } from './analysis-sources.js';
|
|
3
2
|
export class AnalysisResults {
|
|
4
3
|
measurements = [];
|
|
5
4
|
findings = [];
|
|
@@ -14,11 +13,11 @@ export class AnalysisResults {
|
|
|
14
13
|
scanOnly;
|
|
15
14
|
securityOperations;
|
|
16
15
|
usedPlans = new Map();
|
|
17
|
-
constructor(plugins,
|
|
16
|
+
constructor(plugins, oversized) {
|
|
18
17
|
this.products = new ReportProducts(plugins);
|
|
19
18
|
this.diagnostics = oversized.map(oversizedClaim);
|
|
20
19
|
this.scanOnly = new Set(plugins.filter(plugin => plugin.claims?.scanOnly).flatMap(({ id, operations }) => operations.map(operation => `${id}/${operation.id}`)));
|
|
21
|
-
this.securityOperations = new Map(
|
|
20
|
+
this.securityOperations = new Map(plugins.filter(plugin => plugin.kinds.includes('security')).flatMap(plugin => plugin.operations.filter(({ role }) => role === 'inspection').map(({ id }) => [`${plugin.id}/${id}`, plugin.id])));
|
|
22
21
|
}
|
|
23
22
|
remember(task, syntaxProvider) {
|
|
24
23
|
this.usedPlans.set(JSON.stringify([task.key, [...task.inputs], syntaxProvider]), operationProvenance(task, syntaxProvider));
|
|
@@ -51,9 +50,8 @@ export class AnalysisResults {
|
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
recordInspection(task, messages, path, paths) {
|
|
54
|
-
for (const message of messages)
|
|
55
|
-
this.diagnostics.push({ operation: task.key, state: 'partial', message
|
|
56
|
-
...(path === undefined ? {} : { path }) });
|
|
53
|
+
for (const { message, path: own = path } of messages)
|
|
54
|
+
this.diagnostics.push({ operation: task.key, state: 'partial', ...(own === undefined ? {} : { path: own }), message });
|
|
57
55
|
const scanner = this.securityOperations.get(task.key);
|
|
58
56
|
if (scanner)
|
|
59
57
|
this.scanned.add(scanner);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { OperationCacheOptions } from '../core/engine/operation-cache.js';
|
|
2
|
+
import type { PlannedOperation } from '../core/engine/plan.js';
|
|
3
|
+
import type { CodeStructure } from '../core/model/code-structure.js';
|
|
4
|
+
import type { AnalysisInput } from '../core/usecases/inspect.js';
|
|
5
|
+
import type { AnalysisResults } from './analysis-results.js';
|
|
6
|
+
import type { HistoryFiles } from './history-cache.js';
|
|
7
|
+
import type { AnalysisSources } from './phases.js';
|
|
8
|
+
/** A parsed file's structure, kept for the inspections after the files, and the plugin that parsed it. */
|
|
9
|
+
export type ParsedFile = Readonly<{
|
|
10
|
+
path: string;
|
|
11
|
+
structure: CodeStructure;
|
|
12
|
+
parser: string;
|
|
13
|
+
}>;
|
|
14
|
+
/** The plan of a file the first provider parses and nothing claims, recorded before any file so the records keep their order. */
|
|
15
|
+
export declare function defaultFilePlan(sources: AnalysisSources): readonly PlannedOperation[];
|
|
16
|
+
/** Runs each language parsed over the repository on its files, with the plugin's other repository operations. */
|
|
17
|
+
export declare function collectRepositorySyntax(sources: AnalysisSources, results: AnalysisResults, cache?: OperationCacheOptions, history?: HistoryFiles): Promise<Map<string, CodeStructure>>;
|
|
18
|
+
/** Runs each file's inspections, with its provider's parse unless the repository syntax already read the file. */
|
|
19
|
+
export declare function inspectFiles(sources: AnalysisSources, batchFacts: ReadonlyMap<string, CodeStructure>, results: AnalysisResults, cache?: OperationCacheOptions, history?: HistoryFiles): Promise<ParsedFile[]>;
|
|
20
|
+
/** Runs every other repository inspection on the files its plugin claims. */
|
|
21
|
+
export declare function inspectRepositories(sources: AnalysisSources, results: AnalysisResults, cache?: OperationCacheOptions): Promise<void>;
|
|
22
|
+
/** Runs the inspections that read what the files phase gathered: clone sources and, when given, the coverage input. */
|
|
23
|
+
export declare function inspectAfterFiles({ coverage: input, excludedPaths, snapshot }: AnalysisInput, sources: AnalysisSources, parsed: readonly ParsedFile[], results: AnalysisResults, cache?: OperationCacheOptions): Promise<void>;
|