Files
hyperframes/packages/core/scripts/buildInjectedArtifact.ts
T
Vance Ingalls 601d30e569 fix(core): unwire an LFO when its effect is disposed
The §4c item here was "four hand-rolled wet/dry shells whose dispose
lists have already drifted". Reading them, the drift is one specific
thing and it is a leak, not an untidiness: the chorus and the phaser
stopped their LFO and left it out of the nodes they disconnect. So every
chain rebuild that dropped a modulated effect left a modulator still
wired to the delay or the allpass bank it had been driving. Nothing
audible came of it — the shell around it was disconnected — but the nodes
stayed reachable, and a session of edits to a modulated track piled them
up. Same shape as the worklet leak fixed earlier on this stack.

`stopLfo` becomes `retireLfo` and does both halves, which is the whole
fix. The consolidation the item also asks for is not here: the four
shells are wired differently enough (a feedback loop, a modulated delay,
six allpass stages between two trims, a convolver) that one factory over
them would need a config surface bigger than the four dispose lines it
replaces. The leak was the part with a defect behind it.

Also folds the two artifact build scripts together — 50 lines each,
differing in five names. That one is a genuine copy, and the copy is
where a divergence would hide: whichever stopped being edited would go on
producing a subtly different artifact with nothing to say so. Output is
byte-identical, which `check:position-edits-render` proves by diffing the
tracked artifact.

Falsified: dropping the `disconnect` fails the new test.

core 1726 passing (110 files), engine services 736 passing / 3 skipped.
2026-08-10 15:38:57 -07:00

79 lines
2.7 KiB
TypeScript

/**
* Bundle a stub entry into an injectable IIFE, wrapped as a TypeScript constant.
*
* Two artifacts are built this way — the audio-FX runtime and the position-edits
* render — and the engine injects both into the headless browser as a script tag.
* They were two copies of this file differing in five names, which is a poor
* place for a divergence to hide: whichever copy stopped being edited would go on
* producing a subtly different artifact with nothing to say so.
*/
import { execFileSync } from "node:child_process";
import { mkdirSync, writeFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { buildSync } from "esbuild";
export interface InjectedArtifact {
/** The build script's own `import.meta.url`, so paths resolve beside it. */
scriptUrl: string;
/** Entry stub, relative to the package root. */
entry: string;
/** Output file name inside `src/generated`. */
out: string;
/** SCREAMING_CASE name for the string constant holding the IIFE. */
constName: string;
/** The accessor the rest of the codebase imports. */
fnName: string;
/** What that accessor returns, for its doc comment: "the pre-built X". */
what: string;
/** Structured log event name. */
event: string;
}
export function buildInjectedArtifact(spec: InjectedArtifact): void {
const scriptDir = dirname(fileURLToPath(spec.scriptUrl));
const scriptName = spec.scriptUrl.split("/").pop() ?? "";
const repoRoot = resolve(scriptDir, "..");
const entry = resolve(repoRoot, spec.entry);
const generatedDir = resolve(repoRoot, "src/generated");
const outPath = resolve(generatedDir, spec.out);
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 ${spec.entry.split("/").pop()}`);
mkdirSync(generatedDir, { recursive: true });
writeFileSync(
outPath,
[
`// AUTO-GENERATED by scripts/${scriptName} - do not edit`,
`const ${spec.constName}: string = ${JSON.stringify(iife)};`,
"",
`/** Returns the pre-built ${spec.what} as a string constant. */`,
`export function ${spec.fnName}(): string {`,
` return ${spec.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: spec.event, outPath, bytes: iife.length }));
}