mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
fix(core): page runtimes carry no wide characters, so pages stay one byte a char (#8239)
* fix(inspector): the page runtime carries no wide characters, so inspected pages stay one byte a char * fix(core): the inlined page runtime carries no wide characters either * fix(core): the wide-character check lives in core, which every runtime build image copies
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
} from "../src/inline-scripts/hyperframe";
|
||||
import { RUNTIME_ESBUILD_DEFINE } from "../src/inline-scripts/hyperframesRuntime.engine";
|
||||
import { writeGeneratedFile } from "./writeGeneratedFile.js";
|
||||
import { firstCharacterThatMakesPagesTwoByte } from "./page-script-one-byte.mjs";
|
||||
|
||||
const thisDir = dirname(fileURLToPath(import.meta.url));
|
||||
const distDir = resolve(thisDir, "../dist");
|
||||
@@ -20,6 +21,12 @@ const runtimeSourceRaw = loadHyperframeRuntimeSource();
|
||||
if (runtimeSourceRaw === null) {
|
||||
throw new Error("Cannot build runtime artifact: entry.ts not found at expected path");
|
||||
}
|
||||
const wide = firstCharacterThatMakesPagesTwoByte(runtimeSourceRaw);
|
||||
if (wide) {
|
||||
throw new Error(
|
||||
`the page runtime has ${wide}: every page it is inlined into would be stored at two bytes a character`,
|
||||
);
|
||||
}
|
||||
const runtimeSource = `${runtimeSourceRaw}\n`;
|
||||
const runtimeSha256 = createHash("sha256").update(runtimeSource, "utf8").digest("hex");
|
||||
const buildId = process.env.HYPERFRAME_RUNTIME_BUILD_ID?.trim() || "dev";
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export function firstCharacterThatMakesPagesTwoByte(text) {
|
||||
const wide = /[\u{100}-\u{10ffff}]/u.exec(text);
|
||||
return wide && `U+${wide[0].codePointAt(0).toString(16)} at ${wide.index}`;
|
||||
}
|
||||
@@ -19,7 +19,7 @@ export type EditElementResult = {
|
||||
|
||||
export const MAX_EDIT_ENTRIES = 64;
|
||||
export const MAX_EDIT_VALUE = 200_000;
|
||||
const STYLE_NAME = /^(?:-?[a-z][a-z0-9-]*|--[\w\u0080--]+)$/;
|
||||
const STYLE_NAME = /^(?:-?[a-z][a-z0-9-]*|--[\w\u0080-\uffff-]+)$/;
|
||||
const DATA_ATTRIBUTE = /^data-[a-z0-9_-]+$/;
|
||||
const PANEL_ATTRIBUTES = new Set(["loop", "muted", "alt", "title", "src"]);
|
||||
const MEDIA_TAGS = new Set(["img", "video", "audio"]);
|
||||
|
||||
@@ -4,6 +4,7 @@ import { copyFileSync, readFileSync, rmSync } from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { build } from "esbuild";
|
||||
import { firstCharacterThatMakesPagesTwoByte } from "../core/scripts/page-script-one-byte.mjs";
|
||||
import { rewriteRelativeImportExtensions } from "../../scripts/rewrite-relative-import-extensions.mjs";
|
||||
|
||||
const at = (path) => fileURLToPath(new URL(path, import.meta.url));
|
||||
@@ -42,8 +43,16 @@ await Promise.all([
|
||||
bundle: true,
|
||||
platform: "browser",
|
||||
format: "iife",
|
||||
minifyWhitespace: true,
|
||||
}),
|
||||
]);
|
||||
const wide = firstCharacterThatMakesPagesTwoByte(readFileSync(at("./dist/inspection.js"), "utf8"));
|
||||
if (wide) {
|
||||
rmSync(at("./dist/inspection.js"));
|
||||
throw new Error(
|
||||
`dist/inspection.js has ${wide}: every page it joins would be stored at two bytes a character`,
|
||||
);
|
||||
}
|
||||
// Declarations keep the packages/ layout under dist/types, so their relative imports still resolve once packed.
|
||||
rmSync(at("./dist/types"), { recursive: true, force: true });
|
||||
const tsc = createRequire(import.meta.url).resolve("typescript/bin/tsc");
|
||||
|
||||
Reference in New Issue
Block a user