mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-10-30 17:27:09 +00:00
fix(runtime): a composition script that shadows console no longer breaks the render runtime (#6119)
A script with a top-level const console = ... hides the global from every runtime call to console.info/warn. The runtime build now maps console to globalThis.console.
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
HYPERFRAME_RUNTIME_CONTRACT,
|
||||
loadHyperframeRuntimeSource,
|
||||
} from "../src/inline-scripts/hyperframe";
|
||||
import { RUNTIME_ESBUILD_DEFINE } from "../src/inline-scripts/hyperframesRuntime.engine";
|
||||
import { writeGeneratedFile } from "./writeGeneratedFile.js";
|
||||
|
||||
const thisDir = dirname(fileURLToPath(import.meta.url));
|
||||
@@ -32,6 +33,7 @@ const esmBuild = buildSync({
|
||||
target: ["es2020"],
|
||||
minify: true,
|
||||
legalComments: "none",
|
||||
define: RUNTIME_ESBUILD_DEFINE,
|
||||
});
|
||||
const esmSource = `${esmBuild.outputFiles[0]?.text ?? ""}\n`;
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// @vitest-environment node
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildHyperframesRuntimeScript } from "./hyperframesRuntime.engine";
|
||||
|
||||
describe("buildHyperframesRuntimeScript", () => {
|
||||
it("reaches console through globalThis so a composition's own `const console` cannot break it", () => {
|
||||
const script = buildHyperframesRuntimeScript({ minify: false });
|
||||
expect(script).toContain("globalThis.console.info(");
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,8 @@ export type HyperframesRuntimeBuildOptions = {
|
||||
minify?: boolean;
|
||||
};
|
||||
|
||||
export const RUNTIME_ESBUILD_DEFINE = { console: "globalThis.console" };
|
||||
|
||||
function applyDefaultParityMode(script: string, enabled: boolean): string {
|
||||
const parityFlagPattern = /var\s+_parityModeEnabled\s*=\s*(?:true|false)\s*;/;
|
||||
if (!parityFlagPattern.test(script)) return script;
|
||||
@@ -41,6 +43,7 @@ export function buildHyperframesRuntimeScript(
|
||||
target: ["es2020"],
|
||||
minify: options.minify ?? true,
|
||||
legalComments: "none",
|
||||
define: RUNTIME_ESBUILD_DEFINE,
|
||||
});
|
||||
let script = result.outputFiles[0]?.text ?? "";
|
||||
if (typeof options.defaultParityMode === "boolean") {
|
||||
|
||||
Reference in New Issue
Block a user