isApp

tcmts.cli.pages.isApp · #pejpihgu · term · runs anywhere

An app's entry point: it runs in the browser, takes no arguments, nothing named calls it, and it isn't a React hook (named use…: a library's hooks are called by nothing in its own codebase) (what tcm dev is pointed at, like app.main).

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { isHook } from "#codebase/tcmts/cli/pages";
import type { Placement } from "#codebase/tcmts/cli/placement";
import type { DefRecord } from "#codebase/tcmts/core/types";

export const isApp = (cb: Codebase, hash: string, rec: DefRecord, placement: Placement): boolean =>
  rec.kind === "term" &&
  placement.placeOf(hash).place === "browser" &&
  cb.store.namedDependents(hash).length === 0 &&
  !isHook(cb.store.pathsOf(hash)) &&
  (rec.params
    ? rec.params.params.every((p) => p.optional || p.rest)
    : /^\(\)\s*=>/.test(rec.signature))

uses

used by