mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 16:37:32 +00:00
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
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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<RegistryItem[]> {
|
||||
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(", ");
|
||||
|
||||
Reference in New Issue
Block a user