Skip to content

feat(functions): implement Edge Function management system#20

Merged
weroperking merged 1 commit intomainfrom
docs/enhanced-codebase-documentation
Feb 22, 2026
Merged

feat(functions): implement Edge Function management system#20
weroperking merged 1 commit intomainfrom
docs/enhanced-codebase-documentation

Conversation

@weroperking
Copy link
Copy Markdown
Owner

@weroperking weroperking commented Feb 22, 2026

Summary

Implements an Edge Function management system with CLI commands for creating, developing, building, listing, logging, and deploying edge functions.

Changes

  • Add CLI commands: create, dev, build, list, logs, deploy
  • Implement Bun-based bundling for Cloudflare Workers and Vercel Edge
  • Add environment variable synchronization
  • Fix critical Vercel deployment bug (bundle path not passed)
  • Fix secret values being logged to console
  • Fix incorrect fallback URL in Cloudflare deployment

Files Changed

  • packages/cli/src/index.ts - Added function command registration
  • packages/cli/src/commands/function.ts - CLI command implementations
  • packages/core/src/functions/index.ts - Module exports
  • packages/core/src/functions/bundler.ts - Bundling logic
  • packages/core/src/functions/deployer.ts - Deployment logic

Summary by CodeRabbit

  • New Features
    • Added edge function management commands: create, dev, build, list, logs, and deploy.
    • Enabled local development with hot-reload support for edge functions.
    • Added deployment support for Cloudflare Workers and Vercel platforms.
    • Implemented environment variable synchronization during deployment via --sync-env flag.

- Add CLI commands: create, dev, build, list, logs, deploy
- Implement Bun-based bundling for Cloudflare Workers and Vercel Edge
- Add environment variable synchronization
- Fix critical Vercel deployment bug (bundle path not passed)
- Fix secret values being logged to console
- Fix incorrect fallback URL in Cloudflare deployment
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 22, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR introduces a complete edge function workflow for the CLI and supporting core utilities. It adds CLI commands to create, develop, build, list, query logs, and deploy serverless functions with support for Cloudflare Workers and Vercel Edge Runtime, including environment variable synchronization and hot-reload development capabilities.

Changes

Cohort / File(s) Summary
CLI Command Implementation
packages/cli/src/commands/function.ts
New 432-line module implementing runFunctionCommand that orchestrates all function lifecycle operations: create (scaffolding), dev (hot-reload via Bun), build (bundling), list (with build status), logs (platform-specific fetching), and deploy (with optional env sync). Maintains internal process tracking and port allocation for dev servers.
CLI Routing
packages/cli/src/index.ts
Adds top-level "function" namespace with subcommands (create, dev, build, list, logs, deploy) that route to runFunctionCommand with appropriate argument passing and --sync-env flag support for deployments.
Core Bundler
packages/core/src/functions/bundler.ts
New 222-line module providing bundleFunction (Bun-based bundling to ES modules), readFunctionConfig (regex-based config parsing), listFunctions (discovers all functions), and isFunctionBuilt (checks build output). Exports BundleResult, FunctionConfig, and FunctionInfo types.
Core Deployer
packages/core/src/functions/deployer.ts
New 335-line module implementing deployToCloudflare and deployToVercel with wrangler/vercel CLI integration, syncEnvToCloudflare/syncEnvToVercel for environment variable management, and getCloudflareLogs/getVercelLogs for log retrieval. Includes CLI presence validation and wrangler.toml generation.
Core Module Exports
packages/core/src/functions/index.ts
Replaces stub with re-exports from bundler and deployer modules, exposing all public APIs.
Template Documentation
templates/base/src/functions/.gitkeep
Placeholder file with usage guidance for the edge functions directory structure and available CLI commands.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant CLI as CLI
    participant Bundler as Bundler
    participant Deployer as Deployer
    participant Wrangler as Wrangler
    participant Vercel as Vercel
    participant Env as Env Sync

    User->>CLI: runFunctionCommand('deploy', name)
    activate CLI
    
    CLI->>Bundler: bundleFunction(name)
    activate Bundler
    Bundler->>Bundler: read config.ts
    Bundler->>Bundler: Bun.build entry
    Bundler-->>CLI: BundleResult
    deactivate Bundler
    
    CLI->>Bundler: readFunctionConfig(name)
    Bundler-->>CLI: FunctionConfig
    
    alt runtime is cloudflare-workers
        CLI->>Deployer: deployToCloudflare(name, bundle, config)
        activate Deployer
        Deployer->>Deployer: generateWranglerToml()
        Deployer->>Wrangler: spawn wrangler deploy
        Wrangler-->>Deployer: deployment output
        Deployer-->>CLI: DeployResult
        deactivate Deployer
        
        alt syncEnv enabled
            CLI->>Env: syncEnvToCloudflare(name, config)
            activate Env
            Env->>Wrangler: wrangler secret put (per env var)
            Wrangler-->>Env: success
            Env-->>CLI: sync status
            deactivate Env
        end
    else runtime is vercel-edge
        CLI->>Deployer: deployToVercel(name, bundle, config)
        activate Deployer
        Deployer->>Vercel: spawn vercel deploy
        Vercel-->>Deployer: deployment output
        Deployer-->>CLI: DeployResult
        deactivate Deployer
    end
    
    CLI->>User: Report deployment URL
    deactivate CLI
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~55 minutes

Possibly related PRs

  • feat: add new changes for BetterBase #11: Implements the edge functions bundler and deployer modules that fill in previously stubbed function APIs and core surface integrations used by this CLI workflow.

Poem

🐰 Hop, bundle, deploy with glee,
Functions dance from edge to thee,
Cloudflare and Vercel both in sight,
Environment vars sync just right,
CLI commands make it tight!

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docs/enhanced-codebase-documentation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@weroperking weroperking merged commit 7ef67de into main Feb 22, 2026
1 check was pending
@coderabbitai coderabbitai Bot mentioned this pull request Mar 24, 2026
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.

1 participant