packagesIn

tcmts.cli.manifests.packagesIn · #i2bp5ntq · term · runs on the server

uses tcmts.cli.config.configValue, which uses node:path

The packages a branch's names (or a past namespace's) declare: a library's own packages aren't among them.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { configValue } from "#codebase/tcmts/cli/config";
import { inLibrary, librariesOf, RECORD } from "#codebase/tcmts/cli/libraries";
import { isManifestPath, nsOf, validate } from "#codebase/tcmts/cli/manifests";
import type { Pkg } from "#codebase/tcmts/cli/manifests";
import type { NameRow } from "#codebase/tcmts/store";

export function packagesIn(cb: Codebase, rows: NameRow[]): Pkg[] {
  const out: Pkg[] = [];
  // (names given without the files kept with them are a branch's, as `names()` reads them: its records say)
  const records = rows.some((r) => r.kind === "file") ? rows : cb.store.filesNamed(RECORD);
  const libraries = librariesOf(records, (h) => cb.store.getDef(h)?.sourceText ?? "");
  for (const r of rows) {
    if (!isManifestPath(r.path) || r.kind === "type" || inLibrary(libraries, r.path)) continue;
    const manifest = validate(
      r.path,
      configValue(cb, r.hash, r.path),
      cb.store.getDef(r.hash)?.doc,
    );
    const twin = out.find((p) => p.name === manifest.name);
    if (twin)
      throw new Error(
        `two packages are called ${manifest.name}: ${twin.manifestPath} and ${r.path}`,
      );
    out.push({
      name: manifest.name,
      namespace: nsOf(r.path),
      manifestPath: r.path,
      manifestHash: r.hash,
      manifest,
    });
  }
  return out.sort((a, b) => (a.name < b.name ? -1 : 1));
}

uses

used by