withCodebase

tcmts.cli.mcp.withCodebase · #ubsphe2p · term · runs on the server

uses process

fn on the codebase at root as its own branch is, not this process's session's (TCM_BRANCH).

import { Codebase } from "#codebase/tcmts/cli/codebase";

export function withCodebase<T>(root: string, fn: (cb: Codebase) => T): T {
  const session = process.env.TCM_BRANCH;
  delete process.env.TCM_BRANCH;
  try {
    const cb = Codebase.find(root);
    try {
      return fn(cb);
    } finally {
      cb.store.close();
    }
  } finally {
    if (session !== undefined) process.env.TCM_BRANCH = session;
  }
}

uses

used by