@theholocron/cli 5.0.0-alpha.42 → 5.0.0-alpha.420
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 +553 -106
- package/dist/cli.mjs +24267 -6589
- package/dist/cli.mjs.map +1 -1
- package/dist/config-system-CPLUPDn8.mjs +796 -0
- package/dist/index-8QnGZze1.d.mts +4141 -0
- package/dist/index.d.mts +401 -639
- package/dist/index.mjs +470 -354
- package/dist/plugin/capabilities.d.mts +2 -807
- package/dist/plugin/capabilities.mjs +55 -4
- package/dist/presets.d.mts +221 -0
- package/dist/presets.mjs +439 -0
- package/package.json +49 -36
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
import { CARDINALITY, REQUIRED_CAPABILITIES } from "./plugin/capabilities.mjs";
|
|
2
|
+
import { resolvePluginPackage } from "@theholocron/kyber/plugins";
|
|
3
|
+
import { ConfigError, ConfigError as ConfigError$1, ConfigFileError, createConfigSystem, lastWins, mergeByKey, shallowMerge, union } from "@theholocron/kyber/config";
|
|
4
|
+
import { readGitRemote } from "@theholocron/git-utils";
|
|
5
|
+
import { basename, dirname } from "node:path";
|
|
6
|
+
import { readPackageJson } from "@theholocron/pkg-utils";
|
|
7
|
+
import { resolveTaskName } from "@theholocron/astromech";
|
|
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/credentials-environments/layer-environment/layer-environment.ts
|
|
17
|
+
/** The layer words, in the order the docs list them. */
|
|
18
|
+
const ENVIRONMENT_LAYERS = [
|
|
19
|
+
"local",
|
|
20
|
+
"dev",
|
|
21
|
+
"ci",
|
|
22
|
+
"prod"
|
|
23
|
+
];
|
|
24
|
+
/** Whether `value` is exactly one of the layer words (case-sensitive: `Prod` is a literal Environment name). */
|
|
25
|
+
function isEnvironmentLayer(value) {
|
|
26
|
+
return typeof value === "string" && ENVIRONMENT_LAYERS.includes(value);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The Environment a layer of a repository is kept in: `<org/repo> - <layer>`. The one place the name is built, for the
|
|
30
|
+
* `credentials` providers (`environmentLayers()`) and for the config entries that name a `layer`.
|
|
31
|
+
*/
|
|
32
|
+
function layerEnvironment(slug, layer) {
|
|
33
|
+
return `${slug} - ${layer}`;
|
|
34
|
+
}
|
|
35
|
+
// src/config/validate-environment-choice/validate-environment-choice.ts
|
|
36
|
+
/**
|
|
37
|
+
* Check that an entry names its vault Environment one way: a literal `environment`, or a `layer` the name is derived
|
|
38
|
+
* from (spec `tech-environment-layers`, #2069). Both together are an error, and so is a `layer` that is not a layer word
|
|
39
|
+
* or an `environment` that is blank. With neither, the entry is an error unless `required` is false.
|
|
40
|
+
*
|
|
41
|
+
* @param entry - The `environment` and `layer` the entry sets.
|
|
42
|
+
* @param what - How a message names the entry, e.g. "a `repo.secrets.deploy` entry".
|
|
43
|
+
* @param required - Whether the entry must name one of the two. Default true.
|
|
44
|
+
* @returns What the entry names (the environment, else the layer), for the rest of its messages; `undefined` for neither.
|
|
45
|
+
* @throws {ConfigError} Naming the entry and the problem.
|
|
46
|
+
*/
|
|
47
|
+
function validateEnvironmentChoice(entry, what, required = true) {
|
|
48
|
+
const { environment, layer } = entry;
|
|
49
|
+
if (environment !== void 0 && layer !== void 0) throw new ConfigError(`${what} sets both \`layer\` and \`environment\`: name the Environment one way`);
|
|
50
|
+
if (layer !== void 0) {
|
|
51
|
+
if (!isEnvironmentLayer(layer)) throw new ConfigError(`${what} has \`layer\` ${JSON.stringify(layer)}: use ${ENVIRONMENT_LAYERS.map((l) => `"${l}"`).join(", ")}, or \`environment\` for a literal name`);
|
|
52
|
+
return layer;
|
|
53
|
+
}
|
|
54
|
+
if (environment !== void 0) {
|
|
55
|
+
if (typeof environment !== "string" || environment.trim() === "") throw new ConfigError(`${what} needs the name of a vault environment, got an empty \`environment\``);
|
|
56
|
+
return environment;
|
|
57
|
+
}
|
|
58
|
+
if (required) throw new ConfigError(`${what} needs the name of a vault environment (\`environment\`) or a \`layer\``);
|
|
59
|
+
}
|
|
60
|
+
// src/config/validate-secrets-deploy/validate-secrets-deploy.ts
|
|
61
|
+
/**
|
|
62
|
+
* 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
|
|
63
|
+
* non-empty `prefix`. An entry with neither would mean "all keys", which a deployment never gets (spec
|
|
64
|
+
* `tech-deployment-key-allowlist`, #2061), so it is an error here and not a silent skip.
|
|
65
|
+
*
|
|
66
|
+
* @param secrets - `repo.secrets`, if the config has it.
|
|
67
|
+
* @throws {ConfigError} Naming the first problem found.
|
|
68
|
+
*/
|
|
69
|
+
function validateSecretsDeploy(secrets) {
|
|
70
|
+
for (const entry of secrets?.deploy ?? []) {
|
|
71
|
+
const named = validateEnvironmentChoice(entry, "a `repo.secrets.deploy` entry");
|
|
72
|
+
const label = `\`repo.secrets.deploy\` entry for ${JSON.stringify(named)}`;
|
|
73
|
+
const { keys, prefix } = entry;
|
|
74
|
+
if (keys !== void 0 && (!Array.isArray(keys) || keys.some((k) => typeof k !== "string" || k === ""))) throw new ConfigError(`${label} has \`keys\` that is not a list of key names`);
|
|
75
|
+
if (prefix !== void 0 && (typeof prefix !== "string" || prefix === "")) throw new ConfigError(`${label} has an empty \`prefix\``);
|
|
76
|
+
if ((keys === void 0 || keys.length === 0) && prefix === void 0) throw new ConfigError(`${label} needs \`keys\` (a list of names) or \`prefix\` (such as "SENTINEL_"): a deployment never receives every key`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// src/config/validate-secrets-sync/validate-secrets-sync.ts
|
|
80
|
+
/**
|
|
81
|
+
* Check `repo.secrets.sync`: each entry names its vault environment one way, a literal `environment` or a `layer`
|
|
82
|
+
* (spec `tech-environment-layers`, #2069). An organization
|
|
83
|
+
* scope must say who can read the secrets: `visibility: "selected"` (or left out) and a non-empty `repos` list. A
|
|
84
|
+
* concealed value is never readable by every repository, so `visibility: "all"` and `"private"` are errors, and an
|
|
85
|
+
* entry with no list does not load (spec `tech-org-secret-visibility`, #2062). `repos` and `visibility` mean nothing
|
|
86
|
+
* on another scope, so they are errors there. A repository name is `name` or `<org>/name` of the scope's own
|
|
87
|
+
* organization, and one key may not be given two different reader lists at the same organization.
|
|
88
|
+
*
|
|
89
|
+
* @param secrets - `repo.secrets`, if the config has it.
|
|
90
|
+
* @throws {ConfigError} Naming the first problem found.
|
|
91
|
+
*/
|
|
92
|
+
function validateSecretsSync(secrets) {
|
|
93
|
+
const readers = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const entry of secrets?.sync ?? []) {
|
|
95
|
+
const named = validateEnvironmentChoice(entry, "a `repo.secrets.sync` entry");
|
|
96
|
+
const label = `\`repo.secrets.sync\` entry for ${JSON.stringify(named)}`;
|
|
97
|
+
const scope = entry.scope ?? "repo";
|
|
98
|
+
if (!scope.startsWith("org=")) {
|
|
99
|
+
if (entry.visibility !== void 0 || entry.repos !== void 0) throw new ConfigError(`${label} sets \`visibility\` or \`repos\` on scope ${JSON.stringify(scope)}: only an organization scope ("org=<name>") has readers to name`);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const org = scope.slice(4);
|
|
103
|
+
if (entry.visibility !== void 0 && entry.visibility !== "selected") throw new ConfigError(`${label} has visibility ${JSON.stringify(entry.visibility)}: a secret is never readable by every repository, so use "selected" with \`repos\``);
|
|
104
|
+
const { repos } = entry;
|
|
105
|
+
if (!Array.isArray(repos) || repos.length === 0 || repos.some((r) => typeof r !== "string" || !/^(?:[^/]+\/)?[^/]+$/.test(r))) throw new ConfigError(`${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`);
|
|
106
|
+
const names = repos.map((r) => {
|
|
107
|
+
const slash = r.indexOf("/");
|
|
108
|
+
if ((slash < 0 ? org : r.slice(0, slash)) !== org) throw new ConfigError(`${label} lists repository ${JSON.stringify(r)}: use a name in ${JSON.stringify(org)}, such as "holocron"`);
|
|
109
|
+
return r.slice(slash + 1);
|
|
110
|
+
});
|
|
111
|
+
const list = [...new Set(names)].sort().join(", ");
|
|
112
|
+
for (const key of entry.keys ?? []) {
|
|
113
|
+
const id = `${org}/${key.toUpperCase()}`;
|
|
114
|
+
const seen = readers.get(id);
|
|
115
|
+
if (seen !== void 0 && seen !== list) throw new ConfigError(`${label} lists ${key}, which another \`repo.secrets.sync\` entry at org=${org} gives different readers [${seen}]: a secret has one reader list`);
|
|
116
|
+
readers.set(id, list);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// src/config/validate-variables-sync/validate-variables-sync.ts
|
|
121
|
+
/** GitHub treats variable names as case-insensitive, so every comparison goes through this. */
|
|
122
|
+
const key = (name) => name.toUpperCase();
|
|
123
|
+
/**
|
|
124
|
+
* Check `repo.variables.sync`: each entry names a vault environment, one or more keys and a scope that is `repo` or
|
|
125
|
+
* `org=<name>`; a name may not also be a literal value of the same scope (one source per name); and `prune` cannot
|
|
126
|
+
* be combined with `sync`, because `repo setup` would delete the variables the sync wrote.
|
|
127
|
+
*
|
|
128
|
+
* @param variables - `repo.variables`, if the config has it.
|
|
129
|
+
* @throws {ConfigError} Naming the first problem found.
|
|
130
|
+
*/
|
|
131
|
+
function validateVariablesSync(variables) {
|
|
132
|
+
const entries = variables?.sync;
|
|
133
|
+
if (!entries || entries.length === 0) return;
|
|
134
|
+
if (variables?.prune === true) throw new ConfigError("`repo.variables.prune` cannot be combined with `repo.variables.sync`: pruning would delete the variables the sync writes");
|
|
135
|
+
for (const entry of entries) {
|
|
136
|
+
const named = validateEnvironmentChoice(entry, "a `repo.variables.sync` entry");
|
|
137
|
+
const label = `\`repo.variables.sync\` entry for ${JSON.stringify(named)}`;
|
|
138
|
+
if (!Array.isArray(entry.keys) || entry.keys.length === 0 || entry.keys.some((k) => typeof k !== "string" || k === "")) throw new ConfigError(`${label} needs \`keys\`, a list of variable names`);
|
|
139
|
+
const scope = entry.scope ?? "repo";
|
|
140
|
+
const org = scope.startsWith("org=") ? scope.slice(4) : void 0;
|
|
141
|
+
if (scope !== "repo" && (org === void 0 || org === "")) throw new ConfigError(`${label} has scope ${JSON.stringify(scope)}: use "repo" or "org=<name>"`);
|
|
142
|
+
if (entry.visibility !== void 0 && entry.visibility !== "all" && entry.visibility !== "private") throw new ConfigError(`${label} has visibility ${JSON.stringify(entry.visibility)}: use "all" or "private"`);
|
|
143
|
+
const literal = new Set(Object.keys((org === void 0 ? variables?.repo : variables?.org) ?? {}).map(key));
|
|
144
|
+
const both = entry.keys.filter((k) => literal.has(key(k)));
|
|
145
|
+
if (both.length > 0) throw new ConfigError(`${label} lists ${both.join(", ")}, which \`repo.variables.${org === void 0 ? "repo" : "org"}\` also gives a value: keep one source per name`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// src/config/config/config.ts
|
|
149
|
+
const PLUGIN_PREFIX = "@theholocron/holocron-plugin-";
|
|
150
|
+
const COMMUNITY_PREFIX = "holocron-plugin-";
|
|
151
|
+
/**
|
|
152
|
+
* Resolve `"github"` → `"@theholocron/holocron-plugin-github"`.
|
|
153
|
+
* Fully-qualified names (scoped or not) are honored verbatim, which
|
|
154
|
+
* is how third-party plugins published outside the org work.
|
|
155
|
+
*/
|
|
156
|
+
function resolvePluginPackage$1(provider) {
|
|
157
|
+
if (!provider) throw new ConfigError$1("provider name is empty");
|
|
158
|
+
return resolvePluginPackage(provider, PLUGIN_PREFIX, COMMUNITY_PREFIX);
|
|
159
|
+
}
|
|
160
|
+
/** A bare `[provider, options]` tuple, with both elements present? */
|
|
161
|
+
function isOptionsTuple(value) {
|
|
162
|
+
if (!Array.isArray(value)) return false;
|
|
163
|
+
if (value.length !== 2) return false;
|
|
164
|
+
if (typeof value[0] !== "string") return false;
|
|
165
|
+
const opt = value[1];
|
|
166
|
+
return typeof opt === "object" && opt !== null && !Array.isArray(opt);
|
|
167
|
+
}
|
|
168
|
+
function normalizeEntry(entry) {
|
|
169
|
+
if (typeof entry === "string") return {
|
|
170
|
+
provider: entry,
|
|
171
|
+
packageName: resolvePluginPackage$1(entry),
|
|
172
|
+
options: {}
|
|
173
|
+
};
|
|
174
|
+
const [provider, options] = entry;
|
|
175
|
+
return {
|
|
176
|
+
provider,
|
|
177
|
+
packageName: resolvePluginPackage$1(provider),
|
|
178
|
+
options
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/** Resolves one capability's raw provider entry into single or multiple resolved tuples, checking it against the capability's cardinality. */
|
|
182
|
+
function resolveEntry(key, raw) {
|
|
183
|
+
const cardinality = CARDINALITY[key];
|
|
184
|
+
if (typeof raw === "string") {
|
|
185
|
+
if (cardinality === "many") throw new ConfigError$1(`\`${key}\` accepts multiple providers; wrap a single one in an array: ["${raw}"]`);
|
|
186
|
+
return {
|
|
187
|
+
cardinality: "single",
|
|
188
|
+
tuple: normalizeEntry(raw)
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (!Array.isArray(raw)) throw new ConfigError$1(`\`${key}\` entry must be a string or array, got ${typeof raw}`);
|
|
192
|
+
if (isOptionsTuple(raw)) {
|
|
193
|
+
if (cardinality === "many") return {
|
|
194
|
+
cardinality: "many",
|
|
195
|
+
tuples: [normalizeEntry(raw)]
|
|
196
|
+
};
|
|
197
|
+
return {
|
|
198
|
+
cardinality: "single",
|
|
199
|
+
tuple: normalizeEntry(raw)
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
if (cardinality === "single") throw new ConfigError$1(`\`${key}\` accepts exactly one provider; got a multi-provider list with ${raw.length} entries`);
|
|
203
|
+
return {
|
|
204
|
+
cardinality: "many",
|
|
205
|
+
tuples: raw.map((entry, idx) => {
|
|
206
|
+
if (typeof entry === "string") return normalizeEntry(entry);
|
|
207
|
+
if (isOptionsTuple(entry)) return normalizeEntry(entry);
|
|
208
|
+
throw new ConfigError$1(`\`${key}[${idx}]\` must be a provider string or [provider, options] tuple`);
|
|
209
|
+
})
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/** A DNS hostname of at least two labels: no scheme, port, path or space. */
|
|
213
|
+
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])?)+$/;
|
|
214
|
+
/** Throws a {@link ConfigError} naming the first thing wrong with the `githubApps` list. */
|
|
215
|
+
function validateGitHubApps(apps) {
|
|
216
|
+
if (!Array.isArray(apps)) throw new ConfigError$1("`githubApps` must be a list of { name, manifest, environment }");
|
|
217
|
+
apps.forEach((app, idx) => {
|
|
218
|
+
for (const key of ["name", "manifest"]) {
|
|
219
|
+
const value = app?.[key];
|
|
220
|
+
if (typeof value !== "string" || value.trim() === "") throw new ConfigError$1(`\`githubApps[${idx}].${key}\` must be a non-empty string`);
|
|
221
|
+
}
|
|
222
|
+
validateEnvironmentChoice(app, `\`githubApps[${idx}]\``);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/** Throws a {@link ConfigError} naming the first thing wrong with the `ideas` block. */
|
|
226
|
+
function validateIdeas(ideas) {
|
|
227
|
+
const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
|
|
228
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
229
|
+
if (!isObject(ideas)) throw new ConfigError$1("`ideas` must be an object: { states?, dir? (deprecated) }");
|
|
230
|
+
if (ideas.dir !== void 0 && !nonEmpty(ideas.dir)) throw new ConfigError$1("`ideas.dir` must be the path of the notes folder, got an empty value");
|
|
231
|
+
if (ideas.states !== void 0) {
|
|
232
|
+
if (!isObject(ideas.states)) throw new ConfigError$1("`ideas.states` must be an object: { file? }");
|
|
233
|
+
if (ideas.states.file !== void 0 && !nonEmpty(ideas.states.file)) throw new ConfigError$1("`ideas.states.file` must be a state name, got an empty value");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/** Throws a {@link ConfigError} naming the first thing wrong with the `dev` block. */
|
|
237
|
+
function validateDev(dev) {
|
|
238
|
+
const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
|
|
239
|
+
validateEnvironmentChoice(dev, "`dev`", false);
|
|
240
|
+
if (dev.tunnel !== void 0) {
|
|
241
|
+
if (!nonEmpty(dev.tunnel.name)) throw new ConfigError$1("`dev.tunnel.name` must be a name, got an empty value");
|
|
242
|
+
if (typeof dev.tunnel.hostname !== "string" || !HOSTNAME.test(dev.tunnel.hostname)) throw new ConfigError$1(`\`dev.tunnel.hostname\` must be a hostname such as sentinel-dev.example.dev (no scheme or path), got ${JSON.stringify(dev.tunnel.hostname)}`);
|
|
243
|
+
}
|
|
244
|
+
if (dev.port !== void 0 && !(Number.isInteger(dev.port) && dev.port >= 1 && dev.port <= 65535)) throw new ConfigError$1(`\`dev.port\` must be a port from 1 to 65535, got ${JSON.stringify(dev.port)}`);
|
|
245
|
+
if (dev.command !== void 0 && !(Array.isArray(dev.command) && dev.command.length > 0 && dev.command.every(nonEmpty))) throw new ConfigError$1("`dev.command` must be the program and its arguments, e.g. [\"pnpm\", \"run\", \"serve\"]");
|
|
246
|
+
if (dev.serve !== void 0) {
|
|
247
|
+
const { serve } = dev;
|
|
248
|
+
if (!nonEmpty(serve.handler)) throw new ConfigError$1("`dev.serve.handler` must be the path of the module that exports the handler");
|
|
249
|
+
if (serve.export !== void 0 && !nonEmpty(serve.export)) throw new ConfigError$1("`dev.serve.export` must be the name of the handler's export, got an empty value");
|
|
250
|
+
if (serve.required !== void 0 && !(Array.isArray(serve.required) && serve.required.every(nonEmpty))) throw new ConfigError$1("`dev.serve.required` must be a list of variable names");
|
|
251
|
+
if (serve.logging !== void 0 && !(nonEmpty(serve.logging.tokenVar) && nonEmpty(serve.logging.datasetVar))) throw new ConfigError$1("`dev.serve.logging` needs a `tokenVar` and a `datasetVar`, both variable names");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/** Throws a {@link ConfigError} when the `vault` entry's options name an Environment two ways, or a `layer` that is no layer word. */
|
|
255
|
+
function validateVaultLayer(entry) {
|
|
256
|
+
if (entry?.cardinality !== "single") return;
|
|
257
|
+
validateEnvironmentChoice(entry.tuple.options, "the `vault` provider's options", false);
|
|
258
|
+
}
|
|
259
|
+
/** The values `repoValidation.docsCoverage` accepts. */
|
|
260
|
+
const DOCS_COVERAGE_MODES = [
|
|
261
|
+
"off",
|
|
262
|
+
"warn",
|
|
263
|
+
"required"
|
|
264
|
+
];
|
|
265
|
+
/**
|
|
266
|
+
* The environment a `credentials` provider reads: its own `environment` option when it has one, else the shared
|
|
267
|
+
* `credentials.environment`, else `undefined`. The option lets each of several providers name its own (a 1Password
|
|
268
|
+
* Environment and an AWS secret are not called the same thing) without the plugin storing the name.
|
|
269
|
+
*/
|
|
270
|
+
function credentialsEnvironment(tuple, config) {
|
|
271
|
+
const own = tuple.options.environment;
|
|
272
|
+
return typeof own === "string" && own.trim() !== "" ? own : config.credentials?.environment;
|
|
273
|
+
}
|
|
274
|
+
/** Validates a raw `holocron.config` and resolves its provider entries; throws `ConfigError` when `name` or `providers` is missing or an entry is malformed. */
|
|
275
|
+
function resolveConfig(raw) {
|
|
276
|
+
if (!raw.name) throw new ConfigError$1("`name` is required");
|
|
277
|
+
if (!raw.providers || typeof raw.providers !== "object") throw new ConfigError$1("`providers` block is required");
|
|
278
|
+
const providers = {};
|
|
279
|
+
for (const [key, entry] of Object.entries(raw.providers)) {
|
|
280
|
+
if (entry === void 0) continue;
|
|
281
|
+
providers[key] = resolveEntry(key, entry);
|
|
282
|
+
}
|
|
283
|
+
for (const required of REQUIRED_CAPABILITIES) if (!providers[required]) throw new ConfigError$1(`required capability \`${required}\` is missing from providers`);
|
|
284
|
+
let docs;
|
|
285
|
+
if (raw.docs !== void 0) {
|
|
286
|
+
if (!raw.docs.build) throw new ConfigError$1("`docs.build` is required when `docs` is set");
|
|
287
|
+
docs = raw.docs;
|
|
288
|
+
}
|
|
289
|
+
const docsCoverage = raw.repoValidation?.docsCoverage;
|
|
290
|
+
if (docsCoverage !== void 0 && !DOCS_COVERAGE_MODES.includes(docsCoverage)) throw new ConfigError$1(`\`repoValidation.docsCoverage\` must be one of ${DOCS_COVERAGE_MODES.map((m) => `"${m}"`).join(", ")}, got ${JSON.stringify(docsCoverage)}`);
|
|
291
|
+
if (raw.credentials !== void 0) {
|
|
292
|
+
const environment = raw.credentials.environment;
|
|
293
|
+
if (typeof environment !== "string" || environment.trim() === "") throw new ConfigError$1("`credentials.environment` must be the name of an environment, got an empty value");
|
|
294
|
+
}
|
|
295
|
+
if (raw.dev !== void 0) validateDev(raw.dev);
|
|
296
|
+
if (raw.githubApps !== void 0) validateGitHubApps(raw.githubApps);
|
|
297
|
+
if (raw.ideas !== void 0) validateIdeas(raw.ideas);
|
|
298
|
+
validateVariablesSync(raw.repo?.variables);
|
|
299
|
+
validateSecretsDeploy(raw.repo?.secrets);
|
|
300
|
+
validateSecretsSync(raw.repo?.secrets);
|
|
301
|
+
validateVaultLayer(providers.vault);
|
|
302
|
+
const credentialsEntry = providers.credentials;
|
|
303
|
+
if (credentialsEntry?.cardinality === "many") for (const tuple of credentialsEntry.tuples) {
|
|
304
|
+
const own = tuple.options.environment;
|
|
305
|
+
if (own !== void 0 && (typeof own !== "string" || own.trim() === "")) throw new ConfigError$1(`the \`environment\` option of the \`${tuple.provider}\` credentials provider must be the name of an environment, got an empty value`);
|
|
306
|
+
if (credentialsEnvironment(tuple, raw) === void 0 && !derivesEnvironment(tuple.provider)) throw new ConfigError$1(`the \`${tuple.provider}\` credentials provider has no environment to read: give it an \`environment\` option or set \`credentials.environment\``);
|
|
307
|
+
}
|
|
308
|
+
const homepage = raw.homepage ?? (docs?.domain ? `https://${docs.domain}/` : void 0);
|
|
309
|
+
return {
|
|
310
|
+
name: raw.name,
|
|
311
|
+
description: raw.description,
|
|
312
|
+
homepage,
|
|
313
|
+
org: raw.org,
|
|
314
|
+
domain: raw.domain,
|
|
315
|
+
repo: raw.repo,
|
|
316
|
+
repoValidation: raw.repoValidation,
|
|
317
|
+
tasks: raw.tasks,
|
|
318
|
+
syncScripts: raw.syncScripts,
|
|
319
|
+
holocronScript: raw.holocronScript,
|
|
320
|
+
extraRequiredChecks: raw.extraRequiredChecks,
|
|
321
|
+
hooks: raw.hooks,
|
|
322
|
+
providers,
|
|
323
|
+
apps: raw.apps ?? [],
|
|
324
|
+
doctor: raw.doctor ?? {},
|
|
325
|
+
agent: raw.agent,
|
|
326
|
+
skills: raw.skills,
|
|
327
|
+
docs,
|
|
328
|
+
env: raw.env,
|
|
329
|
+
credentials: raw.credentials,
|
|
330
|
+
dev: raw.dev,
|
|
331
|
+
githubApps: raw.githubApps,
|
|
332
|
+
ideas: raw.ideas,
|
|
333
|
+
log: raw.log,
|
|
334
|
+
telemetry: raw.telemetry,
|
|
335
|
+
eslint: raw.eslint
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
// src/credentials-environments/repo-slug/repo-slug.ts
|
|
339
|
+
/**
|
|
340
|
+
* The `<org>/<repo>` of the repository at `cwd`, from its `origin` remote. A remote that is missing or cannot be
|
|
341
|
+
* parsed is a `ConfigError` that names the `environment` option as the fix.
|
|
342
|
+
*/
|
|
343
|
+
async function repoSlug(cwd, exec) {
|
|
344
|
+
const remote = await readGitRemote(cwd, exec ? { exec } : {});
|
|
345
|
+
if (!remote) throw new ConfigError(`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.`);
|
|
346
|
+
return remote.slug;
|
|
347
|
+
}
|
|
348
|
+
// src/config/compose/merge-sync/merge-sync.ts
|
|
349
|
+
/**
|
|
350
|
+
* Merge two lists of `repo.secrets.sync` (or `repo.variables.sync`) entries. An entry is the same sync when its
|
|
351
|
+
* environment and scope match; the keys then add up, and an entry that names no keys (every key the vault holds) stays
|
|
352
|
+
* that way.
|
|
353
|
+
*/
|
|
354
|
+
function mergeSync(a, b) {
|
|
355
|
+
const merged = /* @__PURE__ */ new Map();
|
|
356
|
+
for (const entry of [...a ?? [], ...b ?? []]) {
|
|
357
|
+
const id = JSON.stringify([
|
|
358
|
+
entry.environment,
|
|
359
|
+
entry.layer,
|
|
360
|
+
entry.scope ?? "repo"
|
|
361
|
+
]);
|
|
362
|
+
const have = merged.get(id);
|
|
363
|
+
merged.set(id, have ? {
|
|
364
|
+
...have,
|
|
365
|
+
...have.keys && entry.keys ? { keys: [.../* @__PURE__ */ new Set([...have.keys, ...entry.keys])] } : { keys: void 0 }
|
|
366
|
+
} : { ...entry });
|
|
367
|
+
}
|
|
368
|
+
return [...merged.values()].map(({ keys, ...rest }) => keys ? {
|
|
369
|
+
...rest,
|
|
370
|
+
keys
|
|
371
|
+
} : rest);
|
|
372
|
+
}
|
|
373
|
+
// src/config/compose/merge-repo/merge-repo.ts
|
|
374
|
+
const names = union();
|
|
375
|
+
const properties = shallowMerge();
|
|
376
|
+
const teamsByKey = mergeByKey((t) => typeof t === "string" ? t : t.slug);
|
|
377
|
+
/**
|
|
378
|
+
* Merge one capability's `repo` fragment onto what earlier ones gave. Scalars: last writer wins. `properties`: shallow
|
|
379
|
+
* 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
|
|
380
|
+
* environment and scope. `topics`: union. `teams`: merged by slug.
|
|
381
|
+
*/
|
|
382
|
+
function mergeRepo(prev, next) {
|
|
383
|
+
const { properties: nextProperties, topics, teams, variables, secrets, ...scalars } = next;
|
|
384
|
+
const repo = {
|
|
385
|
+
...prev,
|
|
386
|
+
...scalars
|
|
387
|
+
};
|
|
388
|
+
if (nextProperties) repo.properties = properties.merge(repo.properties ?? {}, nextProperties);
|
|
389
|
+
if (variables) repo.variables = {
|
|
390
|
+
...repo.variables,
|
|
391
|
+
...variables,
|
|
392
|
+
...repo.variables?.repo || variables.repo ? { repo: {
|
|
393
|
+
...repo.variables?.repo,
|
|
394
|
+
...variables.repo
|
|
395
|
+
} } : {},
|
|
396
|
+
...repo.variables?.org || variables.org ? { org: {
|
|
397
|
+
...repo.variables?.org,
|
|
398
|
+
...variables.org
|
|
399
|
+
} } : {},
|
|
400
|
+
...repo.variables?.sync || variables.sync ? { sync: mergeSync(repo.variables?.sync, variables.sync) } : {}
|
|
401
|
+
};
|
|
402
|
+
if (secrets) {
|
|
403
|
+
const environments = { ...repo.secrets?.environments };
|
|
404
|
+
for (const [env, list] of Object.entries(secrets.environments ?? {})) environments[env] = names.merge(environments[env] ?? [], list);
|
|
405
|
+
repo.secrets = {
|
|
406
|
+
...repo.secrets?.repo || secrets.repo ? { repo: names.merge(repo.secrets?.repo ?? [], secrets.repo ?? []) } : {},
|
|
407
|
+
...repo.secrets?.org || secrets.org ? { org: names.merge(repo.secrets?.org ?? [], secrets.org ?? []) } : {},
|
|
408
|
+
...Object.keys(environments).length > 0 ? { environments } : {},
|
|
409
|
+
...repo.secrets?.sync || secrets.sync ? { sync: mergeSync(repo.secrets?.sync, secrets.sync) } : {},
|
|
410
|
+
...repo.secrets?.deploy || secrets.deploy ? { deploy: [...repo.secrets?.deploy ?? [], ...secrets.deploy ?? []] } : {}
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
if (topics) repo.topics = names.merge(repo.topics ?? [], topics);
|
|
414
|
+
if (teams) repo.teams = teamsByKey.merge(repo.teams ?? [], teams);
|
|
415
|
+
return repo;
|
|
416
|
+
}
|
|
417
|
+
// src/config/compose/task-name/task-name.ts
|
|
418
|
+
/**
|
|
419
|
+
* The key a task entry merges under. A name that stands for exactly one flat id (the id itself, or an old dotted
|
|
420
|
+
* alias such as `verification.unitTests`) keys by that id, so the alias overrides the preset's entry instead of
|
|
421
|
+
* sitting next to it; a name that stands for several ids or none (a suite, an unknown name) keys by itself.
|
|
422
|
+
*/
|
|
423
|
+
function taskName(e) {
|
|
424
|
+
const name = typeof e === "string" ? e : e.name;
|
|
425
|
+
const resolved = resolveTaskName(name);
|
|
426
|
+
return resolved.length === 1 ? resolved[0].id : name;
|
|
427
|
+
}
|
|
428
|
+
// src/config/compose/merge-strategies/merge-strategies.ts
|
|
429
|
+
/**
|
|
430
|
+
* How `compose()` merges each key of the capabilities: tasks by name (an old dotted alias overrides the entry it names),
|
|
431
|
+
* providers shallowly, the non-task required checks as a union, `repo` by its own rules, the rest last writer wins.
|
|
432
|
+
*/
|
|
433
|
+
const mergeStrategies = {
|
|
434
|
+
tasks: mergeByKey(taskName),
|
|
435
|
+
providers: shallowMerge(),
|
|
436
|
+
extraRequiredChecks: union(),
|
|
437
|
+
repo: {
|
|
438
|
+
empty: {},
|
|
439
|
+
merge: mergeRepo
|
|
440
|
+
},
|
|
441
|
+
org: lastWins(),
|
|
442
|
+
domain: lastWins(),
|
|
443
|
+
docs: lastWins()
|
|
444
|
+
};
|
|
445
|
+
// src/config/load-config/read-package-json-name/read-package-json-name.ts
|
|
446
|
+
/** The `name` of the `package.json` in `dir` without its scope, or `undefined`. */
|
|
447
|
+
async function readPackageJsonName(dir) {
|
|
448
|
+
const name = (await readPackageJson(dir))?.name;
|
|
449
|
+
return name === void 0 ? void 0 : name.replace(/^@[^/]+\//, "");
|
|
450
|
+
}
|
|
451
|
+
// src/config/load-config/derive-defaults/derive-defaults.ts
|
|
452
|
+
/**
|
|
453
|
+
* Fill in what a `holocron.config` leaves out: `name` from the package or directory, `repo.name` from the GitHub
|
|
454
|
+
* remote, and the task manifest (merged from `astromech.config.*`).
|
|
455
|
+
*/
|
|
456
|
+
async function deriveDefaults(found) {
|
|
457
|
+
const configDir = dirname(found.filepath);
|
|
458
|
+
const result = { ...found.config };
|
|
459
|
+
if (!result.name) result.name = await readPackageJsonName(configDir) ?? basename(configDir);
|
|
460
|
+
if (result.repo && !result.repo.name) {
|
|
461
|
+
const remote = await readGitRemote(configDir);
|
|
462
|
+
if (remote?.host === "github.com") result.repo = {
|
|
463
|
+
...result.repo,
|
|
464
|
+
name: remote.slug
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
const manifest = await loadTasksConfig(configDir, { holocron: found });
|
|
468
|
+
if (manifest.tasks) result.tasks = manifest.tasks;
|
|
469
|
+
if (manifest.syncScripts !== void 0) result.syncScripts = manifest.syncScripts;
|
|
470
|
+
if (manifest.holocronScript !== void 0) result.holocronScript = manifest.holocronScript;
|
|
471
|
+
if (manifest.hooks !== void 0) result.hooks = manifest.hooks;
|
|
472
|
+
if (manifest.extraRequiredChecks) result.extraRequiredChecks = [...result.extraRequiredChecks ?? [], ...manifest.extraRequiredChecks];
|
|
473
|
+
return result;
|
|
474
|
+
}
|
|
475
|
+
// src/config/load-config/holocron-areas/holocron-areas.ts
|
|
476
|
+
/**
|
|
477
|
+
* The closed list of area files `loadConfig` reads from `.holocron/` (the directory is `.<config name>`, set by kyber):
|
|
478
|
+
* `.holocron/notifications.*` fills `providers.notifications`' `layout`, `.holocron/repo.*` fills keys of `repo`, and `.holocron/org.*` fills provider options (`teamId`, `accountId`) a config leaves out.
|
|
479
|
+
* A file not on this list is never read.
|
|
480
|
+
*/
|
|
481
|
+
const HOLOCRON_AREAS = [
|
|
482
|
+
"notifications",
|
|
483
|
+
"repo",
|
|
484
|
+
"org"
|
|
485
|
+
];
|
|
486
|
+
/**
|
|
487
|
+
* The areas a config in a subdirectory also reads from the repository root's `.holocron/` (SPEC-0069): only `org`,
|
|
488
|
+
* because its values are the organization's and every config needs them. `repo` and `notifications` describe the
|
|
489
|
+
* repository itself, so an app's config does not take them from the root.
|
|
490
|
+
*/
|
|
491
|
+
const SHARED_AREAS = ["org"];
|
|
492
|
+
// src/config/load-config/place-notifications/place-notifications.ts
|
|
493
|
+
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]);
|
|
494
|
+
const providerName = (entry) => isTuple$1(entry) ? entry[0] : entry;
|
|
495
|
+
/** Index of the entry the layout belongs to in a multi-provider list: the first `discord`. */
|
|
496
|
+
function findDiscord(entries) {
|
|
497
|
+
return entries.findIndex((entry) => providerName(entry) === "discord");
|
|
498
|
+
}
|
|
499
|
+
function withLayout(entry, layout) {
|
|
500
|
+
return isTuple$1(entry) ? [entry[0], {
|
|
501
|
+
...entry[1],
|
|
502
|
+
layout
|
|
503
|
+
}] : [entry, { layout }];
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Set `layout` on the notifications provider from `.holocron/notifications.*`. The entry may be a name (`"discord"`),
|
|
507
|
+
* a `[name, options]` tuple, or a list (the first `discord` entry gets it). Throws `ConfigError` when the provider is
|
|
508
|
+
* not set or already has an inline `layout`.
|
|
509
|
+
*/
|
|
510
|
+
function placeNotifications(raw, area) {
|
|
511
|
+
if (typeof area.value !== "object" || area.value === null || Array.isArray(area.value)) throw new ConfigError(`${area.path} must export the notifications layout as an object`);
|
|
512
|
+
const entry = raw.providers?.notifications;
|
|
513
|
+
const hint = `Set it in one place: remove the inline \`layout\` or delete ${area.path}`;
|
|
514
|
+
let placed;
|
|
515
|
+
if (entry === void 0) throw new ConfigError(`${area.path} holds the notifications layout, but providers.notifications is not set. Add \`notifications: ["discord", { guildId }]\` to providers`);
|
|
516
|
+
else if (Array.isArray(entry) && !isTuple$1(entry)) {
|
|
517
|
+
const index = findDiscord(entry);
|
|
518
|
+
if (index === -1) throw new ConfigError(`${area.path} holds the notifications layout, but providers.notifications has no discord entry`);
|
|
519
|
+
const target = entry[index];
|
|
520
|
+
if (isTuple$1(target) && target[1].layout !== void 0) throw new ConfigError(`the notifications layout is set in providers.notifications and in ${area.path}. ${hint}`);
|
|
521
|
+
placed = entry.map((item, i) => i === index ? withLayout(item, area.value) : item);
|
|
522
|
+
} else {
|
|
523
|
+
if (isTuple$1(entry) && entry[1].layout !== void 0) throw new ConfigError(`the notifications layout is set in providers.notifications and in ${area.path}. ${hint}`);
|
|
524
|
+
placed = withLayout(entry, area.value);
|
|
525
|
+
}
|
|
526
|
+
return {
|
|
527
|
+
...raw,
|
|
528
|
+
providers: {
|
|
529
|
+
...raw.providers,
|
|
530
|
+
notifications: placed
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
// src/config/load-config/place-org/place-org.ts
|
|
535
|
+
/** The options each provider key of `.holocron/org.*` may hold. Checked against `OrgConfig` by the type. */
|
|
536
|
+
const ORG_OPTIONS = {
|
|
537
|
+
cloudflare: ["accountId"],
|
|
538
|
+
vercel: ["teamId"],
|
|
539
|
+
checkly: ["accountId"],
|
|
540
|
+
sentry: ["org"]
|
|
541
|
+
};
|
|
542
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
543
|
+
const isTuple = (entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && isObject(entry[1]);
|
|
544
|
+
/**
|
|
545
|
+
* Check the shape of the area file: the top-level `domain` (a non-empty string), then a closed list of providers,
|
|
546
|
+
* each with a closed list of string options.
|
|
547
|
+
*/
|
|
548
|
+
function validate(area) {
|
|
549
|
+
if (!isObject(area.value)) throw new ConfigError(`${area.path} must export the org settings as an object`);
|
|
550
|
+
const { domain, ...rest } = area.value;
|
|
551
|
+
if (domain !== void 0 && (typeof domain !== "string" || domain === "")) throw new ConfigError(`${area.path}: "domain" must be a non-empty string`);
|
|
552
|
+
for (const [provider, options] of Object.entries(rest)) {
|
|
553
|
+
const allowed = ORG_OPTIONS[provider];
|
|
554
|
+
if (allowed === void 0) throw new ConfigError(`${area.path} has an unknown provider "${provider}". Known: ${Object.keys(ORG_OPTIONS).join(", ")}`);
|
|
555
|
+
if (!isObject(options)) throw new ConfigError(`${area.path}: "${provider}" must be an object of options`);
|
|
556
|
+
for (const [option, value] of Object.entries(options)) {
|
|
557
|
+
if (!allowed.includes(option)) throw new ConfigError(`${area.path}: "${provider}.${option}" is not an org option. Known: ${allowed.join(", ")}`);
|
|
558
|
+
if (typeof value !== "string" || value === "") throw new ConfigError(`${area.path}: "${provider}.${option}" must be a non-empty string`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
...domain !== void 0 ? { domain } : {},
|
|
563
|
+
providers: rest
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* The org options of an area and, when the repository root has the same area, the root's under them: an option set in
|
|
568
|
+
* both takes the config's own value, option by option (the root's other options stay). Each file is checked on its own.
|
|
569
|
+
*/
|
|
570
|
+
function merge(area) {
|
|
571
|
+
const providers = {};
|
|
572
|
+
let domain;
|
|
573
|
+
for (const layer of area.root ? [area.root, area] : [area]) {
|
|
574
|
+
const checked = validate(layer);
|
|
575
|
+
if (checked.domain !== void 0) domain = {
|
|
576
|
+
value: checked.domain,
|
|
577
|
+
path: layer.path
|
|
578
|
+
};
|
|
579
|
+
for (const [provider, options] of Object.entries(checked.providers)) {
|
|
580
|
+
const sourced = providers[provider] ??= {};
|
|
581
|
+
for (const [option, value] of Object.entries(options)) sourced[option] = {
|
|
582
|
+
value,
|
|
583
|
+
path: layer.path
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return {
|
|
588
|
+
...domain ? { domain } : {},
|
|
589
|
+
providers
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
/** Fill one entry when it names a provider the area holds; throws when the config already sets one of its options. */
|
|
593
|
+
function fill(entry, org, capability) {
|
|
594
|
+
const [provider, options] = isTuple(entry) ? entry : [entry, {}];
|
|
595
|
+
const values = org[provider];
|
|
596
|
+
if (values === void 0 || Object.keys(values).length === 0) return entry;
|
|
597
|
+
const filled = {};
|
|
598
|
+
for (const [option, { value, path }] of Object.entries(values)) {
|
|
599
|
+
if (options[option] !== void 0) throw new ConfigError(`${provider}.${option} is set in providers.${capability} and in ${path}. Set it in one place: remove the inline option or the key from ${path}`);
|
|
600
|
+
filled[option] = value;
|
|
601
|
+
}
|
|
602
|
+
return [provider, {
|
|
603
|
+
...options,
|
|
604
|
+
...filled
|
|
605
|
+
}];
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Fill `.holocron/org.*` into the config. Its top-level `domain` (the org's zone) is set on a config that leaves
|
|
609
|
+
* `domain` out; set inline and in the file it is a `ConfigError` naming both. Its provider options go into the
|
|
610
|
+
* providers the config uses. A provider entry (a name, a
|
|
611
|
+
* `[name, options]` tuple, or either inside a list) that names a provider the file holds gets each option it leaves
|
|
612
|
+
* out. An option set inline and in the file is a `ConfigError` naming both (no merge, no precedence); a provider the
|
|
613
|
+
* config does not use is ignored; a provider or option the file lists but `OrgConfig` does not know is an error.
|
|
614
|
+
* When the area also came from the repository root (`area.root`, a config in a subdirectory), the two files combine
|
|
615
|
+
* option by option and the config's own file wins; that is not an error.
|
|
616
|
+
*/
|
|
617
|
+
function placeOrg(raw, area) {
|
|
618
|
+
const { domain, providers: org } = merge(area);
|
|
619
|
+
if (domain !== void 0 && raw.domain !== void 0) throw new ConfigError(`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}`);
|
|
620
|
+
const withDomain = domain === void 0 ? raw : {
|
|
621
|
+
...raw,
|
|
622
|
+
domain: domain.value
|
|
623
|
+
};
|
|
624
|
+
if (withDomain.providers === void 0) return withDomain;
|
|
625
|
+
const providers = { ...withDomain.providers };
|
|
626
|
+
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);
|
|
627
|
+
return {
|
|
628
|
+
...withDomain,
|
|
629
|
+
providers
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
// src/config/load-config/place-repo/place-repo.ts
|
|
633
|
+
/**
|
|
634
|
+
* Add the keys of `.holocron/repo.*` to `repo`. The keys of the two sources must differ (`repo.defaultBranch` stays
|
|
635
|
+
* inline so Sentinel can find the branch to read): a key set both inline and in the file is a `ConfigError` naming
|
|
636
|
+
* both.
|
|
637
|
+
*/
|
|
638
|
+
function placeRepo(raw, area) {
|
|
639
|
+
if (typeof area.value !== "object" || area.value === null || Array.isArray(area.value)) throw new ConfigError(`${area.path} must export the repo settings as an object`);
|
|
640
|
+
const fromFile = area.value;
|
|
641
|
+
const inline = raw.repo ?? {};
|
|
642
|
+
for (const key of Object.keys(fromFile)) if (inline[key] !== void 0) throw new ConfigError(`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}`);
|
|
643
|
+
return {
|
|
644
|
+
...raw,
|
|
645
|
+
repo: {
|
|
646
|
+
...inline,
|
|
647
|
+
...fromFile
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
// src/config/load-config/place-areas/place-areas.ts
|
|
652
|
+
/**
|
|
653
|
+
* Put the area files of `.holocron/` into the config as loaded, before `deriveDefaults` runs: `notifications` becomes
|
|
654
|
+
* 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
|
|
655
|
+
* is a `ConfigError` naming both (no merge, no precedence). With no area files the config is returned as it was.
|
|
656
|
+
*/
|
|
657
|
+
function placeAreas(areas, raw) {
|
|
658
|
+
let result = raw;
|
|
659
|
+
for (const area of areas) if (area.area === "notifications") result = placeNotifications(result, area);
|
|
660
|
+
else if (area.area === "repo") result = placeRepo(result, area);
|
|
661
|
+
else if (area.area === "org") result = placeOrg(result, area);
|
|
662
|
+
return result;
|
|
663
|
+
}
|
|
664
|
+
// src/config/resolve-layers/resolve-layers.ts
|
|
665
|
+
/**
|
|
666
|
+
* Turns every `layer` in a loaded config into the `environment` it names (spec `tech-environment-layers`, #2069), so
|
|
667
|
+
* the commands and doctors that read Environments see one literal name and none of them derives it again. The name is
|
|
668
|
+
* `layerEnvironment()` over the `origin` remote of `input.repoRoot`, read at most once and only when an entry names a
|
|
669
|
+
* layer. A remote that cannot be read is a `ConfigError` naming the `environment` option (`repoSlug()`); nothing is
|
|
670
|
+
* guessed. Covers `repo.secrets.sync`, `repo.secrets.deploy`, `repo.variables.sync`, `githubApps`, `dev` and the
|
|
671
|
+
* `vault` provider's `layer` option. Returns a new config; the one passed in is not changed.
|
|
672
|
+
*
|
|
673
|
+
* @param config - The resolved config, validated by `resolveConfig()`.
|
|
674
|
+
* @param input - Where to read the remote, and how.
|
|
675
|
+
* @returns The config with each `layer` replaced by its `environment`.
|
|
676
|
+
*/
|
|
677
|
+
async function resolveLayers(config, input) {
|
|
678
|
+
let slug;
|
|
679
|
+
const named = async (entry) => {
|
|
680
|
+
if (entry.layer === void 0) return entry;
|
|
681
|
+
const { layer, ...rest } = entry;
|
|
682
|
+
slug ??= repoSlug(input.repoRoot, input.gitExec);
|
|
683
|
+
return {
|
|
684
|
+
...rest,
|
|
685
|
+
environment: layerEnvironment(await slug, layer)
|
|
686
|
+
};
|
|
687
|
+
};
|
|
688
|
+
const all = (list) => Promise.all(list.map(named));
|
|
689
|
+
const out = { ...config };
|
|
690
|
+
const { repo } = config;
|
|
691
|
+
if (repo) {
|
|
692
|
+
const next = { ...repo };
|
|
693
|
+
if (repo.secrets) {
|
|
694
|
+
next.secrets = { ...repo.secrets };
|
|
695
|
+
if (repo.secrets.sync) next.secrets.sync = await all(repo.secrets.sync);
|
|
696
|
+
if (repo.secrets.deploy) next.secrets.deploy = await all(repo.secrets.deploy);
|
|
697
|
+
}
|
|
698
|
+
if (repo.variables?.sync) next.variables = {
|
|
699
|
+
...repo.variables,
|
|
700
|
+
sync: await all(repo.variables.sync)
|
|
701
|
+
};
|
|
702
|
+
out.repo = next;
|
|
703
|
+
}
|
|
704
|
+
if (config.githubApps) out.githubApps = await all(config.githubApps);
|
|
705
|
+
if (config.dev) out.dev = await named(config.dev);
|
|
706
|
+
const vault = config.providers.vault;
|
|
707
|
+
if (vault?.cardinality === "single" && vault.tuple.options.layer !== void 0) {
|
|
708
|
+
const { layer, ...options } = vault.tuple.options;
|
|
709
|
+
const resolved = await named({ layer });
|
|
710
|
+
out.providers = {
|
|
711
|
+
...config.providers,
|
|
712
|
+
vault: {
|
|
713
|
+
cardinality: "single",
|
|
714
|
+
tuple: {
|
|
715
|
+
...vault.tuple,
|
|
716
|
+
options: {
|
|
717
|
+
...options,
|
|
718
|
+
environment: resolved.environment
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
return out;
|
|
725
|
+
}
|
|
726
|
+
// src/config/config-system.ts
|
|
727
|
+
/**
|
|
728
|
+
* Holocron's config system: `defineConfig`, `loadConfig` and `compose`, all built from one
|
|
729
|
+
* `createConfigSystem` call.
|
|
730
|
+
*
|
|
731
|
+
* File discovery, the walk up to `.git`, module loading (typed configs via `tsx`) and the derive-then-resolve flow come
|
|
732
|
+
* from `@theholocron/kyber/config`. The holocron-specific parts are `deriveDefaults` (name, `repo.name`, the task
|
|
733
|
+
* manifest), `placeAreas` (the `.holocron/` area files, placed before `deriveDefaults`), `resolveConfig` and `mergeStrategies`.
|
|
734
|
+
*
|
|
735
|
+
* The three functions live together because each is only a method of the one system object; splitting them back into
|
|
736
|
+
* one file apiece would just be pass-through wrappers (an exception to the one-function-per-file rule).
|
|
737
|
+
*
|
|
738
|
+
* Probe order is TS-first (`.ts` → `.js` → `.mjs` → `.cjs` → `.json`) —
|
|
739
|
+
* see ADR-0010 / issue #75 / #81.
|
|
740
|
+
*/
|
|
741
|
+
const system = createConfigSystem({
|
|
742
|
+
name: "holocron",
|
|
743
|
+
areas: HOLOCRON_AREAS,
|
|
744
|
+
shared: SHARED_AREAS,
|
|
745
|
+
place: placeAreas,
|
|
746
|
+
derive: deriveDefaults,
|
|
747
|
+
resolve: resolveConfig,
|
|
748
|
+
merge: mergeStrategies
|
|
749
|
+
});
|
|
750
|
+
/** Returns the config unchanged; it exists to type and autocomplete a `holocron.config.ts`. */
|
|
751
|
+
const defineConfig = system.defineConfig;
|
|
752
|
+
/**
|
|
753
|
+
* Read + parse + resolve `holocron.config.*` starting from the given
|
|
754
|
+
* directory, walking up through ancestors to the nearest `.git` boundary
|
|
755
|
+
* when `cwd` itself has no match — every command is usable from any
|
|
756
|
+
* subdirectory of a repo, not only its exact root (see
|
|
757
|
+
* `@theholocron/datapad`'s own doc comment for the stop conditions).
|
|
758
|
+
* Throws `ConfigFileError` when nothing is found or a file cannot
|
|
759
|
+
* be loaded, or `ConfigError` when the config fails schema checks.
|
|
760
|
+
*
|
|
761
|
+
* Every `layer` an entry names becomes the `environment` it stands for (`resolveLayers()`, spec
|
|
762
|
+
* `tech-environment-layers`, #2069), read from the `origin` remote at `cwd`; `input` lets a test pass a fake remote.
|
|
763
|
+
*/
|
|
764
|
+
async function loadConfig(cwd, input = {}) {
|
|
765
|
+
const loaded = await system.loadConfig(cwd);
|
|
766
|
+
return {
|
|
767
|
+
...loaded,
|
|
768
|
+
resolved: await resolveLayers(loaded.resolved, {
|
|
769
|
+
repoRoot: cwd,
|
|
770
|
+
...input
|
|
771
|
+
})
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Merge any number of capability fragments into a single preset object that
|
|
776
|
+
* spreads directly into `defineConfig()`.
|
|
777
|
+
*
|
|
778
|
+
* - Accepts individual capabilities or nested arrays (for bundle presets).
|
|
779
|
+
* - Deduplicates by `id` — when the same ID appears more than once, the last
|
|
780
|
+
* occurrence wins. This lets callers override bundle defaults by listing an
|
|
781
|
+
* explicit capability after the bundle.
|
|
782
|
+
* - Validates all `requires` at call time and throws `ConfigError` if any are
|
|
783
|
+
* unmet, listing every missing dependency in a single message.
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* // docs-only site — no typecheck
|
|
787
|
+
* const preset = compose(node(), docs());
|
|
788
|
+
*
|
|
789
|
+
* // library with docs
|
|
790
|
+
* const preset = compose(node(), typecheck(), docs());
|
|
791
|
+
*
|
|
792
|
+
* // nextjs() is a bundle that returns Capability[]
|
|
793
|
+
* const preset = compose(node(), nextjs());
|
|
794
|
+
*/
|
|
795
|
+
const compose = system.compose;
|
|
796
|
+
export { placeAreas as a, repoSlug as c, resolveConfig as d, resolveEntry as f, layerEnvironment as h, loadConfig as i, ConfigError$1 as l, isEnvironmentLayer as m, compose as n, HOLOCRON_AREAS as o, resolvePluginPackage$1 as p, defineConfig as r, SHARED_AREAS as s, ConfigFileError as t, credentialsEnvironment as u };
|