Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/registry/src/version-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ describe("discoverVersions", () => {
);
});

it("fetches hex versions and filters to defined ranges", async () => {
const hexDef: VersionedDefinition = {
...mockDefinition,
name: "phoenix",
registry: "hex",
};

const mockFetch = vi.mocked(fetch);
mockFetch.mockResolvedValueOnce({
ok: true,
json: async () => ({
releases: [
{ version: "1.7.0", inserted_at: "2024-06-01T00:00:00Z" },
{ version: "1.6.0", inserted_at: "2024-03-01T00:00:00Z" },
{ version: "1.5.0", inserted_at: "2024-01-01T00:00:00Z" },
],
}),
} as Response);

const versions = await discoverVersions(hexDef);

expect(versions.map((v) => v.version)).toEqual(["1.7.0", "1.6.0", "1.5.0"]);
expect(mockFetch).toHaveBeenCalledWith(
expect.stringContaining("hex.pm/api/packages/phoenix"),
);
});

it("throws for unsupported registry", async () => {
const def = { ...mockDefinition, registry: "cargo" };
await expect(discoverVersions(def)).rejects.toThrow(
Expand Down
26 changes: 25 additions & 1 deletion packages/registry/src/version-check.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Version discovery from package registry APIs (npm, pip, maven).
* Version discovery from package registry APIs (npm, pip, maven, hex).
*
* Queries public registry APIs to find available versions,
* filters to defined ranges, and deduplicates to latest-patch-per-minor.
Expand Down Expand Up @@ -32,6 +32,7 @@ const registryFetchers: Record<string, RegistryFetcher> = {
npm: fetchNpmVersions,
pip: fetchPipVersions,
maven: fetchMavenVersions,
hex: fetchHexVersions,
};

/**
Expand Down Expand Up @@ -196,6 +197,29 @@ async function fetchMavenVersions(packageName: string): Promise<VersionInfo[]> {
}));
}

/**
* Fetch versions from Hex.pm API.
* Package names are lowercase with underscores (e.g., "phoenix", "phoenix_live_view").
*/
async function fetchHexVersions(packageName: string): Promise<VersionInfo[]> {
const res = await fetchWithRetry(
`https://hex.pm/api/packages/${encodeURIComponent(packageName)}`,
`Hex`,
packageName,
);

const data = (await res.json()) as {
releases?: Array<{ version?: string; inserted_at?: string }>;
};

const releases = data.releases ?? [];

return releases.map((r) => ({
version: r.version ?? "",
publishedAt: r.inserted_at,
}));
}

/**
* Public registries occasionally return 504/503 under load. Retry 5xx and
* network errors with exponential backoff; 4xx aborts immediately.
Expand Down
8 changes: 8 additions & 0 deletions registry/hex/elixir.yaml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib/ is mostly Elixir source, not docs. The build filters to .md/.mdx/etc, so this'll scrape stray markdown rather than the real guides, which live in lib/elixir/pages/. Can you double-check what ends up in the built package? docs_path: lib/elixir/pages is probably what you want.


Generated by Claude Code

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: elixir
description: "A dynamic, functional language for building scalable and maintainable applications"
repository: https://github.com/elixir-lang/elixir

source:
type: git
url: https://github.com/elixir-lang/elixir
docs_path: lib/elixir/pages
11 changes: 11 additions & 0 deletions registry/hex/phoenix.yaml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two entries are identical apart from the range. I checked guides/ at both v1.5.0 and v1.7.0 — same path, same v{version} tag scheme on both sides. So the split doesn't actually change anything at build time.

Can we collapse it to one?

versions:
  - min_version: "1.5.0"
    source:
      type: git
      url: https://github.com/phoenixframework/phoenix
      docs_path: guides
    tag_pattern: "v{version}"

Generated by Claude Code

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: phoenix
description: "A productive web framework for building modern web applications in Elixir"
repository: https://github.com/phoenixframework/phoenix

versions:
- min_version: "1.5.0"
source:
type: git
url: https://github.com/phoenixframework/phoenix
docs_path: guides
tag_pattern: "v{version}"
11 changes: 11 additions & 0 deletions registry/hex/phoenix_live_view.yaml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here. guides/ is there at both v0.17.0 and v0.20.0 with the same path and tag scheme, so the two entries are doing the same job. Let's fold them into one:

versions:
  - min_version: "0.17.0"
    source:
      type: git
      url: https://github.com/phoenixframework/phoenix_live_view
      docs_path: guides
    tag_pattern: "v{version}"

Generated by Claude Code

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: phoenix_live_view
description: "Rich, real-time user experiences with server-rendered HTML in Elixir"
repository: https://github.com/phoenixframework/phoenix_live_view

versions:
- min_version: "0.17.0"
source:
type: git
url: https://github.com/phoenixframework/phoenix_live_view
docs_path: guides
tag_pattern: "v{version}"
Loading