@theholocron/cli 5.5.1 → 5.7.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
@@ -1224,7 +1224,7 @@ const moveTagEntry = {
1224
1224
  // src/commands/new/new-repo.entry.ts
1225
1225
  const newRepoEntry = {
1226
1226
  name: "new repo",
1227
- description: "Scaffold a new repo from a GitHub template (e.g. cli, react, nextjs, node, monorepo, base)",
1227
+ description: "Scaffold a new repo from a GitHub template (e.g. cli, react, nextjs, node, monorepo, monorepo-react, base)",
1228
1228
  positionals: [],
1229
1229
  skipOptions: [
1230
1230
  "description",
@@ -25560,7 +25560,7 @@ function isGenerated(text) {
25560
25560
  }
25561
25561
  // src/commands/probe/tasks/is-scanned.ts
25562
25562
  /** Files that describe the old names on purpose: specs, ADRs, the changelog, tests, and this probe's own folder. */
25563
- const SKIPPED = [
25563
+ const SKIPPED$1 = [
25564
25564
  /(^|\/)CHANGELOG\.md$/,
25565
25565
  /^\.notes\//,
25566
25566
  /^docs\/wiki\//,
@@ -25579,7 +25579,7 @@ const SCANNED = [
25579
25579
  ];
25580
25580
  /** Whether `path` (repo-relative) is a hand-written kind of place to scan for old task names. */
25581
25581
  function isScanned(path) {
25582
- return SCANNED.some((p) => p.test(path)) && !SKIPPED.some((p) => p.test(path));
25582
+ return SCANNED.some((p) => p.test(path)) && !SKIPPED$1.some((p) => p.test(path));
25583
25583
  }
25584
25584
  // src/commands/probe/tasks/legacy-replacements.ts
25585
25585
  /**
@@ -34909,7 +34909,7 @@ async function runNew(input) {
34909
34909
  // src/commands/new/new-repo.args.ts
34910
34910
  const newRepoArgs = (y) => y.positional("type", {
34911
34911
  type: "string",
34912
- describe: "Template type — maps to theholocron/<type>-template (e.g. cli, react, nextjs, node, monorepo, base)"
34912
+ describe: "Template type — maps to theholocron/<type>-template (e.g. cli, react, nextjs, node, monorepo, monorepo-react, base)"
34913
34913
  }).positional("name", {
34914
34914
  type: "string",
34915
34915
  describe: "New repo name (kebab-case, e.g. my-tool)"
@@ -34996,6 +34996,14 @@ async function askNewRepoAnswers(argv, prompts = {
34996
34996
  name: "monorepo — Turbo monorepo",
34997
34997
  value: "monorepo"
34998
34998
  },
34999
+ {
35000
+ name: "monorepo-react — Turbo monorepo of React libraries",
35001
+ value: "monorepo-react"
35002
+ },
35003
+ {
35004
+ name: "monorepo-nextjs — Turbo monorepo with a Next.js app",
35005
+ value: "monorepo-nextjs"
35006
+ },
34999
35007
  {
35000
35008
  name: "react — React component library",
35001
35009
  value: "react"
@@ -35156,7 +35164,7 @@ async function askNewRepoAnswers(argv, prompts = {
35156
35164
  // src/commands/new/new-repo.command.ts
35157
35165
  const newRepoCommand = {
35158
35166
  command: "repo [type] [name]",
35159
- describe: "Scaffold a new repo from a GitHub template (e.g. cli, react, nextjs, node, monorepo, base)",
35167
+ describe: "Scaffold a new repo from a GitHub template (e.g. cli, react, nextjs, node, monorepo, monorepo-react, base)",
35160
35168
  builder: newRepoArgs,
35161
35169
  handler: async (argv) => {
35162
35170
  try {
@@ -44352,46 +44360,79 @@ const syncRequestsCommand = {
44352
44360
  })).status === "fail") process.exitCode = 1;
44353
44361
  }
44354
44362
  };
44363
+ // src/commands/sync-templates/blob-sha/blob-sha.ts
44364
+ /** The git blob sha of some bytes: `sha1("blob <size>\0" + bytes)`, what `git hash-object` prints, so a file is compared with a tree entry without reading it. */
44365
+ function blobSha(bytes) {
44366
+ return createHash("sha1").update(`blob ${bytes.byteLength}\0`).update(bytes).digest("hex");
44367
+ }
44355
44368
  // src/commands/sync-templates/plan-template-sync/plan-template-sync.ts
44356
- /** Compares a template folder with its repo and lists only what differs: files to create, to replace and to remove. */
44357
- async function planTemplateSync(input) {
44358
- const remote = new Set(input.remotePaths);
44359
- const paths = Object.keys(input.files).sort();
44369
+ /**
44370
+ * Compares a template folder with its repo's tree by path, mode and git blob sha (computed here, so no file is read
44371
+ * from the repo) and lists only what differs: files to create, to replace (other content or other mode) and to remove.
44372
+ */
44373
+ function planTemplateSync(input) {
44374
+ const remote = new Map(input.remote.map((e) => [e.path, e]));
44360
44375
  const plan = {
44376
+ changes: [],
44361
44377
  create: [],
44362
44378
  update: [],
44363
- remove: []
44379
+ remove: [],
44380
+ modes: []
44364
44381
  };
44365
- for (const path of paths) {
44366
- if (!remote.has(path)) {
44367
- plan.create.push(path);
44368
- continue;
44369
- }
44370
- const file = await input.read(path);
44371
- if (!file) plan.create.push(path);
44372
- else if (file.content !== input.files[path]) plan.update.push({
44373
- path,
44374
- version: file.version
44382
+ for (const file of input.files) {
44383
+ const have = remote.get(file.path);
44384
+ if (have && have.mode === file.mode && have.sha === blobSha(file.content)) continue;
44385
+ plan.changes.push({
44386
+ path: file.path,
44387
+ mode: file.mode,
44388
+ content: file.content
44389
+ });
44390
+ (have ? plan.update : plan.create).push(file.path);
44391
+ if (have?.mode !== file.mode && (have || file.mode !== "100644")) plan.modes.push({
44392
+ path: file.path,
44393
+ ...have ? { from: have.mode } : {},
44394
+ to: file.mode
44375
44395
  });
44376
44396
  }
44377
- plan.remove = [...remote].filter((p) => !(p in input.files)).sort();
44397
+ const kept = new Set(input.files.map((f) => f.path));
44398
+ plan.remove = [...remote.keys()].filter((p) => !kept.has(p)).sort();
44399
+ for (const path of plan.remove) plan.changes.push({
44400
+ path,
44401
+ remove: true
44402
+ });
44378
44403
  return plan;
44379
44404
  }
44380
44405
  // src/commands/sync-templates/template-files/template-files.ts
44406
+ /** Folders a template never publishes, wherever they are. */
44407
+ const SKIPPED = /* @__PURE__ */ new Set([".git", "node_modules"]);
44381
44408
  /**
44382
- * Every file of one template folder as `path from the folder -> text`, with `/` separators. `.git` and
44383
- * `node_modules` are not entered. A file with a NUL byte is binary and throws: the `source` capability writes text, so
44384
- * publishing it would corrupt it.
44409
+ * Every file and symbolic link of one template folder, sorted by path (`/` separators). A regular file keeps its
44410
+ * bytes (binary files too) and its execute bit (`100755` when the owner can execute it); a symbolic link is listed
44411
+ * as a `120000` entry whose content is its target and is never followed. `.git` and `node_modules` are not entered.
44385
44412
  */
44386
44413
  function templateFiles(dir) {
44387
- const files = {};
44388
- for (const full of walkFilesSync(dir)) {
44389
- const path = relative(dir, full).split(sep).join("/");
44390
- const bytes = readFileSync(full);
44391
- if (bytes.includes(0)) throw new Error(`${path} is a binary file; templates publish text files only`);
44392
- files[path] = bytes.toString("utf8");
44393
- }
44394
- return files;
44414
+ const files = [];
44415
+ const walk = (folder, prefix) => {
44416
+ for (const entry of readdirSync(folder, { withFileTypes: true })) {
44417
+ const full = join(folder, entry.name);
44418
+ const path = `${prefix}${entry.name}`;
44419
+ const stat = lstatSync(full);
44420
+ if (stat.isSymbolicLink()) files.push({
44421
+ path,
44422
+ mode: "120000",
44423
+ content: Buffer.from(readlinkSync(full))
44424
+ });
44425
+ else if (stat.isDirectory()) {
44426
+ if (!SKIPPED.has(entry.name)) walk(full, `${path}/`);
44427
+ } else if (stat.isFile()) files.push({
44428
+ path,
44429
+ mode: stat.mode & 64 ? "100755" : "100644",
44430
+ content: readFileSync(full)
44431
+ });
44432
+ }
44433
+ };
44434
+ walk(dir, "");
44435
+ return files.sort((a, b) => Number(a.path > b.path) - Number(a.path < b.path));
44395
44436
  }
44396
44437
  // src/commands/sync-templates/template-folders/template-folders.ts
44397
44438
  /**
@@ -44427,14 +44468,16 @@ function templatesVersion(templatesDir) {
44427
44468
  * `holocron sync templates` -- publish each `templates/<type>/` folder to `<org>/<type>-template` and tag that repo
44428
44469
  * `templates-v<version>` (spec `tech-template-repos`, rollout step 3, #2926).
44429
44470
  *
44430
- * Each folder is compared with its repo's default branch; only the difference is written through the `source`
44431
- * capability (files made, replaced, and removed when the repo has them and the folder no longer does), then the repo is
44432
- * tagged with the `templates` group's version from `templates/package.json`. A rerun writes nothing and a tag already at
44433
- * the same content is left alone. It never creates or deletes a repository: a missing template repo is a failing row.
44471
+ * Each folder is compared with its repo's default branch by path, mode and git blob sha; only the difference is written
44472
+ * through the `source` capability, as ONE commit per template (files made or replaced, symlinks and the executable bit
44473
+ * included, and files removed when the repo has them and the folder no longer does), a fast-forward that is refused
44474
+ * when the branch moved since it was read. Then the repo is tagged with the `templates` group's version from `templates/package.json`, and the major tag (`templates-v1`) is moved
44475
+ * to the same commit, so a caller that follows it gets the newest minor. A rerun makes no commit, a version tag already
44476
+ * 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.
44434
44477
  * One template failing does not stop the others. It writes, so it asks first; `--yes` skips the question and, without a
44435
44478
  * terminal, a run with neither `--yes` nor `--dry-run` refuses.
44436
44479
  */
44437
- const counts = (p) => `${p.create.length} to create, ${p.update.length} to replace, ${p.remove.length} to remove`;
44480
+ const counts = (p) => `${p.create.length} to create, ${p.update.length} to replace, ${p.remove.length} to remove${p.modes.length > 0 ? ` (modes: ${p.modes.map((m) => `${m.path} ${m.from ?? "new"} -> ${m.to}`).join(", ")})` : ""}`;
44438
44481
  async function runSyncTemplates(input) {
44439
44482
  const print = input.print ?? ((line) => console.log(line));
44440
44483
  const row = (status, ...parts) => print(statusRow$1(status, ["sync templates", ...parts]));
@@ -44465,29 +44508,29 @@ async function runSyncTemplates(input) {
44465
44508
  const org = input.context.org;
44466
44509
  if (!org) return stop("fail", "no organization to publish to: set `org` in the config or pass --org");
44467
44510
  const tag = `templates-v${version}`;
44511
+ const majorTag = `templates-v${version.split(".")[0]}`;
44468
44512
  /* v8 ignore next -- the real loader is only built outside tests, which always inject one */
44469
44513
  const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
44470
44514
  await loader.load();
44471
44515
  assertPluginsResolvable(loader, "sync templates");
44472
44516
  const source = loader.has("source") ? loader.get("source") : void 0;
44473
- 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"));
44474
- const { readFile, writeFile, listFiles, deleteFile, ensureTag } = source;
44517
+ if (!source?.readTree || !source.commitFiles || !source.ensureTag || !source.moveTag) return stop("fail", whyMissing(loader, "source", "no `source` provider that can read a file tree (`readTree`), commit files (`commitFiles`) and tag is available"));
44518
+ const { readTree, commitFiles, ensureTag, moveTag } = source;
44475
44519
  const results = [];
44476
44520
  const planned = [];
44477
44521
  for (const name of names) {
44478
44522
  const repo = `${org}/${name}-template`;
44479
44523
  try {
44480
44524
  const files = templateFiles(join(dir, name));
44481
- const plan = await planTemplateSync({
44482
- files,
44483
- remotePaths: await listFiles.call(source, repo),
44484
- read: (path) => readFile.call(source, path, repo)
44485
- });
44525
+ const tree = await readTree.call(source, repo);
44486
44526
  planned.push({
44487
44527
  name,
44488
44528
  repo,
44489
- files,
44490
- plan
44529
+ base: tree.commit,
44530
+ plan: planTemplateSync({
44531
+ files,
44532
+ remote: tree.entries
44533
+ })
44491
44534
  });
44492
44535
  } catch (err) {
44493
44536
  row("fail", name, repo, describeError(err));
@@ -44504,7 +44547,7 @@ async function runSyncTemplates(input) {
44504
44547
  }
44505
44548
  if (dryRun) {
44506
44549
  for (const p of planned) {
44507
- row("skip", p.name, p.repo, `dry run, nothing written: ${counts(p.plan)}; would tag ${tag}`);
44550
+ row("skip", p.name, p.repo, `dry run, nothing written: ${counts(p.plan)}; would tag ${tag} and move ${majorTag}`);
44508
44551
  results.push({
44509
44552
  name: p.name,
44510
44553
  repo: p.repo,
@@ -44526,7 +44569,7 @@ async function runSyncTemplates(input) {
44526
44569
  if (!await (input.confirm ?? ((q) => confirm({
44527
44570
  message: q,
44528
44571
  default: false
44529
- })))(`Publish ${planned.length} template(s) as ${tag}?`)) {
44572
+ })))(`Publish ${planned.length} template(s) as ${tag} (and ${majorTag})?`)) {
44530
44573
  for (const p of planned) {
44531
44574
  row("skip", p.name, p.repo, "cancelled; nothing was changed");
44532
44575
  results.push({
@@ -44547,7 +44590,7 @@ async function runSyncTemplates(input) {
44547
44590
  }
44548
44591
  }
44549
44592
  const message = `chore: sync from ${HOLOCRON_REPO$1} ${tag}`;
44550
- for (const { name, repo, files, plan } of planned) {
44593
+ for (const { name, repo, base, plan } of planned) {
44551
44594
  const result = {
44552
44595
  name,
44553
44596
  repo,
@@ -44557,30 +44600,20 @@ async function runSyncTemplates(input) {
44557
44600
  removed: 0
44558
44601
  };
44559
44602
  try {
44560
- for (const path of plan.create) {
44561
- await writeFile.call(source, path, files[path], {
44562
- message,
44563
- repo
44564
- });
44565
- result.created++;
44566
- }
44567
- for (const { path, version: fileVersion } of plan.update) {
44568
- await writeFile.call(source, path, files[path], {
44603
+ if (plan.changes.length > 0) {
44604
+ result.commit = (await commitFiles.call(source, {
44605
+ repo,
44569
44606
  message,
44570
- version: fileVersion,
44571
- repo
44572
- });
44573
- result.updated++;
44574
- }
44575
- for (const path of plan.remove) {
44576
- await deleteFile.call(source, path, {
44577
- message,
44578
- repo
44579
- });
44580
- result.removed++;
44607
+ changes: plan.changes,
44608
+ base
44609
+ })).commit;
44610
+ result.created = plan.create.length;
44611
+ result.updated = plan.update.length;
44612
+ result.removed = plan.remove.length;
44581
44613
  }
44582
44614
  result.tagged = await ensureTag.call(source, tag, repo);
44583
- row("ok", name, repo, `${result.created} created, ${result.updated} replaced, ${result.removed} removed; ${result.tagged ? `tagged ${tag}` : `${tag} already there`}`);
44615
+ result.majorMoved = await moveTag.call(source, majorTag, repo);
44616
+ row("ok", name, repo, `${result.commit ? `committed ${result.commit.slice(0, 7)} (${result.created} created, ${result.updated} replaced, ${result.removed} removed)` : "already up to date"}; ${result.tagged ? `tagged ${tag}` : `${tag} already there`}; ${result.majorMoved ? `${majorTag} moved here` : `${majorTag} already here`}`);
44584
44617
  } catch (err) {
44585
44618
  result.status = "fail";
44586
44619
  result.reason = errorMessage(err);