Skip to content

Commit 60f1fa6

Browse files
authored
Merge pull request #12 from Gladium-AI/codex/js-worker-runtime-support
Add native JavaScript Worker runtime support
2 parents d67112b + f328287 commit 60f1fa6

22 files changed

Lines changed: 596 additions & 112 deletions

File tree

README.md

Lines changed: 65 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
[![Go Version](https://img.shields.io/badge/Go-1.26.0-00ADD8?logo=go)](https://go.dev/)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
55

6-
`flare-edge-cli` scaffolds, validates, builds, deploys, tails, and tears down Go-for-Wasm Cloudflare Workers projects. It generates the Worker shim and Wrangler config, runs compatibility checks against a Workers/Wasm profile, and delegates Cloudflare operations to Wrangler and Cloudflare APIs where appropriate.
6+
`flare-edge-cli` scaffolds, validates, builds, deploys, tails, and tears down Cloudflare Workers projects. It supports both Go-for-Wasm Workers and native JavaScript module Workers, generates Wrangler config, runs Go compatibility checks where appropriate, and delegates Cloudflare operations to Wrangler and Cloudflare APIs where appropriate.
77

8-
This CLI is designed first for AI agents. Humans can use it directly, but the primary goal is to give coding agents a stable, scriptable control surface for creating and operating Cloudflare edge functions and lightweight microservices in Go.
8+
This CLI is designed first for AI agents. Humans can use it directly, but the primary goal is to give coding agents a stable, scriptable control surface for creating and operating Cloudflare edge functions and lightweight microservices in Go or native JavaScript.
99

1010
## Why This Tool Exists
1111

12-
`flare-edge-cli` exists to standardize the end-to-end agent workflow for Go on Cloudflare:
12+
`flare-edge-cli` exists to standardize the end-to-end agent workflow for Cloudflare Workers:
1313

1414
- scaffold a deployable project with deterministic structure
1515
- validate whether the Go code fits Workers/Wasm constraints
16-
- build the `.wasm` artifact and Worker shim correctly every time
16+
- build the `.wasm` artifact and Worker shim correctly for Go projects
17+
- stage native JavaScript Worker entrypoints without changing the deploy flow
1718
- provision and manage Cloudflare resources through one consistent interface
1819
- emit machine-readable output that agents can inspect and chain into later actions
1920
- tear down remote and local side effects when an ephemeral environment is no longer needed
@@ -29,7 +30,7 @@ The intended operator is usually an AI agent acting on behalf of a developer. Be
2930

3031
## Primary Use Case
3132

32-
The primary use case is simple: an AI agent needs a standard way to create and deploy an edge function or small microservice on Cloudflare using Go without rebuilding the same scaffolding, compatibility analysis, build orchestration, deployment logic, and cleanup flow for every task.
33+
The primary use case is simple: an AI agent needs a standard way to create and deploy an edge function or small microservice on Cloudflare without rebuilding the same scaffolding, compatibility analysis, build orchestration, deployment logic, and cleanup flow for every task.
3334

3435
This means `flare-edge-cli` is not just a deploy wrapper. It is an agent-oriented execution surface for:
3536

@@ -43,9 +44,10 @@ This means `flare-edge-cli` is not just a deploy wrapper. It is an agent-oriente
4344

4445
## What It Does
4546

46-
- Scaffolds Go Worker projects with a reproducible layout
47+
- Scaffolds Go/Wasm and native JavaScript Worker projects with a reproducible layout
4748
- Validates Go code against a Workers/Wasm compatibility profile
48-
- Builds `.wasm` artifacts and the JavaScript Worker shim
49+
- Builds `.wasm` artifacts and the JavaScript Worker shim for Go projects
50+
- Stages native JavaScript Worker entrypoints for deploy, route, and doctor workflows
4951
- Runs local or remote dev sessions through Wrangler
5052
- Configures Workers AI bindings for Go-based AI Workers
5153
- Deploys versioned Workers and manages routes, secrets, KV, D1, R2, and releases
@@ -65,10 +67,11 @@ The implementation is intentionally biased toward agent use:
6567

6668
## Requirements
6769

68-
- Go `1.26.0`
70+
- Go `1.26.0` for Go/Wasm projects
6971
- [Wrangler](https://developers.cloudflare.com/workers/wrangler/) installed and available on `PATH`
7072
- Cloudflare authentication already configured through Wrangler or an API token
7173
- Optional: TinyGo for `--tinygo` builds
74+
- Optional: Cloudflare `nodejs_compat` compatibility flag for JavaScript Workers via `project init --node-compat`
7275

7376
## Install
7477

@@ -123,12 +126,18 @@ go run ./cmd/flare-edge-cli --help
123126

124127
## Typical Workflow
125128

126-
Initialize a project:
129+
Initialize a Go project:
127130

128131
```bash
129132
./flare-edge-cli project init my-worker --module-path github.com/example/my-worker
130133
```
131134

135+
Initialize a JavaScript Worker:
136+
137+
```bash
138+
./flare-edge-cli project init my-js-worker --runtime js
139+
```
140+
132141
Check compatibility:
133142

134143
```bash
@@ -161,7 +170,9 @@ Clean everything up later:
161170

162171
## Generated Project Layout
163172

164-
`project init` creates a Go Worker project with these important files:
173+
`project init` creates runtime-specific Worker projects.
174+
175+
Go/Wasm projects:
165176

166177
```text
167178
<project>/
@@ -182,17 +193,29 @@ Important generated paths:
182193
- `dist/app.wasm`: compiled artifact after build
183194
- `dist/worker.mjs`: Worker shim after build
184195

196+
JavaScript projects:
197+
198+
```text
199+
<project>/
200+
flare-edge.json
201+
wrangler.jsonc
202+
src/worker.mjs
203+
README.md
204+
.gitignore
205+
```
206+
185207
## Configuration Files
186208

187209
### `flare-edge.json`
188210

189211
This is the CLI’s typed project metadata file. It tracks:
190212

191213
- project and module names
192-
- Go entrypoint
214+
- runtime, entrypoint, and deployed main module
193215
- output directory and artifact names
194216
- Worker name
195217
- compatibility date and profile
218+
- optional Node.js compatibility flag
196219
- bindings for KV, D1, R2, vars, and secrets
197220
- generated shim metadata
198221

@@ -254,12 +277,13 @@ Notes:
254277
Create and inspect projects.
255278

256279
```bash
257-
./flare-edge-cli project init <name> [--cwd <dir>] [--module-path <go_module>] [--package <pkg>] [--template <name>] [--compat-date <YYYY-MM-DD>] [--env <name>] [--use-jsonc] [--with-git] [--yes]
280+
./flare-edge-cli project init <name> [--cwd <dir>] [--runtime go|js] [--module-path <module>] [--package <pkg>] [--template <name>] [--compat-date <YYYY-MM-DD>] [--node-compat] [--env <name>] [--use-jsonc] [--with-git] [--yes]
258281
./flare-edge-cli project info [--cwd <dir>] [--json] [--show-generated] [--show-bindings]
259282
```
260283

261284
Supported templates:
262285

286+
- `js-worker`
263287
- `edge-http`
264288
- `edge-json`
265289
- `scheduled`
@@ -284,6 +308,11 @@ AI templates:
284308
- `ai-image`: text-to-image scaffold using `@cf/black-forest-labs/flux-2-klein-9b`
285309
- `ai-embeddings`: embeddings scaffold using `@cf/qwen/qwen3-embedding-0.6b`
286310

311+
Notes:
312+
313+
- `--runtime js` defaults to the `js-worker` template
314+
- `--node-compat` only adds Wrangler's `nodejs_compat` compatibility flag; it does not switch the runtime to Node.js automatically
315+
287316
### `ai`
288317

289318
Manage the Workers AI binding stored in local project config.
@@ -304,15 +333,15 @@ Notes:
304333
Run the Go/Wasm compatibility analyzer or inspect built-in rules.
305334

306335
```bash
307-
./flare-edge-cli compat check [--path <dir>] [--entry <pkg-or-file>] [--profile worker-wasm] [--strict] [--json] [--sarif] [--fail-on warning|error] [--exclude <glob>]
336+
./flare-edge-cli compat check [--path <dir>] [--entry <pkg-or-file>] [--profile <name>] [--strict] [--json] [--sarif] [--fail-on warning|error] [--exclude <glob>]
308337
./flare-edge-cli compat rules [--json] [--severity error|warning|info]
309338
```
310339

311-
Diagnostics include structured fields such as rule ID, severity, file, line, message, why, and fix hint.
340+
Diagnostics include structured fields such as rule ID, severity, file, line, message, why, and fix hint. JavaScript Worker projects skip Go static analysis and return an empty result.
312341

313342
### `build`
314343

315-
Compile Go to Wasm and inspect artifacts.
344+
Build Go/Wasm projects or stage JavaScript Workers for deploy.
316345

317346
```bash
318347
./flare-edge-cli build [--path <dir>] [--entry <pkg-or-file>] [--out-dir <dir>] [--out-file <file.wasm>] [--shim-out <file>] [--target js/wasm] [--optimize size|speed] [--tinygo] [--no-shim] [--clean] [--json]
@@ -326,6 +355,8 @@ The build writes:
326355
- `dist/worker.mjs`
327356
- `dist/wasm_exec.js`
328357

358+
For JavaScript projects, `build` validates that the configured Worker entrypoint exists and returns it without compiling. `build wasm` remains the explicit Go-only subcommand.
359+
329360
### `dev`
330361

331362
Start a Wrangler-powered development session.
@@ -338,16 +369,17 @@ Flags `--open` and `--watch` exist as reserved compatibility flags.
338369

339370
### `deploy`
340371

341-
Validate, build, and deploy the Worker.
372+
Validate, build if needed, and deploy the Worker.
342373

343374
```bash
344375
./flare-edge-cli deploy [--path <dir>] [--env <name>] [--name <worker>] [--compat-date <YYYY-MM-DD>] [--route <pattern>] [--custom-domain <hostname>] [--workers-dev] [--dry-run] [--upload-only] [--message <text>] [--var <KEY=VALUE>] [--keep-vars] [--minify] [--latest] [--json]
345376
```
346377

347378
Behavior:
348379

349-
- runs compatibility checks first
350-
- builds the Wasm artifact and Worker shim
380+
- runs compatibility checks first for Go/Wasm projects
381+
- builds the Wasm artifact and Worker shim for Go/Wasm projects
382+
- stages the configured main module for JavaScript projects
351383
- updates Wrangler config
352384
- deploys through Wrangler
353385
- can attach routes and custom domains during deploy
@@ -439,12 +471,12 @@ Check whether the local environment and project are deployable.
439471

440472
`doctor` checks:
441473

442-
- Go installation
474+
- Go installation when the project runtime requires it
443475
- Wrangler installation
444476
- auth health
445477
- project config validity
446478
- compatibility date presence
447-
- Wasm build readiness
479+
- Wasm build readiness for Go projects or JavaScript entrypoint presence for JS projects
448480
- binding/config sanity
449481

450482
### `teardown`
@@ -477,7 +509,7 @@ flare-edge-cli tail -> flare-edge-cli logs tail
477509
flare-edge-cli rollback -> flare-edge-cli release rollback
478510
```
479511

480-
The top-level `build` command is itself the primary Wasm build entrypoint, with `build wasm` available as an explicit subcommand.
512+
The top-level `build` command is runtime-aware, with `build wasm` available as the explicit Go/Wasm subcommand.
481513

482514
## Examples
483515

@@ -487,6 +519,18 @@ Scaffold a JSON worker:
487519
./flare-edge-cli init test-project --module-path github.com/example/test-project --template edge-json
488520
```
489521

522+
Scaffold a native JavaScript Worker:
523+
524+
```bash
525+
./flare-edge-cli init js-worker --runtime js
526+
```
527+
528+
Scaffold a JavaScript Worker with Node.js compatibility enabled:
529+
530+
```bash
531+
./flare-edge-cli init js-worker --runtime js --node-compat
532+
```
533+
490534
Scaffold a Go-based AI Worker:
491535

492536
```bash

app_structure_llm.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# App Structure - flare-edge-cli
2-
# Last updated: 2026-03-19
2+
# Last updated: 2026-03-25
33

44
## Repositories
55
- GitHub: https://github.com/Gladium-AI/flare-edge-cli
@@ -15,6 +15,6 @@
1515
- CLOUDFLARE_ACCOUNT_ID (optional, for account selection)
1616

1717
## Notes
18-
- Local-first CLI project for Cloudflare Workers Go/Wasm workflows.
18+
- Local-first CLI project for Cloudflare Workers Go/Wasm and native JavaScript workflows.
1919
- Uses Wrangler for deployment and resource operations.
2020
- GitHub automation includes CI quality gates, security scanning, and Dependabot updates under `.github/`.

internal/cli/aliases.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ func newInitAliasCommand(deps Dependencies) *cobra.Command {
2828
},
2929
}
3030
cmd.Flags().StringVar(&options.Dir, "cwd", ".", "Target parent directory")
31-
cmd.Flags().StringVar(&options.ModulePath, "module-path", "", "Go module path")
31+
cmd.Flags().StringVar(&options.Runtime, "runtime", "go", "Project runtime: go|js")
32+
cmd.Flags().StringVar(&options.ModulePath, "module-path", "", "Module path")
3233
cmd.Flags().StringVar(&options.PackageName, "package", "", "Package name")
33-
cmd.Flags().StringVar(&options.Template, "template", "edge-http", "Starter template: edge-http|edge-json|scheduled|kv-api|d1-api|r2-api|ai-text|ai-chat|ai-vision|ai-stt|ai-tts|ai-image|ai-embeddings")
34+
cmd.Flags().StringVar(&options.Template, "template", "", "Starter template. Go: edge-http|edge-json|scheduled|kv-api|d1-api|r2-api|ai-text|ai-chat|ai-vision|ai-stt|ai-tts|ai-image|ai-embeddings. JS: js-worker")
3435
cmd.Flags().StringVar(&options.CompatDate, "compat-date", "", "Compatibility date")
36+
cmd.Flags().BoolVar(&options.NodeCompat, "node-compat", false, "Enable Cloudflare's nodejs_compat flag for JavaScript workers")
3537
cmd.Flags().StringVar(&options.Env, "env", "", "Wrangler environment")
3638
cmd.Flags().BoolVar(&options.UseJSONC, "use-jsonc", false, "Generate wrangler.jsonc")
3739
cmd.Flags().BoolVar(&options.WithGit, "with-git", true, "Generate .gitignore")
@@ -79,7 +81,7 @@ func newCheckAliasCommand(deps Dependencies) *cobra.Command {
7981
}
8082
cmd.Flags().StringVar(&options.Path, "path", ".", "Project path")
8183
cmd.Flags().StringVar(&options.Entry, "entry", "", "Package or file entry selector")
82-
cmd.Flags().StringVar(&options.Profile, "profile", "worker-wasm", "Profile name")
84+
cmd.Flags().StringVar(&options.Profile, "profile", "", "Profile name")
8385
cmd.Flags().StringVar(&options.FailOn, "fail-on", "error", "Threshold")
8486
cmd.Flags().StringArrayVar(&options.Exclude, "exclude", nil, "Exclude globs")
8587
cmd.Flags().BoolVar(&jsonOutput, "json", false, "Emit machine-readable JSON")

internal/cli/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ func newBuildCommand(deps Dependencies) *cobra.Command {
1515

1616
cmd := &cobra.Command{
1717
Use: "build",
18-
Short: "Build Wasm artifacts for Workers",
18+
Short: "Build or stage Worker artifacts",
1919
Aliases: []string{"compile"},
2020
RunE: func(cmd *cobra.Command, _ []string) error {
21-
result, err := deps.Services.Build.Wasm(context.Background(), options)
21+
result, err := deps.Services.Build.Build(context.Background(), options)
2222
if err != nil {
2323
return err
2424
}

internal/cli/compat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func newCompatCheckCommand(deps Dependencies) *cobra.Command {
5252

5353
cmd.Flags().StringVar(&options.Path, "path", ".", "Project path to analyze")
5454
cmd.Flags().StringVar(&options.Entry, "entry", "", "Package or file entry selector")
55-
cmd.Flags().StringVar(&options.Profile, "profile", "worker-wasm", "Compatibility rule profile")
55+
cmd.Flags().StringVar(&options.Profile, "profile", "", "Compatibility rule profile")
5656
cmd.Flags().BoolVar(&options.Strict, "strict", false, "Enable stricter compatibility checks")
5757
cmd.Flags().BoolVar(&jsonOutput, "json", false, "Emit machine-readable JSON")
5858
cmd.Flags().BoolVar(&sarif, "sarif", false, "Emit SARIF JSON")

internal/cli/project.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func newProjectInitCommand(deps Dependencies) *cobra.Command {
2626

2727
cmd := &cobra.Command{
2828
Use: "init <name>",
29-
Short: "Scaffold a Workers-ready Go/Wasm project",
29+
Short: "Scaffold a Workers-ready project",
3030
Args: cobra.ExactArgs(1),
3131
RunE: func(cmd *cobra.Command, args []string) error {
3232
options.Name = args[0]
@@ -39,10 +39,12 @@ func newProjectInitCommand(deps Dependencies) *cobra.Command {
3939
},
4040
}
4141

42-
cmd.Flags().StringVar(&options.ModulePath, "module-path", "", "Go module path to initialize")
42+
cmd.Flags().StringVar(&options.Runtime, "runtime", "go", "Project runtime: go|js")
43+
cmd.Flags().StringVar(&options.ModulePath, "module-path", "", "Module path to initialize")
4344
cmd.Flags().StringVar(&options.PackageName, "package", "", "Package name for generated Go entrypoint")
44-
cmd.Flags().StringVar(&options.Template, "template", "edge-http", "Starter template: edge-http|edge-json|scheduled|kv-api|d1-api|r2-api|ai-text|ai-chat|ai-vision|ai-stt|ai-tts|ai-image|ai-embeddings")
45+
cmd.Flags().StringVar(&options.Template, "template", "", "Starter template. Go: edge-http|edge-json|scheduled|kv-api|d1-api|r2-api|ai-text|ai-chat|ai-vision|ai-stt|ai-tts|ai-image|ai-embeddings. JS: js-worker")
4546
cmd.Flags().StringVar(&options.CompatDate, "compat-date", "", "Cloudflare compatibility date")
47+
cmd.Flags().BoolVar(&options.NodeCompat, "node-compat", false, "Enable Cloudflare's nodejs_compat flag for JavaScript workers")
4648
cmd.Flags().StringVar(&options.Env, "env", "", "Default Wrangler environment")
4749
cmd.Flags().BoolVar(&options.UseJSONC, "use-jsonc", false, "Generate wrangler.jsonc output")
4850
cmd.Flags().BoolVar(&options.WithGit, "with-git", true, "Generate .gitignore in the scaffolded project")

internal/cli/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func NewRootCommand(deps Dependencies) *cobra.Command {
1111

1212
cmd := &cobra.Command{
1313
Use: "flare-edge-cli",
14-
Short: "Build and deploy Go/Wasm Workers with Cloudflare",
14+
Short: "Build and deploy Cloudflare Workers",
1515
SilenceUsage: true,
1616
SilenceErrors: true,
1717
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {

0 commit comments

Comments
 (0)