Something went wrong. Try again.
Local-first knowledge base made for Typst and the Atmosphere. typbase.at
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131import { existsSync, readFileSync, statSync } from "node:fs";import path from "node:path";
/** * Checks the shippable package manifests against what `pnpm publish` will * actually put on npm. Run after `pnpm packages:build`, so dist files exist. */
const root = path.resolve(import.meta.dirname, "../..");const packages = ["typing", "storage", "spaces", "plugin-sdk", "skin", "codemirror", "cli"];
const errors = [];const warnings = [];
function relative(file) { return path.relative(root, file) || ".";}
function readJson(file) { return JSON.parse(readFileSync(file, "utf8"));}
function requireFile(file, label) { if (!existsSync(file)) { errors.push(`${label}: missing ${relative(file)}`); return false; }
return true;}
function checkExportTargets(exports, dir, label) { if (!exports || typeof exports !== "object") { errors.push(`${label}: publishConfig.exports is missing`); return; }
const visit = (value, keyPath) => { if (typeof value === "string") { requireFile(path.join(dir, value), `${label} exports.${keyPath}`); return; } if (value && typeof value === "object") { for (const [key, entry] of Object.entries(value)) visit(entry, `${keyPath}.${key}`); } }; visit(exports, ".");}
const baseline = readJson(path.join(root, "packages/typing/package.json")).version;
for (const name of packages) { const dir = path.join(root, "packages", name); const manifestPath = path.join(dir, "package.json"); if (!requireFile(manifestPath, name)) continue; const manifest = readJson(manifestPath); const label = `@typbase/${name}`;
if (!manifest.license) errors.push(`${label}: license is missing`); if (!manifest.repository) errors.push(`${label}: repository is missing`); if (manifest.version !== baseline) { errors.push(`${label}: version ${manifest.version} does not match ${baseline}`); }
const publish = manifest.publishConfig; if (!publish) { errors.push(`${label}: publishConfig is missing`); continue; } if (publish.access !== "public") errors.push(`${label}: publishConfig.access must be public`); if (!publish.registry) errors.push(`${label}: publishConfig.registry is missing`); if (!publish.main) errors.push(`${label}: publishConfig.main is missing`); else requireFile(path.join(dir, publish.main), `${label} main`);
if (name !== "cli") { if (!publish.types) errors.push(`${label}: publishConfig.types is missing`); else requireFile(path.join(dir, publish.types), `${label} types`); checkExportTargets(publish.exports, dir, label); }
if (!Array.isArray(manifest.files) || !manifest.files.includes("dist")) { errors.push(`${label}: files must include dist`); } if (!requireFile(path.join(dir, "README.md"), `${label} README`)) { warnings.push(`${label}: no package README`); }
if (manifest.bin) { for (const target of Object.values(manifest.bin)) { const file = path.join(dir, target); if (!requireFile(file, `${label} bin`)) continue; if ((statSync(file).mode & 0o111) === 0) { errors.push(`${label}: ${relative(file)} is not executable`); } } }
const depSections = ["dependencies", "peerDependencies", "optionalDependencies"]; for (const section of depSections) { for (const [dep, spec] of Object.entries(manifest[section] ?? {})) { if (String(spec).startsWith("workspace:")) { warnings.push(`${label}: ${section}.${dep} uses ${spec}; pnpm rewrites it on publish`); } } }}
// The engine manifest is generated by wasm-pack and repacked by the workflow.const engineDir = path.join(root, "packages/engine/pkg");try { const engine = readJson(path.join(engineDir, "package.json")); if (engine.version !== baseline) { errors.push(`@typbase/engine: version ${engine.version} does not match ${baseline}`); } for (const file of ["engine.js", "engine.d.ts", "engine_bg.wasm"]) { requireFile(path.join(engineDir, file), "@typbase/engine"); }} catch { errors.push("@typbase/engine: packages/engine/pkg/package.json is missing; run engine:build");}
for (const warning of warnings) console.warn(`warning: ${warning}`);for (const error of errors) console.error(`error: ${error}`);
if (errors.length) { console.error(`\n${errors.length} publish problem(s) found.`); process.exit(1);}
console.log(`Published package manifests look good (${packages.length + 1} packages).`);