exportsOf

tcmts.cli.manifests.exportsOf · #pys5f2hd · term · runs anywhere

What a package exports: each exported name, with the subpath it's exported from.

import { absolute, owns, within } from "#codebase/tcmts/cli/manifests";
import type { Pkg } from "#codebase/tcmts/cli/manifests";
import type { NameRow } from "#codebase/tcmts/store";

export function exportsOf(pkg: Pkg, all: Pkg[], rows: NameRow[]): Map<string, string> {
  const out = new Map<string, string>();
  for (const [sub, targets] of Object.entries(pkg.manifest.exports)) {
    for (const t of targets) {
      const abs = absolute(pkg.namespace, t);
      const hit = rows.filter((r) => within(abs, r.path) && owns(pkg, all, r.path));
      if (!hit.length) throw new Error(`${pkg.manifestPath}: exports["${sub}"] names '${t}', which isn't in ${pkg.namespace || "the codebase"}`);
      for (const r of hit) if (!out.has(r.path)) out.set(r.path, sub);
    }
  }
  return out;
}

uses

used by