mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(media-use): carve runs its own copy of core's analysis, never the project's (#7926)
* fix(media-use): carve runs its own copy of core's analysis, never the project's carve.mjs loaded @hyperframes/core from the composition's own node_modules, so carving a project ran whatever that project shipped under that name. It now imports a bundle of core's carve and audio-fx functions generated beside it, with a test that fails when the bundle drifts from core's source. * fix(media-use): lint and format skip the carve bundle on the CLI path too
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { describe, it } from "node:test";
|
||||
import { generate } from "./generate-media-use-audio-carve.mjs";
|
||||
|
||||
// The carve analysis lives in packages/core/src/audioCarve.ts and audioFx.ts; the skill's copy is a generated
|
||||
// bundle. This trips on a hand edit of the bundle or a source change that was not regenerated.
|
||||
describe("media-use audio-carve.mjs matches a fresh regeneration", () => {
|
||||
it("is byte-identical to `node scripts/generate-media-use-audio-carve.mjs`", async () => {
|
||||
const committed = readFileSync(
|
||||
resolve(import.meta.dirname, "../skills/media-use/audio/scripts/lib/audio-carve.mjs"),
|
||||
"utf8",
|
||||
);
|
||||
assert.equal(
|
||||
committed,
|
||||
await generate(),
|
||||
"skills/media-use/audio/scripts/lib/audio-carve.mjs is stale. Run: node scripts/generate-media-use-audio-carve.mjs",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env node
|
||||
// Bundles the carve analysis carve.mjs uses (packages/core/src/audioCarve.ts and audioFx.ts) into a single
|
||||
// import-free .mjs beside the skill, so the skill never loads @hyperframes/core from the project it edits.
|
||||
// Regenerate after editing the source: node scripts/generate-media-use-audio-carve.mjs
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname, resolve } from "node:path";
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
const CORE_SRC = resolve(here, "../packages/core/src");
|
||||
const OUTFILE = resolve(here, "../skills/media-use/audio/scripts/lib/audio-carve.mjs");
|
||||
// scripts/ has no node_modules of its own (bun's per-consumer linking); reach into the one
|
||||
// package that already depends on esbuild rather than adding a root-level dependency.
|
||||
const { build } = await import(resolve(here, "../packages/core/node_modules/esbuild/lib/main.js"));
|
||||
|
||||
const ENTRY = `export {
|
||||
analyseCarveBands,
|
||||
analyseCarveDuck,
|
||||
carveBandsToChain,
|
||||
carveProfile,
|
||||
classifyAudioName,
|
||||
clipsOverlap,
|
||||
mixCarveSources,
|
||||
} from "./audioCarve.ts";
|
||||
export {
|
||||
defaultAudioFxParams,
|
||||
mintAudioFxNodeId,
|
||||
parseAudioFxChain,
|
||||
serializeAudioFxChain,
|
||||
} from "./audioFx.ts";
|
||||
`;
|
||||
|
||||
const HEADER = `// GENERATED: do not hand-edit. Source: packages/core/src/audioCarve.ts and audioFx.ts, bundled by
|
||||
// scripts/generate-media-use-audio-carve.mjs so carve.mjs runs the same analysis as Studio without
|
||||
// loading @hyperframes/core from the project. Regenerate: node scripts/generate-media-use-audio-carve.mjs
|
||||
`;
|
||||
|
||||
export async function generate() {
|
||||
const result = await build({
|
||||
stdin: {
|
||||
contents: ENTRY,
|
||||
resolveDir: CORE_SRC,
|
||||
loader: "ts",
|
||||
sourcefile: "audio-carve-entry.ts",
|
||||
},
|
||||
bundle: true,
|
||||
format: "esm",
|
||||
platform: "node",
|
||||
write: false,
|
||||
minify: true,
|
||||
legalComments: "none",
|
||||
});
|
||||
return HEADER + result.outputFiles[0].text;
|
||||
}
|
||||
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
const code = await generate();
|
||||
writeFileSync(OUTFILE, code);
|
||||
console.log(`wrote ${OUTFILE} (${code.length} bytes)`);
|
||||
}
|
||||
Reference in New Issue
Block a user