@theholocron/cli 5.5.0 → 5.6.0

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 CHANGED
@@ -871,10 +871,11 @@ See the [command pages](https://theholocron.dev/holocron/commands/setup-notifica
871
871
  - **`holocron sync templates [--dry-run] [--yes]`** — publishes each `templates/<type>/` folder to
872
872
  `<org>/<type>-template` (spec `tech-template-repos`, #2926): compares the folder with the repo's default branch,
873
873
  writes only the difference through the `source` provider (files made, replaced, and removed when the folder no longer
874
- has them), then tags the repo `templates-v<version>` with the version in `templates/package.json`. A rerun writes
874
+ has them), then tags the repo `templates-v<version>` with the version in `templates/package.json` and moves its major tag
875
+ (`templates-v1`) to the same commit. The `templates` release runs it after tagging (#2934). A rerun writes
875
876
  nothing; a tag already at the same content is a success and one at other content is a failing row. It never creates
876
877
  or deletes a repository (a missing one fails its row), and one failing template does not stop the others. Needs a
877
- `source` provider with the optional `listFiles`, `deleteFile` and `ensureTag` beside `readFile` and `writeFile`
878
+ `source` provider with the optional `listFiles`, `deleteFile`, `ensureTag` and `moveTag` beside `readFile` and `writeFile`
878
879
  (GitHub). See the [command page](../../docs/src/content/docs/commands/sync-templates.mdx).
879
880
 
880
881
  ## Syncing issues
package/dist/cli.mjs CHANGED
@@ -34452,6 +34452,36 @@ const secretSetCommand = {
34452
34452
  })).status === "fail") process.exitCode = 1;
34453
34453
  }
34454
34454
  };
34455
+ // src/commands/new/without-tokens/without-tokens.ts
34456
+ /** The names of variables that hold a credential for GitHub, this CLI or 1Password. */
34457
+ const CREDENTIAL_NAME = /^(HOLOCRON|GITHUB|GH|OP)_.*(TOKEN|SECRET|KEY)$/;
34458
+ /**
34459
+ * A copy of `env` without the variables that hold a credential for GitHub (`GITHUB_TOKEN`, `GH_TOKEN`), this CLI
34460
+ * (`HOLOCRON_*_TOKEN`) or 1Password (`OP_SERVICE_ACCOUNT_TOKEN`): names that start with one of those prefixes and end in
34461
+ * `TOKEN`, `SECRET` or `KEY`. Everything else (`PATH`, `HOME`, proxy and registry settings) stays, so a program started
34462
+ * with it still finds its tools.
34463
+ */
34464
+ function withoutTokens(env) {
34465
+ return Object.fromEntries(Object.entries(env).filter(([name]) => !CREDENTIAL_NAME.test(name)));
34466
+ }
34467
+ // src/commands/new/default-exec/default-exec.ts
34468
+ /**
34469
+ * Runs `cmd` with `args` in `opts.cwd`, printing to this terminal. `opts.env` is added to this process's environment;
34470
+ * with `opts.cleanEnv` the credential variables are removed from it first (`withoutTokens()`), for a step that runs code
34471
+ * the person did not write, such as the lifecycle scripts of a package install.
34472
+ */
34473
+ function defaultExec$1(cmd, args, opts) {
34474
+ const extra = opts.env ?? {};
34475
+ const needsEnv = opts.cleanEnv === true || Object.keys(extra).length > 0;
34476
+ execFileSync(cmd, args, {
34477
+ cwd: opts.cwd,
34478
+ stdio: opts.stdio,
34479
+ ...needsEnv ? { env: {
34480
+ ...opts.cleanEnv ? withoutTokens(process.env) : process.env,
34481
+ ...extra
34482
+ } } : {}
34483
+ });
34484
+ }
34455
34485
  // src/commands/new/new.ts
34456
34486
  /**
34457
34487
  * `holocron new repo <type> <name>` — create a GitHub repo from a template and
@@ -34621,16 +34651,6 @@ function preflight() {
34621
34651
  const result = spawnSync("gh", ["--version"], { encoding: "utf8" });
34622
34652
  if (result.error != null || result.status !== 0) throw new NewError("`gh` CLI is not installed or not on PATH. Install it from https://cli.github.com");
34623
34653
  }
34624
- function defaultExec$1(cmd, args, opts) {
34625
- execFileSync(cmd, args, {
34626
- cwd: opts.cwd,
34627
- stdio: opts.stdio,
34628
- ...opts.env && Object.keys(opts.env).length > 0 ? { env: {
34629
- ...process.env,
34630
- ...opts.env
34631
- } } : {}
34632
- });
34633
- }
34634
34654
  function keychainLookup(key) {
34635
34655
  const result = spawnSync("security", [
34636
34656
  "find-generic-password",
@@ -34725,6 +34745,16 @@ async function runNew(input) {
34725
34745
  } catch {}
34726
34746
  let templateSlug = `${input.type}-template`;
34727
34747
  const pkgJsonPath = path.join(repoDir, "package.json");
34748
+ const canRead = (file) => {
34749
+ try {
34750
+ readFn(file);
34751
+ return true;
34752
+ } catch {
34753
+ return false;
34754
+ }
34755
+ };
34756
+ const hasPackageJson = canRead(pkgJsonPath);
34757
+ const hasJsonConfig = canRead(path.join(repoDir, "holocron.config.json"));
34728
34758
  if (existsSync(pkgJsonPath)) try {
34729
34759
  const pkg = JSON.parse(readFn(pkgJsonPath));
34730
34760
  if (typeof pkg.name === "string") templateSlug = pkg.name.split("/").at(-1) || templateSlug;
@@ -34754,26 +34784,29 @@ async function runNew(input) {
34754
34784
  print(` ✓ tsconfig.json (display)`);
34755
34785
  }
34756
34786
  } catch {}
34757
- const configContent = generateHolocronConfig({
34758
- name: input.name,
34759
- type: input.type,
34760
- org,
34761
- description: input.description,
34762
- homepage: input.homepage,
34763
- vaultProvider: input.vaultProvider,
34764
- vaultProject: input.vaultProject,
34765
- vaultConfig: input.vaultConfig,
34766
- deploymentProvider: input.deploymentProvider,
34767
- agent: input.agent,
34768
- runtimeEnvironment: input.runtimeEnvironment,
34769
- protection: input.protection,
34770
- openSource: input.openSource,
34771
- usesExternalPackages: input.usesExternalPackages,
34772
- topics: input.topics,
34773
- skills: input.skills
34774
- });
34775
- writeFn(path.join(repoDir, "holocron.config.ts"), configContent);
34776
- print(` Generated holocron.config.ts`);
34787
+ if (hasJsonConfig) print(` Kept holocron.config.json`);
34788
+ else {
34789
+ const configContent = generateHolocronConfig({
34790
+ name: input.name,
34791
+ type: input.type,
34792
+ org,
34793
+ description: input.description,
34794
+ homepage: input.homepage,
34795
+ vaultProvider: input.vaultProvider,
34796
+ vaultProject: input.vaultProject,
34797
+ vaultConfig: input.vaultConfig,
34798
+ deploymentProvider: input.deploymentProvider,
34799
+ agent: input.agent,
34800
+ runtimeEnvironment: input.runtimeEnvironment,
34801
+ protection: input.protection,
34802
+ openSource: input.openSource,
34803
+ usesExternalPackages: input.usesExternalPackages,
34804
+ topics: input.topics,
34805
+ skills: input.skills
34806
+ });
34807
+ writeFn(path.join(repoDir, "holocron.config.ts"), configContent);
34808
+ print(` Generated holocron.config.ts`);
34809
+ }
34777
34810
  execFn("git", ["add", "-A"], {
34778
34811
  cwd: repoDir,
34779
34812
  stdio: "inherit"
@@ -34790,10 +34823,12 @@ async function runNew(input) {
34790
34823
  if (!input.noVerify) {
34791
34824
  print("");
34792
34825
  print(" Installing dependencies…");
34793
- try {
34826
+ if (!hasPackageJson) print(" No package.json: skipping pnpm install");
34827
+ else try {
34794
34828
  execFn("pnpm", ["install"], {
34795
34829
  cwd: repoDir,
34796
- stdio: "inherit"
34830
+ stdio: "inherit",
34831
+ cleanEnv: true
34797
34832
  });
34798
34833
  } catch (err) {
34799
34834
  print(` ✗ pnpm install failed — ${errorMessage(err)}`);
@@ -44394,8 +44429,9 @@ function templatesVersion(templatesDir) {
44394
44429
  *
44395
44430
  * Each folder is compared with its repo's default branch; only the difference is written through the `source`
44396
44431
  * capability (files made, replaced, and removed when the repo has them and the folder no longer does), then the repo is
44397
- * tagged with the `templates` group's version from `templates/package.json`. A rerun writes nothing and a tag already at
44398
- * the same content is left alone. It never creates or deletes a repository: a missing template repo is a failing row.
44432
+ * tagged with the `templates` group's version from `templates/package.json`, and the major tag (`templates-v1`) is moved
44433
+ * to the same commit, so a caller that follows it gets the newest minor. A rerun writes nothing, a version tag already
44434
+ * at the same content is left alone and a major tag already there stays. It never creates or deletes a repository: a missing template repo is a failing row.
44399
44435
  * One template failing does not stop the others. It writes, so it asks first; `--yes` skips the question and, without a
44400
44436
  * terminal, a run with neither `--yes` nor `--dry-run` refuses.
44401
44437
  */
@@ -44430,13 +44466,14 @@ async function runSyncTemplates(input) {
44430
44466
  const org = input.context.org;
44431
44467
  if (!org) return stop("fail", "no organization to publish to: set `org` in the config or pass --org");
44432
44468
  const tag = `templates-v${version}`;
44469
+ const majorTag = `templates-v${version.split(".")[0]}`;
44433
44470
  /* v8 ignore next -- the real loader is only built outside tests, which always inject one */
44434
44471
  const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
44435
44472
  await loader.load();
44436
44473
  assertPluginsResolvable(loader, "sync templates");
44437
44474
  const source = loader.has("source") ? loader.get("source") : void 0;
44438
- if (!source?.readFile || !source.writeFile || !source.listFiles || !source.deleteFile || !source.ensureTag) return stop("fail", whyMissing(loader, "source", "no `source` provider that can read, write, list and delete files and tag is available"));
44439
- const { readFile, writeFile, listFiles, deleteFile, ensureTag } = source;
44475
+ if (!source?.readFile || !source.writeFile || !source.listFiles || !source.deleteFile || !source.ensureTag || !source.moveTag) return stop("fail", whyMissing(loader, "source", "no `source` provider that can read, write, list and delete files and tag is available"));
44476
+ const { readFile, writeFile, listFiles, deleteFile, ensureTag, moveTag } = source;
44440
44477
  const results = [];
44441
44478
  const planned = [];
44442
44479
  for (const name of names) {
@@ -44469,7 +44506,7 @@ async function runSyncTemplates(input) {
44469
44506
  }
44470
44507
  if (dryRun) {
44471
44508
  for (const p of planned) {
44472
- row("skip", p.name, p.repo, `dry run, nothing written: ${counts(p.plan)}; would tag ${tag}`);
44509
+ row("skip", p.name, p.repo, `dry run, nothing written: ${counts(p.plan)}; would tag ${tag} and move ${majorTag}`);
44473
44510
  results.push({
44474
44511
  name: p.name,
44475
44512
  repo: p.repo,
@@ -44491,7 +44528,7 @@ async function runSyncTemplates(input) {
44491
44528
  if (!await (input.confirm ?? ((q) => confirm({
44492
44529
  message: q,
44493
44530
  default: false
44494
- })))(`Publish ${planned.length} template(s) as ${tag}?`)) {
44531
+ })))(`Publish ${planned.length} template(s) as ${tag} (and ${majorTag})?`)) {
44495
44532
  for (const p of planned) {
44496
44533
  row("skip", p.name, p.repo, "cancelled; nothing was changed");
44497
44534
  results.push({
@@ -44545,7 +44582,8 @@ async function runSyncTemplates(input) {
44545
44582
  result.removed++;
44546
44583
  }
44547
44584
  result.tagged = await ensureTag.call(source, tag, repo);
44548
- row("ok", name, repo, `${result.created} created, ${result.updated} replaced, ${result.removed} removed; ${result.tagged ? `tagged ${tag}` : `${tag} already there`}`);
44585
+ result.majorMoved = await moveTag.call(source, majorTag, repo);
44586
+ row("ok", name, repo, `${result.created} created, ${result.updated} replaced, ${result.removed} removed; ${result.tagged ? `tagged ${tag}` : `${tag} already there`}; ${result.majorMoved ? `${majorTag} moved here` : `${majorTag} already here`}`);
44549
44587
  } catch (err) {
44550
44588
  result.status = "fail";
44551
44589
  result.reason = errorMessage(err);