IF Commons GitHub

host

Written to: 2 requirements: 2 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-kanon-checker FR-007, 0001-kanon-checker FR-012

The host side of the check of Kanon (commons 0033-kanon FR-012, FR-014): it reads a library's manifest for its table, the exports of its package and its .ts files, and gives the findings of the import check over them, judged against a baseline of findings that only shrinks. The pure check is importFindings; this is the only module of the package that reads files.

Effects are at the edge and behind a port: every function here takes Files, a typed record of the four functions it reads with, and systemFiles is the real one; a failure the host can cause (a missing file, a package that is not JSON) is a Result, never a throw. Every .ts file under the library's root is read but node_modules, dist and the spec kit's folder, so that a file that no unit of the table holds is found (layers/unclassified).

Source: commons/kanon/src/host.ts

8 of 14 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

MANIFESTconstno test imports it
const MANIFEST: "library.ts"

The name of a library's manifest in its folder.

CONSUMER_MANIFESTconstno test imports it
const CONSUMER_MANIFEST: "kanon.ts"

The name of the manifest of a consumer, a package that is not a library of commons (0033-kanon FR-027): the export kanon, a table in the form of the field kanon of library.ts.

BASELINEconst
const BASELINE: "kanon.baseline.txt"

The name of the baseline of findings a library holds, in its folder.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

Filestype
type Files = {
  readonly exists: (path: string) => boolean;
  readonly readDir: (path: string) => readonly { readonly name: string; readonly isDirectory: boolean }[];
  readonly readText: (path: string) => string;
  /** The bytes of a file, for a bundle (0002-kanon-content-checks FR-011). */
  readonly readBytes?: (path: string) => Uint8Array;
};

What the host reads with: a port, a record of functions, so that a test or another host may give its own.

Imported by 9 tests of the run (9 passed, 0 failed): the library's results

systemFilesconstno test imports it
const systemFiles: Files

The real file system.

Exportstypeno test imports it
type Exports = ExportsMap;

An exports map: each subpath to its target, a string or an object of conditions of strings.

readTablefunction
function readTable(root: string, files?: Files): Result<Table, string>

The table of the library at root, from the field kanon of its manifest; an error as a sentence where there is none or it is not a table.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

readTableOffunction
function readTableOf(root: string, files?: Files): Result<{ readonly table: Table; readonly manifest: "kanon.ts" | "library.ts"; }, string>

The table of a package and the manifest it was read from: library.ts (its field kanon) or, where there is none, the consumer's kanon.ts (0002-kanon-content-checks FR-007).

Imported by 9 tests of the run (9 passed, 0 failed): the library's results

readBundlefunction
function readBundle(dir: string, files?: Files): Result<{ readonly manifest: string; readonly files: ReadonlyMap<string, Uint8Array<ArrayBufferLike>>; }, string>

The files of a bundle in a folder, and the text of its manifest, read and nothing written: every file under the folder but the manifest, by its path from the folder with / (0002-kanon-content-checks FR-011).

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

readSourcesfunction
function readSources(root: string, files?: Files, dir?: string): Result<readonly SourceFile[], string>

The .ts files under dir, as paths from root with /, in the order of their names.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

readExportsfunction
function readExports(root: string, files?: Files): Result<Readonly<Record<string, string | { readonly [condition: string]: string; }>>, string>

The exports of the package at root, each subpath to its target.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

findingsfunction
function findings(root: string, files?: Files): Result<readonly Finding[], string>

Every finding of the import check over the library at root, or why its table, its package or its files cannot be read.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

parseBaselinefunctionno test imports it
function parseBaseline(text: string): ReadonlySet<string>

A baseline's keys, from its text: a line that is not a comment or blank.

judgefunctionno test imports it
function judge(found: readonly Finding[], baseline: ReadonlySet<string>): { readonly fresh: readonly Finding[]; readonly stale: readonly string[]; }

The judgement of findings against a baseline: the new ones, and the lines of the baseline that no longer occur (both fail the check).

Titles, headings, exports, tables, columns and requirements. Esc closes.