mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 12:54:29 +00:00
* refactor(producer): extract HDR compositor from renderOrchestrator Move ~700 LOC of HDR compositing primitives (countNonZeroAlpha, countNonZeroRgb48, cropRgb48le, HdrVideoFrameSource, closeHdrVideoFrameSource, blitHdrVideoLayer, HdrImageBuffer, blitHdrImageLayer, CompositeTransfer, shouldUseLayeredComposite, resolveCompositeTransfer, HdrCompositeContext, compositeHdrFrame, HdrTransitionMeta, TransitionRange) into a dedicated hdrCompositor.ts module. Remove backward-compat re-exports from renderOrchestrator (hdrPerf, captureCost, shared) and rewire all import sites to the authoritative source modules. * refactor(producer): delete 4 re-export shim files screenshotService.ts, videoFrameExtractor.ts, videoFrameInjector.ts, and streamingEncoder.ts existed solely to re-export symbols from @hyperframes/engine. No internal consumer imported from them except index.ts → videoFrameInjector, which now imports directly from engine. * refactor(producer): delete unused PNG decode/blit worker pool The pool (455 LOC) and worker (127 LOC) were built speculatively for pipelining Chrome screenshots with PNG decode/blit but were never wired into any capture path. Zero non-test source files imported them. Also removed the esbuild entry point from producer/build.mjs, the tsup entry point + alpha-blit alias from cli/tsup.config.ts, and the PNG worker bootstrap from cli/src/cli.ts. * refactor(producer): centralize frame filename construction Replace 4 inline padStart(6) template literals with shared helpers: - formatCaptureFrameName(index, ext): zero-based, for internal capture - formatExportFrameName(index, ext): zero-based input, one-based output for user-facing png-sequence export * perf(producer): hoist allElementIds out of compositing loop Move fullStacking.map() from inside the per-layer iteration to before the loop, computing the element ID list once per frame instead of once per DOM layer per frame. * refactor(producer): consolidate HDR timing instrumentation * refactor(producer): remove typecasts and deduplicate HDR capture patterns - Extract seekInjectAndQueryStacking() and seekAndInject() helpers to deduplicate the seek+inject+query pattern across sequential loop, hybrid loop, and per-scene transition capture (3 call sites → 1 helper) - Fix sceneBuf as Buffer casts by properly typing the scene-capture arrays as [Buffer, Set<string>][] instead of using as const + cast - Replace as NonNullable<> cast on outputFormat with as const fallback - Add explanatory comments on inherent linkedom DOM casts * refactor(producer): name constants, type matrix, extract opacity helper - Replace magic 0.001/0.999 with TRANSFORM_IDENTITY_EPSILON and OPAQUE_ALPHA_THRESHOLD; replace BPP=6 with RGB48_BYTES_PER_PIXEL - Add AffineMatrix tuple type + isAffineMatrix guard, eliminating all 4 non-null assertions on matrix indices - Extract resolveBlitOpacity() to replace 5 identical ternaries - Narrow fallow-ignore-file to line-level complexity suppressions
93 lines
3.4 KiB
JavaScript
93 lines
3.4 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));
|
|
|
|
// The banner provides a real `require` function via createRequire so that
|
|
// esbuild's CJS interop (__require) works correctly in ESM output.
|
|
// Without this, bundled CJS deps (recast, yauzl, etc.) that call
|
|
// require("fs") throw "Dynamic require of 'fs' is not supported".
|
|
const cjsBanner = {
|
|
js: "import { createRequire as __cjsRequire } from 'module'; const require = __cjsRequire(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\/engine\/alpha-blit$/ }, () => ({
|
|
path: resolve(scriptDir, "../engine/src/utils/alphaBlit.ts"),
|
|
}));
|
|
build.onResolve({ filter: /^@hyperframes\/engine\/shader-transitions$/ }, () => ({
|
|
path: resolve(scriptDir, "../engine/src/utils/shaderTransitions.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"),
|
|
}));
|
|
},
|
|
};
|
|
|
|
const sharedOpts = {
|
|
bundle: true,
|
|
platform: "node",
|
|
target: "node22",
|
|
format: "esm",
|
|
external: ["puppeteer", "esbuild", "postcss"],
|
|
plugins: [workspaceAliasPlugin],
|
|
minify: false,
|
|
sourcemap: true,
|
|
banner: cjsBanner,
|
|
};
|
|
|
|
await Promise.all([
|
|
build({ ...sharedOpts, entryPoints: ["src/index.ts"], outfile: "dist/index.js" }),
|
|
build({ ...sharedOpts, entryPoints: ["src/server.ts"], outfile: "dist/public-server.js" }),
|
|
build({
|
|
...sharedOpts,
|
|
entryPoints: ["src/services/shaderTransitionWorker.ts"],
|
|
outfile: "dist/services/shaderTransitionWorker.js",
|
|
}),
|
|
build({ ...sharedOpts, entryPoints: ["src/distributed.ts"], outfile: "dist/distributed.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");
|