Development
Prerequisites
- Bun (the package manager — workspaces are
apps/*andpackages/*) - A Riot API key from developer.riotgames.com (a dev key is fine for local work)
- A Cloudflare account if you want to test against real D1/KV
Setup
bash
bun installCreate apps/web/.dev.vars for local secrets:
RIOT_API_KEY=RGAPI-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxApply migrations to the local D1 instance:
bash
bunx wrangler d1 migrations apply mmr-calculator --localCommon commands
bash
bun run dev # SvelteKit + wrangler dev (localhost:5173)
bun run build # vite build → SvelteKit cloudflare adapter → DO/cron injection
bun test # vitest with the workers pool
bun run typecheck # svelte-check + tsc --noEmit across all workspaces
bun run lint # biome check
bun run format # biome format --write
bun run docs:dev # vitepress dev server
bun run docs:build # build static site to docs/.vitepress/distWhat bun run build does
vite buildproduces the SvelteKit output underapps/web/.svelte-kit/cloudflare/.apps/web/scripts/inject-do.mjsruns:- Bundles
RateLimiterDOfromsrc/lib/server/rate-limiter.do.tsinto_rate_limiter_do.js. - Bundles the
scheduled()cron handler fromsrc/lib/server/cron.tsinto_cron.js. - Rewrites
_worker.jsto re-export the DO class and to add the cron handler.
- Bundles
This wrapper exists because @sveltejs/adapter-cloudflare does not natively know about Durable Object class exports or scheduled handlers.
Adding a new API route
Create apps/web/src/routes/api/v1/<name>/+server.ts. SvelteKit picks it up automatically. For shared logic, prefer adding helpers under apps/web/src/lib/server/ rather than expanding the +server.ts file inline.
Testing the estimator math
packages/core is pure — no Worker bindings, no fetch. Run its tests directly:
bash
bun --cwd packages/core testFor tests that need bindings (DB, KV, Riot client), vitest run at the root will use the @cloudflare/vitest-pool-workers pool to spin up a Miniflare environment.