# runtime/entrypoints/manifest.entrypoint.ts

> 96 lines of code and 28 definitions.

Tree: GovLab Quality
Language: typescript
Layer: runtime
Canonical: https://banes-lab.com/anatomy/quality#file-quality-runtime-entrypoints-manifest-entrypoint-ts
Source text: https://banes-lab.com/source/quality/runtime/entrypoints/manifest.entrypoint.ts.txt

Listed in [runtime/entrypoints](https://banes-lab.com/api/source/quality/runtime/entrypoints.md), after [runtime/entrypoints/invocation.entrypoint.ts](https://banes-lab.com/source/quality/runtime/entrypoints/invocation.entrypoint.ts.md) and before [runtime/entrypoints/rule.entrypoint.ts](https://banes-lab.com/source/quality/runtime/entrypoints/rule.entrypoint.ts.md).

## Definitions

- `isRecord` (lexical_declaration, line 32)
- `importManifest` (lexical_declaration, line 36)
- `stringField` (lexical_declaration, line 41)
- `recordField` (lexical_declaration, line 50)
- `Drift` (interface_declaration, line 10)
- `GOVERNED_MEMBER` (lexical_declaration, line 16)
- `EXPORT_FORMS` (lexical_declaration, line 17)
- `drift` (lexical_declaration, line 26)
- `record` (lexical_declaration, line 28)
- `loaded` (lexical_declaration, line 37)
- `stringArrayField` (lexical_declaration, line 45)
- `declared` (lexical_declaration, line 51)
- `allowlistModule` (lexical_declaration, line 55)
- `stagedEntries` (lexical_declaration, line 58)
- `taxonomyModule` (lexical_declaration, line 62)
- `taxonomy` (lexical_declaration, line 63)
- `declaredContainers` (lexical_declaration, line 64)
- `declaredSpecial` (lexical_declaration, line 65)
- `allowlistDrift` (lexical_declaration, line 67)
- `sep` (lexical_declaration, line 68)
- `path` (lexical_declaration, line 69)
- `name` (lexical_declaration, line 76)
- `text` (lexical_declaration, line 77)
- `exported` (lexical_declaration, line 78)
- `entry` (lexical_declaration, line 83)
- `reason` (lexical_declaration, line 84)
- `containers` (lexical_declaration, line 91)
- `special` (lexical_declaration, line 96)

## Contained in

- [runtime/entrypoints](https://banes-lab.com/anatomy/quality/folder-quality-runtime-entrypoints.md)

## Enforces

- [Manifest-Based Design](https://banes-lab.com/records/architecture/manifest-based-design.md)

## Linked from

- [runtime/entrypoints](https://banes-lab.com/anatomy/quality/folder-quality-runtime-entrypoints.md)

## Source

```typescript
import { MANIFESTS_CLEAN, manifestsFailed } from "#configuration/strings/validation.strings";
import { ROOT as WORKSPACE_ROOT, absolutePath, relativePath } from "@ssot/paths";
import { existsSync, readFileSync } from "node:fs";
import { defineCheck } from "@govlab/context/check";
import { join } from "node:path";
import { pathToFileURL } from "node:url";

defineCheck({ detects: [], enforces: ["architecture:manifest-based-design"] });

interface Drift {
    manifest: string;
    entry: string;
    reason: string;
}

const GOVERNED_MEMBER = join(WORKSPACE_ROOT, relativePath("app.root"));
const EXPORT_FORMS = [
    "export const ",
    "export function ",
    "export class ",
    "export type ",
    "export interface ",
    "export { ",
];

const drift: Drift[] = [];

const record = function record(manifest: string, entry: string, reason: string): void {
    drift.push({ entry, manifest, reason });
};

const isRecord = function isRecord(value: unknown): value is Record<string, unknown> {
    return typeof value === "object" && value !== null;
};

const importManifest = async function importManifest(absolute: string): Promise<Record<string, unknown>> {
    const loaded: unknown = await import(pathToFileURL(absolute).href);
    return isRecord(loaded) ? loaded : {};
};

const stringField = function stringField(value: unknown, key: string): string {
    return isRecord(value) && typeof value[key] === "string" ? value[key] : "";
};

const stringArrayField = function stringArrayField(value: unknown, key: string): string[] {
    const declared = isRecord(value) ? value[key] : undefined;
    return Array.isArray(declared) ? declared.filter((item): item is string => typeof item === "string") : [];
};

const recordField = function recordField(value: unknown, key: string): Record<string, unknown> {
    const declared = isRecord(value) ? value[key] : undefined;
    return isRecord(declared) ? declared : {};
};

const allowlistModule = await importManifest(
    join(absolutePath("govlabHost.shared"), "allowlists", "export.allowlist.ts"),
);
const stagedEntries = Array.isArray(allowlistModule["STAGED_FUTURE_ALLOWLIST"])
    ? allowlistModule["STAGED_FUTURE_ALLOWLIST"]
    : [];

const taxonomyModule = await importManifest(absolutePath("govlabHost.taxonomy"));
const taxonomy = recordField(taxonomyModule, "taxonomy");
const declaredContainers = recordField(taxonomy, "containers");
const declaredSpecial = recordField(taxonomy, "specialContainers");

const allowlistDrift = function allowlistDrift(entry: string): string | null {
    const sep = entry.indexOf("::");
    const path = sep === -1 ? entry : entry.slice(0, sep);
    if (!existsSync(join(GOVERNED_MEMBER, path))) {
        return "file does not exist";
    }
    if (sep === -1) {
        return null;
    }
    const name = entry.slice(sep + 2);
    const text = readFileSync(join(GOVERNED_MEMBER, path), "utf8");
    const exported = EXPORT_FORMS.some((form) => text.includes(`${form}${name}`)) || text.includes(`, ${name}`);
    return exported ? null : `no export named '${name}' in the file`;
};

for (const staged of stagedEntries) {
    const entry = stringField(staged, "file");
    const reason = entry.length === 0 ? null : allowlistDrift(entry);
    if (reason !== null) {
        record("dead-exports-allowlist", entry, reason);
    }
}

for (const root of Object.keys(declaredContainers)) {
    const containers = stringArrayField(declaredContainers, root);
    if (!existsSync(join(WORKSPACE_ROOT, root))) {
        record("taxonomy-config.containers", root, "governed root does not exist on disk");
        continue;
    }
    const special = stringArrayField(declaredSpecial, root);
    for (const container of [...containers, ...special]) {
        if (!existsSync(join(WORKSPACE_ROOT, root, container))) {
            record("taxonomy-config.containers", `${root}/${container}`, "declared container does not exist on disk");
        }
    }
}

if (drift.length === 0) {
    process.stdout.write(MANIFESTS_CLEAN);
    process.exit(0);
}

process.stderr.write(manifestsFailed(drift.length));
for (const d of drift) {
    process.stderr.write(`  ${d.manifest}  "${d.entry}"  ${d.reason}\n`);
}
process.exit(1);
```
