70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
3.1 KiB
3.1 KiB
Miniflare — Agent Guide
Overview
Local dev simulator for Cloudflare Workers, powered by workerd runtime. Main class Miniflare in src/index.ts.
Structure
src/index.ts— MainMiniflareclass, server setup, plugin orchestration, all exportssrc/workers/— ~30 embedded worker scripts (D1, KV, R2, caches, etc.), built viaworker:virtual import schemesrc/workers/shared/— Shared utilities across embedded workerssrc/workers/core/dev-registry-proxy.worker.ts— Proxy worker for cross-process service bindings via debug port RPCsrc/workers/core/dev-registry-proxy-shared.worker.ts— Shared proxy logic (registry Map, DO proxy class, tail serializers)src/shared/dev-registry.ts— Filesystem-based worker registry (chokidar watch, heartbeat, stale cleanup)src/shared/DEV_REGISTRY.md— Full architecture doc for the dev registrysrc/runtime/config/generated/workerd.ts— Generated workerd Cap'n Proto config typestest/— Tests (.spec.tsnaming, NOT.test.ts)test/test-shared/— Shared test utilitiesbootstrap.js— Deprecated CLI stub (prints error directing towrangler dev)scripts/build.mjs— Custom esbuild build script
Build
- Custom
scripts/build.mjsbundlessrc/index.tsas CJS →dist/src/index.js - Also compiles ~30 embedded worker scripts via
worker:...virtual import scheme — each triggers a nested esbuild sub-build producing standalone ESM worker scripts - Build outputs:
dist/,bootstrap.js,worker-metafiles/
Lint Status (Transitional)
- Many shared ESLint rules temporarily DISABLED:
curly,no-explicit-any,consistent-type-imports,no-shadow,no-floating-promises, others - Comment in config: "temporarily enabled while we transition Miniflare to use the standard workers-sdk eslint config"
no-console: erroris on, except forsrc/workers/andscripts/
TypeScript
- Does NOT extend shared
@cloudflare/workers-tsconfig— has its own full config - Uses
experimentalDecorators - Path aliases:
miniflare:shared,miniflare:zod declaration: true(emits .d.ts)
Testing
- Test files use
.spec.ts(NOT.test.ts) pool: "forks",maxWorkers: 1(Vitest 4 equivalent of the oldsingleFork: true)- Does NOT extend
vitest.shared.ts— own full vitest config - Timeouts: 30s test, 30s hook
globals: true- Factory pattern:
miniflareTest(opts, handler?)creates instance inbeforeAll, disposes inafterAll useDispose(mf)/disposeWithRetry()— exponential backoff for Windows EPERM file lockinguseServer()— temp HTTP server with auto-cleanupTestLog— captures log entries by level
Generated Files
src/runtime/config/generated/workerd.ts— generated Cap'n Proto types, do not edit directlysrc/workers/local-explorer/openapi.local.json— generated fromscripts/openapi-filter-config.ts, modify the config not the output
Version Pinning
- Miniflare minor version must match workerd minor version
.github/changeset-version.jsenforces this: if changeset bumps miniflare minor beyond workerd's, it converts to patch