sessionDirsGone

tcmts.cli.codebase.sessionDirsGone · #5257q7hr · term · runs on the server

uses node:path

The session directories (.tcm/sessions) that none of branches has: left by a session whose branch is gone.

import { sessionDirFor } from "#codebase/tcmts/cli/codebase";
import fs from "node:fs";
import path from "node:path";

export function sessionDirsGone(root: string, branches: string[]): string[] {
  const parent = path.join(root, ".tcm", "sessions");
  if (!fs.existsSync(parent)) return [];
  const kept = new Set(branches.map((b) => sessionDirFor(root, b)));
  return fs
    .readdirSync(parent, { withFileTypes: true })
    .filter((d) => d.isDirectory())
    .map((d) => path.join(parent, d.name))
    .filter((d) => !kept.has(d));
}

uses

used by