@theholocron/cli 5.0.0-alpha.58 → 5.0.0-alpha.580
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 +680 -107
- package/dist/cli.mjs +42061 -8179
- package/dist/cli.mjs.map +1 -1
- package/dist/config-system-kv3gASRw.mjs +1131 -0
- package/dist/index-D8o6BRQO.d.mts +5686 -0
- package/dist/index.d.mts +859 -654
- package/dist/index.mjs +1317 -396
- package/dist/plugin/capabilities.d.mts +2 -807
- package/dist/plugin/capabilities.mjs +59 -4
- package/dist/presets.d.mts +224 -0
- package/dist/presets.mjs +441 -0
- package/package.json +50 -42
|
@@ -0,0 +1,1131 @@
|
|
|
1
|
+
import { CARDINALITY, REQUIRED_CAPABILITIES } from "./plugin/capabilities.mjs";
|
|
2
|
+
import { resolveTaskName } from "@theholocron/astromech";
|
|
3
|
+
import { basename, dirname } from "node:path";
|
|
4
|
+
import { resolvePluginPackage as resolvePluginPackage$1 } from "@theholocron/kyber/plugins";
|
|
5
|
+
import { ConfigError, ConfigError as ConfigError$1, ConfigFileError, createConfigSystem, lastWins, mergeByKey, shallowMerge, union } from "@theholocron/kyber/config";
|
|
6
|
+
import { readGitRemote } from "@theholocron/git-utils";
|
|
7
|
+
import { readPackageJson } from "@theholocron/pkg-utils";
|
|
8
|
+
import { loadTasksConfig } from "@theholocron/astromech/config";
|
|
9
|
+
// src/credentials-environments/derives-environment/derives-environment.ts
|
|
10
|
+
/** The providers whose `credentials` entry may leave `environment` out and have it derived (#2063). */
|
|
11
|
+
const DERIVING = /* @__PURE__ */ new Set(["1password"]);
|
|
12
|
+
/** Whether a `credentials` provider with no `environment` option derives its Environment names. */
|
|
13
|
+
function derivesEnvironment(provider) {
|
|
14
|
+
return DERIVING.has(provider);
|
|
15
|
+
}
|
|
16
|
+
// src/config/split-agent/split-agent.ts
|
|
17
|
+
const AGENT_OPTIONS = ["dcg", "denyRead"];
|
|
18
|
+
/**
|
|
19
|
+
* Reads `agent` in either form, a name (`"claude"`) or a name with options (`["claude", { dcg: true }]`), the form a
|
|
20
|
+
* provider takes. The name keeps its place in the resolved config, so everything that installs skills reads it as before;
|
|
21
|
+
* the options, when there are any, are kept beside it. A malformed value, an option that does not exist, a `dcg` that is
|
|
22
|
+
* not a boolean, and `dcg: true` on an agent that has no `.claude/settings.json` are a `ConfigError` naming the problem.
|
|
23
|
+
*/
|
|
24
|
+
function splitAgent(raw) {
|
|
25
|
+
if (raw === void 0) return {};
|
|
26
|
+
if (typeof raw === "string") return { agent: raw };
|
|
27
|
+
if (!Array.isArray(raw) || typeof raw[0] !== "string" || raw.length > 2) throw new ConfigError$1("`agent` must be a name, or a name with its options: \"claude\" or [\"claude\", { dcg: true }]");
|
|
28
|
+
const [agent, options] = raw;
|
|
29
|
+
if (options === void 0) return { agent };
|
|
30
|
+
if (typeof options !== "object" || options === null || Array.isArray(options)) throw new ConfigError$1(`the options of the \`${agent}\` agent must be an object, like { dcg: true }`);
|
|
31
|
+
for (const key of Object.keys(options)) if (!AGENT_OPTIONS.includes(key)) throw new ConfigError$1(`the \`${agent}\` agent has no option \`${key}\` (the options are: ${AGENT_OPTIONS.join(", ")})`);
|
|
32
|
+
if (options.dcg !== void 0 && typeof options.dcg !== "boolean") throw new ConfigError$1(`the \`dcg\` option of the \`${agent}\` agent must be true or false`);
|
|
33
|
+
if (options.dcg === true && agent !== "claude") throw new ConfigError$1(`\`dcg\` wires a hook into .claude/settings.json, so it is an option of "claude", not "${agent}"`);
|
|
34
|
+
if (options.denyRead !== void 0) {
|
|
35
|
+
const paths = options.denyRead;
|
|
36
|
+
if (!Array.isArray(paths) || paths.some((path) => typeof path !== "string" || path === "")) throw new ConfigError$1(`the \`denyRead\` option of the \`${agent}\` agent must be a list of paths`);
|
|
37
|
+
if (paths.length > 0 && agent !== "claude") throw new ConfigError$1(`\`denyRead\` writes permission rules into .claude/settings.json, so it is an option of "claude", not "${agent}"`);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
agent,
|
|
41
|
+
agentOptions: options
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// src/credentials-environments/layer-environment/layer-environment.ts
|
|
45
|
+
/** The layer words, in the order the docs list them. */
|
|
46
|
+
const ENVIRONMENT_LAYERS = [
|
|
47
|
+
"local",
|
|
48
|
+
"dev",
|
|
49
|
+
"ci",
|
|
50
|
+
"prod",
|
|
51
|
+
"preview",
|
|
52
|
+
"agent"
|
|
53
|
+
];
|
|
54
|
+
/** Whether `value` is exactly one of the layer words (case-sensitive: `Prod` is a literal Environment name). */
|
|
55
|
+
function isEnvironmentLayer(value) {
|
|
56
|
+
return typeof value === "string" && ENVIRONMENT_LAYERS.includes(value);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The Environment a layer of a repository is kept in: `<org/repo> - <layer>`. The one place the name is built, for the
|
|
60
|
+
* `credentials` providers (`environmentLayers()`) and for the config entries that name a `layer`.
|
|
61
|
+
*/
|
|
62
|
+
function layerEnvironment(slug, layer) {
|
|
63
|
+
return `${slug} - ${layer}`;
|
|
64
|
+
}
|
|
65
|
+
// src/config/validate-environment-choice/validate-environment-choice.ts
|
|
66
|
+
/**
|
|
67
|
+
* Check that an entry names its vault Environment one way: a literal `environment`, or a `layer` the name is derived
|
|
68
|
+
* from (spec `tech-environment-layers`, #2069). Both together are an error, and so is a `layer` that is not a layer word
|
|
69
|
+
* or an `environment` that is blank. With neither, the entry is an error unless `required` is false.
|
|
70
|
+
*
|
|
71
|
+
* @param entry - The `environment` and `layer` the entry sets.
|
|
72
|
+
* @param what - How a message names the entry, e.g. "a `repo.secrets.deploy` entry".
|
|
73
|
+
* @param required - Whether the entry must name one of the two. Default true.
|
|
74
|
+
* @returns What the entry names (the environment, else the layer), for the rest of its messages; `undefined` for neither.
|
|
75
|
+
* @throws {ConfigError} Naming the entry and the problem.
|
|
76
|
+
*/
|
|
77
|
+
function validateEnvironmentChoice(entry, what, required = true) {
|
|
78
|
+
const { environment, layer } = entry;
|
|
79
|
+
if (environment !== void 0 && layer !== void 0) throw new ConfigError$1(`${what} sets both \`layer\` and \`environment\`: name the Environment one way`);
|
|
80
|
+
if (layer !== void 0) {
|
|
81
|
+
if (!isEnvironmentLayer(layer)) throw new ConfigError$1(`${what} has \`layer\` ${JSON.stringify(layer)}: use ${ENVIRONMENT_LAYERS.map((l) => `"${l}"`).join(", ")}, or \`environment\` for a literal name`);
|
|
82
|
+
return layer;
|
|
83
|
+
}
|
|
84
|
+
if (environment !== void 0) {
|
|
85
|
+
if (typeof environment !== "string" || environment.trim() === "") throw new ConfigError$1(`${what} needs the name of a vault environment, got an empty \`environment\``);
|
|
86
|
+
return environment;
|
|
87
|
+
}
|
|
88
|
+
if (required) throw new ConfigError$1(`${what} needs the name of a vault environment (\`environment\`) or a \`layer\``);
|
|
89
|
+
}
|
|
90
|
+
// src/config/validate-issue-types/validate-issue-types.ts
|
|
91
|
+
/** The colour words GitHub's issue Types take. */
|
|
92
|
+
const ISSUE_TYPE_COLORS = [
|
|
93
|
+
"gray",
|
|
94
|
+
"blue",
|
|
95
|
+
"green",
|
|
96
|
+
"yellow",
|
|
97
|
+
"orange",
|
|
98
|
+
"red",
|
|
99
|
+
"pink",
|
|
100
|
+
"purple"
|
|
101
|
+
];
|
|
102
|
+
/** The Conventional Commit types a Type's `commit` may name (the ones `start work` and commitlint know). */
|
|
103
|
+
const COMMIT_TYPES = [
|
|
104
|
+
"feat",
|
|
105
|
+
"fix",
|
|
106
|
+
"chore",
|
|
107
|
+
"docs",
|
|
108
|
+
"refactor",
|
|
109
|
+
"perf",
|
|
110
|
+
"test",
|
|
111
|
+
"ci",
|
|
112
|
+
"build",
|
|
113
|
+
"style",
|
|
114
|
+
"revert"
|
|
115
|
+
];
|
|
116
|
+
const isObject$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
117
|
+
const KEYS$1 = [
|
|
118
|
+
"name",
|
|
119
|
+
"description",
|
|
120
|
+
"color",
|
|
121
|
+
"enabled",
|
|
122
|
+
"label",
|
|
123
|
+
"commit"
|
|
124
|
+
];
|
|
125
|
+
/**
|
|
126
|
+
* Checks the organization's `issueTypes` list (spec `tech-org-issue-types`, #2512) and returns it. `at` names where it
|
|
127
|
+
* came from (`.holocron/org.ts` or `issueTypes`) so the error says which file to fix. A name that repeats ignoring
|
|
128
|
+
* case, a `color` that is not one of GitHub's eight words, a `commit` that is not a Conventional Commit type, a key
|
|
129
|
+
* the list does not know or a value that is not text is a {@link ConfigError} naming the entry.
|
|
130
|
+
*/
|
|
131
|
+
function validateIssueTypes(value, at = "issueTypes") {
|
|
132
|
+
if (!Array.isArray(value)) throw new ConfigError$1(`${at} must be a list of { name, description?, color?, ... }`);
|
|
133
|
+
const seen = /* @__PURE__ */ new Set();
|
|
134
|
+
return value.map((entry, index) => {
|
|
135
|
+
const where = `${at}[${index}]`;
|
|
136
|
+
if (!isObject$2(entry)) throw new ConfigError$1(`${where} must be an object with a "name"`);
|
|
137
|
+
for (const key of Object.keys(entry)) if (!KEYS$1.includes(key)) throw new ConfigError$1(`${where}: "${key}" is not an issue Type option. Known: ${KEYS$1.join(", ")}`);
|
|
138
|
+
const { name, description, color, enabled, label, commit } = entry;
|
|
139
|
+
if (typeof name !== "string" || name.trim() === "") throw new ConfigError$1(`${where}: "name" must be a non-empty string`);
|
|
140
|
+
const key = name.trim().toLowerCase();
|
|
141
|
+
if (seen.has(key)) throw new ConfigError$1(`${where}: the name "${name}" repeats an earlier Type (names are compared ignoring case)`);
|
|
142
|
+
seen.add(key);
|
|
143
|
+
for (const [option, text] of [["description", description], ["label", label]]) if (text !== void 0 && (typeof text !== "string" || text.trim() === "")) throw new ConfigError$1(`${where}: "${option}" must be a non-empty string`);
|
|
144
|
+
if (color !== void 0 && !ISSUE_TYPE_COLORS.includes(color)) throw new ConfigError$1(`${where}: "color" must be one of ${ISSUE_TYPE_COLORS.join(", ")}, got ${JSON.stringify(color)}`);
|
|
145
|
+
if (commit !== void 0 && !COMMIT_TYPES.includes(commit)) throw new ConfigError$1(`${where}: "commit" must be a Conventional Commit type (${COMMIT_TYPES.join(", ")}), got ${JSON.stringify(commit)}`);
|
|
146
|
+
if (enabled !== void 0 && typeof enabled !== "boolean") throw new ConfigError$1(`${where}: "enabled" must be true or false`);
|
|
147
|
+
return {
|
|
148
|
+
name: name.trim(),
|
|
149
|
+
...description !== void 0 ? { description } : {},
|
|
150
|
+
...color !== void 0 ? { color } : {},
|
|
151
|
+
...enabled !== void 0 ? { enabled } : {},
|
|
152
|
+
...label !== void 0 ? { label } : {},
|
|
153
|
+
...commit !== void 0 ? { commit } : {}
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/** GitHub's longest wait timer: 30 days, in minutes. */
|
|
158
|
+
const MAX_WAIT_TIMER = 43200;
|
|
159
|
+
const KEYS = /* @__PURE__ */ new Set([
|
|
160
|
+
"name",
|
|
161
|
+
"reviewers",
|
|
162
|
+
"waitTimer",
|
|
163
|
+
"preventSelfReview"
|
|
164
|
+
]);
|
|
165
|
+
const REVIEWER_KEYS = /* @__PURE__ */ new Set(["type", "id"]);
|
|
166
|
+
const isObject$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
167
|
+
/** Checks one reviewer of the Environment spelled `named`, and records it in `seen` so none is listed twice. */
|
|
168
|
+
function validateReviewer(raw, named, seen) {
|
|
169
|
+
if (!isObject$1(raw)) throw new ConfigError$1(`${named}: a reviewer must be an object`);
|
|
170
|
+
const extra = Object.keys(raw).find((key) => !REVIEWER_KEYS.has(key));
|
|
171
|
+
if (extra !== void 0) throw new ConfigError$1(`${named}: a reviewer has no \`${extra}\` (a numeric \`id\`, not a login)`);
|
|
172
|
+
const { type, id } = raw;
|
|
173
|
+
if (type !== "User" && type !== "Team") throw new ConfigError$1(`${named}: a reviewer's \`type\` is "User" or "Team"`);
|
|
174
|
+
if (typeof id !== "number" || !Number.isInteger(id) || id <= 0) throw new ConfigError$1(`${named}: a reviewer's \`id\` is GitHub's numeric id, a positive whole number`);
|
|
175
|
+
const key = `${type}:${id}`;
|
|
176
|
+
if (seen.has(key)) throw new ConfigError$1(`${named}: reviewer ${key} is listed twice`);
|
|
177
|
+
seen.add(key);
|
|
178
|
+
}
|
|
179
|
+
/** Checks one entry of `repo.environments`, which is at position `index` and whose name is not yet in `seen`. */
|
|
180
|
+
function validateEntry(raw, index, seen) {
|
|
181
|
+
const at = `\`repo.environments[${index}]\``;
|
|
182
|
+
if (!isObject$1(raw)) throw new ConfigError$1(`${at} must be an object`);
|
|
183
|
+
const unknown = Object.keys(raw).find((key) => !KEYS.has(key));
|
|
184
|
+
if (unknown !== void 0) throw new ConfigError$1(`${at} has no \`${unknown}\` (use ${[...KEYS].map((k) => `\`${k}\``).join(", ")})`);
|
|
185
|
+
const { name, waitTimer, preventSelfReview, reviewers } = raw;
|
|
186
|
+
if (typeof name !== "string" || name.trim() === "") throw new ConfigError$1(`${at} needs a \`name\``);
|
|
187
|
+
const lower = name.toLowerCase();
|
|
188
|
+
if (seen.has(lower)) throw new ConfigError$1(`${at}: ${JSON.stringify(name)} is declared twice (names ignore case)`);
|
|
189
|
+
seen.add(lower);
|
|
190
|
+
const named = `\`repo.environments[${name}]\``;
|
|
191
|
+
if (waitTimer !== void 0) {
|
|
192
|
+
if (typeof waitTimer !== "number" || !Number.isInteger(waitTimer) || waitTimer < 0 || waitTimer > 43200) throw new ConfigError$1(`${named}: \`waitTimer\` is a whole number of minutes from 0 to ${MAX_WAIT_TIMER}`);
|
|
193
|
+
}
|
|
194
|
+
if (preventSelfReview !== void 0 && typeof preventSelfReview !== "boolean") throw new ConfigError$1(`${named}: \`preventSelfReview\` is true or false`);
|
|
195
|
+
if (reviewers === void 0) return;
|
|
196
|
+
if (!Array.isArray(reviewers)) throw new ConfigError$1(`${named}: \`reviewers\` must be a list`);
|
|
197
|
+
const list = reviewers;
|
|
198
|
+
if (list.length > 6) throw new ConfigError$1(`${named}: GitHub allows at most 6 reviewers, got ${list.length}`);
|
|
199
|
+
const seenReviewers = /* @__PURE__ */ new Set();
|
|
200
|
+
for (const reviewer of list) validateReviewer(reviewer, named, seenReviewers);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Check `repo.environments` (#2674): each entry names an Environment once (names ignore case) and uses only the keys of
|
|
204
|
+
* `RepoEnvironment`; a reviewer is a `User` or a `Team` with a positive whole `id` (a login would be ignored by GitHub),
|
|
205
|
+
* at most six and none twice; `waitTimer` is a whole number of minutes from 0 to 43200; `preventSelfReview` is a boolean.
|
|
206
|
+
*
|
|
207
|
+
* @param environments - `repo.environments`, if the config has it.
|
|
208
|
+
* @throws {ConfigError} Naming the path of the first problem found.
|
|
209
|
+
*/
|
|
210
|
+
function validateRepoEnvironments(environments) {
|
|
211
|
+
if (environments === void 0) return;
|
|
212
|
+
const list = environments;
|
|
213
|
+
if (!Array.isArray(list)) throw new ConfigError$1("`repo.environments` must be a list");
|
|
214
|
+
const seen = /* @__PURE__ */ new Set();
|
|
215
|
+
list.forEach((entry, index) => validateEntry(entry, index, seen));
|
|
216
|
+
}
|
|
217
|
+
// src/config/validate-repo-labels/validate-repo-labels.ts
|
|
218
|
+
/** What an area name may be: the rest of `area:<name>`, so no colon, comma, space or leading symbol. */
|
|
219
|
+
const AREA_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
220
|
+
/** GitHub's longest label name is 50 characters, and `area:` takes five. */
|
|
221
|
+
const MAX_NAME = 45;
|
|
222
|
+
/** GitHub's longest label name. */
|
|
223
|
+
const MAX_LABEL = 50;
|
|
224
|
+
/** `owner/name`, as GitHub spells a repository. */
|
|
225
|
+
const REPOSITORY = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
226
|
+
/** Checks one label-to-Type table and records each label (lower case) in `seen`, so no label is in two tables. */
|
|
227
|
+
function validateKinds(key, table, seen) {
|
|
228
|
+
for (const [label, type] of Object.entries(table ?? {})) {
|
|
229
|
+
const at = `\`repo.labels.${key}.${label}\``;
|
|
230
|
+
if (label.trim() === "" || label.length > MAX_LABEL) throw new ConfigError$1(`${at}: a label name is 1 to ${MAX_LABEL} characters`);
|
|
231
|
+
if (typeof type !== "string" || type.trim() === "") throw new ConfigError$1(`${at} needs the name of an issue Type, such as "Bug"`);
|
|
232
|
+
const lower = label.toLowerCase();
|
|
233
|
+
const first = seen.get(lower);
|
|
234
|
+
if (first !== void 0) throw new ConfigError$1(`${at}: ${JSON.stringify(label)} is already in \`${first}\``);
|
|
235
|
+
seen.set(lower, `repo.labels.${key}.${label}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Check `repo.labels` (spec `tech-github-area-labels`): each area name must be usable as the suffix of a label (letters,
|
|
240
|
+
* digits, `.`, `_` and `-`, at most 45 characters) and appear once whatever the case (GitHub's labels are
|
|
241
|
+
* case-insensitive), each area needs a list of patterns with at least one that includes a path, and each scope names a
|
|
242
|
+
* declared area. `kinds` and `fallbackKinds` map a label name (at most 50 characters, in one table only) to a Type name,
|
|
243
|
+
* and `repos` lists `owner/name` repositories; whether a Type exists is the organization's to say, so the probe checks it.
|
|
244
|
+
*
|
|
245
|
+
* @param labels - `repo.labels`, if the config has it.
|
|
246
|
+
* @throws {ConfigError} Naming the path of the first problem found.
|
|
247
|
+
*/
|
|
248
|
+
function validateRepoLabels(labels) {
|
|
249
|
+
if (labels === void 0) return;
|
|
250
|
+
const areas = labels.areas ?? {};
|
|
251
|
+
const seen = /* @__PURE__ */ new Map();
|
|
252
|
+
for (const [name, patterns] of Object.entries(areas)) {
|
|
253
|
+
const at = `\`repo.labels.areas.${name}\``;
|
|
254
|
+
if (!AREA_NAME.test(name) || name.length > MAX_NAME) throw new ConfigError$1(`${at}: ${JSON.stringify(name)} cannot be the name of an \`area:<name>\` label (use letters, digits, ".", "_" or "-", at most ${MAX_NAME} characters)`);
|
|
255
|
+
const lower = name.toLowerCase();
|
|
256
|
+
const first = seen.get(lower);
|
|
257
|
+
if (first !== void 0) throw new ConfigError$1(`${at}: duplicates \`repo.labels.areas.${first}\` (label names ignore case)`);
|
|
258
|
+
seen.set(lower, name);
|
|
259
|
+
if (!Array.isArray(patterns) || patterns.length === 0) throw new ConfigError$1(`${at} needs a list of folder patterns, got none`);
|
|
260
|
+
for (const pattern of patterns) if (typeof pattern !== "string" || pattern.replace(/^!/, "").trim() === "") throw new ConfigError$1(`${at} has an empty pattern`);
|
|
261
|
+
if (patterns.every((p) => p.startsWith("!"))) throw new ConfigError$1(`${at} has only exclusions ("!..."), so no path could be in it`);
|
|
262
|
+
}
|
|
263
|
+
for (const [scope, area] of Object.entries(labels.scopes ?? {})) {
|
|
264
|
+
const at = `\`repo.labels.scopes.${scope}\``;
|
|
265
|
+
if (scope.trim() === "") throw new ConfigError$1("`repo.labels.scopes` has an empty scope name");
|
|
266
|
+
if (typeof area !== "string" || !Object.hasOwn(areas, area)) {
|
|
267
|
+
const known = Object.keys(areas);
|
|
268
|
+
throw new ConfigError$1(`${at} names the unknown area ${JSON.stringify(area)}; ${known.length > 0 ? `the declared areas are ${known.join(", ")}` : "`repo.labels.areas` declares none"}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
272
|
+
validateKinds("kinds", labels.kinds, kinds);
|
|
273
|
+
validateKinds("fallbackKinds", labels.fallbackKinds, kinds);
|
|
274
|
+
const repos = labels.repos ?? [];
|
|
275
|
+
if (!Array.isArray(repos)) throw new ConfigError$1("`repo.labels.repos` is a list of `owner/name` repositories");
|
|
276
|
+
for (const repo of repos) if (typeof repo !== "string" || !REPOSITORY.test(repo)) throw new ConfigError$1(`\`repo.labels.repos\` has ${JSON.stringify(repo)}, which is not an \`owner/name\` repository`);
|
|
277
|
+
}
|
|
278
|
+
// src/config/validate-repo-views/validate-repo-views.ts
|
|
279
|
+
/**
|
|
280
|
+
* Check `repo.views` (spec `tech-issue-views`, #2733): each view needs a name and a filter (non-empty text), the names
|
|
281
|
+
* are unique whatever the case, `visibility` is `private` or `public`, and `description`, `icon` and `color` are
|
|
282
|
+
* non-empty text when given. GitHub does not document its icons and colours, so any text is accepted for them.
|
|
283
|
+
*
|
|
284
|
+
* @param views - `repo.views`, if the config has it.
|
|
285
|
+
* @throws {ConfigError} Naming the path of the first problem found.
|
|
286
|
+
*/
|
|
287
|
+
function validateRepoViews(views) {
|
|
288
|
+
if (views === void 0) return;
|
|
289
|
+
if (typeof views !== "object" || views === null || Array.isArray(views)) throw new ConfigError$1("`repo.views` is a table of views by slug");
|
|
290
|
+
const names = /* @__PURE__ */ new Map();
|
|
291
|
+
for (const [slug, view] of Object.entries(views)) {
|
|
292
|
+
const at = `\`repo.views.${slug}\``;
|
|
293
|
+
if (slug.trim() === "") throw new ConfigError$1("`repo.views` has a view with an empty slug");
|
|
294
|
+
if (typeof view !== "object" || view === null) throw new ConfigError$1(`${at} must be an object`);
|
|
295
|
+
if (typeof view.name !== "string" || view.name.trim() === "") throw new ConfigError$1(`${at} needs a \`name\``);
|
|
296
|
+
if (typeof view.filter !== "string" || view.filter.trim() === "") throw new ConfigError$1(`${at} needs a \`filter\`, the search text of the view`);
|
|
297
|
+
const lower = view.name.trim().toLowerCase();
|
|
298
|
+
const first = names.get(lower);
|
|
299
|
+
if (first !== void 0) throw new ConfigError$1(`${at}: the name ${JSON.stringify(view.name)} duplicates \`repo.views.${first}\` (names ignore case)`);
|
|
300
|
+
names.set(lower, slug);
|
|
301
|
+
for (const key of [
|
|
302
|
+
"description",
|
|
303
|
+
"icon",
|
|
304
|
+
"color"
|
|
305
|
+
]) {
|
|
306
|
+
const value = view[key];
|
|
307
|
+
if (value !== void 0 && (typeof value !== "string" || value.trim() === "")) throw new ConfigError$1(`${at}.${key} must be non-empty text when given`);
|
|
308
|
+
}
|
|
309
|
+
const visibility = view.visibility;
|
|
310
|
+
if (visibility !== void 0 && visibility !== "private" && visibility !== "public") throw new ConfigError$1(`${at}.visibility is ${JSON.stringify(visibility)}; use "private" or "public"`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// src/config/validate-required-checks/validate-required-checks.ts
|
|
314
|
+
/**
|
|
315
|
+
* Checks `repo.requiredChecks`, the list of status-check contexts a `strict` ruleset requires, when a repo writes it down
|
|
316
|
+
* (`.holocron/repo.ts`) instead of leaving `holocron setup` to derive it from the tasks. Each entry is the context as GitHub
|
|
317
|
+
* shows it (`test:unit / Run unit tests and collect coverage`), so a blank one, a non-string and a repeat are errors named
|
|
318
|
+
* by position. An empty list is refused too: a ruleset that requires nothing is `protection: "none"`, not this.
|
|
319
|
+
*/
|
|
320
|
+
function validateRequiredChecks(checks) {
|
|
321
|
+
if (checks === void 0) return;
|
|
322
|
+
if (!Array.isArray(checks) || checks.length === 0) throw new ConfigError$1("`repo.requiredChecks` is a non-empty list of status-check contexts");
|
|
323
|
+
const seen = /* @__PURE__ */ new Set();
|
|
324
|
+
checks.forEach((context, index) => {
|
|
325
|
+
const at = `\`repo.requiredChecks[${index}]\``;
|
|
326
|
+
if (typeof context !== "string" || context.trim() === "") throw new ConfigError$1(`${at} needs a status-check context, such as "typecheck / Run typecheck"`);
|
|
327
|
+
if (seen.has(context)) throw new ConfigError$1(`${at}: "${context}" is listed twice`);
|
|
328
|
+
seen.add(context);
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
// src/credentials-environments/repo-slug/repo-slug.ts
|
|
332
|
+
/**
|
|
333
|
+
* The `<org>/<repo>` of the repository at `cwd`, from its `origin` remote. A remote that is missing or cannot be
|
|
334
|
+
* parsed is a `ConfigError` that names the `environment` option as the fix.
|
|
335
|
+
*/
|
|
336
|
+
async function repoSlug(cwd, exec) {
|
|
337
|
+
const remote = await readGitRemote(cwd, exec ? { exec } : {});
|
|
338
|
+
if (!remote) throw new ConfigError$1(`cannot derive the 1Password Environment name: the \`origin\` remote of ${cwd} is missing or not an owner/repo URL. Give the \`credentials\` provider an \`environment\` option to name it.`);
|
|
339
|
+
return remote.slug;
|
|
340
|
+
}
|
|
341
|
+
// src/credentials-environments/unsynced-layer/unsynced-layer.ts
|
|
342
|
+
/**
|
|
343
|
+
* The layers this machine reads for itself (`agent` is the one an agent's process reads, spec `tech-agent-secrets`). They
|
|
344
|
+
* are never synced to GitHub, a deployment or a Worker (#2104).
|
|
345
|
+
*/
|
|
346
|
+
const UNSYNCED_LAYERS = [
|
|
347
|
+
"local",
|
|
348
|
+
"dev",
|
|
349
|
+
"agent"
|
|
350
|
+
];
|
|
351
|
+
/** Whether `layer` is one of {@link UNSYNCED_LAYERS}. */
|
|
352
|
+
function isUnsyncedLayer(layer) {
|
|
353
|
+
return isEnvironmentLayer(layer) && UNSYNCED_LAYERS.includes(layer);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* The text of the error for an Environment of an unsynced layer, shared by the command and the config checks.
|
|
357
|
+
*
|
|
358
|
+
* @param what - What names the layer, e.g. "`sync secrets --env dev`" or "a `repo.secrets.sync` entry".
|
|
359
|
+
* @param layer - The unsynced layer.
|
|
360
|
+
*/
|
|
361
|
+
function unsyncedLayerMessage(what, layer) {
|
|
362
|
+
return `${what} names the \`${layer}\` layer: \`local\`, \`dev\` and \`agent\` are read by this machine and are never synced. Only ${ENVIRONMENT_LAYERS.filter((l) => !isUnsyncedLayer(l)).map((l) => `\`${String(l)}\``).join(" and ")} can be synced`;
|
|
363
|
+
}
|
|
364
|
+
// src/config/validate-secrets-deploy/validate-secrets-deploy.ts
|
|
365
|
+
/**
|
|
366
|
+
* Check `repo.secrets.deploy`: each entry names a vault environment (or a `layer`) and at least one of a non-empty `keys` list and a
|
|
367
|
+
* non-empty `prefix`. An entry with neither would mean "all keys", which a deployment never gets (spec
|
|
368
|
+
* `tech-deployment-key-allowlist`, #2061), so it is an error here and not a silent skip.
|
|
369
|
+
*
|
|
370
|
+
* @param secrets - `repo.secrets`, if the config has it.
|
|
371
|
+
* @throws {ConfigError} Naming the first problem found.
|
|
372
|
+
*/
|
|
373
|
+
function validateSecretsDeploy(secrets) {
|
|
374
|
+
for (const entry of secrets?.deploy ?? []) {
|
|
375
|
+
const named = validateEnvironmentChoice(entry, "a `repo.secrets.deploy` entry");
|
|
376
|
+
const label = `\`repo.secrets.deploy\` entry for ${JSON.stringify(named)}`;
|
|
377
|
+
if (isUnsyncedLayer(entry.layer)) throw new ConfigError$1(unsyncedLayerMessage(label, entry.layer));
|
|
378
|
+
const { keys, prefix } = entry;
|
|
379
|
+
if (keys !== void 0 && (!Array.isArray(keys) || keys.some((k) => typeof k !== "string" || k === ""))) throw new ConfigError$1(`${label} has \`keys\` that is not a list of key names`);
|
|
380
|
+
if (prefix !== void 0 && (typeof prefix !== "string" || prefix === "")) throw new ConfigError$1(`${label} has an empty \`prefix\``);
|
|
381
|
+
if ((keys === void 0 || keys.length === 0) && prefix === void 0) throw new ConfigError$1(`${label} needs \`keys\` (a list of names) or \`prefix\` (such as "SENTINEL_"): a deployment never receives every key`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
// src/config/validate-secrets-sync/validate-secrets-sync.ts
|
|
385
|
+
/**
|
|
386
|
+
* Check `repo.secrets.sync`: each entry names its vault environment one way, a literal `environment` or a `layer`
|
|
387
|
+
* (spec `tech-environment-layers`, #2069). An organization
|
|
388
|
+
* scope must say who can read the secrets: `visibility: "selected"` (or left out) and a non-empty `repos` list. A
|
|
389
|
+
* concealed value is never readable by every repository, so `visibility: "all"` and `"private"` are errors, and an
|
|
390
|
+
* entry with no list does not load (spec `tech-org-secret-visibility`, #2062). `repos` and `visibility` mean nothing
|
|
391
|
+
* on another scope, so they are errors there. A repository name is `name` or `<org>/name` of the scope's own
|
|
392
|
+
* organization, and one key may not be given two different reader lists at the same organization.
|
|
393
|
+
*
|
|
394
|
+
* @param secrets - `repo.secrets`, if the config has it.
|
|
395
|
+
* @throws {ConfigError} Naming the first problem found.
|
|
396
|
+
*/
|
|
397
|
+
function validateSecretsSync(secrets) {
|
|
398
|
+
const readers = /* @__PURE__ */ new Map();
|
|
399
|
+
for (const entry of secrets?.sync ?? []) {
|
|
400
|
+
const named = validateEnvironmentChoice(entry, "a `repo.secrets.sync` entry");
|
|
401
|
+
const label = `\`repo.secrets.sync\` entry for ${JSON.stringify(named)}`;
|
|
402
|
+
if (isUnsyncedLayer(entry.layer)) throw new ConfigError$1(unsyncedLayerMessage(label, entry.layer));
|
|
403
|
+
const scope = entry.scope ?? "repo";
|
|
404
|
+
if (!scope.startsWith("org=")) {
|
|
405
|
+
if (entry.visibility !== void 0 || entry.repos !== void 0) throw new ConfigError$1(`${label} sets \`visibility\` or \`repos\` on scope ${JSON.stringify(scope)}: only an organization scope ("org=<name>") has readers to name`);
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
const org = scope.slice(4);
|
|
409
|
+
if (entry.visibility !== void 0 && entry.visibility !== "selected") throw new ConfigError$1(`${label} has visibility ${JSON.stringify(entry.visibility)}: a secret is never readable by every repository, so use "selected" with \`repos\``);
|
|
410
|
+
const { repos } = entry;
|
|
411
|
+
if (!Array.isArray(repos) || repos.length === 0 || repos.some((r) => typeof r !== "string" || !/^(?:[^/]+\/)?[^/]+$/.test(r))) throw new ConfigError$1(`${label} needs \`repos\`, a non-empty list of the repositories (\`name\` or \`<org>/name\`) that can read the secrets: an organization secret is never readable by every repository`);
|
|
412
|
+
const names = repos.map((r) => {
|
|
413
|
+
const slash = r.indexOf("/");
|
|
414
|
+
if ((slash < 0 ? org : r.slice(0, slash)) !== org) throw new ConfigError$1(`${label} lists repository ${JSON.stringify(r)}: use a name in ${JSON.stringify(org)}, such as "holocron"`);
|
|
415
|
+
return r.slice(slash + 1);
|
|
416
|
+
});
|
|
417
|
+
const list = [...new Set(names)].sort().join(", ");
|
|
418
|
+
for (const key of entry.keys ?? []) {
|
|
419
|
+
const id = `${org}/${key.toUpperCase()}`;
|
|
420
|
+
const seen = readers.get(id);
|
|
421
|
+
if (seen !== void 0 && seen !== list) throw new ConfigError$1(`${label} lists ${key}, which another \`repo.secrets.sync\` entry at org=${org} gives different readers [${seen}]: a secret has one reader list`);
|
|
422
|
+
readers.set(id, list);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
// src/config/validate-variables-sync/validate-variables-sync.ts
|
|
427
|
+
/** GitHub treats variable names as case-insensitive, so every comparison goes through this. */
|
|
428
|
+
const key = (name) => name.toUpperCase();
|
|
429
|
+
/**
|
|
430
|
+
* Check `repo.variables.sync`: each entry names a vault environment, one or more keys and a scope that is `repo` or
|
|
431
|
+
* `org=<name>`; a name may not also be a literal value of the same scope (one source per name); and `prune` cannot
|
|
432
|
+
* be combined with `sync`, because `setup` would delete the variables the sync wrote.
|
|
433
|
+
*
|
|
434
|
+
* @param variables - `repo.variables`, if the config has it.
|
|
435
|
+
* @throws {ConfigError} Naming the first problem found.
|
|
436
|
+
*/
|
|
437
|
+
function validateVariablesSync(variables) {
|
|
438
|
+
const entries = variables?.sync;
|
|
439
|
+
if (!entries || entries.length === 0) return;
|
|
440
|
+
if (variables?.prune === true) throw new ConfigError$1("`repo.variables.prune` cannot be combined with `repo.variables.sync`: pruning would delete the variables the sync writes");
|
|
441
|
+
for (const entry of entries) {
|
|
442
|
+
const named = validateEnvironmentChoice(entry, "a `repo.variables.sync` entry");
|
|
443
|
+
const label = `\`repo.variables.sync\` entry for ${JSON.stringify(named)}`;
|
|
444
|
+
if (!Array.isArray(entry.keys) || entry.keys.length === 0 || entry.keys.some((k) => typeof k !== "string" || k === "")) throw new ConfigError$1(`${label} needs \`keys\`, a list of variable names`);
|
|
445
|
+
const scope = entry.scope ?? "repo";
|
|
446
|
+
const org = scope.startsWith("org=") ? scope.slice(4) : void 0;
|
|
447
|
+
if (scope !== "repo" && (org === void 0 || org === "")) throw new ConfigError$1(`${label} has scope ${JSON.stringify(scope)}: use "repo" or "org=<name>"`);
|
|
448
|
+
if (entry.visibility !== void 0 && entry.visibility !== "all" && entry.visibility !== "private") throw new ConfigError$1(`${label} has visibility ${JSON.stringify(entry.visibility)}: use "all" or "private"`);
|
|
449
|
+
const literal = new Set(Object.keys((org === void 0 ? variables?.repo : variables?.org) ?? {}).map(key));
|
|
450
|
+
const both = entry.keys.filter((k) => literal.has(key(k)));
|
|
451
|
+
if (both.length > 0) throw new ConfigError$1(`${label} lists ${both.join(", ")}, which \`repo.variables.${org === void 0 ? "repo" : "org"}\` also gives a value: keep one source per name`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
// src/config/config/config.ts
|
|
455
|
+
const PLUGIN_PREFIX = "@theholocron/holocron-plugin-";
|
|
456
|
+
const COMMUNITY_PREFIX = "holocron-plugin-";
|
|
457
|
+
/**
|
|
458
|
+
* Resolve `"github"` → `"@theholocron/holocron-plugin-github"`.
|
|
459
|
+
* Fully-qualified names (scoped or not) are honored verbatim, which
|
|
460
|
+
* is how third-party plugins published outside the org work.
|
|
461
|
+
*/
|
|
462
|
+
function resolvePluginPackage(provider) {
|
|
463
|
+
if (!provider) throw new ConfigError("provider name is empty");
|
|
464
|
+
return resolvePluginPackage$1(provider, PLUGIN_PREFIX, COMMUNITY_PREFIX);
|
|
465
|
+
}
|
|
466
|
+
/** A bare `[provider, options]` tuple, with both elements present? */
|
|
467
|
+
function isOptionsTuple(value) {
|
|
468
|
+
if (!Array.isArray(value)) return false;
|
|
469
|
+
if (value.length !== 2) return false;
|
|
470
|
+
if (typeof value[0] !== "string") return false;
|
|
471
|
+
const opt = value[1];
|
|
472
|
+
return typeof opt === "object" && opt !== null && !Array.isArray(opt);
|
|
473
|
+
}
|
|
474
|
+
function normalizeEntry(entry) {
|
|
475
|
+
if (typeof entry === "string") return {
|
|
476
|
+
provider: entry,
|
|
477
|
+
packageName: resolvePluginPackage(entry),
|
|
478
|
+
options: {}
|
|
479
|
+
};
|
|
480
|
+
const [provider, options] = entry;
|
|
481
|
+
return {
|
|
482
|
+
provider,
|
|
483
|
+
packageName: resolvePluginPackage(provider),
|
|
484
|
+
options
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
/** Resolves one capability's raw provider entry into single or multiple resolved tuples, checking it against the capability's cardinality. */
|
|
488
|
+
function resolveEntry(key, raw) {
|
|
489
|
+
const cardinality = CARDINALITY[key];
|
|
490
|
+
if (typeof raw === "string") {
|
|
491
|
+
if (cardinality === "many") throw new ConfigError(`\`${key}\` accepts multiple providers; wrap a single one in an array: ["${raw}"]`);
|
|
492
|
+
return {
|
|
493
|
+
cardinality: "single",
|
|
494
|
+
tuple: normalizeEntry(raw)
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
if (!Array.isArray(raw)) throw new ConfigError(`\`${key}\` entry must be a string or array, got ${typeof raw}`);
|
|
498
|
+
if (isOptionsTuple(raw)) {
|
|
499
|
+
if (cardinality === "many") return {
|
|
500
|
+
cardinality: "many",
|
|
501
|
+
tuples: [normalizeEntry(raw)]
|
|
502
|
+
};
|
|
503
|
+
return {
|
|
504
|
+
cardinality: "single",
|
|
505
|
+
tuple: normalizeEntry(raw)
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
if (cardinality === "single") throw new ConfigError(`\`${key}\` accepts exactly one provider; got a multi-provider list with ${raw.length} entries`);
|
|
509
|
+
return {
|
|
510
|
+
cardinality: "many",
|
|
511
|
+
tuples: raw.map((entry, idx) => {
|
|
512
|
+
if (typeof entry === "string") return normalizeEntry(entry);
|
|
513
|
+
if (isOptionsTuple(entry)) return normalizeEntry(entry);
|
|
514
|
+
throw new ConfigError(`\`${key}[${idx}]\` must be a provider string or [provider, options] tuple`);
|
|
515
|
+
})
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
/** A DNS hostname of at least two labels: no scheme, port, path or space. */
|
|
519
|
+
const HOSTNAME = /^[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?)+$/;
|
|
520
|
+
/** Throws a {@link ConfigError} naming the first thing wrong with the `githubApps` list. */
|
|
521
|
+
function validateGitHubApps(apps) {
|
|
522
|
+
if (!Array.isArray(apps)) throw new ConfigError("`githubApps` must be a list of { name, manifest, environment }");
|
|
523
|
+
apps.forEach((app, idx) => {
|
|
524
|
+
for (const key of ["name", "manifest"]) {
|
|
525
|
+
const value = app?.[key];
|
|
526
|
+
if (typeof value !== "string" || value.trim() === "") throw new ConfigError(`\`githubApps[${idx}].${key}\` must be a non-empty string`);
|
|
527
|
+
}
|
|
528
|
+
for (const key of ["app", "label"]) {
|
|
529
|
+
const value = app?.[key];
|
|
530
|
+
if (value !== void 0 && (typeof value !== "string" || value.trim() === "")) throw new ConfigError(`\`githubApps[${idx}].${key}\` must be a non-empty string`);
|
|
531
|
+
}
|
|
532
|
+
validateEnvironmentChoice(app, `\`githubApps[${idx}]\``);
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
/** Throws a {@link ConfigError} naming the first thing wrong with the `ideas` block. */
|
|
536
|
+
function validateIdeas(ideas) {
|
|
537
|
+
const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
|
|
538
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
539
|
+
if (!isObject(ideas)) throw new ConfigError("`ideas` must be an object: { states?, dir? (deprecated) }");
|
|
540
|
+
if (ideas.dir !== void 0 && !nonEmpty(ideas.dir)) throw new ConfigError("`ideas.dir` must be the path of the notes folder, got an empty value");
|
|
541
|
+
if (ideas.states !== void 0) {
|
|
542
|
+
if (!isObject(ideas.states)) throw new ConfigError("`ideas.states` must be an object: { file? }");
|
|
543
|
+
if (ideas.states.file !== void 0 && !nonEmpty(ideas.states.file)) throw new ConfigError("`ideas.states.file` must be a state name, got an empty value");
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
/** Throws a {@link ConfigError} naming the first thing wrong with the `dev` block. */
|
|
547
|
+
function validateDev(dev) {
|
|
548
|
+
const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
|
|
549
|
+
validateEnvironmentChoice(dev, "`dev`", false);
|
|
550
|
+
if (dev.tunnel !== void 0) {
|
|
551
|
+
if (!nonEmpty(dev.tunnel.name)) throw new ConfigError("`dev.tunnel.name` must be a name, got an empty value");
|
|
552
|
+
if (typeof dev.tunnel.hostname !== "string" || !HOSTNAME.test(dev.tunnel.hostname)) throw new ConfigError(`\`dev.tunnel.hostname\` must be a hostname such as sentinel-dev.example.dev (no scheme or path), got ${JSON.stringify(dev.tunnel.hostname)}`);
|
|
553
|
+
}
|
|
554
|
+
if (dev.port !== void 0 && !(Number.isInteger(dev.port) && dev.port >= 1 && dev.port <= 65535)) throw new ConfigError(`\`dev.port\` must be a port from 1 to 65535, got ${JSON.stringify(dev.port)}`);
|
|
555
|
+
if (dev.command !== void 0 && !(Array.isArray(dev.command) && dev.command.length > 0 && dev.command.every(nonEmpty))) throw new ConfigError("`dev.command` must be the program and its arguments, e.g. [\"pnpm\", \"run\", \"serve\"]");
|
|
556
|
+
if (dev.suspendWhenIdle !== void 0 && typeof dev.suspendWhenIdle !== "boolean") throw new ConfigError(`\`dev.suspendWhenIdle\` must be true or false, got ${JSON.stringify(dev.suspendWhenIdle)}`);
|
|
557
|
+
if (dev.serve !== void 0) {
|
|
558
|
+
const { serve } = dev;
|
|
559
|
+
if (!nonEmpty(serve.handler)) throw new ConfigError("`dev.serve.handler` must be the path of the module that exports the handler");
|
|
560
|
+
if (serve.export !== void 0 && !nonEmpty(serve.export)) throw new ConfigError("`dev.serve.export` must be the name of the handler's export, got an empty value");
|
|
561
|
+
if (serve.required !== void 0 && !(Array.isArray(serve.required) && serve.required.every(nonEmpty))) throw new ConfigError("`dev.serve.required` must be a list of variable names");
|
|
562
|
+
if (serve.logging !== void 0 && !(nonEmpty(serve.logging.tokenVar) && nonEmpty(serve.logging.datasetVar))) throw new ConfigError("`dev.serve.logging` needs a `tokenVar` and a `datasetVar`, both variable names");
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
/** Throws a {@link ConfigError} when the `vault` entry's options name an Environment two ways, or a `layer` that is no layer word. */
|
|
566
|
+
function validateVaultLayer(entry) {
|
|
567
|
+
if (entry?.cardinality !== "single") return;
|
|
568
|
+
validateEnvironmentChoice(entry.tuple.options, "the `vault` provider's options", false);
|
|
569
|
+
}
|
|
570
|
+
/** The values `repoValidation.docsCoverage` accepts. */
|
|
571
|
+
const DOCS_COVERAGE_MODES = [
|
|
572
|
+
"off",
|
|
573
|
+
"warn",
|
|
574
|
+
"required"
|
|
575
|
+
];
|
|
576
|
+
/** The values `ci.aggregate` accepts. */
|
|
577
|
+
const CI_AGGREGATE_POSTERS = [
|
|
578
|
+
"actions",
|
|
579
|
+
"sentinel",
|
|
580
|
+
"none"
|
|
581
|
+
];
|
|
582
|
+
/**
|
|
583
|
+
* The environment a `credentials` provider reads: its own `environment` option when it has one, else the shared
|
|
584
|
+
* `credentials.environment`, else `undefined`. The option lets each of several providers name its own (a 1Password
|
|
585
|
+
* Environment and an AWS secret are not called the same thing) without the plugin storing the name.
|
|
586
|
+
*/
|
|
587
|
+
function credentialsEnvironment(tuple, config) {
|
|
588
|
+
const own = tuple.options.environment;
|
|
589
|
+
return typeof own === "string" && own.trim() !== "" ? own : config.credentials?.environment;
|
|
590
|
+
}
|
|
591
|
+
/** Validates a raw `holocron.config` and resolves its provider entries; throws `ConfigError` when `name` or `providers` is missing or an entry is malformed. */
|
|
592
|
+
function resolveConfig(raw) {
|
|
593
|
+
if (!raw.name) throw new ConfigError("`name` is required");
|
|
594
|
+
if (!raw.providers || typeof raw.providers !== "object") throw new ConfigError("`providers` block is required");
|
|
595
|
+
const providers = {};
|
|
596
|
+
for (const [key, entry] of Object.entries(raw.providers)) {
|
|
597
|
+
if (entry === void 0) continue;
|
|
598
|
+
providers[key] = resolveEntry(key, entry);
|
|
599
|
+
}
|
|
600
|
+
for (const required of REQUIRED_CAPABILITIES) if (!providers[required]) throw new ConfigError(`required capability \`${required}\` is missing from providers`);
|
|
601
|
+
let docs;
|
|
602
|
+
if (raw.docs !== void 0) {
|
|
603
|
+
if (!raw.docs.build) throw new ConfigError("`docs.build` is required when `docs` is set");
|
|
604
|
+
docs = raw.docs;
|
|
605
|
+
}
|
|
606
|
+
const docsCoverage = raw.repoValidation?.docsCoverage;
|
|
607
|
+
if (docsCoverage !== void 0 && !DOCS_COVERAGE_MODES.includes(docsCoverage)) throw new ConfigError(`\`repoValidation.docsCoverage\` must be one of ${DOCS_COVERAGE_MODES.map((m) => `"${m}"`).join(", ")}, got ${JSON.stringify(docsCoverage)}`);
|
|
608
|
+
const aggregate = raw.ci?.aggregate;
|
|
609
|
+
if (aggregate !== void 0 && !CI_AGGREGATE_POSTERS.includes(aggregate)) throw new ConfigError(`\`ci.aggregate\` must be one of ${CI_AGGREGATE_POSTERS.map((m) => `"${m}"`).join(", ")}, got ${JSON.stringify(aggregate)}`);
|
|
610
|
+
const pin = raw.ci?.pin;
|
|
611
|
+
if (pin !== void 0 && (typeof pin !== "object" || pin === null || !Number.isSafeInteger(pin.integrationId) || pin.integrationId <= 0)) throw new ConfigError(`\`ci.pin.integrationId\` must be a positive integer (the GitHub App's id), got ${JSON.stringify(pin)}`);
|
|
612
|
+
if (raw.credentials !== void 0) {
|
|
613
|
+
const environment = raw.credentials.environment;
|
|
614
|
+
if (typeof environment !== "string" || environment.trim() === "") throw new ConfigError("`credentials.environment` must be the name of an environment, got an empty value");
|
|
615
|
+
}
|
|
616
|
+
if (raw.dev !== void 0) validateDev(raw.dev);
|
|
617
|
+
if (raw.githubApps !== void 0) validateGitHubApps(raw.githubApps);
|
|
618
|
+
if (raw.ideas !== void 0) validateIdeas(raw.ideas);
|
|
619
|
+
if (raw.issueTypes !== void 0) validateIssueTypes(raw.issueTypes);
|
|
620
|
+
validateRepoLabels(raw.repo?.labels);
|
|
621
|
+
validateRepoViews(raw.repo?.views);
|
|
622
|
+
validateRepoEnvironments(raw.repo?.environments);
|
|
623
|
+
validateRequiredChecks(raw.repo?.requiredChecks);
|
|
624
|
+
validateVariablesSync(raw.repo?.variables);
|
|
625
|
+
validateSecretsDeploy(raw.repo?.secrets);
|
|
626
|
+
validateSecretsSync(raw.repo?.secrets);
|
|
627
|
+
validateVaultLayer(providers.vault);
|
|
628
|
+
const credentialsEntry = providers.credentials;
|
|
629
|
+
if (credentialsEntry?.cardinality === "many") for (const tuple of credentialsEntry.tuples) {
|
|
630
|
+
const own = tuple.options.environment;
|
|
631
|
+
if (own !== void 0 && (typeof own !== "string" || own.trim() === "")) throw new ConfigError(`the \`environment\` option of the \`${tuple.provider}\` credentials provider must be the name of an environment, got an empty value`);
|
|
632
|
+
if (credentialsEnvironment(tuple, raw) === void 0 && !derivesEnvironment(tuple.provider)) throw new ConfigError(`the \`${tuple.provider}\` credentials provider has no environment to read: give it an \`environment\` option or set \`credentials.environment\``);
|
|
633
|
+
}
|
|
634
|
+
const homepage = raw.homepage ?? (docs?.domain ? `https://${docs.domain}/` : void 0);
|
|
635
|
+
const { agent, agentOptions } = splitAgent(raw.agent);
|
|
636
|
+
return {
|
|
637
|
+
name: raw.name,
|
|
638
|
+
description: raw.description,
|
|
639
|
+
homepage,
|
|
640
|
+
org: raw.org,
|
|
641
|
+
domain: raw.domain,
|
|
642
|
+
issueTypes: raw.issueTypes,
|
|
643
|
+
repo: raw.repo,
|
|
644
|
+
repoValidation: raw.repoValidation,
|
|
645
|
+
tasks: raw.tasks,
|
|
646
|
+
syncScripts: raw.syncScripts,
|
|
647
|
+
holocronScript: raw.holocronScript,
|
|
648
|
+
extraRequiredChecks: raw.extraRequiredChecks,
|
|
649
|
+
ci: raw.ci,
|
|
650
|
+
hooks: raw.hooks,
|
|
651
|
+
providers,
|
|
652
|
+
apps: raw.apps ?? [],
|
|
653
|
+
doctor: raw.doctor ?? {},
|
|
654
|
+
agent,
|
|
655
|
+
...agentOptions ? { agentOptions } : {},
|
|
656
|
+
skills: raw.skills,
|
|
657
|
+
docs,
|
|
658
|
+
env: raw.env,
|
|
659
|
+
credentials: raw.credentials,
|
|
660
|
+
dev: raw.dev,
|
|
661
|
+
githubApps: raw.githubApps,
|
|
662
|
+
ideas: raw.ideas,
|
|
663
|
+
log: raw.log,
|
|
664
|
+
telemetry: raw.telemetry,
|
|
665
|
+
eslint: raw.eslint
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
// src/config/compose/merge-sync/merge-sync.ts
|
|
669
|
+
/**
|
|
670
|
+
* Merge two lists of `repo.secrets.sync` (or `repo.variables.sync`) entries. An entry is the same sync when its
|
|
671
|
+
* environment and scope match; the keys then add up, and an entry that names no keys (every key the vault holds) stays
|
|
672
|
+
* that way.
|
|
673
|
+
*/
|
|
674
|
+
function mergeSync(a, b) {
|
|
675
|
+
const merged = /* @__PURE__ */ new Map();
|
|
676
|
+
for (const entry of [...a ?? [], ...b ?? []]) {
|
|
677
|
+
const id = JSON.stringify([
|
|
678
|
+
entry.environment,
|
|
679
|
+
entry.layer,
|
|
680
|
+
entry.scope ?? "repo"
|
|
681
|
+
]);
|
|
682
|
+
const have = merged.get(id);
|
|
683
|
+
merged.set(id, have ? {
|
|
684
|
+
...have,
|
|
685
|
+
...have.keys && entry.keys ? { keys: [.../* @__PURE__ */ new Set([...have.keys, ...entry.keys])] } : { keys: void 0 }
|
|
686
|
+
} : { ...entry });
|
|
687
|
+
}
|
|
688
|
+
return [...merged.values()].map(({ keys, ...rest }) => keys ? {
|
|
689
|
+
...rest,
|
|
690
|
+
keys
|
|
691
|
+
} : rest);
|
|
692
|
+
}
|
|
693
|
+
// src/config/compose/merge-repo/merge-repo.ts
|
|
694
|
+
const names = union();
|
|
695
|
+
const properties = shallowMerge();
|
|
696
|
+
const teamsByKey = mergeByKey((t) => typeof t === "string" ? t : t.slug);
|
|
697
|
+
/**
|
|
698
|
+
* Merge one capability's `repo` fragment onto what earlier ones gave. Scalars: last writer wins. `properties`: shallow
|
|
699
|
+
* merge. `variables`: merged per scope (`repo`, `org`), and `sync` entries by environment and scope. `secrets`: each name list is a union, and `sync` entries merge by
|
|
700
|
+
* environment and scope. `topics`: union. `teams`: merged by slug.
|
|
701
|
+
*/
|
|
702
|
+
function mergeRepo(prev, next) {
|
|
703
|
+
const { properties: nextProperties, topics, teams, variables, secrets, ...scalars } = next;
|
|
704
|
+
const repo = {
|
|
705
|
+
...prev,
|
|
706
|
+
...scalars
|
|
707
|
+
};
|
|
708
|
+
if (nextProperties) repo.properties = properties.merge(repo.properties ?? {}, nextProperties);
|
|
709
|
+
if (variables) repo.variables = {
|
|
710
|
+
...repo.variables,
|
|
711
|
+
...variables,
|
|
712
|
+
...repo.variables?.repo || variables.repo ? { repo: {
|
|
713
|
+
...repo.variables?.repo,
|
|
714
|
+
...variables.repo
|
|
715
|
+
} } : {},
|
|
716
|
+
...repo.variables?.org || variables.org ? { org: {
|
|
717
|
+
...repo.variables?.org,
|
|
718
|
+
...variables.org
|
|
719
|
+
} } : {},
|
|
720
|
+
...repo.variables?.sync || variables.sync ? { sync: mergeSync(repo.variables?.sync, variables.sync) } : {}
|
|
721
|
+
};
|
|
722
|
+
if (secrets) {
|
|
723
|
+
const environments = { ...repo.secrets?.environments };
|
|
724
|
+
for (const [env, list] of Object.entries(secrets.environments ?? {})) environments[env] = names.merge(environments[env] ?? [], list);
|
|
725
|
+
repo.secrets = {
|
|
726
|
+
...repo.secrets?.repo || secrets.repo ? { repo: names.merge(repo.secrets?.repo ?? [], secrets.repo ?? []) } : {},
|
|
727
|
+
...repo.secrets?.org || secrets.org ? { org: names.merge(repo.secrets?.org ?? [], secrets.org ?? []) } : {},
|
|
728
|
+
...Object.keys(environments).length > 0 ? { environments } : {},
|
|
729
|
+
...repo.secrets?.sync || secrets.sync ? { sync: mergeSync(repo.secrets?.sync, secrets.sync) } : {},
|
|
730
|
+
...repo.secrets?.deploy || secrets.deploy ? { deploy: [...repo.secrets?.deploy ?? [], ...secrets.deploy ?? []] } : {}
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
if (topics) repo.topics = names.merge(repo.topics ?? [], topics);
|
|
734
|
+
if (teams) repo.teams = teamsByKey.merge(repo.teams ?? [], teams);
|
|
735
|
+
return repo;
|
|
736
|
+
}
|
|
737
|
+
// src/config/compose/task-name/task-name.ts
|
|
738
|
+
/**
|
|
739
|
+
* The key a task entry merges under. A name that stands for exactly one flat id (the id itself, or an old dotted
|
|
740
|
+
* alias such as `verification.unitTests`) keys by that id, so the alias overrides the preset's entry instead of
|
|
741
|
+
* sitting next to it; a name that stands for several ids or none (a suite, an unknown name) keys by itself.
|
|
742
|
+
*/
|
|
743
|
+
function taskName(e) {
|
|
744
|
+
const name = typeof e === "string" ? e : e.name;
|
|
745
|
+
const resolved = resolveTaskName(name);
|
|
746
|
+
return resolved.length === 1 ? resolved[0].id : name;
|
|
747
|
+
}
|
|
748
|
+
// src/config/compose/merge-strategies/merge-strategies.ts
|
|
749
|
+
/**
|
|
750
|
+
* How `compose()` merges each key of the capabilities: tasks by name (an old dotted alias overrides the entry it names),
|
|
751
|
+
* providers shallowly, the non-task required checks as a union, `repo` by its own rules, the rest last writer wins.
|
|
752
|
+
*/
|
|
753
|
+
const mergeStrategies = {
|
|
754
|
+
tasks: mergeByKey(taskName),
|
|
755
|
+
providers: shallowMerge(),
|
|
756
|
+
extraRequiredChecks: union(),
|
|
757
|
+
repo: {
|
|
758
|
+
empty: {},
|
|
759
|
+
merge: mergeRepo
|
|
760
|
+
},
|
|
761
|
+
org: lastWins(),
|
|
762
|
+
domain: lastWins(),
|
|
763
|
+
docs: lastWins()
|
|
764
|
+
};
|
|
765
|
+
// src/config/load-config/read-package-json-name/read-package-json-name.ts
|
|
766
|
+
/** The `name` of the `package.json` in `dir` without its scope, or `undefined`. */
|
|
767
|
+
async function readPackageJsonName(dir) {
|
|
768
|
+
const name = (await readPackageJson(dir))?.name;
|
|
769
|
+
return name === void 0 ? void 0 : name.replace(/^@[^/]+\//, "");
|
|
770
|
+
}
|
|
771
|
+
// src/config/load-config/derive-defaults/derive-defaults.ts
|
|
772
|
+
/**
|
|
773
|
+
* Fill in what a `holocron.config` leaves out: `name` from the package or directory, `repo.name` from the GitHub
|
|
774
|
+
* remote, and the task manifest (merged from `astromech.config.*`).
|
|
775
|
+
*/
|
|
776
|
+
async function deriveDefaults(found) {
|
|
777
|
+
const configDir = dirname(found.filepath);
|
|
778
|
+
const result = { ...found.config };
|
|
779
|
+
if (!result.name) result.name = await readPackageJsonName(configDir) ?? basename(configDir);
|
|
780
|
+
if (result.repo && !result.repo.name) {
|
|
781
|
+
const remote = await readGitRemote(configDir);
|
|
782
|
+
if (remote?.host === "github.com") result.repo = {
|
|
783
|
+
...result.repo,
|
|
784
|
+
name: remote.slug
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
const manifest = await loadTasksConfig(configDir, { holocron: found });
|
|
788
|
+
if (manifest.tasks) result.tasks = manifest.tasks;
|
|
789
|
+
if (manifest.syncScripts !== void 0) result.syncScripts = manifest.syncScripts;
|
|
790
|
+
if (manifest.holocronScript !== void 0) result.holocronScript = manifest.holocronScript;
|
|
791
|
+
if (manifest.hooks !== void 0) result.hooks = manifest.hooks;
|
|
792
|
+
if (manifest.ci !== void 0) result.ci = manifest.ci;
|
|
793
|
+
if (manifest.extraRequiredChecks) result.extraRequiredChecks = [...result.extraRequiredChecks ?? [], ...manifest.extraRequiredChecks];
|
|
794
|
+
return result;
|
|
795
|
+
}
|
|
796
|
+
// src/config/load-config/holocron-areas/holocron-areas.ts
|
|
797
|
+
/**
|
|
798
|
+
* The closed list of area files `loadConfig` reads from `.holocron/` (the directory is `.<config name>`, set by kyber):
|
|
799
|
+
* `.holocron/notifications.*` fills `providers.notifications`' `layout`, `.holocron/repo.*` fills keys of `repo`, and `.holocron/org.*` fills provider options (`teamId`, `accountId`) a config leaves out.
|
|
800
|
+
* A file not on this list is never read.
|
|
801
|
+
*/
|
|
802
|
+
const HOLOCRON_AREAS = [
|
|
803
|
+
"notifications",
|
|
804
|
+
"repo",
|
|
805
|
+
"org"
|
|
806
|
+
];
|
|
807
|
+
/**
|
|
808
|
+
* The areas a config in a subdirectory also reads from the repository root's `.holocron/` (SPEC-0069): only `org`,
|
|
809
|
+
* because its values are the organization's and every config needs them. `repo` and `notifications` describe the
|
|
810
|
+
* repository itself, so an app's config does not take them from the root.
|
|
811
|
+
*/
|
|
812
|
+
const SHARED_AREAS = ["org"];
|
|
813
|
+
// src/config/load-config/place-notifications/place-notifications.ts
|
|
814
|
+
const isTuple$1 = (entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && typeof entry[1] === "object" && entry[1] !== null && !Array.isArray(entry[1]);
|
|
815
|
+
const providerName = (entry) => isTuple$1(entry) ? entry[0] : entry;
|
|
816
|
+
/** Index of the entry the layout belongs to in a multi-provider list: the first `discord`. */
|
|
817
|
+
function findDiscord(entries) {
|
|
818
|
+
return entries.findIndex((entry) => providerName(entry) === "discord");
|
|
819
|
+
}
|
|
820
|
+
function withLayout(entry, layout) {
|
|
821
|
+
return isTuple$1(entry) ? [entry[0], {
|
|
822
|
+
...entry[1],
|
|
823
|
+
layout
|
|
824
|
+
}] : [entry, { layout }];
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Set `layout` on the notifications provider from `.holocron/notifications.*`. The entry may be a name (`"discord"`),
|
|
828
|
+
* a `[name, options]` tuple, or a list (the first `discord` entry gets it). Throws `ConfigError` when the provider is
|
|
829
|
+
* not set or already has an inline `layout`.
|
|
830
|
+
*/
|
|
831
|
+
function placeNotifications(raw, area) {
|
|
832
|
+
if (typeof area.value !== "object" || area.value === null || Array.isArray(area.value)) throw new ConfigError$1(`${area.path} must export the notifications layout as an object`);
|
|
833
|
+
const entry = raw.providers?.notifications;
|
|
834
|
+
const hint = `Set it in one place: remove the inline \`layout\` or delete ${area.path}`;
|
|
835
|
+
let placed;
|
|
836
|
+
if (entry === void 0) throw new ConfigError$1(`${area.path} holds the notifications layout, but providers.notifications is not set. Add \`notifications: ["discord", { guildId }]\` to providers`);
|
|
837
|
+
else if (Array.isArray(entry) && !isTuple$1(entry)) {
|
|
838
|
+
const index = findDiscord(entry);
|
|
839
|
+
if (index === -1) throw new ConfigError$1(`${area.path} holds the notifications layout, but providers.notifications has no discord entry`);
|
|
840
|
+
const target = entry[index];
|
|
841
|
+
if (isTuple$1(target) && target[1].layout !== void 0) throw new ConfigError$1(`the notifications layout is set in providers.notifications and in ${area.path}. ${hint}`);
|
|
842
|
+
placed = entry.map((item, i) => i === index ? withLayout(item, area.value) : item);
|
|
843
|
+
} else {
|
|
844
|
+
if (isTuple$1(entry) && entry[1].layout !== void 0) throw new ConfigError$1(`the notifications layout is set in providers.notifications and in ${area.path}. ${hint}`);
|
|
845
|
+
placed = withLayout(entry, area.value);
|
|
846
|
+
}
|
|
847
|
+
return {
|
|
848
|
+
...raw,
|
|
849
|
+
providers: {
|
|
850
|
+
...raw.providers,
|
|
851
|
+
notifications: placed
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
// src/config/load-config/place-org/place-org.ts
|
|
856
|
+
/** The options each provider key of `.holocron/org.*` may hold. Checked against `OrgConfig` by the type. */
|
|
857
|
+
const ORG_OPTIONS = {
|
|
858
|
+
cloudflare: ["accountId", "zone"],
|
|
859
|
+
vercel: ["teamId"],
|
|
860
|
+
checkly: ["accountId"],
|
|
861
|
+
sentry: ["org"]
|
|
862
|
+
};
|
|
863
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
864
|
+
const isTuple = (entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && isObject(entry[1]);
|
|
865
|
+
/**
|
|
866
|
+
* Check the shape of the area file: the top-level `domain` (a non-empty string), then a closed list of providers,
|
|
867
|
+
* each with a closed list of string options.
|
|
868
|
+
*/
|
|
869
|
+
function validate(area) {
|
|
870
|
+
if (!isObject(area.value)) throw new ConfigError$1(`${area.path} must export the org settings as an object`);
|
|
871
|
+
const { domain, issueTypes, ...rest } = area.value;
|
|
872
|
+
if (domain !== void 0 && (typeof domain !== "string" || domain === "")) throw new ConfigError$1(`${area.path}: "domain" must be a non-empty string`);
|
|
873
|
+
const types = issueTypes === void 0 ? void 0 : validateIssueTypes(issueTypes, `${area.path}: issueTypes`);
|
|
874
|
+
for (const [provider, options] of Object.entries(rest)) {
|
|
875
|
+
const allowed = ORG_OPTIONS[provider];
|
|
876
|
+
if (allowed === void 0) throw new ConfigError$1(`${area.path} has an unknown provider "${provider}". Known: ${Object.keys(ORG_OPTIONS).join(", ")}`);
|
|
877
|
+
if (!isObject(options)) throw new ConfigError$1(`${area.path}: "${provider}" must be an object of options`);
|
|
878
|
+
for (const [option, value] of Object.entries(options)) {
|
|
879
|
+
if (!allowed.includes(option)) throw new ConfigError$1(`${area.path}: "${provider}.${option}" is not an org option. Known: ${allowed.join(", ")}`);
|
|
880
|
+
if (typeof value !== "string" || value === "") throw new ConfigError$1(`${area.path}: "${provider}.${option}" must be a non-empty string`);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
return {
|
|
884
|
+
...domain !== void 0 ? { domain } : {},
|
|
885
|
+
...types !== void 0 ? { issueTypes: types } : {},
|
|
886
|
+
providers: rest
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* The org options of an area and, when the repository root has the same area, the root's under them: an option set in
|
|
891
|
+
* both takes the config's own value, option by option (the root's other options stay). Each file is checked on its own.
|
|
892
|
+
*/
|
|
893
|
+
function merge(area) {
|
|
894
|
+
const providers = {};
|
|
895
|
+
let domain;
|
|
896
|
+
let issueTypes;
|
|
897
|
+
for (const layer of area.root ? [area.root, area] : [area]) {
|
|
898
|
+
const checked = validate(layer);
|
|
899
|
+
if (checked.domain !== void 0) domain = {
|
|
900
|
+
value: checked.domain,
|
|
901
|
+
path: layer.path
|
|
902
|
+
};
|
|
903
|
+
if (checked.issueTypes !== void 0) issueTypes = {
|
|
904
|
+
value: checked.issueTypes,
|
|
905
|
+
path: layer.path
|
|
906
|
+
};
|
|
907
|
+
for (const [provider, options] of Object.entries(checked.providers)) {
|
|
908
|
+
const sourced = providers[provider] ??= {};
|
|
909
|
+
for (const [option, value] of Object.entries(options)) sourced[option] = {
|
|
910
|
+
value,
|
|
911
|
+
path: layer.path
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return {
|
|
916
|
+
...domain ? { domain } : {},
|
|
917
|
+
...issueTypes ? { issueTypes } : {},
|
|
918
|
+
providers
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
/** Fill one entry when it names a provider the area holds; throws when the config already sets one of its options. */
|
|
922
|
+
function fill(entry, org, capability) {
|
|
923
|
+
const [provider, options] = isTuple(entry) ? entry : [entry, {}];
|
|
924
|
+
const values = org[provider];
|
|
925
|
+
if (values === void 0 || Object.keys(values).length === 0) return entry;
|
|
926
|
+
const filled = {};
|
|
927
|
+
for (const [option, { value, path }] of Object.entries(values)) {
|
|
928
|
+
if (options[option] !== void 0) throw new ConfigError$1(`${provider}.${option} is set in providers.${capability} and in ${path}. Set it in one place: remove the inline option or the key from ${path}`);
|
|
929
|
+
filled[option] = value;
|
|
930
|
+
}
|
|
931
|
+
return [provider, {
|
|
932
|
+
...options,
|
|
933
|
+
...filled
|
|
934
|
+
}];
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Fill `.holocron/org.*` into the config. Its top-level `domain` (the org's zone) is set on a config that leaves
|
|
938
|
+
* `domain` out; set inline and in the file it is a `ConfigError` naming both. Its `issueTypes` (#2512) are placed the
|
|
939
|
+
* same way, a list that the subdirectory file replaces whole. Its provider options go into the
|
|
940
|
+
* providers the config uses. A provider entry (a name, a
|
|
941
|
+
* `[name, options]` tuple, or either inside a list) that names a provider the file holds gets each option it leaves
|
|
942
|
+
* out. An option set inline and in the file is a `ConfigError` naming both (no merge, no precedence); a provider the
|
|
943
|
+
* config does not use is ignored; a provider or option the file lists but `OrgConfig` does not know is an error.
|
|
944
|
+
* When the area also came from the repository root (`area.root`, a config in a subdirectory), the two files combine
|
|
945
|
+
* option by option and the config's own file wins; that is not an error.
|
|
946
|
+
*/
|
|
947
|
+
function placeOrg(raw, area) {
|
|
948
|
+
const { domain, issueTypes, providers: org } = merge(area);
|
|
949
|
+
if (domain !== void 0 && raw.domain !== void 0) throw new ConfigError$1(`domain is set in the config and in ${domain.path}. Set it in one place: remove the inline value or the key from ${domain.path}`);
|
|
950
|
+
if (issueTypes !== void 0 && raw.issueTypes !== void 0) throw new ConfigError$1(`issueTypes is set in the config and in ${issueTypes.path}. Set it in one place: remove the inline value or the key from ${issueTypes.path}`);
|
|
951
|
+
const withTypes = issueTypes === void 0 ? raw : {
|
|
952
|
+
...raw,
|
|
953
|
+
issueTypes: issueTypes.value
|
|
954
|
+
};
|
|
955
|
+
const withDomain = domain === void 0 ? withTypes : {
|
|
956
|
+
...withTypes,
|
|
957
|
+
domain: domain.value
|
|
958
|
+
};
|
|
959
|
+
if (withDomain.providers === void 0) return withDomain;
|
|
960
|
+
const providers = { ...withDomain.providers };
|
|
961
|
+
for (const [capability, entry] of Object.entries(withDomain.providers)) providers[capability] = Array.isArray(entry) && !isTuple(entry) ? entry.map((item) => fill(item, org, capability)) : fill(entry, org, capability);
|
|
962
|
+
return {
|
|
963
|
+
...withDomain,
|
|
964
|
+
providers
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
// src/config/load-config/place-repo/place-repo.ts
|
|
968
|
+
/**
|
|
969
|
+
* Add the keys of `.holocron/repo.*` to `repo`. The keys of the two sources must differ (`repo.defaultBranch` stays
|
|
970
|
+
* inline so Sentinel can find the branch to read): a key set both inline and in the file is a `ConfigError` naming
|
|
971
|
+
* both.
|
|
972
|
+
*/
|
|
973
|
+
function placeRepo(raw, area) {
|
|
974
|
+
if (typeof area.value !== "object" || area.value === null || Array.isArray(area.value)) throw new ConfigError$1(`${area.path} must export the repo settings as an object`);
|
|
975
|
+
const fromFile = area.value;
|
|
976
|
+
const inline = raw.repo ?? {};
|
|
977
|
+
for (const key of Object.keys(fromFile)) if (inline[key] !== void 0) throw new ConfigError$1(`repo.${key} is set in the config and in ${area.path}. Set it in one place: remove the inline value or the key from ${area.path}`);
|
|
978
|
+
return {
|
|
979
|
+
...raw,
|
|
980
|
+
repo: {
|
|
981
|
+
...inline,
|
|
982
|
+
...fromFile
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
// src/config/load-config/place-areas/place-areas.ts
|
|
987
|
+
/**
|
|
988
|
+
* Put the area files of `.holocron/` into the config as loaded, before `deriveDefaults` runs: `notifications` becomes
|
|
989
|
+
* the `layout` of the notifications provider and `repo` supplies keys of `repo` and `org` fills the provider options a config leaves out. A value set both inline and in a file
|
|
990
|
+
* is a `ConfigError` naming both (no merge, no precedence). With no area files the config is returned as it was.
|
|
991
|
+
*/
|
|
992
|
+
function placeAreas(areas, raw) {
|
|
993
|
+
let result = raw;
|
|
994
|
+
for (const area of areas) if (area.area === "notifications") result = placeNotifications(result, area);
|
|
995
|
+
else if (area.area === "repo") result = placeRepo(result, area);
|
|
996
|
+
else if (area.area === "org") result = placeOrg(result, area);
|
|
997
|
+
return result;
|
|
998
|
+
}
|
|
999
|
+
// src/config/resolve-layers/resolve-layers.ts
|
|
1000
|
+
/**
|
|
1001
|
+
* Turns every `layer` in a loaded config into the `environment` it names (spec `tech-environment-layers`, #2069), so
|
|
1002
|
+
* the commands and doctors that read Environments see one literal name and none of them derives it again. The name is
|
|
1003
|
+
* `layerEnvironment()` over the `origin` remote of `input.repoRoot`, read at most once and only when an entry names a
|
|
1004
|
+
* layer. A remote that cannot be read is a `ConfigError` naming the `environment` option (`repoSlug()`); nothing is
|
|
1005
|
+
* guessed. Covers `repo.secrets.sync`, `repo.secrets.deploy`, `repo.variables.sync`, `githubApps`, `dev` and the
|
|
1006
|
+
* `vault` provider's `layer` option. Returns a new config; the one passed in is not changed.
|
|
1007
|
+
*
|
|
1008
|
+
* @param config - The resolved config, validated by `resolveConfig()`.
|
|
1009
|
+
* @param input - Where to read the remote, and how.
|
|
1010
|
+
* @returns The config with each `layer` replaced by its `environment`.
|
|
1011
|
+
*/
|
|
1012
|
+
async function resolveLayers(config, input) {
|
|
1013
|
+
let slug;
|
|
1014
|
+
const named = async (entry) => {
|
|
1015
|
+
if (entry.layer === void 0) return entry;
|
|
1016
|
+
const { layer, ...rest } = entry;
|
|
1017
|
+
slug ??= repoSlug(input.repoRoot, input.gitExec);
|
|
1018
|
+
return {
|
|
1019
|
+
...rest,
|
|
1020
|
+
environment: layerEnvironment(await slug, layer)
|
|
1021
|
+
};
|
|
1022
|
+
};
|
|
1023
|
+
const all = (list) => Promise.all(list.map(named));
|
|
1024
|
+
const out = { ...config };
|
|
1025
|
+
const { repo } = config;
|
|
1026
|
+
if (repo) {
|
|
1027
|
+
const next = { ...repo };
|
|
1028
|
+
if (repo.secrets) {
|
|
1029
|
+
next.secrets = { ...repo.secrets };
|
|
1030
|
+
if (repo.secrets.sync) next.secrets.sync = await all(repo.secrets.sync);
|
|
1031
|
+
if (repo.secrets.deploy) next.secrets.deploy = await all(repo.secrets.deploy);
|
|
1032
|
+
}
|
|
1033
|
+
if (repo.variables?.sync) next.variables = {
|
|
1034
|
+
...repo.variables,
|
|
1035
|
+
sync: await all(repo.variables.sync)
|
|
1036
|
+
};
|
|
1037
|
+
out.repo = next;
|
|
1038
|
+
}
|
|
1039
|
+
if (config.githubApps) out.githubApps = await all(config.githubApps);
|
|
1040
|
+
if (config.dev) out.dev = await named(config.dev);
|
|
1041
|
+
const vault = config.providers.vault;
|
|
1042
|
+
if (vault?.cardinality === "single" && vault.tuple.options.layer !== void 0) {
|
|
1043
|
+
const { layer, ...options } = vault.tuple.options;
|
|
1044
|
+
const resolved = await named({ layer });
|
|
1045
|
+
out.providers = {
|
|
1046
|
+
...config.providers,
|
|
1047
|
+
vault: {
|
|
1048
|
+
cardinality: "single",
|
|
1049
|
+
tuple: {
|
|
1050
|
+
...vault.tuple,
|
|
1051
|
+
options: {
|
|
1052
|
+
...options,
|
|
1053
|
+
environment: resolved.environment
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
return out;
|
|
1060
|
+
}
|
|
1061
|
+
// src/config/config-system.ts
|
|
1062
|
+
/**
|
|
1063
|
+
* Holocron's config system: `defineConfig`, `loadConfig` and `compose`, all built from one
|
|
1064
|
+
* `createConfigSystem` call.
|
|
1065
|
+
*
|
|
1066
|
+
* File discovery, the walk up to `.git`, module loading (typed configs via `tsx`) and the derive-then-resolve flow come
|
|
1067
|
+
* from `@theholocron/kyber/config`. The holocron-specific parts are `deriveDefaults` (name, `repo.name`, the task
|
|
1068
|
+
* manifest), `placeAreas` (the `.holocron/` area files, placed before `deriveDefaults`), `resolveConfig` and `mergeStrategies`.
|
|
1069
|
+
*
|
|
1070
|
+
* The three functions live together because each is only a method of the one system object; splitting them back into
|
|
1071
|
+
* one file apiece would just be pass-through wrappers (an exception to the one-function-per-file rule).
|
|
1072
|
+
*
|
|
1073
|
+
* Probe order is TS-first (`.ts` → `.js` → `.mjs` → `.cjs` → `.json`) —
|
|
1074
|
+
* see ADR-0010 / issue #75 / #81.
|
|
1075
|
+
*/
|
|
1076
|
+
const system = createConfigSystem({
|
|
1077
|
+
name: "holocron",
|
|
1078
|
+
areas: HOLOCRON_AREAS,
|
|
1079
|
+
shared: SHARED_AREAS,
|
|
1080
|
+
place: placeAreas,
|
|
1081
|
+
derive: deriveDefaults,
|
|
1082
|
+
resolve: resolveConfig,
|
|
1083
|
+
merge: mergeStrategies
|
|
1084
|
+
});
|
|
1085
|
+
/** Returns the config unchanged; it exists to type and autocomplete a `holocron.config.ts`. */
|
|
1086
|
+
const defineConfig = system.defineConfig;
|
|
1087
|
+
/**
|
|
1088
|
+
* Read + parse + resolve `holocron.config.*` starting from the given
|
|
1089
|
+
* directory, walking up through ancestors to the nearest `.git` boundary
|
|
1090
|
+
* when `cwd` itself has no match — every command is usable from any
|
|
1091
|
+
* subdirectory of a repo, not only its exact root (see
|
|
1092
|
+
* `@theholocron/datapad`'s own doc comment for the stop conditions).
|
|
1093
|
+
* Throws `ConfigFileError` when nothing is found or a file cannot
|
|
1094
|
+
* be loaded, or `ConfigError` when the config fails schema checks.
|
|
1095
|
+
*
|
|
1096
|
+
* Every `layer` an entry names becomes the `environment` it stands for (`resolveLayers()`, spec
|
|
1097
|
+
* `tech-environment-layers`, #2069), read from the `origin` remote at `cwd`; `input` lets a test pass a fake remote.
|
|
1098
|
+
*/
|
|
1099
|
+
async function loadConfig(cwd, input = {}) {
|
|
1100
|
+
const loaded = await system.loadConfig(cwd);
|
|
1101
|
+
return {
|
|
1102
|
+
...loaded,
|
|
1103
|
+
resolved: await resolveLayers(loaded.resolved, {
|
|
1104
|
+
repoRoot: cwd,
|
|
1105
|
+
...input
|
|
1106
|
+
})
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Merge any number of capability fragments into a single preset object that
|
|
1111
|
+
* spreads directly into `defineConfig()`.
|
|
1112
|
+
*
|
|
1113
|
+
* - Accepts individual capabilities or nested arrays (for bundle presets).
|
|
1114
|
+
* - Deduplicates by `id` — when the same ID appears more than once, the last
|
|
1115
|
+
* occurrence wins. This lets callers override bundle defaults by listing an
|
|
1116
|
+
* explicit capability after the bundle.
|
|
1117
|
+
* - Validates all `requires` at call time and throws `ConfigError` if any are
|
|
1118
|
+
* unmet, listing every missing dependency in a single message.
|
|
1119
|
+
*
|
|
1120
|
+
* @example
|
|
1121
|
+
* // docs-only site — no typecheck
|
|
1122
|
+
* const preset = compose(node(), docs());
|
|
1123
|
+
*
|
|
1124
|
+
* // library with docs
|
|
1125
|
+
* const preset = compose(node(), typecheck(), docs());
|
|
1126
|
+
*
|
|
1127
|
+
* // nextjs() is a bundle that returns Capability[]
|
|
1128
|
+
* const preset = compose(node(), nextjs());
|
|
1129
|
+
*/
|
|
1130
|
+
const compose = system.compose;
|
|
1131
|
+
export { placeAreas as a, ConfigError as c, resolveEntry as d, resolvePluginPackage as f, layerEnvironment as g, isEnvironmentLayer as h, loadConfig as i, credentialsEnvironment as l, ENVIRONMENT_LAYERS as m, compose as n, HOLOCRON_AREAS as o, repoSlug as p, defineConfig as r, SHARED_AREAS as s, ConfigFileError as t, resolveConfig as u };
|