Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions .github/workflows/claude.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,30 @@ jobs:
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && contains(github.event.issue.body, '@claude'))
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
uses: actions/checkout@v7
with:
fetch-depth: 1

- name: Install pnpm
uses: pnpm/action-setup@v4

- name: Setup Node.js
uses: actions/setup-node@v6
- name: Setup Vite+
uses: voidzero-dev/setup-vp@v1.22.0
with:
node-version: "lts/*"
cache: "pnpm"
node-version: "24"
cache: true

- name: Install dependencies
run: pnpm install
run: vp install

- name: Run Claude PR Action
uses: anthropics/claude-code-action@beta
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
timeout_minutes: "5"
allowed_tools: |
Bash(pnpm install)
Bash(pnpm run:*)
Bash(pnpm exec vp:*)
claude_args: |
--allowedTools "Bash(pnpm install),Bash(pnpm run:*),Bash(vp:*)"
4 changes: 2 additions & 2 deletions .github/workflows/semantic-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: marocchino/sticky-pull-request-comment@v2
- uses: marocchino/sticky-pull-request-comment@v3.0.5
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.lint_pr_title.outputs.error_message != null)
Expand All @@ -48,7 +48,7 @@ jobs:

# Delete a previous comment when the issue has been resolved
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
uses: marocchino/sticky-pull-request-comment@v2
uses: marocchino/sticky-pull-request-comment@v3.0.5
with:
header: pr-title-lint-error
delete: true
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v7
- name: Setup Vite+
uses: voidzero-dev/setup-vp@v1.21.1
uses: voidzero-dev/setup-vp@v1.22.0
with:
node-version: "24"
cache: true
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ pnpm-debug.log*
# environment variables
.env
.env.*
!.env.example
.dev.vars
.dev.vars.*
!.dev.vars.example

# macOS-specific files
.DS_Store
Expand Down
36 changes: 17 additions & 19 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This file provides guidance to agentic coding tools when working with code in th

1. **Worker name**: Update `worker.name` in `cloudflare.config.ts` and `name` in `package.json` to your new Worker name
2. **README**: Update README.md with your project information
3. **Test files**: Update the greeting string in `src/index.ts` and the matching assertion in `test/index.test.ts`, and rename the test file if appropriate
4. **Workers Builds**: Deploys run on Cloudflare's [Workers Builds](https://developers.cloudflare.com/workers/ci-cd/builds/), not GitHub Actions. Tell the user to connect the repository in the Cloudflare dashboard (Worker → **Settings** → **Build**), leaving the build command empty and setting the deploy command to `pnpm run deploy` (`vp build`, then `cf deploy --prebuilt`).
3. **Test files**: Update the `GREETING` binding in `cloudflare.config.ts` and the matching assertion in `test/index.test.ts`, and rename the test file if appropriate
4. **Workers Builds**: Deploys run on Cloudflare's [Workers Builds](https://developers.cloudflare.com/workers/ci-cd/builds/), not GitHub Actions. Tell the user to connect the repository in the Cloudflare dashboard (Worker → **Settings** → **Build**), leaving the build command empty and setting the deploy command to `pnpm run deploy` (`cf deploy`, which builds first).

5. **GitHub Secrets**: For `CLAUDE_CODE_OAUTH_TOKEN` (used by claude.yml): Tell the user to open Claude Code and run the `/install-github-app` command, which will guide them through setting up the GitHub app and automatically add the secret to their repository. Note: The user must be a repository admin to install the GitHub app and add secrets.

Expand Down Expand Up @@ -79,42 +79,40 @@ After setup, remove this section from AGENTS.md.

## Repository Structure

A standalone Cloudflare Worker built with Vite+ and the Cloudflare Vite plugin.
A standalone Cloudflare Worker built with the `cf` CLI, Vite+ and the Cloudflare Vite plugin.

- `src/index.ts` — the Worker entrypoint
- `test/` — Vitest tests in Node. Integration tests run the built Worker in Miniflare (`test/harness.ts`); `test/global-setup.ts` builds it first
- `test/` — Vitest tests that run inside workerd via `@cloudflare/vitest-plugin`, using the Worker and bindings from `cloudflare.config.ts`
- `cloudflare.config.ts` — Worker configuration, via `defineConfig` from `cf/config` (there is no wrangler.jsonc, and no Wrangler dependency at all)
- `compatibility.ts` — compatibility date/flags, shared between the Worker config and the test runtime
- `vite.config.ts` — unified Vite+ config: Vite plugins, Vitest, oxlint, and oxfmt
- `vite.config.ts` — Vite+ config: the Cloudflare Vite plugin, oxlint, and oxfmt
- `vitest.config.ts` — test config: `cloudflareTest({ config: true })`, which loads `cloudflare.config.ts`
- `.cloudflare/types/` — generated `Env` and runtime types; not committed. `cf workers types` regenerates them (runs on `postinstall`, or `pnpm types`)

## Commands

- `pnpm dev` — start the dev server (`vp dev`). `cf dev` and `cf build` expect a `vite` binary, which Vite+ doesn't provide, so use `vp`
- `pnpm test` — build the Worker, then run tests against it in Miniflare
- `pnpm dev` — start the dev server (`cf dev`, which delegates to `vp dev`). The local explorer is at `/cdn-cgi/local/explorer`
- `pnpm test` — run the tests in workerd (`vp test`)
- `pnpm check` — format check, lint, and type check in one pass (`vp check`)
- `pnpm fix` — apply formatting and safe lint fixes
- `pnpm build` — production build
- `pnpm build` — production build (`cf build`, which delegates to `vp build`) into `.cloudflare/output/`
- `pnpm types` — regenerate the types in `.cloudflare/types/` (`cf workers types`)
- `pnpm deploy` — `vp build` then `cf deploy --prebuilt` (requires `cf auth login` or `CLOUDFLARE_API_TOKEN`). Production deploys normally happen via Workers Builds on push to main, not from CI or local machines
- `pnpm deploy` — `cf deploy`, which builds and then deploys (requires `cf auth login` or `CLOUDFLARE_API_TOKEN`). Pass `--prebuilt` to reuse an existing build. Production deploys normally happen via Workers Builds on push to main, not from CI or local machines

## Configuration Architecture

- **`cloudflare.config.ts` is the source of truth for the Worker**: name, entrypoint, compatibility, bindings, observability. It uses `defineConfig({ worker: { ... } })` from `cf/config`, which both the `cf` CLI and the Vite plugin read.
- **`cloudflare.config.ts` is the source of truth for the Worker**: name, entrypoint, compatibility date and flags, bindings, observability. It uses `defineConfig({ worker: { ... } })` from `cf/config`, which the `cf` CLI, the Vite plugin and the Vitest plugin all read. Its exports are schema-validated, so don't add extra exports.
- The entrypoint uses the `with { type: "cf-worker" }` import attribute. This is what makes `Env` and `exports` inference work — keep that form when changing the entrypoint.
- **Bindings**: declare them in `cloudflare.config.ts` (e.g. `env: { MY_KV: bindings.kv() }` with `bindings` from the same import). The `Env` type is inferred from them — run `pnpm types` after config changes. If tests need the bindings, declare them for Miniflare in `test/harness.ts` too, and keep the two in step.
- **`compatibility.ts`** exists so the test runtime (`test/harness.ts`) always matches the deployed runtime. Extra exports are not allowed in `cloudflare.config.ts` (its exports are schema-validated), which is why this is a separate file.
- **Version pins that must move together**: the `vite@*` and `vitest@*` overrides in `pnpm-workspace.yaml` pin Vite to `@voidzero-dev/vite-plus-core` at the installed `vite-plus` version, and Vitest to the version `vp toolchain vitest` reports. Update them whenever `vite-plus` changes. There are no direct `vite` or `vitest` dependencies: import test APIs from `vite-plus/test`.
- **`miniflare`** is pinned to the version `cf` and `@cloudflare/vite-plugin` use (check with `pnpm why miniflare`), so tests run on the same runtime as dev.
- **Bindings**: declare them in `cloudflare.config.ts` under `env` (e.g. `MY_KV: bindings.kv()`, `GREETING: bindings.text("...")`, with `bindings` from `cf/config`). The `Env` type is inferred from them — run `pnpm types` after config changes. Read them in the Worker with `import { env } from "cloudflare:workers"`. Tests pick them up automatically.
- **Version pins that must move together**: `vite` and `vitest` are dev dependencies _and_ `pnpm-workspace.yaml` overrides, pinned to exactly what the installed `vite-plus` depends on (`pnpm view vite-plus@<version> dependencies`: `vite` is `npm:@voidzero-dev/vite-plus-core@<version>`). Update all four whenever `vite-plus` changes, so plugins share Vite+'s Vite and Vitest. Import test APIs from `vite-plus/test`.
- `pnpm-workspace.yaml` also has `minimumReleaseAgeExclude` entries for releases that were less than a day old when the lockfile was updated (pnpm holds those back by default). Remove them once they've aged.

## Testing

- Unit tests run in Node. Integration tests use `startWorker()` from `test/harness.ts`, which loads the built Worker (`.cloudflare/output/v0/workers/default/bundle/index.js`) into Miniflare; use `mf.dispatchFetch()` for HTTP. Create the instance in `beforeAll` and dispose of it in `afterAll`.
- `test/global-setup.ts` runs `vp build` once per test run, with `VITEST` unset so `vite.config.ts` loads the Cloudflare plugin.
- `test/tsconfig.json` extends the root config with Node types; the root `tsconfig.json` excludes `test`.
- Tests run inside workerd through `@cloudflare/vitest-plugin`. Use `SELF.fetch()` from `cloudflare:test` for integration tests against the Worker's default export; `env` from `cloudflare:workers` gives the configured bindings. Unit tests can import modules from `src/` directly.
- The root `tsconfig.json` covers `test/` too, with `@cloudflare/vitest-plugin/types` for the `cloudflare:test` module.

## Development Workflow

- Uses **pnpm**, wrapped by **Vite+** (`vp`). Format and lint are oxfmt/oxlint via `vp check` — there is no prettier or eslint. Type checking runs inside `vp check` (tsgolint with `typeAware`/`typeCheck` enabled).
- Uses **pnpm**, wrapped by **Vite+** (`vp`), with **`cf`** for Cloudflare-specific commands. Format and lint are oxfmt/oxlint via `vp check` — there is no prettier or eslint. Type checking runs inside `vp check` (tsgolint with `typeAware`/`typeCheck` enabled).
- Formatting uses tabs (configured in `vite.config.ts` under `fmt`).
- CI (test.yml) runs `vp check`, `vp test`, and `vp build` via the `voidzero-dev/setup-vp` action.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ Template for standalone Cloudflare Workers.
## Stack

- [Vite+](https://viteplus.dev/) (`vp`) — dev server, build, test, lint, format, and type checking in one toolchain
- [`cf`](https://www.npmjs.com/package/cf) — the Cloudflare CLI (technical preview), for deploys and everything Cloudflare
- [`cf`](https://www.npmjs.com/package/cf) — the Cloudflare CLI (1.0 release candidate), for dev, build, deploy and everything Cloudflare
- [`@cloudflare/vite-plugin`](https://developers.cloudflare.com/workers/vite-plugin/) 2.0, with `cloudflare.config.ts` from `cf/config`
- Vitest in Node, with integration tests running the built Worker in [Miniflare](https://www.npmjs.com/package/miniflare). No Wrangler
- Vitest with [`@cloudflare/vitest-plugin`](https://www.npmjs.com/package/@cloudflare/vitest-plugin), running tests inside workerd against the config in `cloudflare.config.ts`. No Wrangler
- TypeScript, pnpm

## Commands

```sh
pnpm dev # dev server (with the Cloudflare local explorer at /cdn-cgi/local/explorer)
pnpm test # build, then test the Worker in Miniflare
pnpm test # test the Worker in workerd
pnpm check # format, lint, and type check
pnpm fix # same, but auto-fix
pnpm build # production build
Expand All @@ -25,8 +25,8 @@ pnpm deploy # build and deploy via cf
## Configuration

- [cloudflare.config.ts](cloudflare.config.ts) — the Worker itself: name, entrypoint, compatibility, bindings. `Env` types are inferred from the bindings you declare here and generated into `.cloudflare/types/` by `cf workers types` (run on install, or with `pnpm types`).
- [compatibility.ts](compatibility.ts) — compatibility date and flags, shared with the test runtime.
- [vite.config.ts](vite.config.ts) — everything else: Vite, Vitest, oxlint, and oxfmt in one file.
- [vite.config.ts](vite.config.ts) — Vite, oxlint, and oxfmt.
- [vitest.config.ts](vitest.config.ts) — tests, via `cloudflareTest({ config: true })`, which reads `cloudflare.config.ts`.

## Template setup

Expand Down
8 changes: 5 additions & 3 deletions cloudflare.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { bindings, defineConfig } from "cf/config";
import { compatibilityDate, compatibilityFlags } from "./compatibility.ts";
import * as entrypoint from "./src/index.ts" with { type: "cf-worker" };

export default defineConfig({
worker: {
name: "worker-template",
entrypoint,
compatibilityDate,
compatibilityFlags,
compatibilityDate: "2026-12-01",
compatibilityFlags: ["nodejs_compat"],
env: {
GREETING: bindings.text("Hello from worker-template"),
},
observability: {
enabled: true,
},
Expand Down
4 changes: 0 additions & 4 deletions compatibility.ts

This file was deleted.

21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@
"type": "module",
"scripts": {
"postinstall": "cf workers types",
"dev": "vp dev",
"build": "vp build",
"deploy": "vp build && cf deploy --prebuilt",
"dev": "cf dev",
"build": "cf build",
"deploy": "cf deploy",
"types": "cf workers types",
"test": "vp test",
"check": "vp check",
"fix": "vp check --fix"
},
"devDependencies": {
"@cloudflare/vite-plugin": "2.0.0-beta.sha-91c870c02",
"@types/node": "^26.6.4",
"cf": "1.0.0-beta.14",
"miniflare": "5.20261006.1-alpha",
"@cloudflare/vite-plugin": "2.0.0-rc.9",
"@cloudflare/vitest-plugin": "^1.10.3",
"cf": "1.0.0-rc.7",
"typescript": "^7.0.2",
"vite-plus": "^1.1.0"
"vite": "npm:@voidzero-dev/vite-plus-core@8.4.0",
"vite-plus": "^1.9.0",
"vitest": "5.1.2"
},
"engines": {
"node": ">=22"
"node": "^22.23.0 || ^24.22.0 || ^26.12.0"
},
"packageManager": "pnpm@10.33.4"
"packageManager": "pnpm@12.26.0"
}
Loading