@theholocron/cli 5.0.0-alpha.23 → 5.0.0-alpha.231
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 +319 -55
- package/dist/cli.mjs +8274 -2833
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +277 -127
- package/dist/index.mjs +55 -58
- package/dist/plugin/capabilities.d.mts +885 -48
- package/dist/plugin/capabilities.mjs +15 -2
- package/package.json +19 -13
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { CARDINALITY, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, isMulti } from "./plugin/capabilities.mjs";
|
|
1
|
+
import { CARDINALITY, ElevationRequiredError, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, isMulti } from "./plugin/capabilities.mjs";
|
|
2
2
|
import { AuthError, createResolveToken as createResolveToken$1, createRestClient } from "@theholocron/http-client";
|
|
3
|
-
import { createEnvLookup } from "@theholocron/env-utils";
|
|
3
|
+
import { createEnvLookup, withEnvPrefix } from "@theholocron/env-utils";
|
|
4
4
|
import { Entry, findCredentials } from "@napi-rs/keyring";
|
|
5
|
-
import { readFile } from "node:fs/promises";
|
|
6
5
|
import { basename, dirname, join } from "node:path";
|
|
7
|
-
import {
|
|
8
|
-
import { promisify } from "node:util";
|
|
6
|
+
import { readPackageJson } from "@theholocron/pkg-utils";
|
|
9
7
|
import { loadTasksConfig } from "@theholocron/astromech/config";
|
|
10
8
|
import { ConfigFileError, ConfigFileError as ConfigFileError$1, loadConfigFile } from "@theholocron/datapad";
|
|
11
|
-
|
|
9
|
+
import { readGitRemote } from "@theholocron/git-utils";
|
|
10
|
+
//#region src/env/env.ts
|
|
11
|
+
/** Singleton env for simple global lookups throughout the CLI. */
|
|
12
|
+
const env = createEnvLookup();
|
|
13
|
+
withEnvPrefix(env, "HOLOCRON");
|
|
12
14
|
/**
|
|
13
15
|
* Create an injectable env for commands that accept a fake env in tests.
|
|
14
16
|
* Pass `input.env` when available, falls back to `process.env`.
|
|
@@ -17,7 +19,7 @@ function makeEnv(source) {
|
|
|
17
19
|
return createEnvLookup(source);
|
|
18
20
|
}
|
|
19
21
|
//#endregion
|
|
20
|
-
//#region src/auth/keyring.ts
|
|
22
|
+
//#region src/auth/keyring/keyring.ts
|
|
21
23
|
/**
|
|
22
24
|
* Keyring-backed bootstrap credential store.
|
|
23
25
|
*
|
|
@@ -87,7 +89,7 @@ function listStoredProviders() {
|
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
//#endregion
|
|
90
|
-
//#region src/auth/auth-resolver.ts
|
|
92
|
+
//#region src/auth/auth-resolver/auth-resolver.ts
|
|
91
93
|
/** Wraps `createResolveToken` from `@theholocron/http` and injects the
|
|
92
94
|
* system keyring so plugins stay at a one-liner call site. */
|
|
93
95
|
function createResolveToken(config) {
|
|
@@ -108,12 +110,12 @@ function createFeatureResolver(config) {
|
|
|
108
110
|
const env = makeEnv(input.env);
|
|
109
111
|
const keyring = input.keyring ?? getToken;
|
|
110
112
|
const token = input.cliToken || env.get(config.envName) || keyring(config.keyringKey);
|
|
111
|
-
if (!token) throw new AuthError(`no GitHub token found for this operation. Pass --token <
|
|
113
|
+
if (!token) throw new AuthError(`no ${config.vendor ?? "GitHub"} token found for this operation. Pass --token <token>, set ${config.envName}, or run: holocron auth set ${config.keyringKey} <token>`);
|
|
112
114
|
return token;
|
|
113
115
|
};
|
|
114
116
|
}
|
|
115
117
|
//#endregion
|
|
116
|
-
//#region src/commands/setup/derived-properties.ts
|
|
118
|
+
//#region src/commands/setup/derived-properties/derived-properties.ts
|
|
117
119
|
/**
|
|
118
120
|
* Repo archetype, in priority order:
|
|
119
121
|
* 1. `*-template` repo name → `template` (independent of package shape).
|
|
@@ -184,7 +186,7 @@ function deriveCapabilities(providers) {
|
|
|
184
186
|
return Object.keys(providers ?? {}).sort();
|
|
185
187
|
}
|
|
186
188
|
/**
|
|
187
|
-
* `source` + `ci` are the minimal baseline every repo `holocron setup`
|
|
189
|
+
* `source` + `ci` are the minimal baseline every repo `holocron repo setup`
|
|
188
190
|
* touches wires — every `holocron.config.ts` in this org already satisfies
|
|
189
191
|
* this, so `non-compliant` here means drift (a provider manually removed
|
|
190
192
|
* after setup), not an unmet aspirational policy. Deliberately not a richer
|
|
@@ -213,14 +215,14 @@ function missingCapabilities(capabilities) {
|
|
|
213
215
|
*/
|
|
214
216
|
async function readWorkspacePackageJsons(repoRoot, workspacePackages) {
|
|
215
217
|
const results = [];
|
|
216
|
-
for (const { slug, dir = "packages" } of workspacePackages)
|
|
217
|
-
const
|
|
218
|
-
results.push(
|
|
219
|
-
}
|
|
218
|
+
for (const { slug, dir = "packages" } of workspacePackages) {
|
|
219
|
+
const pkg = await readPackageJson(join(repoRoot, dir, slug));
|
|
220
|
+
if (pkg) results.push(pkg);
|
|
221
|
+
}
|
|
220
222
|
return results;
|
|
221
223
|
}
|
|
222
224
|
//#endregion
|
|
223
|
-
//#region src/config/config.ts
|
|
225
|
+
//#region src/config/config/config.ts
|
|
224
226
|
var ConfigError = class extends Error {
|
|
225
227
|
name = "ConfigError";
|
|
226
228
|
};
|
|
@@ -324,11 +326,12 @@ function resolveConfig(raw) {
|
|
|
324
326
|
docs,
|
|
325
327
|
env: raw.env,
|
|
326
328
|
log: raw.log,
|
|
327
|
-
telemetry: raw.telemetry
|
|
329
|
+
telemetry: raw.telemetry,
|
|
330
|
+
eslint: raw.eslint
|
|
328
331
|
};
|
|
329
332
|
}
|
|
330
333
|
//#endregion
|
|
331
|
-
//#region src/config/compose.ts
|
|
334
|
+
//#region src/config/compose/compose.ts
|
|
332
335
|
function taskName(e) {
|
|
333
336
|
return typeof e === "string" ? e : e.name;
|
|
334
337
|
}
|
|
@@ -378,7 +381,7 @@ function compose(...args) {
|
|
|
378
381
|
let repo = {};
|
|
379
382
|
for (const cap of caps) {
|
|
380
383
|
if (!cap.repo) continue;
|
|
381
|
-
const { properties, topics, teams, ...scalars } = cap.repo;
|
|
384
|
+
const { properties, topics, teams, variables, ...scalars } = cap.repo;
|
|
382
385
|
repo = {
|
|
383
386
|
...repo,
|
|
384
387
|
...scalars
|
|
@@ -387,6 +390,18 @@ function compose(...args) {
|
|
|
387
390
|
...repo.properties,
|
|
388
391
|
...properties
|
|
389
392
|
};
|
|
393
|
+
if (variables) repo.variables = {
|
|
394
|
+
...repo.variables,
|
|
395
|
+
...variables,
|
|
396
|
+
...repo.variables?.repo || variables.repo ? { repo: {
|
|
397
|
+
...repo.variables?.repo,
|
|
398
|
+
...variables.repo
|
|
399
|
+
} } : {},
|
|
400
|
+
...repo.variables?.org || variables.org ? { org: {
|
|
401
|
+
...repo.variables?.org,
|
|
402
|
+
...variables.org
|
|
403
|
+
} } : {}
|
|
404
|
+
};
|
|
390
405
|
if (topics) {
|
|
391
406
|
const merged = /* @__PURE__ */ new Set([...repo.topics ?? [], ...topics]);
|
|
392
407
|
repo.topics = [...merged];
|
|
@@ -416,12 +431,12 @@ function compose(...args) {
|
|
|
416
431
|
};
|
|
417
432
|
}
|
|
418
433
|
//#endregion
|
|
419
|
-
//#region src/config/define-config.ts
|
|
434
|
+
//#region src/config/define-config/define-config.ts
|
|
420
435
|
function defineConfig(config) {
|
|
421
436
|
return config;
|
|
422
437
|
}
|
|
423
438
|
//#endregion
|
|
424
|
-
//#region src/config/load-config.ts
|
|
439
|
+
//#region src/config/load-config/load-config.ts
|
|
425
440
|
/**
|
|
426
441
|
* `holocron.config.{ts,js,mjs,cjs,json}` loader.
|
|
427
442
|
*
|
|
@@ -433,34 +448,39 @@ function defineConfig(config) {
|
|
|
433
448
|
* Probe order is TS-first (`.ts` → `.js` → `.mjs` → `.cjs` → `.json`) —
|
|
434
449
|
* see ADR-0010 / issue #75 / #81.
|
|
435
450
|
*/
|
|
436
|
-
const execFileAsync = promisify(execFile);
|
|
437
451
|
/**
|
|
438
|
-
* Read + parse + resolve `holocron.config.*` from the given
|
|
452
|
+
* Read + parse + resolve `holocron.config.*` starting from the given
|
|
453
|
+
* directory, walking up through ancestors to the nearest `.git` boundary
|
|
454
|
+
* when `cwd` itself has no match — every command is usable from any
|
|
455
|
+
* subdirectory of a repo, not only its exact root (see
|
|
456
|
+
* `@theholocron/datapad`'s own doc comment for the stop conditions).
|
|
439
457
|
* Throws {@link ConfigFileError} when nothing is found or a file cannot
|
|
440
|
-
* be loaded, or `ConfigError` when the config
|
|
458
|
+
* be loaded, or `ConfigError` when the config fails schema checks.
|
|
441
459
|
*/
|
|
442
460
|
async function loadConfig(cwd) {
|
|
443
461
|
const found = await loadConfigFile({
|
|
444
462
|
cwd,
|
|
445
|
-
name: "holocron"
|
|
463
|
+
name: "holocron",
|
|
464
|
+
walkUp: true
|
|
446
465
|
});
|
|
447
466
|
if (!found) throw new ConfigFileError$1(`no holocron.config.{ts,js,mjs,cjs,json} found in ${cwd}. Create one — see the README for the schema.`);
|
|
448
467
|
return {
|
|
449
|
-
resolved: resolveConfig(await deriveDefaults(
|
|
468
|
+
resolved: resolveConfig(await deriveDefaults(found)),
|
|
450
469
|
filepath: found.filepath
|
|
451
470
|
};
|
|
452
471
|
}
|
|
453
|
-
async function deriveDefaults(
|
|
454
|
-
const
|
|
472
|
+
async function deriveDefaults(found) {
|
|
473
|
+
const configDir = dirname(found.filepath);
|
|
474
|
+
const result = { ...found.config };
|
|
455
475
|
if (!result.name) result.name = await readPackageJsonName(configDir) ?? basename(configDir);
|
|
456
476
|
if (result.repo && !result.repo.name) {
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
477
|
+
const remote = await readGitRemote(configDir);
|
|
478
|
+
if (remote?.host === "github.com") result.repo = {
|
|
459
479
|
...result.repo,
|
|
460
|
-
name:
|
|
480
|
+
name: remote.slug
|
|
461
481
|
};
|
|
462
482
|
}
|
|
463
|
-
const manifest = await loadTasksConfig(configDir);
|
|
483
|
+
const manifest = await loadTasksConfig(configDir, { holocron: found });
|
|
464
484
|
if (manifest.tasks) result.tasks = manifest.tasks;
|
|
465
485
|
if (manifest.syncScripts !== void 0) result.syncScripts = manifest.syncScripts;
|
|
466
486
|
if (manifest.holocronScript !== void 0) result.holocronScript = manifest.holocronScript;
|
|
@@ -469,31 +489,8 @@ async function deriveDefaults(configDir, raw) {
|
|
|
469
489
|
return result;
|
|
470
490
|
}
|
|
471
491
|
async function readPackageJsonName(dir) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
const pkg = JSON.parse(content);
|
|
475
|
-
return typeof pkg.name === "string" ? pkg.name.replace(/^@[^/]+\//, "") : void 0;
|
|
476
|
-
} catch {
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
async function readGitRemote(dir) {
|
|
481
|
-
try {
|
|
482
|
-
const { stdout } = await execFileAsync("git", [
|
|
483
|
-
"remote",
|
|
484
|
-
"get-url",
|
|
485
|
-
"origin"
|
|
486
|
-
], { cwd: dir });
|
|
487
|
-
return parseGitRemoteUrl(stdout.trim());
|
|
488
|
-
} catch {
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
function parseGitRemoteUrl(url) {
|
|
493
|
-
const httpsMatch = url.match(/github\.com\/([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
494
|
-
if (httpsMatch) return httpsMatch[1];
|
|
495
|
-
const sshMatch = url.match(/github\.com:([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
496
|
-
if (sshMatch) return sshMatch[1];
|
|
492
|
+
const name = (await readPackageJson(dir))?.name;
|
|
493
|
+
return name === void 0 ? void 0 : name.replace(/^@[^/]+\//, "");
|
|
497
494
|
}
|
|
498
495
|
//#endregion
|
|
499
|
-
export { AuthError, CARDINALITY, ConfigError, ConfigFileError, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, compose, createFeatureResolver, createResolveToken, createRestClient, defineConfig, deleteToken, deriveCapabilities, deriveCompliance, deriveProfile, deriveStack, getToken, isMulti, listStoredProviders, loadConfig, missingCapabilities, readWorkspacePackageJsons, resolveConfig, resolveEntry, resolvePluginPackage, setToken };
|
|
496
|
+
export { AuthError, CARDINALITY, ConfigError, ConfigFileError, ElevationRequiredError, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, compose, createFeatureResolver, createResolveToken, createRestClient, defineConfig, deleteToken, deriveCapabilities, deriveCompliance, deriveProfile, deriveStack, getToken, isMulti, listStoredProviders, loadConfig, missingCapabilities, readWorkspacePackageJsons, resolveConfig, resolveEntry, resolvePluginPackage, setToken };
|