testManifestFieldsReadTheSource
A manifest is read from its source: its fields, its names relative to its namespace, never run.
import { manifestFields, packageFileName } from "#codebase/tcmts/share"; import type { NameRow } from "#codebase/tcmts/store"; import assert from "node:assert/strict"; export const testManifestFieldsReadTheSource = () => { const m = manifestFields(`/** doc */ export const manifest = { name: "pkg", exports: { ".": ["a.b", ""], "./x": ["c"] } as const, bin: { run: "cli.main", "two-words": "cli.other" }, // a comment files: ["../README.md", "docs"], computed: 1 + 2, "quoted-key": \`t\${x}\`, apps: { share: "share.App" } satisfies Record<string, string>, };`); assert.deepEqual(m, { name: "pkg", exports: { ".": ["a.b", ""], "./x": ["c"] }, bin: { run: "cli.main", "two-words": "cli.other" }, files: ["../README.md", "docs"], apps: { share: "share.App" }, }); assert.deepEqual(manifestFields(`{ name: "bare" }`), { name: "bare" }); const rows = ["lib.README", "lib.docs.intro", "LICENSE"].map((path) => ({ path }) as NameRow); assert.equal(packageFileName(rows, "lib", "../README.md"), "lib.README"); assert.equal(packageFileName(rows, "lib", "docs"), "lib.docs"); assert.equal(packageFileName(rows, "lib", "../LICENSE"), "LICENSE"); assert.equal(packageFileName(rows, "lib", "nothing"), undefined); }