Files
Ekklesia/packages/module-ui-sdk/tests/browser-safety.test.ts
T
ekklesiaandClaude Opus 5.5 89d5d0f2da
CI / verify (pull_request) Successful in 1m2s
CI / infrastructure-smoke (pull_request) Successful in 28s
CI / migration-smoke (pull_request) Successful in 1m52s
CI / standalone-module (pull_request) Successful in 26s
CI / image-build (pull_request) Successful in 30s
CI / deploy-smoke (same-origin) (pull_request) Successful in 50s
CI / deploy-smoke (split) (pull_request) Successful in 1m42s
feat: standalone module-build readiness for the public @ekklesia packages (ADR 0053)
Makes the public module-development package set usable from a module
repository outside the monorepo. Nothing is published.

- Curated @ekklesia/module-sdk: an explicit author API, no contracts
  barrel, no identity/authorization internals, no Drizzle and no legacy
  ModuleDatabase type. defineModuleRuntime returns the SDK's own named
  interfaces so a module's emitted declarations never reach into
  @ekklesia/contracts. defineModuleSchema is gone; createModuleTable and
  defineModuleSchemaMetadata live in @ekklesia/module-database.
- Drizzle: no longer a dependency of module-sdk or contracts. Core keeps
  the legacy Drizzle schema validator (moved to core/src/modules) and
  its legacy runtime support; drizzle-orm is an optional peer only.
- React is a peer (plus devDependency) of @ekklesia/ui; the boundary
  checker allows exactly that consumer-selected peer.
- @ekklesia/typescript-config is publishable; module-ui-host is private.
  Every public package carries "ekklesia.distribution":
  "module-development" and no monorepo-root prepack.
- module-pack reads the Node.js range from the module's own engines.node
  and recognizes Ekklesia packages by name plus that marker, so
  registry-installed packages are incorporated, SDK-compatibility
  checked, and never credited as third-party.
- scripts/pack-public-packages.ts (pnpm packages:pack) rebuilds, packs
  and inspects the nine public tarballs; scripts/test-standalone-module.sh
  (pnpm test:standalone-module, new CI job) installs them into a fixture
  module outside the repository and proves it typechecks, builds,
  packages, and verifies.
- Public-package boundary tests and module-development docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-08 07:28:54 -05:00

71 lines
3.4 KiB
TypeScript

import { readdir, readFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
const sourceDirectory = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "src");
async function sourceFiles(): Promise<string[]> {
const entries = await readdir(sourceDirectory);
return entries.filter((entry) => entry.endsWith(".ts")).sort();
}
/**
* This package is bundled into a browser. `@ekklesia/module-sdk` is built on `@ekklesia/contracts`,
* which pulls Zod and semver behind one barrel export, so a single value import from a backend
* package here would drag that whole graph into every module UI bundle
* (ADR 0022). ADR 0024 removed even the former type-only contracts dependency because its type graph
* leaked Node globals into browser programs; this package must remain completely dependency-free.
*/
describe("module UI SDK stays browser-safe", () => {
it("imports nothing from another package at all, at type level or runtime", async () => {
// Stronger than "type-only imports are fine". A type-only import is erased at runtime but still
// drags the imported package's *type graph* into every consuming program — which is exactly how
// Node globals reached browser-only module UI before ADR 0024. This package now imports nothing
// external, so there is no graph to drag.
for (const file of await sourceFiles()) {
const source = await readFile(path.join(sourceDirectory, file), "utf8");
const externalImports = [...source.matchAll(/^(?:import|export)\s[^;]*?from\s+"([^"]+)"/gmu)]
.map(([, specifier]) => specifier)
.filter((specifier) => specifier !== undefined && !specifier.startsWith("."));
expect(externalImports, `${file} imports outside this package`).toEqual([]);
}
});
it("declares no dependencies whatsoever", async () => {
const manifestPath = path.join(sourceDirectory, "..", "package.json");
const manifest = JSON.parse(await readFile(manifestPath, "utf8")) as {
dependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
};
expect(Object.keys(manifest.dependencies ?? {})).toEqual([]);
expect(Object.keys(manifest.peerDependencies ?? {})).toEqual([]);
});
it("does not depend on a UI framework, so the contract stays framework-neutral", async () => {
const manifestPath = path.join(sourceDirectory, "..", "package.json");
const manifest = JSON.parse(await readFile(manifestPath, "utf8")) as {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
};
const declared = [
...Object.keys(manifest.dependencies ?? {}),
...Object.keys(manifest.devDependencies ?? {}),
...Object.keys(manifest.peerDependencies ?? {}),
];
// React is the supported way to *author* module UI. It is deliberately absent from the host
// contract, so a host never has to match a module's rendering library.
for (const framework of ["react", "react-dom", "vue", "svelte", "preact"]) {
expect(declared).not.toContain(framework);
}
// Backend graphs must not reappear through a development dependency either.
for (const backend of ["drizzle-orm", "zod", "semver", "@ekklesia/contracts"]) {
expect(declared).not.toContain(backend);
}
});
});