@theholocron/cli 5.0.0-alpha.28 → 5.0.0-alpha.280

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.
@@ -0,0 +1,252 @@
1
+ import { CARDINALITY, REQUIRED_CAPABILITIES } from "./plugin/capabilities.mjs";
2
+ // src/config/config/config.ts
3
+ /** Thrown when a `holocron.config` is invalid. */
4
+ var ConfigError = class extends Error {
5
+ /** The error's name, `"ConfigError"`. */
6
+ name = "ConfigError";
7
+ };
8
+ const PLUGIN_PREFIX = "@theholocron/holocron-plugin-";
9
+ const COMMUNITY_PREFIX = "holocron-plugin-";
10
+ /**
11
+ * Resolve `"github"` → `"@theholocron/holocron-plugin-github"`.
12
+ * Fully-qualified names (scoped or not) are honored verbatim, which
13
+ * is how third-party plugins published outside the org work.
14
+ */
15
+ function resolvePluginPackage(provider) {
16
+ if (!provider) throw new ConfigError("provider name is empty");
17
+ if (provider.startsWith("@")) return provider;
18
+ if (provider.startsWith(COMMUNITY_PREFIX)) return provider;
19
+ if (provider.includes("/")) return provider;
20
+ return PLUGIN_PREFIX + provider;
21
+ }
22
+ /** A bare `[provider, options]` tuple, with both elements present? */
23
+ function isOptionsTuple(value) {
24
+ if (!Array.isArray(value)) return false;
25
+ if (value.length !== 2) return false;
26
+ if (typeof value[0] !== "string") return false;
27
+ const opt = value[1];
28
+ return typeof opt === "object" && opt !== null && !Array.isArray(opt);
29
+ }
30
+ function normalizeEntry(entry) {
31
+ if (typeof entry === "string") return {
32
+ provider: entry,
33
+ packageName: resolvePluginPackage(entry),
34
+ options: {}
35
+ };
36
+ const [provider, options] = entry;
37
+ return {
38
+ provider,
39
+ packageName: resolvePluginPackage(provider),
40
+ options
41
+ };
42
+ }
43
+ /** Resolves one capability's raw provider entry into single or multiple resolved tuples, checking it against the capability's cardinality. */
44
+ function resolveEntry(key, raw) {
45
+ const cardinality = CARDINALITY[key];
46
+ if (typeof raw === "string") {
47
+ if (cardinality === "many") throw new ConfigError(`\`${key}\` accepts multiple providers; wrap a single one in an array: ["${raw}"]`);
48
+ return {
49
+ cardinality: "single",
50
+ tuple: normalizeEntry(raw)
51
+ };
52
+ }
53
+ if (!Array.isArray(raw)) throw new ConfigError(`\`${key}\` entry must be a string or array, got ${typeof raw}`);
54
+ if (isOptionsTuple(raw)) {
55
+ if (cardinality === "many") return {
56
+ cardinality: "many",
57
+ tuples: [normalizeEntry(raw)]
58
+ };
59
+ return {
60
+ cardinality: "single",
61
+ tuple: normalizeEntry(raw)
62
+ };
63
+ }
64
+ if (cardinality === "single") throw new ConfigError(`\`${key}\` accepts exactly one provider; got a multi-provider list with ${raw.length} entries`);
65
+ return {
66
+ cardinality: "many",
67
+ tuples: raw.map((entry, idx) => {
68
+ if (typeof entry === "string") return normalizeEntry(entry);
69
+ if (isOptionsTuple(entry)) return normalizeEntry(entry);
70
+ throw new ConfigError(`\`${key}[${idx}]\` must be a provider string or [provider, options] tuple`);
71
+ })
72
+ };
73
+ }
74
+ /** The values `repoValidation.docsCoverage` accepts. */
75
+ const DOCS_COVERAGE_MODES = [
76
+ "off",
77
+ "warn",
78
+ "required"
79
+ ];
80
+ /** Validates a raw `holocron.config` and resolves its provider entries; throws `ConfigError` when `name` or `providers` is missing or an entry is malformed. */
81
+ function resolveConfig(raw) {
82
+ if (!raw.name) throw new ConfigError("`name` is required");
83
+ if (!raw.providers || typeof raw.providers !== "object") throw new ConfigError("`providers` block is required");
84
+ const providers = {};
85
+ for (const [key, entry] of Object.entries(raw.providers)) {
86
+ if (entry === void 0) continue;
87
+ providers[key] = resolveEntry(key, entry);
88
+ }
89
+ for (const required of REQUIRED_CAPABILITIES) if (!providers[required]) throw new ConfigError(`required capability \`${required}\` is missing from providers`);
90
+ let docs;
91
+ if (raw.docs !== void 0) {
92
+ if (!raw.docs.build) throw new ConfigError("`docs.build` is required when `docs` is set");
93
+ docs = raw.docs;
94
+ }
95
+ const docsCoverage = raw.repoValidation?.docsCoverage;
96
+ 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)}`);
97
+ const homepage = raw.homepage ?? (docs?.domain ? `https://${docs.domain}/` : void 0);
98
+ return {
99
+ name: raw.name,
100
+ description: raw.description,
101
+ homepage,
102
+ org: raw.org,
103
+ domain: raw.domain,
104
+ repo: raw.repo,
105
+ repoValidation: raw.repoValidation,
106
+ tasks: raw.tasks,
107
+ syncScripts: raw.syncScripts,
108
+ holocronScript: raw.holocronScript,
109
+ extraRequiredChecks: raw.extraRequiredChecks,
110
+ hooks: raw.hooks,
111
+ providers,
112
+ apps: raw.apps ?? [],
113
+ doctor: raw.doctor ?? {},
114
+ agent: raw.agent,
115
+ skills: raw.skills,
116
+ docs,
117
+ env: raw.env,
118
+ log: raw.log,
119
+ telemetry: raw.telemetry,
120
+ eslint: raw.eslint
121
+ };
122
+ }
123
+ // src/config/compose/compose.ts
124
+ function taskName(e) {
125
+ return typeof e === "string" ? e : e.name;
126
+ }
127
+ /**
128
+ * Merge two lists of `repo.secrets.sync` entries. An entry is the same sync when its environment and scope match;
129
+ * the keys then add up, and an entry that names no keys (every key the vault holds) stays that way.
130
+ */
131
+ function mergeSync(a, b) {
132
+ const merged = /* @__PURE__ */ new Map();
133
+ for (const entry of [...a ?? [], ...b ?? []]) {
134
+ const id = `${entry.environment}\0${entry.scope ?? "repo"}`;
135
+ const have = merged.get(id);
136
+ merged.set(id, have ? {
137
+ ...have,
138
+ ...have.keys && entry.keys ? { keys: [.../* @__PURE__ */ new Set([...have.keys, ...entry.keys])] } : { keys: void 0 }
139
+ } : { ...entry });
140
+ }
141
+ return [...merged.values()].map(({ keys, ...rest }) => keys ? {
142
+ ...rest,
143
+ keys
144
+ } : rest);
145
+ }
146
+ /**
147
+ * Merge any number of capability fragments into a single preset object that
148
+ * spreads directly into `defineConfig()`.
149
+ *
150
+ * - Accepts individual capabilities or nested arrays (for bundle presets).
151
+ * - Deduplicates by `id` — when the same ID appears more than once, the last
152
+ * occurrence wins. This lets callers override bundle defaults by listing an
153
+ * explicit capability after the bundle.
154
+ * - Validates all `requires` at call time and throws `ConfigError` if any are
155
+ * unmet, listing every missing dependency in a single message.
156
+ *
157
+ * @example
158
+ * // docs-only site — no typecheck
159
+ * const preset = compose(node(), docs());
160
+ *
161
+ * // library with docs
162
+ * const preset = compose(node(), typecheck(), docs());
163
+ *
164
+ * // nextjs() is a bundle that returns Capability[]
165
+ * const preset = compose(node(), nextjs());
166
+ */
167
+ function compose(...args) {
168
+ const flat = args.flat();
169
+ const byId = /* @__PURE__ */ new Map();
170
+ for (const cap of flat) byId.set(cap.id, cap);
171
+ const caps = [...byId.values()];
172
+ const available = new Set(caps.map((c) => c.id));
173
+ const errors = [];
174
+ for (const cap of caps) for (const req of cap.requires ?? []) if (!available.has(req)) errors.push(`"${cap.id}" requires "${req}"`);
175
+ if (errors.length > 0) throw new ConfigError(`compose(): unmet dependencies — ${errors.join(", ")}`);
176
+ const taskMap = /* @__PURE__ */ new Map();
177
+ for (const cap of caps) for (const entry of cap.tasks ?? []) taskMap.set(taskName(entry), entry);
178
+ let providers = {};
179
+ for (const cap of caps) if (cap.providers) providers = {
180
+ ...providers,
181
+ ...cap.providers
182
+ };
183
+ const checksSeen = /* @__PURE__ */ new Set();
184
+ const extraRequiredChecks = [];
185
+ for (const cap of caps) for (const check of cap.extraRequiredChecks ?? []) if (!checksSeen.has(check)) {
186
+ checksSeen.add(check);
187
+ extraRequiredChecks.push(check);
188
+ }
189
+ let repo = {};
190
+ for (const cap of caps) {
191
+ if (!cap.repo) continue;
192
+ const { properties, topics, teams, variables, secrets, ...scalars } = cap.repo;
193
+ repo = {
194
+ ...repo,
195
+ ...scalars
196
+ };
197
+ if (properties) repo.properties = {
198
+ ...repo.properties,
199
+ ...properties
200
+ };
201
+ if (variables) repo.variables = {
202
+ ...repo.variables,
203
+ ...variables,
204
+ ...repo.variables?.repo || variables.repo ? { repo: {
205
+ ...repo.variables?.repo,
206
+ ...variables.repo
207
+ } } : {},
208
+ ...repo.variables?.org || variables.org ? { org: {
209
+ ...repo.variables?.org,
210
+ ...variables.org
211
+ } } : {}
212
+ };
213
+ if (secrets) {
214
+ const union = (a, b) => [.../* @__PURE__ */ new Set([...a ?? [], ...b ?? []])];
215
+ const environments = { ...repo.secrets?.environments };
216
+ for (const [env, names] of Object.entries(secrets.environments ?? {})) environments[env] = union(environments[env], names);
217
+ repo.secrets = {
218
+ ...repo.secrets?.repo || secrets.repo ? { repo: union(repo.secrets?.repo, secrets.repo) } : {},
219
+ ...repo.secrets?.org || secrets.org ? { org: union(repo.secrets?.org, secrets.org) } : {},
220
+ ...Object.keys(environments).length > 0 ? { environments } : {},
221
+ ...repo.secrets?.sync || secrets.sync ? { sync: mergeSync(repo.secrets?.sync, secrets.sync) } : {}
222
+ };
223
+ }
224
+ if (topics) {
225
+ const merged = /* @__PURE__ */ new Set([...repo.topics ?? [], ...topics]);
226
+ repo.topics = [...merged];
227
+ }
228
+ if (teams) {
229
+ const teamMap = new Map((repo.teams ?? []).map((t) => [typeof t === "string" ? t : t.slug, t]));
230
+ for (const t of teams) teamMap.set(typeof t === "string" ? t : t.slug, t);
231
+ repo.teams = [...teamMap.values()];
232
+ }
233
+ }
234
+ let org;
235
+ let domain;
236
+ let docs;
237
+ for (const cap of caps) {
238
+ if (cap.org !== void 0) org = cap.org;
239
+ if (cap.domain !== void 0) domain = cap.domain;
240
+ if (cap.docs !== void 0) docs = cap.docs;
241
+ }
242
+ return {
243
+ tasks: [...taskMap.values()],
244
+ providers,
245
+ repo,
246
+ extraRequiredChecks,
247
+ ...org !== void 0 ? { org } : {},
248
+ ...domain !== void 0 ? { domain } : {},
249
+ ...docs !== void 0 ? { docs } : {}
250
+ };
251
+ }
252
+ export { resolvePluginPackage as a, resolveEntry as i, ConfigError as n, resolveConfig as r, compose as t };