From 3408057eb3ea10c233a023d933c11ec2d0799518 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 21 Nov 2026 16:14:50 -0800 Subject: [PATCH] Serve moq.dev/moq-ffi from the go.moq.dev module proxy The /moq-ffi vanity page now answers with a mod go-import tag pointing at https://go.moq.dev and drops its go-source tag, since no repo holds the module. /moq is unchanged. Co-Authored-By: Claude Opus 5.5 --- worker/vanity.test.ts | 13 ++++++++----- worker/vanity.ts | 37 ++++++++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/worker/vanity.test.ts b/worker/vanity.test.ts index 4815c5c4..25398700 100644 --- a/worker/vanity.test.ts +++ b/worker/vanity.test.ts @@ -16,14 +16,17 @@ describe("vanity", () => { // The go command asks about the full import path, so the prefix in the tag // has to stay the module path rather than what was requested. const res = goGet("/moq-ffi/moq"); - expect(await res?.text()).toContain( - ``, - ); + expect(await res?.text()).toContain(``); + }); + + test("links source only for a module in a repo", async () => { + expect(await goGet("/moq")?.text()).toContain(` { - expect(await goGet("/moq-ffi")?.text()).toContain("moq-go-ffi"); - expect(await goGet("/moq")?.text()).not.toContain("moq-go-ffi"); + expect(await goGet("/moq-ffi")?.text()).toContain("go.moq.dev"); + expect(await goGet("/moq")?.text()).not.toContain("go.moq.dev"); }); test("sends people to the docs", () => { diff --git a/worker/vanity.ts b/worker/vanity.ts index 3ef82580..108c58fb 100644 --- a/worker/vanity.ts +++ b/worker/vanity.ts @@ -8,13 +8,22 @@ * instead of a breaking change for everyone who imported it. */ -/** A published module: the path it answers to, and the repo behind it. */ -interface Module { +/** A published module: the path it answers to, and where the go command fetches it. */ +type Module = { /** Path on this host, which is also the module path in its `go.mod`. */ dir: string; - /** Repo the go command clones. */ - repo: string; -} +} & ( + | { + vcs: "git"; + /** Repo the go command clones. */ + repo: string; + } + | { + vcs: "mod"; + /** Module proxy (GOPROXY protocol) the go command downloads zips from, for a module no repo holds. */ + proxy: string; + } +); /** * The host the modules are published under. @@ -27,8 +36,9 @@ const HOST = "moq.dev"; /** Every module published under HOST. */ const MODULES: Module[] = [ - { dir: "/moq", repo: "https://github.com/moq-dev/moq-go" }, - { dir: "/moq-ffi", repo: "https://github.com/moq-dev/moq-go-ffi" }, + { dir: "/moq", vcs: "git", repo: "https://github.com/moq-dev/moq-go" }, + // Prebuilt static libraries, kept out of git. See infra/go in moq-dev/moq. + { dir: "/moq-ffi", vcs: "mod", proxy: "https://go.moq.dev" }, ]; /** The go-get response for a vanity path, or undefined to serve the request normally. */ @@ -53,18 +63,23 @@ export function vanity(url: URL): Response | undefined { function page(module: Module): string { const path = HOST + module.dir; + const origin = module.vcs === "git" ? module.repo : module.proxy; // go-import is the one the go command needs. go-source is what pkg.go.dev - // follows to link a symbol back to the line that declares it. + // follows to link a symbol back to the line that declares it, so only a + // module in a repo has one. + const source = + module.vcs === "git" + ? `\n\t\t` + : ""; return ` - - + ${source} - ${path} is served from ${module.repo}. + ${path} is served from ${origin}. `;