mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
fix: make registry blocks pass lint errors (#564)
This commit is contained in:
@@ -181,9 +181,9 @@ describe("runAdd (integration, mocked registry)", () => {
|
||||
expect(result.type).toBe("hyperframes:block");
|
||||
expect(result.written).toHaveLength(1);
|
||||
expect(existsSync(join(dir, "compositions/my-block.html"))).toBe(true);
|
||||
expect(readFileSync(join(dir, "compositions/my-block.html"), "utf-8")).toContain(
|
||||
"my-block.html",
|
||||
);
|
||||
const installed = readFileSync(join(dir, "compositions/my-block.html"), "utf-8");
|
||||
expect(installed).toContain("<!-- hyperframes-registry-item: my-block -->");
|
||||
expect(installed).toContain("my-block.html");
|
||||
expect(result.snippet).toContain("compositions/my-block.html");
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* runtime to reject traversal even if the registry JSON schema was bypassed.
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { resolve, relative, isAbsolute } from "node:path";
|
||||
import type { FileTarget, RegistryItem } from "@hyperframes/core";
|
||||
import { fetchItemFile, DEFAULT_REGISTRY_URL } from "./remote.js";
|
||||
@@ -45,6 +46,22 @@ export function assertSafeTarget(destDir: string, target: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
function isInstalledRegistryBlockComposition(item: RegistryItem, file: FileTarget): boolean {
|
||||
return (
|
||||
item.type === "hyperframes:block" &&
|
||||
file.type === "hyperframes:composition" &&
|
||||
file.target.toLowerCase().endsWith(".html")
|
||||
);
|
||||
}
|
||||
|
||||
function addRegistryItemMarker(source: string, item: RegistryItem): string {
|
||||
if (/^\s*<!--\s*hyperframes-registry-item:[^>]*-->/i.test(source.slice(0, 512))) {
|
||||
return source;
|
||||
}
|
||||
|
||||
return `<!-- hyperframes-registry-item: ${item.name} -->\n${source}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install a resolved `RegistryItem` into `destDir` by fetching each file in
|
||||
* parallel and writing it to its validated target path.
|
||||
@@ -65,6 +82,10 @@ export async function installItem(
|
||||
item.files.map(async (file: FileTarget) => {
|
||||
const destPath = resolve(destDir, file.target);
|
||||
await fetchItemFile(item, file, destPath, baseUrl);
|
||||
if (isInstalledRegistryBlockComposition(item, file)) {
|
||||
const source = readFileSync(destPath, "utf-8");
|
||||
writeFileSync(destPath, addRegistryItemMarker(source, item), "utf-8");
|
||||
}
|
||||
return destPath;
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user