@theholocron/cli 5.0.0-alpha.35 → 5.0.0-alpha.350
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 +487 -104
- package/dist/cli.mjs +20858 -7893
- package/dist/cli.mjs.map +1 -1
- package/dist/config-system-5rdWyUAw.mjs +421 -0
- package/dist/config-system-C6MsRNbo.d.mts +848 -0
- package/dist/index-CArtx6o0.d.mts +2635 -0
- package/dist/index.d.mts +241 -606
- package/dist/index.mjs +264 -368
- package/dist/plugin/capabilities.d.mts +2 -807
- package/dist/plugin/capabilities.mjs +53 -4
- package/dist/presets.d.mts +223 -0
- package/dist/presets.mjs +423 -0
- package/package.json +41 -34
|
@@ -0,0 +1,421 @@
|
|
|
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 { basename, dirname } from "node:path";
|
|
5
|
+
import { readPackageJson } from "@theholocron/pkg-utils";
|
|
6
|
+
import { resolveTaskName } from "@theholocron/astromech";
|
|
7
|
+
import { loadTasksConfig } from "@theholocron/astromech/config";
|
|
8
|
+
import { readGitRemote } from "@theholocron/git-utils";
|
|
9
|
+
// src/config/config/config.ts
|
|
10
|
+
const PLUGIN_PREFIX = "@theholocron/holocron-plugin-";
|
|
11
|
+
const COMMUNITY_PREFIX = "holocron-plugin-";
|
|
12
|
+
/**
|
|
13
|
+
* Resolve `"github"` → `"@theholocron/holocron-plugin-github"`.
|
|
14
|
+
* Fully-qualified names (scoped or not) are honored verbatim, which
|
|
15
|
+
* is how third-party plugins published outside the org work.
|
|
16
|
+
*/
|
|
17
|
+
function resolvePluginPackage$1(provider) {
|
|
18
|
+
if (!provider) throw new ConfigError$1("provider name is empty");
|
|
19
|
+
return resolvePluginPackage(provider, PLUGIN_PREFIX, COMMUNITY_PREFIX);
|
|
20
|
+
}
|
|
21
|
+
/** A bare `[provider, options]` tuple, with both elements present? */
|
|
22
|
+
function isOptionsTuple(value) {
|
|
23
|
+
if (!Array.isArray(value)) return false;
|
|
24
|
+
if (value.length !== 2) return false;
|
|
25
|
+
if (typeof value[0] !== "string") return false;
|
|
26
|
+
const opt = value[1];
|
|
27
|
+
return typeof opt === "object" && opt !== null && !Array.isArray(opt);
|
|
28
|
+
}
|
|
29
|
+
function normalizeEntry(entry) {
|
|
30
|
+
if (typeof entry === "string") return {
|
|
31
|
+
provider: entry,
|
|
32
|
+
packageName: resolvePluginPackage$1(entry),
|
|
33
|
+
options: {}
|
|
34
|
+
};
|
|
35
|
+
const [provider, options] = entry;
|
|
36
|
+
return {
|
|
37
|
+
provider,
|
|
38
|
+
packageName: resolvePluginPackage$1(provider),
|
|
39
|
+
options
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Resolves one capability's raw provider entry into single or multiple resolved tuples, checking it against the capability's cardinality. */
|
|
43
|
+
function resolveEntry(key, raw) {
|
|
44
|
+
const cardinality = CARDINALITY[key];
|
|
45
|
+
if (typeof raw === "string") {
|
|
46
|
+
if (cardinality === "many") throw new ConfigError$1(`\`${key}\` accepts multiple providers; wrap a single one in an array: ["${raw}"]`);
|
|
47
|
+
return {
|
|
48
|
+
cardinality: "single",
|
|
49
|
+
tuple: normalizeEntry(raw)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (!Array.isArray(raw)) throw new ConfigError$1(`\`${key}\` entry must be a string or array, got ${typeof raw}`);
|
|
53
|
+
if (isOptionsTuple(raw)) {
|
|
54
|
+
if (cardinality === "many") return {
|
|
55
|
+
cardinality: "many",
|
|
56
|
+
tuples: [normalizeEntry(raw)]
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
cardinality: "single",
|
|
60
|
+
tuple: normalizeEntry(raw)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (cardinality === "single") throw new ConfigError$1(`\`${key}\` accepts exactly one provider; got a multi-provider list with ${raw.length} entries`);
|
|
64
|
+
return {
|
|
65
|
+
cardinality: "many",
|
|
66
|
+
tuples: raw.map((entry, idx) => {
|
|
67
|
+
if (typeof entry === "string") return normalizeEntry(entry);
|
|
68
|
+
if (isOptionsTuple(entry)) return normalizeEntry(entry);
|
|
69
|
+
throw new ConfigError$1(`\`${key}[${idx}]\` must be a provider string or [provider, options] tuple`);
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** A DNS hostname of at least two labels: no scheme, port, path or space. */
|
|
74
|
+
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])?)+$/;
|
|
75
|
+
/** Throws a {@link ConfigError} naming the first thing wrong with the `dev` block. */
|
|
76
|
+
function validateDev(dev) {
|
|
77
|
+
const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
|
|
78
|
+
if (dev.environment !== void 0 && !nonEmpty(dev.environment)) throw new ConfigError$1("`dev.environment` must be the name of a vault environment, got an empty value");
|
|
79
|
+
if (dev.tunnel !== void 0) {
|
|
80
|
+
if (!nonEmpty(dev.tunnel.name)) throw new ConfigError$1("`dev.tunnel.name` must be a name, got an empty value");
|
|
81
|
+
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)}`);
|
|
82
|
+
}
|
|
83
|
+
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)}`);
|
|
84
|
+
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\"]");
|
|
85
|
+
if (dev.serve !== void 0) {
|
|
86
|
+
const { serve } = dev;
|
|
87
|
+
if (!nonEmpty(serve.handler)) throw new ConfigError$1("`dev.serve.handler` must be the path of the module that exports the handler");
|
|
88
|
+
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");
|
|
89
|
+
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");
|
|
90
|
+
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");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** The values `repoValidation.docsCoverage` accepts. */
|
|
94
|
+
const DOCS_COVERAGE_MODES = [
|
|
95
|
+
"off",
|
|
96
|
+
"warn",
|
|
97
|
+
"required"
|
|
98
|
+
];
|
|
99
|
+
/**
|
|
100
|
+
* The environment a `credentials` provider reads: its own `environment` option when it has one, else the shared
|
|
101
|
+
* `credentials.environment`, else `undefined`. The option lets each of several providers name its own (a 1Password
|
|
102
|
+
* Environment and an AWS secret are not called the same thing) without the plugin storing the name.
|
|
103
|
+
*/
|
|
104
|
+
function credentialsEnvironment(tuple, config) {
|
|
105
|
+
const own = tuple.options.environment;
|
|
106
|
+
return typeof own === "string" && own.trim() !== "" ? own : config.credentials?.environment;
|
|
107
|
+
}
|
|
108
|
+
/** Validates a raw `holocron.config` and resolves its provider entries; throws `ConfigError` when `name` or `providers` is missing or an entry is malformed. */
|
|
109
|
+
function resolveConfig(raw) {
|
|
110
|
+
if (!raw.name) throw new ConfigError$1("`name` is required");
|
|
111
|
+
if (!raw.providers || typeof raw.providers !== "object") throw new ConfigError$1("`providers` block is required");
|
|
112
|
+
const providers = {};
|
|
113
|
+
for (const [key, entry] of Object.entries(raw.providers)) {
|
|
114
|
+
if (entry === void 0) continue;
|
|
115
|
+
providers[key] = resolveEntry(key, entry);
|
|
116
|
+
}
|
|
117
|
+
for (const required of REQUIRED_CAPABILITIES) if (!providers[required]) throw new ConfigError$1(`required capability \`${required}\` is missing from providers`);
|
|
118
|
+
let docs;
|
|
119
|
+
if (raw.docs !== void 0) {
|
|
120
|
+
if (!raw.docs.build) throw new ConfigError$1("`docs.build` is required when `docs` is set");
|
|
121
|
+
docs = raw.docs;
|
|
122
|
+
}
|
|
123
|
+
const docsCoverage = raw.repoValidation?.docsCoverage;
|
|
124
|
+
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)}`);
|
|
125
|
+
if (raw.credentials !== void 0) {
|
|
126
|
+
const environment = raw.credentials.environment;
|
|
127
|
+
if (typeof environment !== "string" || environment.trim() === "") throw new ConfigError$1("`credentials.environment` must be the name of an environment, got an empty value");
|
|
128
|
+
}
|
|
129
|
+
if (raw.dev !== void 0) validateDev(raw.dev);
|
|
130
|
+
const credentialsEntry = providers.credentials;
|
|
131
|
+
if (credentialsEntry?.cardinality === "many") for (const tuple of credentialsEntry.tuples) {
|
|
132
|
+
const own = tuple.options.environment;
|
|
133
|
+
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`);
|
|
134
|
+
if (credentialsEnvironment(tuple, raw) === void 0) throw new ConfigError$1(`the \`${tuple.provider}\` credentials provider has no environment to read: give it an \`environment\` option or set \`credentials.environment\``);
|
|
135
|
+
}
|
|
136
|
+
const homepage = raw.homepage ?? (docs?.domain ? `https://${docs.domain}/` : void 0);
|
|
137
|
+
return {
|
|
138
|
+
name: raw.name,
|
|
139
|
+
description: raw.description,
|
|
140
|
+
homepage,
|
|
141
|
+
org: raw.org,
|
|
142
|
+
domain: raw.domain,
|
|
143
|
+
repo: raw.repo,
|
|
144
|
+
repoValidation: raw.repoValidation,
|
|
145
|
+
tasks: raw.tasks,
|
|
146
|
+
syncScripts: raw.syncScripts,
|
|
147
|
+
holocronScript: raw.holocronScript,
|
|
148
|
+
extraRequiredChecks: raw.extraRequiredChecks,
|
|
149
|
+
hooks: raw.hooks,
|
|
150
|
+
providers,
|
|
151
|
+
apps: raw.apps ?? [],
|
|
152
|
+
doctor: raw.doctor ?? {},
|
|
153
|
+
agent: raw.agent,
|
|
154
|
+
skills: raw.skills,
|
|
155
|
+
docs,
|
|
156
|
+
env: raw.env,
|
|
157
|
+
credentials: raw.credentials,
|
|
158
|
+
dev: raw.dev,
|
|
159
|
+
log: raw.log,
|
|
160
|
+
telemetry: raw.telemetry,
|
|
161
|
+
eslint: raw.eslint
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
// src/config/compose/merge-sync/merge-sync.ts
|
|
165
|
+
/**
|
|
166
|
+
* Merge two lists of `repo.secrets.sync` entries. An entry is the same sync when its environment and scope match;
|
|
167
|
+
* the keys then add up, and an entry that names no keys (every key the vault holds) stays that way.
|
|
168
|
+
*/
|
|
169
|
+
function mergeSync(a, b) {
|
|
170
|
+
const merged = /* @__PURE__ */ new Map();
|
|
171
|
+
for (const entry of [...a ?? [], ...b ?? []]) {
|
|
172
|
+
const id = `${entry.environment}\0${entry.scope ?? "repo"}`;
|
|
173
|
+
const have = merged.get(id);
|
|
174
|
+
merged.set(id, have ? {
|
|
175
|
+
...have,
|
|
176
|
+
...have.keys && entry.keys ? { keys: [.../* @__PURE__ */ new Set([...have.keys, ...entry.keys])] } : { keys: void 0 }
|
|
177
|
+
} : { ...entry });
|
|
178
|
+
}
|
|
179
|
+
return [...merged.values()].map(({ keys, ...rest }) => keys ? {
|
|
180
|
+
...rest,
|
|
181
|
+
keys
|
|
182
|
+
} : rest);
|
|
183
|
+
}
|
|
184
|
+
// src/config/compose/merge-repo/merge-repo.ts
|
|
185
|
+
const names = union();
|
|
186
|
+
const properties = shallowMerge();
|
|
187
|
+
const teamsByKey = mergeByKey((t) => typeof t === "string" ? t : t.slug);
|
|
188
|
+
/**
|
|
189
|
+
* Merge one capability's `repo` fragment onto what earlier ones gave. Scalars: last writer wins. `properties`: shallow
|
|
190
|
+
* merge. `variables`: merged per scope (`repo`, `org`). `secrets`: each name list is a union, and `sync` entries merge by
|
|
191
|
+
* environment and scope. `topics`: union. `teams`: merged by slug.
|
|
192
|
+
*/
|
|
193
|
+
function mergeRepo(prev, next) {
|
|
194
|
+
const { properties: nextProperties, topics, teams, variables, secrets, ...scalars } = next;
|
|
195
|
+
const repo = {
|
|
196
|
+
...prev,
|
|
197
|
+
...scalars
|
|
198
|
+
};
|
|
199
|
+
if (nextProperties) repo.properties = properties.merge(repo.properties ?? {}, nextProperties);
|
|
200
|
+
if (variables) repo.variables = {
|
|
201
|
+
...repo.variables,
|
|
202
|
+
...variables,
|
|
203
|
+
...repo.variables?.repo || variables.repo ? { repo: {
|
|
204
|
+
...repo.variables?.repo,
|
|
205
|
+
...variables.repo
|
|
206
|
+
} } : {},
|
|
207
|
+
...repo.variables?.org || variables.org ? { org: {
|
|
208
|
+
...repo.variables?.org,
|
|
209
|
+
...variables.org
|
|
210
|
+
} } : {}
|
|
211
|
+
};
|
|
212
|
+
if (secrets) {
|
|
213
|
+
const environments = { ...repo.secrets?.environments };
|
|
214
|
+
for (const [env, list] of Object.entries(secrets.environments ?? {})) environments[env] = names.merge(environments[env] ?? [], list);
|
|
215
|
+
repo.secrets = {
|
|
216
|
+
...repo.secrets?.repo || secrets.repo ? { repo: names.merge(repo.secrets?.repo ?? [], secrets.repo ?? []) } : {},
|
|
217
|
+
...repo.secrets?.org || secrets.org ? { org: names.merge(repo.secrets?.org ?? [], secrets.org ?? []) } : {},
|
|
218
|
+
...Object.keys(environments).length > 0 ? { environments } : {},
|
|
219
|
+
...repo.secrets?.sync || secrets.sync ? { sync: mergeSync(repo.secrets?.sync, secrets.sync) } : {}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
if (topics) repo.topics = names.merge(repo.topics ?? [], topics);
|
|
223
|
+
if (teams) repo.teams = teamsByKey.merge(repo.teams ?? [], teams);
|
|
224
|
+
return repo;
|
|
225
|
+
}
|
|
226
|
+
// src/config/compose/task-name/task-name.ts
|
|
227
|
+
/**
|
|
228
|
+
* The key a task entry merges under. A name that stands for exactly one flat id (the id itself, or an old dotted
|
|
229
|
+
* alias such as `verification.unitTests`) keys by that id, so the alias overrides the preset's entry instead of
|
|
230
|
+
* sitting next to it; a name that stands for several ids or none (a suite, an unknown name) keys by itself.
|
|
231
|
+
*/
|
|
232
|
+
function taskName(e) {
|
|
233
|
+
const name = typeof e === "string" ? e : e.name;
|
|
234
|
+
const resolved = resolveTaskName(name);
|
|
235
|
+
return resolved.length === 1 ? resolved[0].id : name;
|
|
236
|
+
}
|
|
237
|
+
// src/config/compose/merge-strategies/merge-strategies.ts
|
|
238
|
+
/**
|
|
239
|
+
* How `compose()` merges each key of the capabilities: tasks by name (an old dotted alias overrides the entry it names),
|
|
240
|
+
* providers shallowly, the non-task required checks as a union, `repo` by its own rules, the rest last writer wins.
|
|
241
|
+
*/
|
|
242
|
+
const mergeStrategies = {
|
|
243
|
+
tasks: mergeByKey(taskName),
|
|
244
|
+
providers: shallowMerge(),
|
|
245
|
+
extraRequiredChecks: union(),
|
|
246
|
+
repo: {
|
|
247
|
+
empty: {},
|
|
248
|
+
merge: mergeRepo
|
|
249
|
+
},
|
|
250
|
+
org: lastWins(),
|
|
251
|
+
domain: lastWins(),
|
|
252
|
+
docs: lastWins()
|
|
253
|
+
};
|
|
254
|
+
// src/config/load-config/read-package-json-name/read-package-json-name.ts
|
|
255
|
+
/** The `name` of the `package.json` in `dir` without its scope, or `undefined`. */
|
|
256
|
+
async function readPackageJsonName(dir) {
|
|
257
|
+
const name = (await readPackageJson(dir))?.name;
|
|
258
|
+
return name === void 0 ? void 0 : name.replace(/^@[^/]+\//, "");
|
|
259
|
+
}
|
|
260
|
+
// src/config/load-config/derive-defaults/derive-defaults.ts
|
|
261
|
+
/**
|
|
262
|
+
* Fill in what a `holocron.config` leaves out: `name` from the package or directory, `repo.name` from the GitHub
|
|
263
|
+
* remote, and the task manifest (merged from `astromech.config.*`).
|
|
264
|
+
*/
|
|
265
|
+
async function deriveDefaults(found) {
|
|
266
|
+
const configDir = dirname(found.filepath);
|
|
267
|
+
const result = { ...found.config };
|
|
268
|
+
if (!result.name) result.name = await readPackageJsonName(configDir) ?? basename(configDir);
|
|
269
|
+
if (result.repo && !result.repo.name) {
|
|
270
|
+
const remote = await readGitRemote(configDir);
|
|
271
|
+
if (remote?.host === "github.com") result.repo = {
|
|
272
|
+
...result.repo,
|
|
273
|
+
name: remote.slug
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const manifest = await loadTasksConfig(configDir, { holocron: found });
|
|
277
|
+
if (manifest.tasks) result.tasks = manifest.tasks;
|
|
278
|
+
if (manifest.syncScripts !== void 0) result.syncScripts = manifest.syncScripts;
|
|
279
|
+
if (manifest.holocronScript !== void 0) result.holocronScript = manifest.holocronScript;
|
|
280
|
+
if (manifest.hooks !== void 0) result.hooks = manifest.hooks;
|
|
281
|
+
if (manifest.extraRequiredChecks) result.extraRequiredChecks = [...result.extraRequiredChecks ?? [], ...manifest.extraRequiredChecks];
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
// src/config/load-config/holocron-areas/holocron-areas.ts
|
|
285
|
+
/**
|
|
286
|
+
* The closed list of area files `loadConfig` reads from `.holocron/` (the directory is `.<config name>`, set by kyber):
|
|
287
|
+
* `.holocron/notifications.*` fills `providers.notifications`' `layout`, and `.holocron/repo.*` fills keys of `repo`.
|
|
288
|
+
* A file not on this list is never read.
|
|
289
|
+
*/
|
|
290
|
+
const HOLOCRON_AREAS = ["notifications", "repo"];
|
|
291
|
+
// src/config/load-config/place-notifications/place-notifications.ts
|
|
292
|
+
const isTuple = (entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && typeof entry[1] === "object" && entry[1] !== null && !Array.isArray(entry[1]);
|
|
293
|
+
const providerName = (entry) => isTuple(entry) ? entry[0] : entry;
|
|
294
|
+
/** Index of the entry the layout belongs to in a multi-provider list: the first `discord`. */
|
|
295
|
+
function findDiscord(entries) {
|
|
296
|
+
return entries.findIndex((entry) => providerName(entry) === "discord");
|
|
297
|
+
}
|
|
298
|
+
function withLayout(entry, layout) {
|
|
299
|
+
return isTuple(entry) ? [entry[0], {
|
|
300
|
+
...entry[1],
|
|
301
|
+
layout
|
|
302
|
+
}] : [entry, { layout }];
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Set `layout` on the notifications provider from `.holocron/notifications.*`. The entry may be a name (`"discord"`),
|
|
306
|
+
* a `[name, options]` tuple, or a list (the first `discord` entry gets it). Throws `ConfigError` when the provider is
|
|
307
|
+
* not set or already has an inline `layout`.
|
|
308
|
+
*/
|
|
309
|
+
function placeNotifications(raw, area) {
|
|
310
|
+
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`);
|
|
311
|
+
const entry = raw.providers?.notifications;
|
|
312
|
+
const hint = `Set it in one place: remove the inline \`layout\` or delete ${area.path}`;
|
|
313
|
+
let placed;
|
|
314
|
+
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`);
|
|
315
|
+
else if (Array.isArray(entry) && !isTuple(entry)) {
|
|
316
|
+
const index = findDiscord(entry);
|
|
317
|
+
if (index === -1) throw new ConfigError(`${area.path} holds the notifications layout, but providers.notifications has no discord entry`);
|
|
318
|
+
const target = entry[index];
|
|
319
|
+
if (isTuple(target) && target[1].layout !== void 0) throw new ConfigError(`the notifications layout is set in providers.notifications and in ${area.path}. ${hint}`);
|
|
320
|
+
placed = entry.map((item, i) => i === index ? withLayout(item, area.value) : item);
|
|
321
|
+
} else {
|
|
322
|
+
if (isTuple(entry) && entry[1].layout !== void 0) throw new ConfigError(`the notifications layout is set in providers.notifications and in ${area.path}. ${hint}`);
|
|
323
|
+
placed = withLayout(entry, area.value);
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
...raw,
|
|
327
|
+
providers: {
|
|
328
|
+
...raw.providers,
|
|
329
|
+
notifications: placed
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
// src/config/load-config/place-repo/place-repo.ts
|
|
334
|
+
/**
|
|
335
|
+
* Add the keys of `.holocron/repo.*` to `repo`. The keys of the two sources must differ (`repo.defaultBranch` stays
|
|
336
|
+
* inline so Sentinel can find the branch to read): a key set both inline and in the file is a `ConfigError` naming
|
|
337
|
+
* both.
|
|
338
|
+
*/
|
|
339
|
+
function placeRepo(raw, area) {
|
|
340
|
+
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`);
|
|
341
|
+
const fromFile = area.value;
|
|
342
|
+
const inline = raw.repo ?? {};
|
|
343
|
+
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}`);
|
|
344
|
+
return {
|
|
345
|
+
...raw,
|
|
346
|
+
repo: {
|
|
347
|
+
...inline,
|
|
348
|
+
...fromFile
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
// src/config/load-config/place-areas/place-areas.ts
|
|
353
|
+
/**
|
|
354
|
+
* Put the area files of `.holocron/` into the config as loaded, before `deriveDefaults` runs: `notifications` becomes
|
|
355
|
+
* the `layout` of the notifications provider and `repo` supplies keys of `repo`. A value set both inline and in a file
|
|
356
|
+
* is a `ConfigError` naming both (no merge, no precedence). With no area files the config is returned as it was.
|
|
357
|
+
*/
|
|
358
|
+
function placeAreas(areas, raw) {
|
|
359
|
+
let result = raw;
|
|
360
|
+
for (const area of areas) if (area.area === "notifications") result = placeNotifications(result, area);
|
|
361
|
+
else if (area.area === "repo") result = placeRepo(result, area);
|
|
362
|
+
return result;
|
|
363
|
+
}
|
|
364
|
+
// src/config/config-system.ts
|
|
365
|
+
/**
|
|
366
|
+
* Holocron's config system: `defineConfig`, `loadConfig` and `compose`, all built from one
|
|
367
|
+
* `createConfigSystem` call.
|
|
368
|
+
*
|
|
369
|
+
* File discovery, the walk up to `.git`, module loading (typed configs via `tsx`) and the derive-then-resolve flow come
|
|
370
|
+
* from `@theholocron/kyber/config`. The holocron-specific parts are `deriveDefaults` (name, `repo.name`, the task
|
|
371
|
+
* manifest), `placeAreas` (the `.holocron/` area files, placed before `deriveDefaults`), `resolveConfig` and `mergeStrategies`.
|
|
372
|
+
*
|
|
373
|
+
* The three functions live together because each is only a method of the one system object; splitting them back into
|
|
374
|
+
* one file apiece would just be pass-through wrappers (an exception to the one-function-per-file rule).
|
|
375
|
+
*
|
|
376
|
+
* Probe order is TS-first (`.ts` → `.js` → `.mjs` → `.cjs` → `.json`) —
|
|
377
|
+
* see ADR-0010 / issue #75 / #81.
|
|
378
|
+
*/
|
|
379
|
+
const system = createConfigSystem({
|
|
380
|
+
name: "holocron",
|
|
381
|
+
areas: HOLOCRON_AREAS,
|
|
382
|
+
place: placeAreas,
|
|
383
|
+
derive: deriveDefaults,
|
|
384
|
+
resolve: resolveConfig,
|
|
385
|
+
merge: mergeStrategies
|
|
386
|
+
});
|
|
387
|
+
/** Returns the config unchanged; it exists to type and autocomplete a `holocron.config.ts`. */
|
|
388
|
+
const defineConfig = system.defineConfig;
|
|
389
|
+
/**
|
|
390
|
+
* Read + parse + resolve `holocron.config.*` starting from the given
|
|
391
|
+
* directory, walking up through ancestors to the nearest `.git` boundary
|
|
392
|
+
* when `cwd` itself has no match — every command is usable from any
|
|
393
|
+
* subdirectory of a repo, not only its exact root (see
|
|
394
|
+
* `@theholocron/datapad`'s own doc comment for the stop conditions).
|
|
395
|
+
* Throws `ConfigFileError` when nothing is found or a file cannot
|
|
396
|
+
* be loaded, or `ConfigError` when the config fails schema checks.
|
|
397
|
+
*/
|
|
398
|
+
const loadConfig = system.loadConfig;
|
|
399
|
+
/**
|
|
400
|
+
* Merge any number of capability fragments into a single preset object that
|
|
401
|
+
* spreads directly into `defineConfig()`.
|
|
402
|
+
*
|
|
403
|
+
* - Accepts individual capabilities or nested arrays (for bundle presets).
|
|
404
|
+
* - Deduplicates by `id` — when the same ID appears more than once, the last
|
|
405
|
+
* occurrence wins. This lets callers override bundle defaults by listing an
|
|
406
|
+
* explicit capability after the bundle.
|
|
407
|
+
* - Validates all `requires` at call time and throws `ConfigError` if any are
|
|
408
|
+
* unmet, listing every missing dependency in a single message.
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* // docs-only site — no typecheck
|
|
412
|
+
* const preset = compose(node(), docs());
|
|
413
|
+
*
|
|
414
|
+
* // library with docs
|
|
415
|
+
* const preset = compose(node(), typecheck(), docs());
|
|
416
|
+
*
|
|
417
|
+
* // nextjs() is a bundle that returns Capability[]
|
|
418
|
+
* const preset = compose(node(), nextjs());
|
|
419
|
+
*/
|
|
420
|
+
const compose = system.compose;
|
|
421
|
+
export { placeAreas as a, credentialsEnvironment as c, resolvePluginPackage$1 as d, loadConfig as i, resolveConfig as l, compose as n, HOLOCRON_AREAS as o, defineConfig as r, ConfigError$1 as s, ConfigFileError as t, resolveEntry as u };
|