Files
hyperframes/packages/core/scripts/build-inline-artifact.ts
T
Vance Ingalls 7c410fd075 fix(core,studio): clear the remaining Fallow audit findings on the FX panel
- Split FxSection's per-node row into FxNodeRow + FxNodeControls so the
  CRAP score (31.6, threshold 30) splits across two smaller units instead
  of moving wholesale with one extraction.
- Dedupe the repeated "open the add menu, read its items" block in
  propertyPanelFxSection.test.tsx into openAddMenuItems().
- Merge build-audio-fx-runtime.ts and build-position-edits-render.ts into
  one build-inline-artifact.ts, config-selected by CLI arg — the two
  scripts were a byte-for-byte clone save for names.
- Exempt canary.test.ts's rawFnv (a deliberate independent
  reimplementation used to cross-check canaryBucket, per its own
  docstring) and the property-panel test files' shared renderInto/mount
  scaffolding (pre-existing across 9 files, 2 outside this stack) in
  .fallowrc.jsonc, consistent with this file's existing exemptions for
  the same class of intentional/pre-existing duplication.
2026-08-12 10:45:31 -07:00

98 lines
3.2 KiB
TypeScript

/**
* Bundle one canonical-runtime entry to a minified IIFE with esbuild and write
* it into `src/generated` as a string constant behind a getter.
*
* One script handles both inline artifacts — the audio-FX runtime and the
* position-edits render — since they differ only in the entry, output names,
* and log event. Keeping them as separate files produced a byte-for-byte
* clone that fallow kept re-flagging on every unrelated line shift.
*/
import { mkdirSync, writeFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { buildSync } from "esbuild";
import { execFileSync } from "node:child_process";
interface InlineArtifactTarget {
entryRelPath: string;
generatedFileName: string;
constName: string;
getterName: string;
/** Filename shown in the esbuild-failure error. */
entryLabel: string;
/** Human phrase for the generated getter's doc comment, e.g. "audio-FX runtime". */
docLabel: string;
event: string;
}
const TARGETS: Record<string, InlineArtifactTarget> = {
"audio-fx": {
entryRelPath: "stubs/audio-fx-runtime-entry.ts",
generatedFileName: "audio-fx-runtime-inline.ts",
constName: "AUDIO_FX_RUNTIME_IIFE",
getterName: "getAudioFxRuntimeScript",
entryLabel: "audio-fx-runtime-entry.ts",
docLabel: "audio-FX runtime",
event: "audio_fx_runtime_generated",
},
"position-edits": {
entryRelPath: "stubs/position-edits-render-entry.ts",
generatedFileName: "position-edits-render-inline.ts",
constName: "POSITION_EDITS_RENDER_IIFE",
getterName: "getPositionEditsRenderScript",
entryLabel: "position-edits-render-entry.ts",
docLabel: "position-edits render",
event: "position_edits_render_generated",
},
};
const key = process.argv[2] ?? "";
const target = TARGETS[key];
if (!target) {
throw new Error(`Usage: build-inline-artifact.ts <${Object.keys(TARGETS).join("|")}>`);
}
const thisDir = dirname(fileURLToPath(import.meta.url));
const repoRoot = resolve(thisDir, "..");
const entry = resolve(repoRoot, target.entryRelPath);
const generatedDir = resolve(repoRoot, "src/generated");
const outPath = resolve(generatedDir, target.generatedFileName);
const result = buildSync({
entryPoints: [entry],
bundle: true,
write: false,
platform: "browser",
format: "iife",
target: ["es2020"],
minify: true,
legalComments: "none",
});
const iife = result.outputFiles[0]?.text ?? "";
if (!iife) throw new Error(`esbuild produced no output for ${target.entryLabel}`);
mkdirSync(generatedDir, { recursive: true });
writeFileSync(
outPath,
[
"// AUTO-GENERATED by scripts/build-inline-artifact.ts - do not edit",
`const ${target.constName}: string = ${JSON.stringify(iife)};`,
"",
`/** Returns the pre-built ${target.docLabel} IIFE as a string constant. */`,
`export function ${target.getterName}(): string {`,
` return ${target.constName};`,
"}",
"",
].join("\n"),
"utf8",
);
try {
execFileSync("bun", ["x", "oxfmt", outPath], { stdio: "ignore" });
} catch {
// Formatting is best effort when the generator runs in a minimal environment.
}
console.log(JSON.stringify({ event: target.event, outPath, bytes: iife.length }));