Files
hyperframes/packages/producer/build.mjs
T
Miguel Ángel ef2f646c90 fix(producer): extract head assets from non-template sub-comps + fix postcss ESM (#220)
## Summary

Two fixes in the producer:

1. **Head styles/scripts extraction**: mirrors the runtime fix from PR #219. The producer's `inlineSubCompositions()` parsed only `bodyEl.innerHTML` from non-template sub-compositions, discarding all `<head>` content.
2. **Externalize postcss**: postcss is a CJS module with `require("path")` — bundling it into ESM output caused "Dynamic require of path is not supported" at runtime, breaking `npx tsx cli render` and `npx tsx cli preview` from the local dev build.

## Verified

Re-rendered the iris-wipe composition (eval prompt #25, previously scored 1.0/5 — entirely black):

| Frame | Before fix | After fix |
| --- | --- | --- |
| 0\.5s | Black | Red background + "HELLO" text |
| File size | 16\.9 KB (all black) | 64\.8 KB (actual content) |

Scene 1 now renders correctly. Scene 2's clip-path animation has a separate GSAP issue (the lint already warns about it via `scene_layer_missing_visibility_kill`).

## Test plan

- [x] `pnpm --filter @hyperframes/producer build` succeeds
- [x] `node --input-type=module -e "import './dist/index.js'"` loads without error
- [x] Re-render iris-wipe produces visible content (64.8 KB vs 16.9 KB)
- [x] Frame extraction confirms red "HELLO" scene renders correctly
2026-04-07 17:37:26 +02:00

83 lines
2.6 KiB
JavaScript

#!/usr/bin/env node
/**
* Build script for @hyperframes/producer (public OSS package)
*
* Bundles src/server.ts → dist/public-server.js (standalone server).
*/
import { build } from "esbuild";
import { mkdirSync, rmSync } from "fs";
import { resolve, dirname } from "path";
import { fileURLToPath } from "url";
rmSync("dist", { recursive: true, force: true });
mkdirSync("dist", { recursive: true });
const scriptDir = dirname(fileURLToPath(import.meta.url));
const workspaceAliasPlugin = {
name: "workspace-alias",
setup(build) {
build.onResolve({ filter: /^@hyperframes\/engine$/ }, () => ({
path: resolve(scriptDir, "../engine/src/index.ts"),
}));
build.onResolve({ filter: /^@hyperframes\/core$/ }, () => ({
path: resolve(scriptDir, "../core/src/index.ts"),
}));
build.onResolve({ filter: /^@hyperframes\/core\/lint$/ }, () => ({
path: resolve(scriptDir, "../core/src/lint/index.ts"),
}));
},
};
await Promise.all([
build({
bundle: true,
platform: "node",
target: "node22",
format: "esm",
external: ["puppeteer", "esbuild", "postcss"],
plugins: [workspaceAliasPlugin],
minify: false,
sourcemap: true,
entryPoints: ["src/index.ts"],
outfile: "dist/index.js",
}),
build({
bundle: true,
platform: "node",
target: "node22",
format: "esm",
external: ["puppeteer", "esbuild", "postcss"],
plugins: [workspaceAliasPlugin],
minify: false,
sourcemap: true,
entryPoints: ["src/server.ts"],
outfile: "dist/public-server.js",
}),
]);
// Copy core runtime artifacts so the producer can find them at dist/
import { copyFileSync, existsSync, readFileSync } from "fs";
const coreDistDir = resolve(scriptDir, "../core/dist");
try {
const manifestSrc = resolve(coreDistDir, "hyperframe.manifest.json");
if (existsSync(manifestSrc)) {
copyFileSync(manifestSrc, "dist/hyperframe.manifest.json");
const manifest = JSON.parse(readFileSync(manifestSrc, "utf8"));
const runtimeIife = manifest?.artifacts?.iife || "hyperframe.runtime.iife.js";
copyFileSync(resolve(coreDistDir, runtimeIife), `dist/${runtimeIife}`);
console.log(`[Build] Copied runtime: hyperframe.manifest.json, ${runtimeIife}`);
}
} catch (e) {
console.warn("[Build] Warning: Could not copy runtime artifacts:", e.message);
}
// Generate .d.ts declarations (esbuild doesn't emit them)
import { execSync } from "child_process";
execSync("tsc --emitDeclarationOnly --declaration --declarationMap", {
stdio: "inherit",
});
console.log("[Build] Complete: dist/index.js, dist/public-server.js, *.d.ts");