candidateDir

tcmts.dev.candidateDir · #vhejnyed · term · runs on the server

uses node:crypto

Where a verify of branch (main, without one) builds the tcm it checks: dist/candidates/, its own, as each worktree has its own files. (A name a directory can't have as it is, a session's session/…, is made one, with a hash of it to keep it the branch's alone.)

import { createHash } from "node:crypto";
import path from "node:path";

export function candidateDir(dist: string, branch?: string): string {
  const b = branch || "main";
  const safe = b.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^\.+/, "-");
  const name =
    safe === b ? b : `${safe}-${createHash("sha256").update(b).digest("hex").slice(0, 6)}`;
  return path.join(dist, "candidates", name);
}

used by