fix(cli): serve edge functions offline by bundling the runtime template#5678
Merged
Conversation
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>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Supabase CLI previewnpx --yes https://pkg.pr.new/supabase/cli/supabase@383b5bcaf7f8d3b2746c7f19f0806ee18c609fbcPreview package for commit |
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>
Coly010
approved these changes
Jun 24, 2026
This was referenced Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes
supabase functions servestart 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.tshttps://deno.land/std/path/posix/mod.tsjsr:@panva/jose@6With no network these fail to resolve and the worker never boots — the offline failure reported in supabase/supabase#45570.
How
The two
deno.land/stdimports are trivially eliminable;joseis the only real dependency. So:STATUS_CODE/STATUS_TEXTand posixjoin/dirname/toFileUrlmove into a new, normally-typed, unit-testedserve-main-deps.ts(the template imports it relatively).joselocally — a newserve-main-bundler.tsuses esbuild (platform: browser→ jose's Web Crypto build) to bundleserve.main.tsinto a single self-contained ES module withjoseand the helpers inlined.Deno/EdgeRuntimestay as free globals.SUPABASE_FUNCTIONS_SERVE_MAIN_TEMPLATEdefine (now produced by the bundler inbuild.tsand the newbuild-binary.tsused bybuild: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-ingressdoes). That works, but for the CLI it couples the eszip to a single edge-runtime version while users can overrideedge_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.joseis explicitly cross-runtime (Web Crypto), confirmed running underedge-runtime:v1.74.1's Deno.Scope
functions serveisported, so the Go template is not on the released path, and thenext/packages/stacklocal-dev path already has a remote-import-free bootstrap.Closes supabase/supabase#45570