From 0d6b49de575adbe54d843d18882df11820606adf Mon Sep 17 00:00:00 2001 From: Madraka <8898640+Madraka@users.noreply.github.com> Date: Wed, 21 Oct 2026 16:21:03 +0300 Subject: [PATCH] fix(cli): drop wrangler's "(custom domain)" note from deployed URLs Wrangler lists a custom domain target as "cloudhal.com (custom domain)"; deployedUrls turned it into "https://cloudhal.com (custom domain)". A fresh checkout (Workers Builds) then parsed it with new URL() to set the site's domain and failed with "Invalid URL" after both Workers had deployed. Found on cloudhal.com's first CI deploy. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com> --- .changeset/deployed-url-custom-domain.md | 4 ++++ packages/cli/src/cloudflare/wrangler.ts | 13 +++++++++---- packages/cli/test/deployed-urls.test.ts | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 .changeset/deployed-url-custom-domain.md create mode 100644 packages/cli/test/deployed-urls.test.ts diff --git a/.changeset/deployed-url-custom-domain.md b/.changeset/deployed-url-custom-domain.md new file mode 100644 index 00000000..8a9070c5 --- /dev/null +++ b/.changeset/deployed-url-custom-domain.md @@ -0,0 +1,4 @@ +--- +"@cloudhal/cli": patch +--- +`cloudhal deploy` no longer fails with "Invalid URL" after deploying a site with a custom domain from a fresh checkout (Workers Builds): wrangler lists the domain as `example.com (custom domain)`, and the note is now dropped before the address is used. diff --git a/packages/cli/src/cloudflare/wrangler.ts b/packages/cli/src/cloudflare/wrangler.ts index a044dff2..8d86486e 100644 --- a/packages/cli/src/cloudflare/wrangler.ts +++ b/packages/cli/src/cloudflare/wrangler.ts @@ -136,8 +136,13 @@ export async function must( /** URLs of a deployed Worker from wrangler's structured output. */ export function deployedUrls(records: Record[]): string[] { - return records - .filter((r) => r.type === "deploy") - .flatMap((r) => (Array.isArray(r.targets) ? (r.targets as string[]) : [])) - .map((t) => (t.startsWith("http") ? t : `https://${t}`)); + return ( + records + .filter((r) => r.type === "deploy") + .flatMap((r) => (Array.isArray(r.targets) ? (r.targets as string[]) : [])) + // Wrangler lists custom domains as "cloudhal.com (custom domain)": keep the hostname only. + .map((t) => t.trim().split(/\s+/)[0] ?? "") + .filter(Boolean) + .map((t) => (t.startsWith("http") ? t : `https://${t}`)) + ); } diff --git a/packages/cli/test/deployed-urls.test.ts b/packages/cli/test/deployed-urls.test.ts new file mode 100644 index 00000000..45b39378 --- /dev/null +++ b/packages/cli/test/deployed-urls.test.ts @@ -0,0 +1,24 @@ +import { describe, expect, it } from "vitest"; +import { deployedUrls } from "../src/cloudflare/wrangler.ts"; + +describe("deployedUrls", () => { + it("turns wrangler's deploy targets into URLs", () => { + const records = [ + { type: "wrangler-session" }, + { + type: "deploy", + targets: ["cloudhal-com-admin.example.workers.dev", "https://x.example.com"], + }, + ]; + expect(deployedUrls(records)).toEqual([ + "https://cloudhal-com-admin.example.workers.dev", + "https://x.example.com", + ]); + }); + + it("keeps only the hostname of a custom domain target (a fresh CI checkout parses it)", () => { + const urls = deployedUrls([{ type: "deploy", targets: ["cloudhal.com (custom domain)"] }]); + expect(urls).toEqual(["https://cloudhal.com"]); + expect(new URL(urls[0] as string).hostname).toBe("cloudhal.com"); + }); +});