@theholocron/cli 5.0.0-alpha.278 → 5.0.0-alpha.279
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/dist/cli.mjs +212 -11
- package/dist/cli.mjs.map +1 -1
- package/dist/{index-4Xmvf7KG.d.mts → index-B59MneN-.d.mts} +1 -1
- package/dist/{index-D_HJGtOY.d.mts → index-aQ7iGTl7.d.mts} +315 -2
- package/dist/index.d.mts +2 -2
- package/dist/plugin/capabilities.d.mts +1 -1
- package/dist/plugin/capabilities.mjs +23 -0
- package/dist/presets.d.mts +1 -1
- package/package.json +6 -6
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { LOG_LEVELS, NoopAnalyticsSink, NoopErrorSink, redactObject } from "@theholocron/observability/core";
|
|
5
5
|
import yargs from "yargs";
|
|
6
6
|
import { hideBin } from "yargs/helpers";
|
|
@@ -2218,24 +2218,43 @@ function tokenContext(rawTokens) {
|
|
|
2218
2218
|
// src/commands/auth/auth-check.args.ts
|
|
2219
2219
|
const authCheckArgs = (yy) => yy.positional("provider", { type: "string" });
|
|
2220
2220
|
// src/plugin/capabilities/capabilities.ts
|
|
2221
|
+
/** How many providers each capability resolves to: one (`"single"`) or several active at once (`"many"`). */
|
|
2221
2222
|
const CARDINALITY = {
|
|
2223
|
+
/** `source` has exactly one provider. */
|
|
2222
2224
|
source: "single",
|
|
2225
|
+
/** `ci` has exactly one provider. */
|
|
2223
2226
|
ci: "single",
|
|
2227
|
+
/** `secrets` has exactly one provider. */
|
|
2224
2228
|
secrets: "single",
|
|
2229
|
+
/** `environments` has exactly one provider. */
|
|
2225
2230
|
environments: "single",
|
|
2231
|
+
/** `issues` has exactly one provider. */
|
|
2226
2232
|
issues: "single",
|
|
2233
|
+
/** `deployment` has exactly one provider. */
|
|
2227
2234
|
deployment: "single",
|
|
2235
|
+
/** `storage` has exactly one provider. */
|
|
2228
2236
|
storage: "single",
|
|
2237
|
+
/** `auth` has exactly one provider. */
|
|
2229
2238
|
auth: "single",
|
|
2239
|
+
/** `vault` has exactly one provider. */
|
|
2230
2240
|
vault: "single",
|
|
2241
|
+
/** `dns` has exactly one provider. */
|
|
2231
2242
|
dns: "single",
|
|
2243
|
+
/** `tooling` can have several providers active at once. */
|
|
2232
2244
|
tooling: "many",
|
|
2245
|
+
/** `notifications` can have several providers active at once. */
|
|
2233
2246
|
notifications: "many",
|
|
2247
|
+
/** `analytics` can have several providers active at once. */
|
|
2234
2248
|
analytics: "many",
|
|
2249
|
+
/** `errors` has exactly one provider. */
|
|
2235
2250
|
errors: "single",
|
|
2251
|
+
/** `logs` has exactly one provider. */
|
|
2236
2252
|
logs: "single",
|
|
2253
|
+
/** `monitoring` has exactly one provider. */
|
|
2237
2254
|
monitoring: "single",
|
|
2255
|
+
/** `wiki` has exactly one provider. */
|
|
2238
2256
|
wiki: "single",
|
|
2257
|
+
/** `workers` has exactly one provider. */
|
|
2239
2258
|
workers: "single"
|
|
2240
2259
|
};
|
|
2241
2260
|
/**
|
|
@@ -2250,6 +2269,7 @@ const REQUIRED_CAPABILITIES = [];
|
|
|
2250
2269
|
*/
|
|
2251
2270
|
var ElevationRequiredError = class extends Error {
|
|
2252
2271
|
elevation;
|
|
2272
|
+
/** Lets a caller tell this error from any other by name, across package copies. */
|
|
2253
2273
|
name = "ElevationRequiredError";
|
|
2254
2274
|
constructor(message, elevation, options) {
|
|
2255
2275
|
super(message, options);
|
|
@@ -3798,12 +3818,12 @@ async function runDeploy(input) {
|
|
|
3798
3818
|
};
|
|
3799
3819
|
}
|
|
3800
3820
|
}
|
|
3801
|
-
const SKIP_DIRS$
|
|
3821
|
+
const SKIP_DIRS$3 = [
|
|
3802
3822
|
".git",
|
|
3803
3823
|
"node_modules",
|
|
3804
3824
|
".turbo"
|
|
3805
3825
|
];
|
|
3806
|
-
const defaultWalkFiles$2 = (dir) => walkFilesSync(dir, { skip: SKIP_DIRS$
|
|
3826
|
+
const defaultWalkFiles$2 = (dir) => walkFilesSync(dir, { skip: SKIP_DIRS$3 });
|
|
3807
3827
|
/** `holocron deploy --files <dir>` — the non-git counterpart to `runDeploy`. */
|
|
3808
3828
|
async function runDeployFromFiles(input) {
|
|
3809
3829
|
const print = input.print ?? ((line) => console.log(line));
|
|
@@ -9990,13 +10010,13 @@ function generateHolocronConfig(opts) {
|
|
|
9990
10010
|
lines.push(``);
|
|
9991
10011
|
return lines.join("\n");
|
|
9992
10012
|
}
|
|
9993
|
-
const SKIP_DIRS$
|
|
10013
|
+
const SKIP_DIRS$2 = [
|
|
9994
10014
|
".git",
|
|
9995
10015
|
"node_modules",
|
|
9996
10016
|
"dist",
|
|
9997
10017
|
".turbo"
|
|
9998
10018
|
];
|
|
9999
|
-
const defaultWalkFiles$1 = (dir) => walkFilesSync(dir, { skip: SKIP_DIRS$
|
|
10019
|
+
const defaultWalkFiles$1 = (dir) => walkFilesSync(dir, { skip: SKIP_DIRS$2 });
|
|
10000
10020
|
function isBinary(content) {
|
|
10001
10021
|
for (let i = 0; i < Math.min(content.length, 8e3); i++) if (content.charCodeAt(i) === 0) return true;
|
|
10002
10022
|
return false;
|
|
@@ -12501,13 +12521,13 @@ function planDeps(root) {
|
|
|
12501
12521
|
};
|
|
12502
12522
|
}
|
|
12503
12523
|
// src/commands/probe/deps/report-deps.ts
|
|
12504
|
-
const kindOf = (section) => section === "peerDependencies" ? "peer" : section === "devDependencies" ? "dev" : "prod";
|
|
12524
|
+
const kindOf$1 = (section) => section === "peerDependencies" ? "peer" : section === "devDependencies" ? "dev" : "prod";
|
|
12505
12525
|
/** Every package that uses a dependency, with how. */
|
|
12506
12526
|
function usersOf(row) {
|
|
12507
12527
|
const byPkg = /* @__PURE__ */ new Map();
|
|
12508
12528
|
for (const e of row.edges) {
|
|
12509
12529
|
const kinds = byPkg.get(e.pkg) ?? /* @__PURE__ */ new Set();
|
|
12510
|
-
kinds.add(kindOf(e.section));
|
|
12530
|
+
kinds.add(kindOf$1(e.section));
|
|
12511
12531
|
byPkg.set(e.pkg, kinds);
|
|
12512
12532
|
}
|
|
12513
12533
|
return [...byPkg.entries()].map(([pkg, kinds]) => ({
|
|
@@ -12528,7 +12548,7 @@ function detail(p, filter) {
|
|
|
12528
12548
|
for (const e of r.edges) {
|
|
12529
12549
|
const entry = byGroup.get(e.group) ?? /* @__PURE__ */ new Map();
|
|
12530
12550
|
const kinds = entry.get(e.pkg) ?? /* @__PURE__ */ new Set();
|
|
12531
|
-
kinds.add(kindOf(e.section));
|
|
12551
|
+
kinds.add(kindOf$1(e.section));
|
|
12532
12552
|
entry.set(e.pkg, kinds);
|
|
12533
12553
|
byGroup.set(e.group, entry);
|
|
12534
12554
|
}
|
|
@@ -12827,7 +12847,7 @@ function writeLcov(ctx, repoRoot, packages) {
|
|
|
12827
12847
|
function percent(documented, total) {
|
|
12828
12848
|
return `${total === 0 ? 100 : Math.round(100 * documented / total)}%`;
|
|
12829
12849
|
}
|
|
12830
|
-
function summarise$
|
|
12850
|
+
function summarise$2(ctx, packages) {
|
|
12831
12851
|
let total = 0;
|
|
12832
12852
|
let documented = 0;
|
|
12833
12853
|
ctx.say({
|
|
@@ -12872,7 +12892,7 @@ function docsCoverageProbes(repoRoot, typedoc = runTypedoc(repoRoot), diff = rea
|
|
|
12872
12892
|
async run(ctx) {
|
|
12873
12893
|
const packages = measure();
|
|
12874
12894
|
writeLcov(ctx, repoRoot, packages);
|
|
12875
|
-
summarise$
|
|
12895
|
+
summarise$2(ctx, packages);
|
|
12876
12896
|
}
|
|
12877
12897
|
},
|
|
12878
12898
|
patch: {
|
|
@@ -12929,7 +12949,7 @@ function docsCoverageProbes(repoRoot, typedoc = runTypedoc(repoRoot), diff = rea
|
|
|
12929
12949
|
mkdirSync(dirname(file), { recursive: true });
|
|
12930
12950
|
writeFileSync(file, toLcov(packages));
|
|
12931
12951
|
});
|
|
12932
|
-
summarise$
|
|
12952
|
+
summarise$2(ctx, packages);
|
|
12933
12953
|
}
|
|
12934
12954
|
}
|
|
12935
12955
|
};
|
|
@@ -13399,6 +13419,186 @@ function listProbes(groups) {
|
|
|
13399
13419
|
}
|
|
13400
13420
|
return lines;
|
|
13401
13421
|
}
|
|
13422
|
+
// src/commands/probe/references/clone-org.ts
|
|
13423
|
+
const SKIP_DIRS$1 = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
13424
|
+
const MAX_FILE_BYTES = 5242880;
|
|
13425
|
+
/** Every text file under `dir`: not in `.git` or `node_modules`, under 5 MiB, and without a NUL in its first KiB. */
|
|
13426
|
+
function* textFiles(dir, root = dir) {
|
|
13427
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
13428
|
+
if (SKIP_DIRS$1.has(entry.name)) continue;
|
|
13429
|
+
const path = join(dir, entry.name);
|
|
13430
|
+
if (entry.isDirectory()) yield* textFiles(path, root);
|
|
13431
|
+
else if (entry.isFile() && statSync(path).size < MAX_FILE_BYTES) {
|
|
13432
|
+
const buffer = readFileSync(path);
|
|
13433
|
+
if (!buffer.subarray(0, 1024).includes(0)) yield {
|
|
13434
|
+
path: relative(root, path),
|
|
13435
|
+
text: buffer.toString("utf8")
|
|
13436
|
+
};
|
|
13437
|
+
}
|
|
13438
|
+
}
|
|
13439
|
+
}
|
|
13440
|
+
/**
|
|
13441
|
+
* Shallow-clones the default branch of each active (not archived) repository of `org` with `gh`, one at a time, and
|
|
13442
|
+
* removes every clone when the scan ends. Cloning, rather than GitHub code search, because search skips repositories
|
|
13443
|
+
* that are not indexed and gives no guarantee of completeness.
|
|
13444
|
+
*/
|
|
13445
|
+
function cloneOrg(org) {
|
|
13446
|
+
return JSON.parse(execFileSync("gh", [
|
|
13447
|
+
"repo",
|
|
13448
|
+
"list",
|
|
13449
|
+
org,
|
|
13450
|
+
"--limit",
|
|
13451
|
+
"200",
|
|
13452
|
+
"--json",
|
|
13453
|
+
"name,isArchived,isTemplate"
|
|
13454
|
+
], { encoding: "utf8" })).filter((repo) => !repo.isArchived).sort((a, b) => a.name.localeCompare(b.name)).map((repo) => ({
|
|
13455
|
+
name: repo.name,
|
|
13456
|
+
isTemplate: repo.isTemplate,
|
|
13457
|
+
files() {
|
|
13458
|
+
const scratch = mkdtempSync(join(tmpdir(), "refs-"));
|
|
13459
|
+
const dest = join(scratch, repo.name);
|
|
13460
|
+
execFileSync("gh", [
|
|
13461
|
+
"repo",
|
|
13462
|
+
"clone",
|
|
13463
|
+
`${org}/${repo.name}`,
|
|
13464
|
+
dest,
|
|
13465
|
+
"--",
|
|
13466
|
+
"--depth",
|
|
13467
|
+
"1",
|
|
13468
|
+
"--quiet"
|
|
13469
|
+
], { stdio: "pipe" });
|
|
13470
|
+
try {
|
|
13471
|
+
return [...textFiles(dest)];
|
|
13472
|
+
} finally {
|
|
13473
|
+
rmSync(scratch, {
|
|
13474
|
+
recursive: true,
|
|
13475
|
+
force: true
|
|
13476
|
+
});
|
|
13477
|
+
}
|
|
13478
|
+
}
|
|
13479
|
+
}));
|
|
13480
|
+
/* v8 ignore stop */
|
|
13481
|
+
}
|
|
13482
|
+
// src/commands/probe/references/find-references.ts
|
|
13483
|
+
/** The repository that hosts the files; its own references are the starters and shims, not callers. */
|
|
13484
|
+
const HOST_REPO = ".github";
|
|
13485
|
+
/** What a reference points at, from the text after the needle. */
|
|
13486
|
+
function kindOf(line, needle) {
|
|
13487
|
+
const rest = line.slice(line.indexOf(needle) + needle.length);
|
|
13488
|
+
if (rest.startsWith("workflows/")) return "workflow";
|
|
13489
|
+
if (rest.startsWith("actions/")) return "action";
|
|
13490
|
+
return "other";
|
|
13491
|
+
}
|
|
13492
|
+
/** Every line of every file of `repo` that contains `needle`. */
|
|
13493
|
+
function findReferences(repo, needle) {
|
|
13494
|
+
const found = [];
|
|
13495
|
+
for (const file of repo.files()) file.text.split("\n").forEach((line, index) => {
|
|
13496
|
+
if (!line.includes(needle)) return;
|
|
13497
|
+
found.push({
|
|
13498
|
+
repo: repo.name,
|
|
13499
|
+
file: file.path,
|
|
13500
|
+
line: index + 1,
|
|
13501
|
+
kind: kindOf(line, needle),
|
|
13502
|
+
text: line.trim()
|
|
13503
|
+
});
|
|
13504
|
+
});
|
|
13505
|
+
return found;
|
|
13506
|
+
}
|
|
13507
|
+
// src/commands/probe/references/references-probes.ts
|
|
13508
|
+
function scan(repos, needle) {
|
|
13509
|
+
return {
|
|
13510
|
+
repos,
|
|
13511
|
+
found: repos.flatMap((repo) => findReferences(repo, needle))
|
|
13512
|
+
};
|
|
13513
|
+
}
|
|
13514
|
+
function summarise$1(ctx, repos, found, needle, max) {
|
|
13515
|
+
ctx.say({
|
|
13516
|
+
status: "heading",
|
|
13517
|
+
label: `References to ${needle}`
|
|
13518
|
+
});
|
|
13519
|
+
for (const repo of repos) {
|
|
13520
|
+
const own = found.filter((ref) => ref.repo === repo.name);
|
|
13521
|
+
const files = new Set(own.map((ref) => ref.file)).size;
|
|
13522
|
+
const count = (kind) => own.filter((ref) => ref.kind === kind).length;
|
|
13523
|
+
ctx.say({
|
|
13524
|
+
status: "info",
|
|
13525
|
+
label: repo.name === ".github" ? `${repo.name} (host)` : repo.name,
|
|
13526
|
+
detail: `${files} files: ${count("workflow")} workflow, ${count("action")} action, ${count("other")} other`
|
|
13527
|
+
});
|
|
13528
|
+
}
|
|
13529
|
+
const outside = found.filter((ref) => ref.repo !== HOST_REPO).length;
|
|
13530
|
+
const detail = `${found.length - outside} more inside ${HOST_REPO}`;
|
|
13531
|
+
if (max !== void 0 && outside > max) ctx.say({
|
|
13532
|
+
status: "fail",
|
|
13533
|
+
label: `${outside} outside ${HOST_REPO}`,
|
|
13534
|
+
detail: `more than the ${max} allowed; ${detail}`
|
|
13535
|
+
});
|
|
13536
|
+
else ctx.say({
|
|
13537
|
+
status: "ok",
|
|
13538
|
+
label: `${outside} outside ${HOST_REPO}`,
|
|
13539
|
+
detail
|
|
13540
|
+
});
|
|
13541
|
+
}
|
|
13542
|
+
/**
|
|
13543
|
+
* `ci refs` counts the references to the reusable workflows and composite actions hosted in `<org>/.github` across
|
|
13544
|
+
* every active repository of the org. It is the exit test for removing the forwarding shims there: they can go when
|
|
13545
|
+
* the count outside `.github` is zero. `ci refs <max>` fails above `<max>`. `ci ref-list` prints each reference with
|
|
13546
|
+
* its file and line.
|
|
13547
|
+
*/
|
|
13548
|
+
function ciProbes(org, clone = cloneOrg) {
|
|
13549
|
+
const needle = (name) => `${name}/.github/.github/`;
|
|
13550
|
+
const read = (ctx) => {
|
|
13551
|
+
if (!org) {
|
|
13552
|
+
ctx.say({
|
|
13553
|
+
status: "fail",
|
|
13554
|
+
label: "no org",
|
|
13555
|
+
detail: "the config has no org to scan"
|
|
13556
|
+
});
|
|
13557
|
+
return null;
|
|
13558
|
+
}
|
|
13559
|
+
return {
|
|
13560
|
+
org,
|
|
13561
|
+
...scan(clone(org), needle(org))
|
|
13562
|
+
};
|
|
13563
|
+
};
|
|
13564
|
+
return {
|
|
13565
|
+
refs: {
|
|
13566
|
+
summary: "Count references to the reusable workflows and actions hosted in the org's .github repo (arg: max).",
|
|
13567
|
+
writes: false,
|
|
13568
|
+
async run(ctx) {
|
|
13569
|
+
const result = read(ctx);
|
|
13570
|
+
if (!result) return;
|
|
13571
|
+
const max = ctx.args?.[0] === void 0 ? void 0 : Number(ctx.args[0]);
|
|
13572
|
+
if (max !== void 0 && !Number.isInteger(max)) {
|
|
13573
|
+
ctx.say({
|
|
13574
|
+
status: "fail",
|
|
13575
|
+
label: `\`${ctx.args[0]}\` is not a number`,
|
|
13576
|
+
detail: "usage: ci refs [max]"
|
|
13577
|
+
});
|
|
13578
|
+
return;
|
|
13579
|
+
}
|
|
13580
|
+
summarise$1(ctx, result.repos, result.found, needle(result.org), max);
|
|
13581
|
+
}
|
|
13582
|
+
},
|
|
13583
|
+
"ref-list": {
|
|
13584
|
+
summary: "List every reference to the org's .github workflows and actions, with file and line.",
|
|
13585
|
+
writes: false,
|
|
13586
|
+
async run(ctx) {
|
|
13587
|
+
const result = read(ctx);
|
|
13588
|
+
if (!result) return;
|
|
13589
|
+
for (const ref of result.found) ctx.say({
|
|
13590
|
+
status: "info",
|
|
13591
|
+
label: `${ref.repo}:${ref.file}:${ref.line}`,
|
|
13592
|
+
detail: `${ref.kind}: ${ref.text}`
|
|
13593
|
+
});
|
|
13594
|
+
ctx.say({
|
|
13595
|
+
status: "ok",
|
|
13596
|
+
label: `${result.found.length} references`
|
|
13597
|
+
});
|
|
13598
|
+
}
|
|
13599
|
+
}
|
|
13600
|
+
};
|
|
13601
|
+
}
|
|
13402
13602
|
// src/ui/command-failure/command-failure.ts
|
|
13403
13603
|
/**
|
|
13404
13604
|
* Error class names whose `.message` is a complete, actionable sentence. Any other error is printed too, so a command
|
|
@@ -13572,6 +13772,7 @@ async function runProbeCommand(input) {
|
|
|
13572
13772
|
groups.set(DOCS_PROVIDER, docsCoverageProbes(input.context.repoRoot, input.typedoc, void 0, input.loaded.resolved.repoValidation?.docsCoverage ?? "off"));
|
|
13573
13773
|
groups.set(DEPS_PROVIDER, depsProbes(input.context.repoRoot, print));
|
|
13574
13774
|
groups.set(GENERATED_PROVIDER, generatedProbes(input.loaded, input.context.repoRoot));
|
|
13775
|
+
groups.set("ci", ciProbes(input.context.org));
|
|
13575
13776
|
if (!input.provider) {
|
|
13576
13777
|
if (input.pick) await input.pick(groups);
|
|
13577
13778
|
else for (const line of listProbes(groups)) print(line);
|