Skip to content

fix(cli): serve edge functions offline by bundling the runtime template#5678

Merged
jgoux merged 2 commits into
developfrom
claude/crazy-robinson-bcb801
Jun 24, 2026
Merged

fix(cli): serve edge functions offline by bundling the runtime template#5678
jgoux merged 2 commits into
developfrom
claude/crazy-robinson-bcb801

Conversation

@jgoux

@jgoux jgoux commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What

Makes supabase functions serve start fully offline. The edge-runtime bootstrap template (apps/cli/src/shared/functions/serve.main.ts) imported three modules that Deno resolved over the network on every container start:

  • https://deno.land/std/http/status.ts
  • https://deno.land/std/path/posix/mod.ts
  • jsr:@panva/jose@6

With no network these fail to resolve and the worker never boots — the offline failure reported in supabase/supabase#45570.

How

The two deno.land/std imports are trivially eliminable; jose is the only real dependency. So:

  • Inline the std depsSTATUS_CODE/STATUS_TEXT and posix join/dirname/toFileUrl move into a new, normally-typed, unit-tested serve-main-deps.ts (the template imports it relatively).
  • Bundle jose locally — a new serve-main-bundler.ts uses esbuild (platform: browser → jose's Web Crypto build) to bundle serve.main.ts into a single self-contained ES module with jose and the helpers inlined. Deno/EdgeRuntime stay as free globals.
  • Delivery is unchanged in shape — compiled binaries embed the pre-bundled template via the existing SUPABASE_FUNCTIONS_SERVE_MAIN_TEMPLATE define (now produced by the bundler in build.ts and the new build-binary.ts used by build:next/build:legacy). Running from source bundles on demand via a lazy import, so esbuild is never loaded by shipped binaries. The container launch path (heredoc → /root/index.ts, edge-runtime start --main-service=/root) is untouched — only the template contents differ.

Why this approach (and not a pre-bundled eszip)

The edge-functions team suggested shipping the template as a pre-bundled eszip (as hosted ef-ingress does). That works, but for the CLI it couples the eszip to a single edge-runtime version while users can override edge_runtime.image / supabase/.temp/edge-runtime-version, and it adds a Docker bundling step to every release. Local bundling avoids both: no version coupling, no release-pipeline change, and the template stays readable source. jose is explicitly cross-runtime (Web Crypto), confirmed running under edge-runtime:v1.74.1's Deno.

Scope

  • Only the legacy TS native serve is affected — functions serve is ported, so the Go template is not on the released path, and the next/packages/stack local-dev path already has a remote-import-free bootstrap.
  • This fixes the runtime bootstrap. User functions with their own remote imports still fetch on first run (Deno-cached after); the edge-runtime image itself must also be pulled online once.

Closes supabase/supabase#45570

The edge-runtime bootstrap template (`serve.main.ts`) imported `deno.land/std`
and `jsr:@panva/jose` modules that Deno resolved over the network on every
container start, so `supabase functions serve` failed offline even after the
images had been pulled (supabase/supabase#45570).

Inline the two trivial std deps (status codes + posix path helpers) into a
local, unit-tested module, and bundle `jose` (npm) into the template via esbuild
so the runtime entrypoint is fully self-contained. Compiled binaries embed the
pre-bundled template through the existing `SUPABASE_FUNCTIONS_SERVE_MAIN_TEMPLATE`
define; running from source bundles on demand. The container launch path is
unchanged — only the heredoc'd template contents differ.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jgoux jgoux requested a review from a team as a code owner June 24, 2026 09:49
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@383b5bcaf7f8d3b2746c7f19f0806ee18c609fbc

Preview package for commit 383b5bc.

Boot the bundled serve.main.ts template under edge-runtime with `--network none`
and assert it reaches the "Serving functions" log line with no remote module
resolution. This codifies the supabase/supabase#45570 regression contract — a
control run of the unbundled template fails here with a DNS error.

Skips when Docker is unavailable. Exports `LEGACY_EDGE_RUNTIME_IMAGE` so the test
pins the same image the CLI uses.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jgoux jgoux enabled auto-merge June 24, 2026 12:10
@jgoux jgoux added this pull request to the merge queue Jun 24, 2026
Merged via the queue into develop with commit 89e3ccd Jun 24, 2026
20 checks passed
@jgoux jgoux deleted the claude/crazy-robinson-bcb801 branch June 24, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Supabase fails to run offline without an internet connection

2 participants