project

tcmts.core.test.hash.project · #44vfmtw6 · term · runs on the server

uses node:fs

import { analyzeProject } from "#codebase/tcmts/core/analyze";
import { dir } from "#codebase/tcmts/core/test/hash";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";

export function project(files: Record<string, string>) {
  const sub = fs.mkdtempSync(path.join(dir, "proj-"));
  const paths = Object.entries(files).map(([name, text]) => {
    const file = path.join(sub, name);
    fs.mkdirSync(path.dirname(file), { recursive: true });
    fs.writeFileSync(file, text);
    return file;
  });
  const a = analyzeProject(paths, {
    cacheDir: path.join(sub, ".tcm", "cache"),
    resolveName: () => "",
  });
  assert.deepEqual([...a.diagnostics.map((d) => d.message), ...a.errors], []);
  return Object.fromEntries(a.defs.map((d) => [d.nameHint, d]));
}

uses

used by