typeProblems

tcmts.cli.contributions.typeProblems · #sk2xjhyi · term · runs on the server

uses node:util

The type errors in what a contribution brings: the code its branch reaches (its names and everything they use) that the target didn't where the two parted, typechecked here, each definition under the options it was checked under. A server checks that what it receives is what it claims, not that it typechecks (a client could post code no tcm would save): merging is where a contribution's types are judged.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import type { Contribution } from "#codebase/tcmts/store";
import { stripVTControlCharacters } from "node:util";

export function typeProblems(cb: Codebase, c: Contribution): string[] {
  const head = cb.store.head(c.source);
  const base = cb.store.mergeBase(head, cb.store.head(c.target));
  const reached = (causal: string) =>
    cb.closureComponents(
      cb.store.namespaceRows(cb.store.causal(causal)!.namespace).map((n) => n.hash),
    );
  const before = reached(base);
  const brought = [...reached(head)]
    .filter((comp) => !before.has(comp))
    .flatMap((comp) => cb.store.componentMembers(comp).slice(0, 1))
    .filter((m) => m.kind !== "file")
    .map((m) => m.hash);
  return brought.length ? cb.recheck(brought).map((p) => stripVTControlCharacters(p)) : [];
}

uses

used by