buildModules

tcmts.cli.suites.buildModules · #hkdzrnkj · term · runs on the server

uses node:path

The code a build of a command has (a package packed from the codebase): its modules, by their components' hashes. A result kept for code a test ran holds against the build if the build has all of that code; an older tcm.js, or a build that isn't the codebase's, has none of it, and the test runs.

import fs from "node:fs";
import path from "node:path";

export function buildModules(file: string): Set<string> {
  let root = path.dirname(file);
  while (!fs.existsSync(path.join(root, "package.json")) && path.dirname(root) !== root)
    root = path.dirname(root);
  const dir = path.join(root, "modules");
  if (!fs.existsSync(dir)) return new Set();
  return new Set(
    fs
      .readdirSync(dir)
      .map((f) => /^([a-z2-7]{52})\.js$/.exec(f)?.[1])
      .filter((h): h is string => !!h),
  );
}

used by