From b30aaa26d5ad9ad6ba5e4c02ecbc797e2b7b8efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 24 Nov 2026 20:14:45 +0000 Subject: [PATCH] fix(cli): add says why a project's registry was not read (#8754) * fix(cli): add says why a project's registry was not read * test(cli): the registry-reason test typechecks --- packages/cli/src/registry/resolver.test.ts | 13 +++++++++++++ packages/cli/src/registry/resolver.ts | 20 +++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/registry/resolver.test.ts b/packages/cli/src/registry/resolver.test.ts index ba4e448902..a65e006b03 100644 --- a/packages/cli/src/registry/resolver.test.ts +++ b/packages/cli/src/registry/resolver.test.ts @@ -235,6 +235,19 @@ describe("registry resolver", () => { await expect(resolveItem("alpha", { baseUrl })).rejects.toThrow(/unreachable/); }); + // fails without the fix: the reason was dropped and the message said it contacted a host it never reached + it("says why a registry on a private address was not read", async () => { + const fetch = vi.fn(); + vi.stubGlobal("fetch", fetch); + const resolved = resolveItemWithDependencies("alpha", { + baseUrl: "https://127.0.0.1:9/registry", + publicOnly: true, + }); + await expect(resolved).rejects.toThrow("127.0.0.1:9 is not a public address"); + await expect(resolved).rejects.not.toThrow(/contacted/i); + expect(fetch).not.toHaveBeenCalled(); + }); + it("refuses an item that declares registryDependencies", async () => { mockFetch({ dependencies: { beta: ["alpha"] } }); const baseUrl = uniqueBaseUrl(); diff --git a/packages/cli/src/registry/resolver.ts b/packages/cli/src/registry/resolver.ts index 83092a6fd0..a5983873e0 100644 --- a/packages/cli/src/registry/resolver.ts +++ b/packages/cli/src/registry/resolver.ts @@ -10,7 +10,12 @@ import { type RegistryItem, type RegistryManifestEntry, } from "@hyperframes/core"; -import { fetchItemManifest, fetchRegistryManifest, DEFAULT_REGISTRY_URL } from "./remote.js"; +import { + fetchItemManifest, + fetchRegistryManifest, + readRegistryManifest, + DEFAULT_REGISTRY_URL, +} from "./remote.js"; import { runWithConcurrencyLimit } from "../utils/concurrency.js"; import { closestNames } from "../utils/didYouMean.js"; @@ -129,7 +134,7 @@ export async function resolveItem( export function unreachableRegistryMessage(name: string, baseUrl?: string): string { const where = baseUrl && !baseUrl.startsWith(DEFAULT_REGISTRY_URL) - ? ` Contacted ${baseUrl}, set by this project's hyperframes.json, not the public registry.` + ? ` The registry is ${baseUrl}, set by this project's hyperframes.json, not the public one.` : ""; return `Item "${name}" not found — registry unreachable or empty.${where}`; } @@ -153,7 +158,16 @@ export async function resolveItemWithDependencies( name: string, options: ResolveOptions = {}, ): Promise { - const entries = await listRegistryItems(undefined, options); + const manifest = await readRegistryManifest(options.baseUrl ?? DEFAULT_REGISTRY_URL, { + skipCache: options.skipCache, + publicOnly: options.publicOnly, + }).catch((error: unknown) => { + const why = error instanceof Error ? error.message : String(error); + throw new Error(`${unreachableRegistryMessage(name, options.baseUrl)} ${why}`, { + cause: error, + }); + }); + const entries = manifest.items; const entry = entries.find((e) => e.name === name); if (!entry) { const available = entries.map((e) => e.name).join(", ");