@repometry/cli 0.4.0 → 0.5.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 CHANGED
@@ -39,11 +39,13 @@ npm install --global repometry
39
39
 
40
40
  ### Which package
41
41
 
42
- | Package | Command | Languages | Install size |
43
- | --- | --- | --- | --- |
44
- | `@repometry/cli` | `repometry-cli` | JavaScript, TypeScript | about 8 MB |
45
- | `repometry` | `repometry` | The above, Go, Python, Java, PHP | about 15 MB |
46
- | `@repometry/all` | `repometry-all` | The above, Ruby, Kotlin, HCL, Lua, Scala, Elixir, Rust, R, Zig, OCaml, Perl | about 33 MB |
42
+ | Package | Languages | Install size |
43
+ | --- | --- | --- |
44
+ | `@repometry/cli` | JavaScript, TypeScript | about 8 MB |
45
+ | `repometry` | The above, Go, Python, Java, PHP | about 15 MB |
46
+ | `@repometry/all` | The above, Ruby, Kotlin, HCL, Lua, Scala, Elixir, Rust, R, Zig, OCaml, Perl | about 33 MB |
47
+
48
+ Every package uses the `repometry` command. If several are installed together, the command uses the largest distribution.
47
49
 
48
50
  To add a language to `@repometry/cli`, install its `@repometry/language-*` package with your package manager and list it in `plugins`. Repometry never installs a plugin. See [Packages](docs/cli.md#packages).
49
51
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repometry/cli",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Track repository metrics without SaaS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "node": ">=24"
24
24
  },
25
25
  "bin": {
26
- "repometry-cli": "target/main/ts/cli/main.js"
26
+ "repometry": "target/main/ts/cli/main.js"
27
27
  },
28
28
  "exports": {
29
29
  ".": {
@@ -67,7 +67,7 @@
67
67
  "dependencies": {
68
68
  "@babel/parser": "7.29.15",
69
69
  "@babel/types": "7.29.15",
70
- "@repometry/core": "0.7.0",
70
+ "@repometry/core": "0.1.0",
71
71
  "ajv": "8.20.0",
72
72
  "semver": "7.8.6"
73
73
  },
@@ -55,7 +55,7 @@
55
55
  </div>
56
56
  <div class="verdict">
57
57
  <span id="coverage-mark" class="mark ring" aria-hidden="true"></span>
58
- <span class="verdict-text"><button type="button" role="tab" class="verdict-tab" data-metric="coverage" aria-controls="trend" aria-describedby="coverage-detail coverage-kinds">Coverage</button><span id="coverage-detail" class="verdict-detail"></span><span id="coverage-kinds" class="verdict-detail verdict-more" hidden></span></span>
58
+ <span class="verdict-text"><button type="button" role="tab" class="verdict-tab" data-metric="coverage" aria-controls="trend" aria-describedby="coverage-detail">Coverage</button><span id="coverage-detail" class="verdict-detail"></span></span>
59
59
  </div>
60
60
  <div class="verdict" id="security-verdict" data-loaded hidden>
61
61
  <span id="security-mark" class="mark severity"></span>
@@ -271,7 +271,6 @@ main:focus { outline: none; }
271
271
  .verdict-detail { color: var(--secondary); font-size: .875rem; overflow-wrap: anywhere; }
272
272
  /* The coverage kinds beyond lines: a quieter second line under the headline's detail. */
273
273
  .verdict-more { font-size: .8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
274
- .verdict-more > span { white-space: nowrap; }
275
274
  /* A detail that counts something leads to exactly what it counts. */
276
275
  .verdict-detail a { position: relative; z-index: 1; color: inherit; text-decoration-color: var(--rule-strong); }
277
276
  @container (min-width: 33rem) and (max-width: 49rem) {
@@ -0,0 +1,8 @@
1
+ import type { Distribution } from '../compose/distribution.js';
2
+ declare const candidates: readonly [readonly ['all', '@repometry/all/internal/distribution'], readonly ['repometry', 'repometry/internal/distribution']];
3
+ export interface CliDistribution {
4
+ readonly name: 'cli' | (typeof candidates)[number][0];
5
+ readonly distribution?: Distribution;
6
+ }
7
+ export declare function installedDistribution(): Promise<CliDistribution>;
8
+ export {};
@@ -0,0 +1,23 @@
1
+ const candidates = [
2
+ ['all', '@repometry/all/internal/distribution'],
3
+ ['repometry', 'repometry/internal/distribution'],
4
+ ];
5
+ export async function installedDistribution() {
6
+ for (const [name, specifier] of candidates) {
7
+ let entry;
8
+ try {
9
+ entry = import.meta.resolve(specifier);
10
+ }
11
+ catch (error) {
12
+ // A distribution may be absent or predate the optional entry point.
13
+ if (error instanceof Error && 'code' in error
14
+ && (error.code === 'ERR_MODULE_NOT_FOUND' || error.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'))
15
+ continue;
16
+ throw error;
17
+ }
18
+ const { default: distribution } = await import(entry);
19
+ return { name, distribution };
20
+ }
21
+ return { name: 'cli' };
22
+ }
23
+ //# sourceMappingURL=distribution.js.map
@@ -1,2 +1,2 @@
1
- import type { Distribution } from '../compose/distribution.js';
2
- export declare function runCli(distribution?: Distribution): Promise<void>;
1
+ import type { CliDistribution } from './distribution.js';
2
+ export declare function runCli(explicit?: CliDistribution): Promise<void>;
@@ -19,6 +19,7 @@ import { LocalObjectStore } from '../report/json/store/object-store.js';
19
19
  import { checkStore } from '../report/json/store/store-check.js';
20
20
  import { dispatch, flag, option } from './arguments.js';
21
21
  import { configFile, listOption, loadConfig, readConfig, readConfigValue, readDisplayConfig } from './config.js';
22
+ import { installedDistribution } from './distribution.js';
22
23
  import { analyzeCommits, isSaved } from './range-jobs.js';
23
24
  import { importerIds, readInputs } from './imports.js';
24
25
  import { displayLanguages, outputReports, reporterIds, viewTarget } from './reporting.js';
@@ -34,7 +35,7 @@ const storageOptions = { repo: repoOption, store: storeOption };
34
35
  const displayOptions = {
35
36
  ...configOptions, branch: option('NAME', 'Name the branch shown in the report.'), title: option('NAME', 'Set the report title.'),
36
37
  };
37
- function commands(distribution) {
38
+ function commands({ distribution, name }) {
38
39
  return {
39
40
  analyze: {
40
41
  description: 'Analyze and save one revision or a range of commits.', parameters: '[REVISION | BASE..[HEAD]]', max: 1,
@@ -85,7 +86,7 @@ function commands(distribution) {
85
86
  const { root, repository } = await repositoryContext(input);
86
87
  const config = await readConfig(root, input, true, distribution);
87
88
  const missingLanguagePlugins = repository === undefined ? [] : await discoverHead(repository, config);
88
- print({ schema: 'urn:repometry:schema:plugin-list:2', plugins: effectivePlugins(config.plugins, config.parsers),
89
+ print({ schema: 'urn:repometry:schema:plugin-list:2', distribution: name, plugins: effectivePlugins(config.plugins, config.parsers),
89
90
  importers: importerIds, reporters: reporterIds, ci: ['github'], stores: ['local', 'git'], missingLanguagePlugins });
90
91
  },
91
92
  },
@@ -298,11 +299,13 @@ function inspectionSummary(report) {
298
299
  function print(value) {
299
300
  process.stdout.write(JSON.stringify(value, null, 2) + '\n');
300
301
  }
301
- export async function runCli(distribution) {
302
+ export async function runCli(explicit) {
302
303
  try {
304
+ const selection = explicit ?? await installedDistribution();
305
+ const { distribution, name } = selection;
303
306
  const packageUrl = new URL(distribution?.packageUrl ?? '../../../../package.json', import.meta.url);
304
307
  const manifest = JSON.parse(await readFile(packageUrl, 'utf8'));
305
- process.exitCode = await dispatch(commands(distribution), process.argv.slice(2), manifest.version);
308
+ process.exitCode = await dispatch(commands(selection), process.argv.slice(2), `${manifest.version} ${name}`);
306
309
  }
307
310
  catch (error) {
308
311
  process.stderr.write(`repometry: ${error instanceof Error ? error.message : String(error)}\n`);
@@ -1,9 +1,7 @@
1
1
  import { byId, count, percent, quantity } from './viewer-dom.js';
2
2
  import { codeSmellCategories, securityCategories } from './viewer-files.js';
3
- import { coverageGrade, formatMetric, gradeScope, legalFindings, metricValue, pluginSpec, securityGrades, securityRisks } from './viewer-metrics.js';
3
+ import { coverageGrade, gradeScope, legalFindings, securityGrades, securityRisks } from './viewer-metrics.js';
4
4
  import { href } from './viewer-route.js';
5
- /** Coverage kinds beyond lines, by their registry keys, in the words the Overview card uses for them. */
6
- const coverageKinds = [['branch-coverage', 'Branches'], ['function-coverage', 'Functions']];
7
5
  /** A detail that counts something leads to exactly what it counts, where the report has a page for it. */
8
6
  export function detailText(id, text, link) {
9
7
  if (link === undefined) {
@@ -49,21 +47,6 @@ function ring(ratio) {
49
47
  svg.append(...(ratio !== null && ratio > 0 ? [track, arc] : [track]));
50
48
  return svg;
51
49
  }
52
- /** Line coverage leads; the other kinds the coverage report carries follow on a quieter line. */
53
- function renderCoverageKinds(report) {
54
- const kinds = coverageKinds.flatMap(([key, name]) => {
55
- const metric = key;
56
- const value = pluginSpec(metric) ? metricValue(report, metric, undefined) : null;
57
- if (value === null)
58
- return [];
59
- // Each kind keeps its number; a narrow card wraps between kinds, never inside one.
60
- const kind = document.createElement('span');
61
- kind.textContent = `${name} ${formatMetric(value, metric)}`;
62
- return [kind];
63
- });
64
- byId('coverage-kinds').replaceChildren(...kinds.flatMap((kind, index) => index ? [' · ', kind] : [kind]));
65
- byId('coverage-kinds').hidden = kinds.length === 0;
66
- }
67
50
  export function renderInspection(report) {
68
51
  const lines = report.lineCoverage;
69
52
  const coverage = lines && lines.total > 0 ? lines.covered / lines.total : null;
@@ -78,7 +61,6 @@ export function renderInspection(report) {
78
61
  delete mark.dataset.grade;
79
62
  else
80
63
  mark.dataset.grade = coverageGrade(coverage);
81
- renderCoverageKinds(report);
82
64
  }
83
65
  export function renderQuality(report, quality) {
84
66
  const maintainability = quality?.maintainability ?? null;