Skip to content

feat: add supabase functions dev#5186

Open
jgoux wants to merge 24 commits intodevelopfrom
codex/cli-functions-dev
Open

feat: add supabase functions dev#5186
jgoux wants to merge 24 commits intodevelopfrom
codex/cli-functions-dev

Conversation

@jgoux
Copy link
Copy Markdown
Contributor

@jgoux jgoux commented May 6, 2026

Add supabase functions dev for the TypeScript CLI runtime

Summary

This PR adds the new TypeScript implementation of supabase functions dev and wires it into the local stack runtime. The command now starts or connects to a managed local Supabase stack, configures Edge Runtime from the project config, serves local functions, watches function/config/env files, and reloads the runtime as files change.

The branch also includes the stack, process orchestration, Docker networking, test infrastructure, and CI fixes that were needed to make the new functions dev path stable across macOS, Windows, and Linux CI.

User-facing behavior

  • Adds supabase functions dev under the next-generation CLI command tree.
  • Starts the full local Supabase stack when a managed stack is not already running.
  • Connects to an existing managed stack when one is already available.
  • Configures Edge Runtime from local project config and function metadata.
  • Supports --env-file, --no-verify-jwt, and --stack.
  • Serves functions from supabase/functions.
  • Watches function source files, config.toml, and env files.
  • Reloads Edge Runtime when config/env changes.
  • Reloads the served function set when function source files change.
  • Streams Edge Runtime logs while the dev command is running.
  • Cleans up the stack it started when the command exits, while leaving pre-existing stacks running.

CLI changes

  • Added the functions dev command implementation:
    • apps/cli/src/next/commands/functions/dev/dev.command.ts
    • apps/cli/src/next/commands/functions/dev/dev.handler.ts
    • apps/cli/src/next/commands/functions/dev/functions-dev-runtime.ts
    • apps/cli/src/next/commands/functions/dev/functions-dev-config.ts
    • apps/cli/src/next/commands/functions/dev/functions-dev-edge-runtime-config.ts
  • Registered the command under the existing functions command group.
  • Added @parcel/watcher to the CLI package.
  • Added a small file watcher service/layer so command runtime code can subscribe to project file changes through Effect services.
  • Updated functions command integration tests to account for the new subcommand.
  • Updated the alpha command structure docs to include functions dev.

Stack runtime changes

  • Added first-class functions runtime configuration support in packages/stack/src/functions.ts.
  • Added a Deno Edge Runtime entrypoint at packages/stack/src/services/edge-runtime-main.ts.
  • The stack now writes a generated Edge Runtime functions config into the runtime workspace.
  • Function runtime config resolution now handles:
    • function discovery
    • enabled/disabled functions
    • per-function verify_jwt
    • import maps
    • static file patterns
    • project env files
    • function-specific env
    • Supabase local URLs and anon/service role keys
    • JWT secret wiring
  • Added stack APIs for:
    • updating functions config
    • clearing functions config
    • reloading Edge Runtime
    • reloading function routes
    • using those operations locally and through the daemon/remote stack boundary
  • Updated stack lifecycle coordination so function and Edge Runtime reloads are part of the managed stack lifecycle instead of being owned only by CLI command code.
  • Exported the new stack functions helpers from the stack package.

Edge Runtime behavior

  • Added a local Edge Runtime main script that:
    • loads generated runtime JSON config
    • exposes an internal health endpoint
    • serves function routes by function slug
    • passes resolved env vars into workers
    • applies import map and static file configuration
    • performs local HS256 JWT verification when verify_jwt is enabled
    • skips JWT verification for disabled functions, OPTIONS, or functions configured with verify_jwt = false
  • Updated the Edge Runtime service wiring so the generated entrypoint and functions config are used by the local stack.

Docker and networking fixes

The new functions dev E2E surfaced Linux-only stack startup problems. This branch removes those OS-specific differences and makes Docker behavior more consistent across all three supported desktop/CI platforms.

  • Linux no longer relies on Docker host networking for the stack path touched by this work.
  • Docker services use normal port publishing and host.docker.internal style host access instead.
  • Updated platform helpers for Docker host address, network arguments, and port map arguments.
  • Updated analytics so it binds to the right container interface/port.
  • Updated pooler port mapping so the selected proxy port is exposed consistently.
  • Tightened native Postgres Docker access detection so Docker host access is only required when native Postgres is actually used alongside Docker services.
  • Updated service tests and stack builder tests around the new networking behavior.

Process orchestration changes

  • Extended packages/process-compose orchestration behavior used by stack reload paths.
  • Added/updated tests for orchestration state, dependency, restart, shutdown, and failure behavior.
  • These changes support reliable Edge Runtime/function reloads without replacing the whole stack process.

E2E and test infrastructure

  • Added an end-to-end functions dev smoke test covering the critical live workflow:
    • start functions dev
    • wait for Edge Runtime readiness
    • create a function while the command is running
    • verify JWT enforcement
    • update config to disable JWT verification
    • verify the function responds
    • update function source
    • verify the changed response is served
  • Added focused unit tests for:
    • functions dev config resolution
    • Edge Runtime config resolution
    • functions dev runtime helpers
    • stack functions runtime config generation
    • stack lifecycle reload behavior
    • Docker platform/networking behavior
  • Improved shared E2E stack helpers:
    • prefetch/warm stack assets before E2E startup
    • reserve ports more consistently
    • stop leaked stack resources during cleanup
    • handle permission issues in temporary project cleanup
    • force-clean runtime artifacts when ordinary cleanup cannot remove them
  • Tightened functions dev E2E timeouts based on observed green CI runtime so real failures surface faster.
  • Made the stack prefetch unit test deterministic when concurrent downloads finish in a different valid order.
  • Fixed a Go migration repair test that could hang in CI by providing the expected cancellation input.

CI fixes

  • Fixed the Go lint job so golangci-lint runs from apps/cli-go, where the Go module lives.
  • Fixed the Go coverage workflow artifact path so it uploads apps/cli-go/coverage.out.

Documentation

  • Updated stack package docs to mention functions runtime behavior.
  • Updated stack architecture docs for the new runtime/reload flow.
  • Updated CLI command structure docs for the new functions dev command.

Notes for reviewers

  • The command intentionally starts the full local stack. It does not special-case a smaller functions-only stack.
  • The Linux networking changes are part of making the full stack behave consistently across CI and local OSes.
  • The debug logging that was added while diagnosing CI failures has been removed now that the stack startup issue is fixed.
  • The functions dev E2E remains intentionally narrow: it is a live smoke test for startup, config reload, source reload, and JWT behavior rather than broad command coverage.

jgoux added 5 commits May 7, 2026 09:02
# Conflicts:
#	apps/cli/package.json
#	apps/cli/src/next/commands/functions/functions.command.ts
#	apps/cli/src/next/commands/functions/new/new.integration.test.ts
#	pnpm-lock.yaml
@jgoux jgoux marked this pull request as ready for review May 7, 2026 07:49
@jgoux jgoux requested a review from a team as a code owner May 7, 2026 07:49
Comment thread packages/stack/tests/createStack.e2e.test.ts Dismissed
@coveralls
Copy link
Copy Markdown

coveralls commented May 7, 2026

Coverage Report for CI Build 25506471648

Warning

No base build found for commit ef1b13a on develop.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 63.726%

Details

  • Patch coverage: No coverable lines changed in this PR.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 15675
Covered Lines: 9989
Line Coverage: 63.73%
Coverage Strength: 7.06 hits per line

💛 - Coveralls

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.

4 participants