mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-11 23:00:03 +00:00
fix(cli): resolve and install transitive registry dependencies (#1396)
* fix(cli): resolve and install transitive registry dependencies `hyperframes add`, `hyperframes new` (fetchRemoteTemplate), and the studio "add block" path each resolved a single registry item and silently dropped any `registryDependencies` it declared. Add `resolveItemWithDependencies` (DFS topological sort, cycle detection, missing-dependency errors, and dedup of shared/diamond deps) and route all three install paths through it so dependencies are installed before the item that needs them. `resolveItem` becomes a thin guard that throws on dep-bearing items, so no future caller can silently reintroduce the drop. `runAdd` now returns the ordered `installed` list and compatibility-gates every dependency before any write. Reworks the stale PR #414 onto current main and addresses its review feedback: fetchRemoteTemplate installs deps, no out-of-scope files, dead null-checks dropped, diamond test added, and the deliberate serial-fetch tradeoff is noted. Co-authored-by: Rakibul Islam <40rakib70@gmail.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(cli): make getItem async so missing-dep surfaces as rejection Addresses review nit on #1396: getItem was typed Promise<RegistryItem> but threw synchronously on a missing dependency. Marking it async keeps the control flow consistent with the return type — the throw now becomes a rejection. The body has no await, so the item cache is still populated synchronously on first request and dedup is unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(cli): compatibility-gate transitive deps in all install paths Addresses Via's review on #1396: `assertCompatibleOrThrow` only ran inside `runAdd`, so `fetchRemoteTemplate` (hyperframes new) and the Studio "add block" action installed resolved items — now including transitive dependencies — with no minCliVersion enforcement or deprecation warnings. A pre-existing single-item asymmetry that this PR's dep loops amplify across N items. - Add shared `gateRegistryItemsCompatibility` + `RegistryCompatibilityError` to compatibility.ts; all three install paths now gate the full resolved set before any write. `runAdd` keeps its AddError mapping by wrapping the shared gate. - Surface deprecation warnings from the template/studio paths to stderr. - Extract the studio viewport rewrite into `rewriteWrittenToHostViewport` (also drops redundant dynamic node:fs imports) and document that it intentionally rewrites dep-shipped .html too (Via item 3). - Unit-test the shared gate directly (no fetch/cache flakiness): compatible set, accumulated deprecation warnings, and throw-on-incompatible. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Rakibul Islam <40rakib70@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
Rakibul Islam
parent
583b47b039
commit
8eac7e1cda
@@ -15,6 +15,8 @@ const MANIFEST: RegistryManifest = {
|
||||
{ name: "my-block", type: "hyperframes:block" },
|
||||
{ name: "deprecated-block", type: "hyperframes:block" },
|
||||
{ name: "future-block", type: "hyperframes:block" },
|
||||
{ name: "dep-block", type: "hyperframes:block" },
|
||||
{ name: "base-component", type: "hyperframes:component" },
|
||||
{ name: "my-component", type: "hyperframes:component" },
|
||||
{ name: "my-example", type: "hyperframes:example" },
|
||||
],
|
||||
@@ -90,6 +92,36 @@ const FUTURE_BLOCK_ITEM: RegistryItem = {
|
||||
],
|
||||
};
|
||||
|
||||
const BASE_COMPONENT_ITEM: RegistryItem = {
|
||||
$schema: "https://hyperframes.heygen.com/schema/registry-item.json",
|
||||
name: "base-component",
|
||||
type: "hyperframes:component",
|
||||
title: "Base Component",
|
||||
description: "Base component dependency for tests",
|
||||
files: [
|
||||
{
|
||||
path: "base-component.css",
|
||||
target: "compositions/components/base-component/base-component.css",
|
||||
type: "hyperframes:style",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// A block that declares a transitive registryDependency on base-component.
|
||||
const DEP_BLOCK_ITEM: RegistryItem = {
|
||||
...BLOCK_ITEM,
|
||||
name: "dep-block",
|
||||
title: "Dependent Block",
|
||||
registryDependencies: ["base-component"],
|
||||
files: [
|
||||
{
|
||||
path: "dep-block.html",
|
||||
target: "compositions/dep-block.html",
|
||||
type: "hyperframes:composition",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const EXAMPLE_ITEM: RegistryItem = {
|
||||
$schema: "https://hyperframes.heygen.com/schema/registry-item.json",
|
||||
name: "my-example",
|
||||
@@ -105,6 +137,8 @@ const ITEM_BY_NAME: Record<string, RegistryItem> = {
|
||||
"my-block": BLOCK_ITEM,
|
||||
"deprecated-block": DEPRECATED_BLOCK_ITEM,
|
||||
"future-block": FUTURE_BLOCK_ITEM,
|
||||
"dep-block": DEP_BLOCK_ITEM,
|
||||
"base-component": BASE_COMPONENT_ITEM,
|
||||
"my-component": COMPONENT_ITEM,
|
||||
"my-example": EXAMPLE_ITEM,
|
||||
};
|
||||
@@ -232,6 +266,7 @@ describe("runAdd (integration, mocked registry)", () => {
|
||||
expect(result.name).toBe("my-block");
|
||||
expect(result.type).toBe("hyperframes:block");
|
||||
expect(result.written).toHaveLength(1);
|
||||
expect(result.installed).toEqual(["my-block"]);
|
||||
expect(result.warnings).toEqual([]);
|
||||
expect(existsSync(join(dir, "compositions/my-block.html"))).toBe(true);
|
||||
const installed = readFileSync(join(dir, "compositions/my-block.html"), "utf-8");
|
||||
@@ -303,6 +338,27 @@ describe("runAdd (integration, mocked registry)", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("installs transitive registryDependencies before the requested item", async () => {
|
||||
const dir = tmp();
|
||||
try {
|
||||
writeRegistryConfig(dir);
|
||||
|
||||
const result = await runAdd({ name: "dep-block", projectDir: dir, skipClipboard: true });
|
||||
expect(result.name).toBe("dep-block");
|
||||
// Dependency first, requested item last.
|
||||
expect(result.installed).toEqual(["base-component", "dep-block"]);
|
||||
expect(result.written).toHaveLength(2);
|
||||
expect(
|
||||
existsSync(join(dir, "compositions/components/base-component/base-component.css")),
|
||||
).toBe(true);
|
||||
expect(existsSync(join(dir, "compositions/dep-block.html"))).toBe(true);
|
||||
// Snippet points at the requested block, not the dependency.
|
||||
expect(result.snippet).toContain("compositions/dep-block.html");
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("throws AddError with code 'example-type' when asked to add an example", async () => {
|
||||
const dir = tmp();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user