mirror of
https://github.com/PR0M3TH3AN/bitgate.git
synced 2026-10-30 10:01:00 +00:00
A no-build static site couldn't vendor BitGate the way it vendors a single dependency: bare @bitgate/* specifiers don't resolve in a browser, and the headless path spans two packages (the evaluator in core, the kind-1985 label codec in nostr). The widget bundle solved this for the DOM path only. Add @bitgate/standalone (packages/standalone): an entry re-exporting core + nostr, esbuilt into a single self-contained dist/bitgate.js (~44 KB). It's the same canonical code the npm packages ship, with specifiers inlined, and dependency-free -- @bitgate/verify's @noble deps are intentionally not pulled in, so the bundle carries no third-party code. Wired into `npm run build` via build:standalone. Verified: no bare imports in the output (self-contained), and a smoke test composes a full label -> decision flow from the single entry. README Packages table and headless section document it. Addresses the "standalone ESM single-file" item of the Tessera integration feedback (docs/TODO.md). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01BXQCvJPA6sVSQ5j8uBd9bB
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Bundle the headless engine + Nostr codecs into a single self-contained ESM
|
|
* file for no-build static sites.
|
|
*
|
|
* The output (`dist/bitgate.js`) is the same canonical code the npm packages
|
|
* ship — not a second implementation — with the bare `@bitgate/*` specifiers
|
|
* resolved and inlined. Consumers copy it onto their own origin and import it
|
|
* with a single relative path; they never fetch it from someone else's
|
|
* deployment.
|
|
*
|
|
* Usage: node packages/standalone/build.mjs [--watch]
|
|
*/
|
|
import { build, context } from "esbuild";
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
|
|
/** @type {import("esbuild").BuildOptions} */
|
|
const options = {
|
|
entryPoints: [join(HERE, "src", "index.js")],
|
|
outfile: join(HERE, "dist", "bitgate.js"),
|
|
bundle: true,
|
|
format: "esm",
|
|
platform: "browser",
|
|
target: ["es2022"],
|
|
sourcemap: true,
|
|
minify: true,
|
|
legalComments: "inline",
|
|
banner: {
|
|
js: "/*! BitGate (headless standalone) — GPL-3.0-or-later — https://github.com/PR0M3TH3AN/Nostr-Governance */",
|
|
},
|
|
};
|
|
|
|
const watch = process.argv.includes("--watch");
|
|
|
|
if (watch) {
|
|
const ctx = await context(options);
|
|
await ctx.watch();
|
|
console.log("bitgate standalone: watching…");
|
|
} else {
|
|
const result = await build(options);
|
|
if (result.errors.length) {
|
|
process.exit(1);
|
|
}
|
|
console.log(`✓ Built ${options.outfile}`);
|
|
}
|