@davidbyoung/software-factory 0.1.7 → 0.1.9
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 +2 -0
- package/dist/agent/claude-code.mjs +15 -21
- package/dist/board.d.mts +20 -3
- package/dist/board.mjs +126 -38
- package/dist/cli.mjs +75 -9
- package/dist/code-host/github-setup.mjs +2 -2
- package/dist/code-host/github.mjs +4 -0
- package/dist/code-host/types.d.mts +2 -0
- package/dist/columns-suggest.d.mts +0 -1
- package/dist/columns-suggest.mjs +2 -8
- package/dist/commands.d.mts +2 -0
- package/dist/commands.mjs +22 -11
- package/dist/config.d.mts +12 -0
- package/dist/config.mjs +62 -11
- package/dist/doctor.d.mts +9 -1
- package/dist/doctor.mjs +209 -20
- package/dist/explain.d.mts +5 -0
- package/dist/explain.mjs +29 -0
- package/dist/init.d.mts +2 -0
- package/dist/init.mjs +143 -13
- package/dist/lib/color.d.mts +11 -0
- package/dist/lib/color.mjs +15 -0
- package/dist/npmrc.d.mts +29 -0
- package/dist/npmrc.mjs +98 -0
- package/dist/preset-commands.d.mts +2 -2
- package/dist/preset-commands.mjs +20 -24
- package/dist/preset.d.mts +4 -0
- package/dist/preset.mjs +13 -2
- package/dist/runner/github-actions.mjs +47 -10
- package/dist/runner/types.d.mts +13 -0
- package/dist/setup.d.mts +6 -1
- package/dist/site.d.mts +3 -0
- package/dist/site.mjs +8 -1
- package/dist/status.d.mts +5 -2
- package/dist/status.mjs +13 -22
- package/dist/sync.d.mts +14 -1
- package/dist/sync.mjs +83 -7
- package/dist/ticket-fields.d.mts +84 -0
- package/dist/ticket-fields.mjs +374 -0
- package/dist/ticket.mjs +8 -7
- package/dist/tickets/github-setup.mjs +1 -1
- package/dist/tickets/github.mjs +69 -0
- package/dist/tickets/index.d.mts +8 -1
- package/dist/tickets/index.mjs +67 -7
- package/dist/tickets/types.d.mts +27 -1
- package/dist/tickets/types.mjs +4 -0
- package/dist/tools.d.mts +1 -1
- package/docs/cli.md +44 -10
- package/docs/configuration.md +78 -25
- package/docs/design.md +10 -0
- package/docs/developing.md +49 -18
- package/docs/existing-repo.md +137 -8
- package/docs/github/by-hand.md +4 -0
- package/docs/github/reference.md +5 -0
- package/docs/github/setup.md +146 -8
- package/docs/limitations.md +0 -3
- package/docs/presets.md +5 -9
- package/docs/quick-start.md +3 -3
- package/docs/skills.md +3 -1
- package/docs/updating.md +3 -3
- package/package.json +4 -2
- package/settings.schema.json +68 -11
- package/skills/factory-deps/SKILL.md +4 -0
package/dist/config.mjs
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// factory config check # prints nothing when sound
|
|
9
9
|
//
|
|
10
10
|
// A list prints one item per line. A failure names the key and exits 1.
|
|
11
|
+
import { colorOn, painter, plain } from "./lib/color.mjs";
|
|
11
12
|
import { execFileSync } from "node:child_process";
|
|
12
13
|
import { existsSync, readFileSync } from "node:fs";
|
|
13
14
|
import { createRequire } from "node:module";
|
|
@@ -15,6 +16,7 @@ import { dirname, join } from "node:path";
|
|
|
15
16
|
import { DEFAULT_CODE_HOST, unsupportedCodeHost } from "./code-host/index.mjs";
|
|
16
17
|
import { matchesAny } from "./lib/glob.mjs";
|
|
17
18
|
import { DEFAULT_RUNNER, unsupportedRunner } from "./runner/index.mjs";
|
|
19
|
+
import { FACTORY_FIELDS } from "./ticket-fields.mjs";
|
|
18
20
|
import { BUILT, unsupported } from "./tool-names.mjs";
|
|
19
21
|
import { DEFAULT_COLUMNS, STATE_KEYS, sameName, watchOf, } from "./lib/work-status.mjs";
|
|
20
22
|
export class SettingsError extends Error {
|
|
@@ -144,7 +146,10 @@ export const SETTINGS_KEYS = {
|
|
|
144
146
|
],
|
|
145
147
|
tickets: ["type", "board", "columns", "fields"],
|
|
146
148
|
"tickets.columns": Object.keys(STATE_KEYS),
|
|
147
|
-
"tickets.fields":
|
|
149
|
+
"tickets.fields": [
|
|
150
|
+
...Object.keys(FIELD_DEFAULTS),
|
|
151
|
+
...FACTORY_FIELDS.map((f) => f.key),
|
|
152
|
+
],
|
|
148
153
|
"code-host": ["type"],
|
|
149
154
|
builds: ["trigger", "runner", "poll-minutes"],
|
|
150
155
|
specs: ["type", "check"],
|
|
@@ -312,6 +317,36 @@ function names(v, key, defaults) {
|
|
|
312
317
|
return [k, value.trim()];
|
|
313
318
|
}));
|
|
314
319
|
}
|
|
320
|
+
/** A key under `tickets.fields` naming a heading of the repository's own. */
|
|
321
|
+
export const OWN_HEADING = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
322
|
+
/** The ticket-side keys under `tickets.fields`: the four factory fields,
|
|
323
|
+
* each a ticket field's name or none, and any other key a heading of the
|
|
324
|
+
* repository's own. Spec and Acceptance criteria may share a field. */
|
|
325
|
+
function ticketFieldsOf(o) {
|
|
326
|
+
const out = Object.fromEntries(FACTORY_FIELDS.map((f) => [f.key, null]));
|
|
327
|
+
const seen = [];
|
|
328
|
+
for (const [k, value] of Object.entries(o)) {
|
|
329
|
+
if (k in FIELD_DEFAULTS)
|
|
330
|
+
continue;
|
|
331
|
+
const key = `tickets.fields.${k}`;
|
|
332
|
+
if (!FACTORY_FIELDS.some((f) => f.key === k) && !OWN_HEADING.test(k))
|
|
333
|
+
fail(key, "must be a heading in lowercase, with hyphens for spaces");
|
|
334
|
+
if (value === "none") {
|
|
335
|
+
out[k] = null;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (typeof value !== "string" || !value.trim())
|
|
339
|
+
fail(key, "must be a name, or none");
|
|
340
|
+
const name = value.trim();
|
|
341
|
+
const other = seen.find(([o, n]) => sameName(n, name) &&
|
|
342
|
+
!([o, k].includes("spec") && [o, k].includes("acceptance-criteria")));
|
|
343
|
+
if (other)
|
|
344
|
+
fail(key, `names the same field as ${other[0]}`);
|
|
345
|
+
seen.push([k, name]);
|
|
346
|
+
out[k] = name;
|
|
347
|
+
}
|
|
348
|
+
return out;
|
|
349
|
+
}
|
|
315
350
|
/** Each state's columns: a name, a list of names, or none, each left out
|
|
316
351
|
* keeping the factory's own name. Only an approved ticket goes to ready,
|
|
317
352
|
* so it takes one name. */
|
|
@@ -506,7 +541,9 @@ export function parseSettings(raw, exists, built = BUILT) {
|
|
|
506
541
|
const hasBoard = typeof board === "number";
|
|
507
542
|
if (tickets.columns !== undefined && !hasBoard)
|
|
508
543
|
fail("tickets.columns", "needs tickets.board");
|
|
509
|
-
|
|
544
|
+
const rawFields = isObj(tickets.fields) ? tickets.fields : {};
|
|
545
|
+
const boardFields = Object.fromEntries(Object.entries(rawFields).filter(([k]) => k in FIELD_DEFAULTS));
|
|
546
|
+
if (Object.keys(boardFields).length && !hasBoard)
|
|
510
547
|
fail("tickets.fields", "needs tickets.board");
|
|
511
548
|
const columns = columnNames(tickets.columns);
|
|
512
549
|
if (columns.backlog === null)
|
|
@@ -525,7 +562,10 @@ export function parseSettings(raw, exists, built = BUILT) {
|
|
|
525
562
|
}
|
|
526
563
|
if (columns.ready === null && trigger !== "manual")
|
|
527
564
|
fail("tickets.columns.ready", "no column shows ready, so nothing would start a build: name one, or set builds.trigger to manual");
|
|
528
|
-
|
|
565
|
+
if (tickets.fields !== undefined && !isObj(tickets.fields))
|
|
566
|
+
fail("tickets.fields", "must be a block of settings");
|
|
567
|
+
const fieldNames = names(boardFields, "tickets.fields", FIELD_DEFAULTS);
|
|
568
|
+
const ticketFields = ticketFieldsOf(rawFields);
|
|
529
569
|
const specsBlock = typed(top.specs ?? "none", "specs");
|
|
530
570
|
const specs = oneOf(specsBlock.type, "specs", SPECS, "none");
|
|
531
571
|
if (specsBlock.check !== undefined && specs !== "openspec")
|
|
@@ -564,6 +604,7 @@ export function parseSettings(raw, exists, built = BUILT) {
|
|
|
564
604
|
board: typeof board === "number" ? board : null,
|
|
565
605
|
columns,
|
|
566
606
|
fields: fieldNames,
|
|
607
|
+
ticketFields,
|
|
567
608
|
},
|
|
568
609
|
codeHost: { type: codeHost },
|
|
569
610
|
builds: { trigger, runner, pollMinutes },
|
|
@@ -775,6 +816,11 @@ export async function staleOf(d) {
|
|
|
775
816
|
? (P.findPackage(root, pkg)?.version ?? null)
|
|
776
817
|
: undefined),
|
|
777
818
|
load,
|
|
819
|
+
npmrcNames: (await import("./npmrc.mjs")).readNpmrc(d.readNpmrc
|
|
820
|
+
? d.readNpmrc()
|
|
821
|
+
: existsSync(join(root, ".npmrc"))
|
|
822
|
+
? readFileSync(join(root, ".npmrc"), "utf8")
|
|
823
|
+
: null).names,
|
|
778
824
|
});
|
|
779
825
|
}
|
|
780
826
|
/** The settings in the lock, after checking it is current where `check`
|
|
@@ -870,6 +916,7 @@ export const defaultDeps = (root = repoRoot(), env = process.env) => ({
|
|
|
870
916
|
loadYaml: async () => (await import("js-yaml")).load,
|
|
871
917
|
out: (line) => console.log(line),
|
|
872
918
|
err: (line) => console.error(line),
|
|
919
|
+
paint: painter(colorOn()),
|
|
873
920
|
});
|
|
874
921
|
/** The column each state shows in on the board, null for none. */
|
|
875
922
|
export function columnsOf(s) {
|
|
@@ -1000,17 +1047,21 @@ export async function main(argv, d) {
|
|
|
1000
1047
|
d.err(`warning: ${w}`);
|
|
1001
1048
|
if (s.site && !s.plugins.some((p) => p.role === "mockups"))
|
|
1002
1049
|
if (!d.exists(DESIGN_SKILL))
|
|
1003
|
-
d.err(`warning: ${DESIGN_SKILL} is missing: run \`
|
|
1050
|
+
d.err(`warning: ${DESIGN_SKILL} is missing: run \`factory sync\` to give the site its design skill`);
|
|
1051
|
+
d.out(`${(d.paint ?? plain)("green", "✓")} The settings are valid.`);
|
|
1004
1052
|
return 0;
|
|
1005
1053
|
}
|
|
1006
1054
|
if (command === "explain") {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
const
|
|
1013
|
-
|
|
1055
|
+
const { explainLines, markerOf, paintExplainLines } = await import("./explain.mjs");
|
|
1056
|
+
const lines = lockText !== null
|
|
1057
|
+
? lockSettingsLines(lockText)
|
|
1058
|
+
: await explainLines(s, markerOf(resolved.resolution), resolved.exists);
|
|
1059
|
+
// Printed only: the lock holds the settings, not how to read them.
|
|
1060
|
+
const header = [
|
|
1061
|
+
'# The settings in effect. "# default" marks the factory\'s own value,',
|
|
1062
|
+
"# a preset's name marks that preset's, and an unmarked line is yours.",
|
|
1063
|
+
];
|
|
1064
|
+
for (const line of paintExplainLines([...header, ...lines], d.paint ?? plain))
|
|
1014
1065
|
d.out(line);
|
|
1015
1066
|
return 0;
|
|
1016
1067
|
}
|
package/dist/doctor.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Settings } from "./config.mts";
|
|
2
|
+
import { type Paint } from "./lib/color.mts";
|
|
2
3
|
import type { Check } from "./setup.mts";
|
|
3
4
|
import { type Registry } from "./tools.mts";
|
|
4
5
|
export type { Check } from "./setup.mts";
|
|
@@ -19,11 +20,18 @@ export type DoctorDeps = {
|
|
|
19
20
|
hasCommand: (name: string) => boolean;
|
|
20
21
|
tools: Registry;
|
|
21
22
|
out: (line: string) => void;
|
|
23
|
+
paint?: Paint;
|
|
22
24
|
};
|
|
23
25
|
export declare function checks(d: DoctorDeps): Promise<Check[]>;
|
|
26
|
+
/** Whether Dependabot's settings name the registry at `url` under their
|
|
27
|
+
* `registries`, and every npm update lists it, or all of them. */
|
|
28
|
+
export declare function usesRegistry(settings: string, url: string): boolean;
|
|
24
29
|
/** One check as a line: a tick, a cross with what to do, or a dash for a
|
|
25
30
|
* part that is off. */
|
|
26
|
-
export declare function line(c: Check): string;
|
|
31
|
+
export declare function line(c: Check, paint?: Paint): string;
|
|
32
|
+
/** The checks under their headings, each group apart from the next, the
|
|
33
|
+
* whole indented by `indent` spaces. */
|
|
34
|
+
export declare function printChecks(found: Check[], paint?: Paint, indent?: number): string[];
|
|
27
35
|
export declare function main(_argv: string[], d: DoctorDeps): Promise<number>;
|
|
28
36
|
/** The checks, run in the repository this command runs in. */
|
|
29
37
|
export declare function doctorDeps(root?: string): DoctorDeps;
|
package/dist/doctor.mjs
CHANGED
|
@@ -4,17 +4,24 @@
|
|
|
4
4
|
//
|
|
5
5
|
// A stored secret cannot be read back, so a secret is checked only for
|
|
6
6
|
// being set.
|
|
7
|
-
import {
|
|
7
|
+
import { listed } from "./lib/listed.mjs";
|
|
8
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
9
|
+
import { load } from "js-yaml";
|
|
10
|
+
import { bareRegistry, npmrcAt, privateRegistries } from "./npmrc.mjs";
|
|
8
11
|
import { join } from "node:path";
|
|
9
12
|
import { defaultDeps, filesDeps, repoRoot, resolveFiles, staleOf, } from "./config.mjs";
|
|
10
13
|
import { presetChecks } from "./preset-commands.mjs";
|
|
11
14
|
import { hasCommand } from "./lib/has-command.mjs";
|
|
15
|
+
import { colorOn, painter, plain } from "./lib/color.mjs";
|
|
12
16
|
import { neededSecrets, PART_TEXT, PARTS, partsOn, } from "./parts.mjs";
|
|
13
17
|
import { branchDeps, CANNOT_TELL, needDefaultBranch, NoDefaultBranch, } from "./lib/default-branch.mjs";
|
|
14
18
|
import { differences, LOCK, PACKAGE, plan } from "./sync.mjs";
|
|
15
19
|
import { inUse, secretSteps, TOOLS } from "./tools.mjs";
|
|
16
|
-
|
|
17
|
-
const
|
|
20
|
+
import { fieldChecks } from "./ticket-fields.mjs";
|
|
21
|
+
const SYNC = "Run factory sync";
|
|
22
|
+
const INIT = "Run factory init";
|
|
23
|
+
const SETTINGS = "Settings and files";
|
|
24
|
+
const OFF = "Parts that are off";
|
|
18
25
|
const message = (e) => (e instanceof Error ? e.message : String(e));
|
|
19
26
|
/** -1, 0, or 1 as version `a` is older than, the same as, or newer than `b`. */
|
|
20
27
|
function compareVersions(a, b) {
|
|
@@ -37,7 +44,14 @@ export async function checks(d) {
|
|
|
37
44
|
s = await d.settings();
|
|
38
45
|
}
|
|
39
46
|
catch (e) {
|
|
40
|
-
return [
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
state: "fail",
|
|
50
|
+
text: "The settings are valid",
|
|
51
|
+
fix: message(e),
|
|
52
|
+
group: SETTINGS,
|
|
53
|
+
},
|
|
54
|
+
];
|
|
41
55
|
}
|
|
42
56
|
out.push({ state: "pass", text: "The settings are valid" });
|
|
43
57
|
let differ = null;
|
|
@@ -74,6 +88,9 @@ export async function checks(d) {
|
|
|
74
88
|
fix: compareVersions(installed, locked) < 0 ? "Run npm ci" : SYNC,
|
|
75
89
|
});
|
|
76
90
|
out.push(...((await d.lockChecks?.()) ?? []));
|
|
91
|
+
for (const c of out)
|
|
92
|
+
c.group = SETTINGS;
|
|
93
|
+
const under = (group, found) => found.map((c) => ({ ...c, group }));
|
|
77
94
|
const chosen = {
|
|
78
95
|
codeHost: s.codeHost.type,
|
|
79
96
|
tickets: s.tickets.type,
|
|
@@ -95,43 +112,63 @@ export async function checks(d) {
|
|
|
95
112
|
opened,
|
|
96
113
|
});
|
|
97
114
|
const [agent, codeHost, tickets, runner] = inUse(d.tools, chosen);
|
|
98
|
-
out.push(...((await codeHost.setup.checks?.({ ...context([]), secrets: null })) ??
|
|
99
|
-
|
|
100
|
-
|
|
115
|
+
out.push(...under(codeHost.label, (await codeHost.setup.checks?.({ ...context([]), secrets: null })) ?? []));
|
|
116
|
+
// A secret the organization shares with the repository counts as set.
|
|
117
|
+
const isOrganization = await opened.codeHost
|
|
118
|
+
.ownerIsOrganization()
|
|
119
|
+
.catch(() => true);
|
|
120
|
+
const shared = isOrganization
|
|
121
|
+
? await opened.runner.organizationSecretNames().catch(() => [])
|
|
122
|
+
: [];
|
|
123
|
+
let own;
|
|
101
124
|
try {
|
|
102
|
-
|
|
125
|
+
own = await opened.runner.secretNames();
|
|
103
126
|
}
|
|
104
127
|
catch (e) {
|
|
105
|
-
|
|
128
|
+
own = null;
|
|
106
129
|
out.push({
|
|
107
130
|
state: "fail",
|
|
108
131
|
text: "The secrets can be listed",
|
|
109
132
|
fix: message(e),
|
|
133
|
+
group: runner.label,
|
|
110
134
|
});
|
|
111
135
|
}
|
|
136
|
+
const secrets = own === null ? null : [...own, ...shared];
|
|
112
137
|
const cloudNeeds = secretSteps(d.tools, context(["cloud"])).flatMap((x) => x.step.needs.filter((n) => n.part === "cloud"));
|
|
113
138
|
const on = partsOn(s, secrets ?? [], cloudNeeds);
|
|
114
139
|
const needed = neededSecrets(on, secretSteps(d.tools, context(on)));
|
|
115
140
|
const secretLine = (anyOf, forWhat) => {
|
|
116
141
|
const found = anyOf.find((n) => secrets.includes(n));
|
|
142
|
+
const by = found && !own.includes(found) ? " by the organization" : "";
|
|
117
143
|
return found
|
|
118
|
-
? { state: "pass", text: `${found} is set, for ${forWhat}` }
|
|
144
|
+
? { state: "pass", text: `${found} is set${by}, for ${forWhat}` }
|
|
119
145
|
: {
|
|
120
146
|
state: "fail",
|
|
121
147
|
text: `${anyOf.join(" or ")} is not set, for ${forWhat}`,
|
|
122
148
|
fix: INIT,
|
|
123
149
|
};
|
|
124
150
|
};
|
|
151
|
+
// One line per secret, naming every part that reads it.
|
|
152
|
+
const reads = new Map();
|
|
153
|
+
const reading = (anyOf, forWhat) => {
|
|
154
|
+
// Parts can accept different names for one secret: the one set is the
|
|
155
|
+
// line, or the names asked for when none is.
|
|
156
|
+
const key = anyOf.find((n) => secrets.includes(n)) ?? anyOf.join(" or ");
|
|
157
|
+
const entry = reads.get(key) ?? { anyOf, fors: [] };
|
|
158
|
+
if (!entry.fors.includes(forWhat))
|
|
159
|
+
entry.fors.push(forWhat);
|
|
160
|
+
reads.set(key, entry);
|
|
161
|
+
};
|
|
125
162
|
for (const part of PARTS) {
|
|
126
163
|
if (!on.has(part)) {
|
|
127
|
-
out.push({ state: "off", text:
|
|
164
|
+
out.push({ state: "off", text: PART_TEXT[part].name, group: OFF });
|
|
128
165
|
continue;
|
|
129
166
|
}
|
|
130
167
|
if (secrets === null)
|
|
131
168
|
continue;
|
|
132
169
|
const forPart = PART_TEXT[part].name.replace(/^./, (c) => c.toLowerCase());
|
|
133
170
|
for (const need of needed.filter((n) => n.part === part))
|
|
134
|
-
|
|
171
|
+
reading(need.anyOf, forPart);
|
|
135
172
|
}
|
|
136
173
|
// A gate is no part and fails no check: it is shown as off, since a
|
|
137
174
|
// build cannot finish without one.
|
|
@@ -139,29 +176,180 @@ export async function checks(d) {
|
|
|
139
176
|
out.push({
|
|
140
177
|
state: "off",
|
|
141
178
|
text: "commands.gate is not set: a build cannot finish until it is",
|
|
179
|
+
group: SETTINGS,
|
|
142
180
|
});
|
|
143
181
|
if (secrets !== null)
|
|
144
182
|
for (const need of needed.filter((n) => n.part === null))
|
|
145
|
-
|
|
183
|
+
reading(need.anyOf, need.tool);
|
|
184
|
+
for (const { anyOf, fors } of reads.values())
|
|
185
|
+
out.push({ ...secretLine(anyOf, listed(fors)), group: runner.label });
|
|
186
|
+
out.push(...under(runner.label, await npmChecks(d.root, opened, isOrganization, own, shared)));
|
|
146
187
|
for (const tool of [tickets, runner, agent])
|
|
147
|
-
out.push(...((await tool.setup.checks?.({ ...context(on), secrets })) ?? []));
|
|
188
|
+
out.push(...under(tool.label, (await tool.setup.checks?.({ ...context(on), secrets })) ?? []));
|
|
189
|
+
out.push(...under(tickets.label, await fieldChecks(opened.tickets, s.tickets.ticketFields, s.repository, tickets.label)));
|
|
190
|
+
const order = [
|
|
191
|
+
SETTINGS,
|
|
192
|
+
codeHost.label,
|
|
193
|
+
runner.label,
|
|
194
|
+
tickets.label,
|
|
195
|
+
agent.label,
|
|
196
|
+
OFF,
|
|
197
|
+
];
|
|
198
|
+
const rank = (c) => order.indexOf(c.group ?? SETTINGS);
|
|
199
|
+
return out
|
|
200
|
+
.map((c, i) => [c, i])
|
|
201
|
+
.sort(([a, i], [b, j]) => rank(a) - rank(b) || i - j)
|
|
202
|
+
.map(([c]) => c);
|
|
203
|
+
}
|
|
204
|
+
const DEPENDABOT = ".github/dependabot.yml";
|
|
205
|
+
const FOR_NPM = "for installing what .npmrc names";
|
|
206
|
+
const FOR_DEPENDABOT = "for installing on Dependabot's pull requests";
|
|
207
|
+
/** The checks for the variables `.npmrc`'s sign-in lines read: each one's
|
|
208
|
+
* secret for Actions and for Dependabot, and whether Dependabot's settings
|
|
209
|
+
* use each registry `.npmrc` names. */
|
|
210
|
+
async function npmChecks(root, opened, isOrganization, own, shared) {
|
|
211
|
+
const npmrc = npmrcAt(root);
|
|
212
|
+
if (!npmrc.names.length)
|
|
213
|
+
return [];
|
|
214
|
+
const out = [];
|
|
215
|
+
let dependabot;
|
|
216
|
+
try {
|
|
217
|
+
dependabot = await opened.runner.dependabotSecretNames();
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
dependabot = null;
|
|
221
|
+
out.push({
|
|
222
|
+
state: "fail",
|
|
223
|
+
text: "The Dependabot secrets can be listed",
|
|
224
|
+
fix: message(e),
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
const tokens = npmrc.names.filter((n) => n !== "GITHUB_TOKEN");
|
|
228
|
+
const organizations = isOrganization &&
|
|
229
|
+
dependabot !== null &&
|
|
230
|
+
tokens.some((n) => !dependabot.includes(n))
|
|
231
|
+
? await opened.runner.organizationDependabotSecretNames(await opened.codeHost.isPrivate())
|
|
232
|
+
: [];
|
|
233
|
+
for (const name of npmrc.names) {
|
|
234
|
+
if (name === "GITHUB_TOKEN") {
|
|
235
|
+
out.push({
|
|
236
|
+
state: "off",
|
|
237
|
+
text: "GITHUB_TOKEN is the workflow's own token: it installs only the packages that give this repository access",
|
|
238
|
+
});
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (own !== null)
|
|
242
|
+
out.push(own.includes(name)
|
|
243
|
+
? { state: "pass", text: `${name} is set, ${FOR_NPM}` }
|
|
244
|
+
: shared.includes(name)
|
|
245
|
+
? {
|
|
246
|
+
state: "pass",
|
|
247
|
+
text: `${name} is set by the organization, ${FOR_NPM}`,
|
|
248
|
+
}
|
|
249
|
+
: {
|
|
250
|
+
state: "fail",
|
|
251
|
+
text: `${name} is not set, ${FOR_NPM}`,
|
|
252
|
+
fix: INIT,
|
|
253
|
+
});
|
|
254
|
+
if (dependabot === null)
|
|
255
|
+
continue;
|
|
256
|
+
out.push(dependabot.includes(name)
|
|
257
|
+
? {
|
|
258
|
+
state: "pass",
|
|
259
|
+
text: `${name} is set for Dependabot, ${FOR_DEPENDABOT}`,
|
|
260
|
+
}
|
|
261
|
+
: organizations === null
|
|
262
|
+
? {
|
|
263
|
+
state: "unknown",
|
|
264
|
+
text: `${name} is not set for Dependabot on the repository, and only an organization admin can see whether the organization sets it`,
|
|
265
|
+
}
|
|
266
|
+
: organizations.includes(name)
|
|
267
|
+
? {
|
|
268
|
+
state: "pass",
|
|
269
|
+
text: `${name} is set by the organization for Dependabot, ${FOR_DEPENDABOT}`,
|
|
270
|
+
}
|
|
271
|
+
: {
|
|
272
|
+
state: "fail",
|
|
273
|
+
text: `${name} is not set for Dependabot, ${FOR_DEPENDABOT}`,
|
|
274
|
+
fix: INIT,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const path = join(root, DEPENDABOT);
|
|
278
|
+
if (existsSync(path)) {
|
|
279
|
+
const settings = readFileSync(path, "utf8");
|
|
280
|
+
for (const url of privateRegistries(npmrc))
|
|
281
|
+
out.push(usesRegistry(settings, url)
|
|
282
|
+
? {
|
|
283
|
+
state: "pass",
|
|
284
|
+
text: `${DEPENDABOT} uses ${url} for its npm updates`,
|
|
285
|
+
}
|
|
286
|
+
: {
|
|
287
|
+
state: "unknown",
|
|
288
|
+
text: `${DEPENDABOT} doesn't use ${url} for its npm updates: unless your organization sets that registry for Dependabot, it never sees a new version of a package from there. Add it under registries, and name it in the npm entry's registries`,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
148
291
|
return out;
|
|
149
292
|
}
|
|
293
|
+
/** Whether Dependabot's settings name the registry at `url` under their
|
|
294
|
+
* `registries`, and every npm update lists it, or all of them. */
|
|
295
|
+
export function usesRegistry(settings, url) {
|
|
296
|
+
let o;
|
|
297
|
+
try {
|
|
298
|
+
o = load(settings);
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
const isObj = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
304
|
+
if (!isObj(o) || !isObj(o.registries))
|
|
305
|
+
return false;
|
|
306
|
+
const names = Object.entries(o.registries)
|
|
307
|
+
.filter(([, r]) => isObj(r) &&
|
|
308
|
+
typeof r.url === "string" &&
|
|
309
|
+
bareRegistry(r.url) === bareRegistry(url))
|
|
310
|
+
.map(([name]) => name);
|
|
311
|
+
const npm = (Array.isArray(o.updates) ? o.updates : []).filter((u) => isObj(u) && u["package-ecosystem"] === "npm");
|
|
312
|
+
return (names.length > 0 &&
|
|
313
|
+
npm.length > 0 &&
|
|
314
|
+
npm.every((u) => u.registries === "*" ||
|
|
315
|
+
(Array.isArray(u.registries) &&
|
|
316
|
+
u.registries.some((r) => names.includes(String(r))))));
|
|
317
|
+
}
|
|
150
318
|
/** One check as a line: a tick, a cross with what to do, or a dash for a
|
|
151
319
|
* part that is off. */
|
|
152
|
-
export function line(c) {
|
|
320
|
+
export function line(c, paint = plain) {
|
|
153
321
|
if (c.state === "off")
|
|
154
|
-
return
|
|
322
|
+
return `${paint("dim", "-")} ${c.text}`;
|
|
323
|
+
if (c.state === "unknown")
|
|
324
|
+
return `${paint("yellow", "?")} ${c.text}`;
|
|
155
325
|
if (c.state === "pass")
|
|
156
|
-
return
|
|
326
|
+
return `${paint("green", "✓")} ${c.text}`;
|
|
157
327
|
const fix = c.fix ?? "";
|
|
158
328
|
// An instruction follows as its own sentence; a reason, after a colon.
|
|
159
|
-
return
|
|
329
|
+
return `${paint("red", "✗")} ${c.text}${!fix ? "" : /^Run /.test(fix) ? `. ${fix}` : `: ${fix}`}`;
|
|
330
|
+
}
|
|
331
|
+
/** The checks under their headings, each group apart from the next, the
|
|
332
|
+
* whole indented by `indent` spaces. */
|
|
333
|
+
export function printChecks(found, paint = plain, indent = 0) {
|
|
334
|
+
const at = " ".repeat(indent);
|
|
335
|
+
const out = [];
|
|
336
|
+
let heading;
|
|
337
|
+
for (const c of found) {
|
|
338
|
+
if (c.group !== heading || out.length === 0) {
|
|
339
|
+
if (out.length)
|
|
340
|
+
out.push("");
|
|
341
|
+
heading = c.group;
|
|
342
|
+
if (heading)
|
|
343
|
+
out.push(`${at}${heading}`);
|
|
344
|
+
}
|
|
345
|
+
out.push(`${at}${heading ? " " : ""}${line(c, paint)}`);
|
|
346
|
+
}
|
|
347
|
+
return out;
|
|
160
348
|
}
|
|
161
349
|
export async function main(_argv, d) {
|
|
162
350
|
const found = await checks(d);
|
|
163
|
-
for (const
|
|
164
|
-
d.out(
|
|
351
|
+
for (const l of printChecks(found, d.paint))
|
|
352
|
+
d.out(l);
|
|
165
353
|
return found.some((c) => c.state === "fail") ? 1 : 0;
|
|
166
354
|
}
|
|
167
355
|
/** The checks, run in the repository this command runs in. */
|
|
@@ -187,6 +375,7 @@ export function doctorDeps(root = repoRoot()) {
|
|
|
187
375
|
hasCommand,
|
|
188
376
|
tools: TOOLS,
|
|
189
377
|
out: (l) => console.log(l),
|
|
378
|
+
paint: painter(colorOn()),
|
|
190
379
|
};
|
|
191
380
|
}
|
|
192
381
|
export async function run(argv) {
|
package/dist/explain.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Settings } from "./config.mts";
|
|
2
2
|
import { type Resolution } from "./preset.mts";
|
|
3
|
+
import type { Paint } from "./lib/color.mts";
|
|
3
4
|
/** The mark of the value at `path`, or of one item of the list there:
|
|
4
5
|
* `item` is the item for a list of values and the plugin's name for a
|
|
5
6
|
* list of plugins. */
|
|
@@ -13,3 +14,7 @@ export declare function markerOf(r: Resolution): Marker;
|
|
|
13
14
|
/** `exists` says whether a path from the root exists, for the plugins the
|
|
14
15
|
* factory uses where the settings name none. */
|
|
15
16
|
export declare function explainLines(s: Settings, marks: Marker, exists: (path: string) => boolean): Promise<string[]>;
|
|
17
|
+
/** The lines as `config explain` prints them to a terminal: a default's
|
|
18
|
+
* whole line dim, a comment line dim, and any other mark alone dim. It
|
|
19
|
+
* works on the text alone, since the lock keeps only that. */
|
|
20
|
+
export declare function paintExplainLines(lines: string[], paint: Paint): string[];
|
package/dist/explain.mjs
CHANGED
|
@@ -71,6 +71,10 @@ export async function explainLines(s, marks, exists) {
|
|
|
71
71
|
for (const [k, v] of Object.entries(s.tickets.fields))
|
|
72
72
|
put(["tickets", "fields", k], v ?? "none");
|
|
73
73
|
}
|
|
74
|
+
if (s.tickets.board === null)
|
|
75
|
+
block(["tickets", "fields"]);
|
|
76
|
+
for (const [k, v] of Object.entries(s.tickets.ticketFields))
|
|
77
|
+
put(["tickets", "fields", k], v ?? "none");
|
|
74
78
|
put(["code-host"], s.codeHost.type);
|
|
75
79
|
block(["builds"]);
|
|
76
80
|
put(["builds", "trigger"], s.builds.trigger);
|
|
@@ -187,3 +191,28 @@ export async function explainLines(s, marks, exists) {
|
|
|
187
191
|
const at = Math.max(0, ...marked.map((l) => l.text.length)) + 2;
|
|
188
192
|
return lines.map((l) => l.mark !== null ? `${l.text.padEnd(at)}# ${l.mark}` : l.text);
|
|
189
193
|
}
|
|
194
|
+
/** The lines as `config explain` prints them to a terminal: a default's
|
|
195
|
+
* whole line dim, a comment line dim, and any other mark alone dim. It
|
|
196
|
+
* works on the text alone, since the lock keeps only that. */
|
|
197
|
+
export function paintExplainLines(lines, paint) {
|
|
198
|
+
const comment = (l) => l.trimStart().startsWith("#");
|
|
199
|
+
// Every mark starts at one column, two spaces past the longest marked
|
|
200
|
+
// line. A quoted value can hold " # " too, but rarely at that column.
|
|
201
|
+
const counts = new Map();
|
|
202
|
+
for (const l of lines.filter((l) => !comment(l)))
|
|
203
|
+
for (const m of l.matchAll(/ {2}# /g)) {
|
|
204
|
+
const at = m.index + 2;
|
|
205
|
+
counts.set(at, (counts.get(at) ?? 0) + 1);
|
|
206
|
+
}
|
|
207
|
+
const most = Math.max(0, ...counts.values());
|
|
208
|
+
const at = Math.max(-1, ...[...counts].filter(([, n]) => n === most).map(([c]) => c));
|
|
209
|
+
return lines.map((l) => {
|
|
210
|
+
if (comment(l))
|
|
211
|
+
return paint("dim", l);
|
|
212
|
+
if (at < 0 || !l.startsWith(" # ", at - 2))
|
|
213
|
+
return l;
|
|
214
|
+
return l.slice(at) === "# default"
|
|
215
|
+
? paint("dim", l)
|
|
216
|
+
: l.slice(0, at) + paint("dim", l.slice(at));
|
|
217
|
+
});
|
|
218
|
+
}
|
package/dist/init.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Registry } from "./tools.mts";
|
|
2
|
+
import { type Paint } from "./lib/color.mts";
|
|
2
3
|
import { type Check } from "./setup.mts";
|
|
3
4
|
/** The questions init asks. Each is answered at the terminal, and in tests
|
|
4
5
|
* from a script. */
|
|
@@ -28,6 +29,7 @@ export type InitDeps = {
|
|
|
28
29
|
/** The `origin` remote's address, or null without one. */
|
|
29
30
|
remote: () => string | null;
|
|
30
31
|
tools: Registry;
|
|
32
|
+
paint?: Paint;
|
|
31
33
|
sync: () => Promise<number>;
|
|
32
34
|
/** The files a sync with these settings would write or delete. `host`
|
|
33
35
|
* asks the code host for the default branch, where the checkout does not
|