Repository navigation
Accept wrangler.json(c) as a config #8051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,008
−2
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
25ef73c
Accept wrangler.json(c) as a config
ry a65a96c
Address review: bundle dir, DO renames, bundling tests
ry 38fd14a
Apply DO migrations in wrangler's order, with its checks
ry b65c5d4
Address review: DO storage keys, missing main, test coverage
ry f6808fd
Add the license header to the new Rust files
ry cc9b4f5
Merge main into ry/wrangler-json
ry 9dbcdd2
Address review: reject renames onto existing classes, docs
ry c38ecab
Merge main into ry/wrangler-json
ry f8c22ad
Add a sample configured with wrangler.jsonc
ry 6a9d123
Merge main into ry/wrangler-json
ry ef05e63
Fail at once on a missing wrangler config
ry 976e547
Listen on localhost:8787 by default, as wrangler dev does
ry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| exports_files([ | ||
| "helloworld/config.capnp", | ||
| "helloworld/worker.js", | ||
| "wrangler/wrangler.jsonc", | ||
| ]) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .wrangler/ |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Wrangler Config Example | ||
|
|
||
| workerd can run a project configured with a `wrangler.jsonc` instead of a | ||
| `config.capnp`. This one is a TypeScript Worker with a SQLite-backed Durable | ||
| Object that counts visits per path. | ||
|
|
||
| As Wrangler does, workerd bundles `main` with esbuild, so esbuild must be | ||
| installed: in the project (`npm i -D esbuild`), on `PATH`, or named by | ||
| `WORKERD_ESBUILD`. | ||
|
|
||
| To run the example on http://localhost:8787 | ||
|
|
||
| ```sh | ||
| $ ./workerd serve wrangler.jsonc | ||
| ``` | ||
|
|
||
| To run using bazel | ||
|
|
||
| ```sh | ||
| $ bazel run //src/workerd/server:workerd -- serve ~/cloudflare/workerd/samples/wrangler/wrangler.jsonc | ||
| ``` | ||
|
|
||
| To test: | ||
|
|
||
| ```sh | ||
| $ curl http://localhost:8787/alice | ||
| Hello, alice! (visit 1) | ||
| $ curl http://localhost:8787/alice | ||
| Hello, alice! (visit 2) | ||
| ``` | ||
|
|
||
| Counts are stored under `.wrangler/state/workerd/` and survive a restart. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright (c) 2026 Cloudflare, Inc. | ||
| // Licensed under the Apache 2.0 license found in the LICENSE file or at: | ||
| // https://opensource.org/licenses/Apache-2.0 | ||
|
|
||
| import { DurableObject } from 'cloudflare:workers'; | ||
|
|
||
| interface Env { | ||
| GREETING: string; | ||
| COUNTER: DurableObjectNamespace<Counter>; | ||
| } | ||
|
|
||
| // One counter per name, stored in the object's SQLite database. | ||
| export class Counter extends DurableObject<Env> { | ||
| increment(): number { | ||
| const sql = this.ctx.storage.sql; | ||
| sql.exec('CREATE TABLE IF NOT EXISTS n (v INTEGER)'); | ||
| const v = (sql.exec('SELECT v FROM n').toArray()[0]?.v as number) ?? 0; | ||
| sql.exec('DELETE FROM n'); | ||
| sql.exec('INSERT INTO n VALUES (?)', v + 1); | ||
| return v + 1; | ||
| } | ||
| } | ||
|
|
||
| export default { | ||
| async fetch(request: Request, env: Env): Promise<Response> { | ||
| const name = new URL(request.url).pathname.slice(1) || 'world'; | ||
| const n = await env.COUNTER.getByName(name).increment(); | ||
| return new Response(`${env.GREETING}, ${name}! (visit ${n})\n`); | ||
| }, | ||
| } satisfies ExportedHandler<Env>; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| // workerd reads this file directly: `workerd serve wrangler.jsonc`. | ||
| "name": "counter", | ||
| "main": "src/index.ts", | ||
| "compatibility_date": "2026-10-01", | ||
| "vars": { "GREETING": "Hello" }, | ||
| "durable_objects": { | ||
| "bindings": [{ "name": "COUNTER", "class_name": "Counter" }], | ||
| }, | ||
| "migrations": [{ "tag": "v1", "new_sqlite_classes": ["Counter"] }], | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.