|
| 1 | +# Copilot Instructions for oak |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +oak is a middleware framework for Deno's native HTTP server, |
| 6 | +[Deno Deploy](https://deno.com/deploy), Node.js, [Bun](https://bun.sh/), and |
| 7 | +[Cloudflare Workers](https://workers.cloudflare.com/). It is inspired by |
| 8 | +[Koa](https://github.com/koajs/koa/) and includes a middleware router inspired |
| 9 | +by [@koa/router](https://github.com/koajs/router/). The package is distributed |
| 10 | +via [JSR](https://jsr.io/@oak/oak). |
| 11 | + |
| 12 | +## Repository Structure |
| 13 | + |
| 14 | +- **Root-level `.ts` files** — Core framework modules (e.g., `application.ts`, |
| 15 | + `router.ts`, `context.ts`, `request.ts`, `response.ts`, `body.ts`, `send.ts`). |
| 16 | +- **`middleware/`** — Built-in middleware (etag, proxy, serve). |
| 17 | +- **`utils/`** — Internal utility functions and type guards. |
| 18 | +- **`*.test.ts`** — Test files co-located with source files. |
| 19 | +- **`deps.ts`** — Centralized runtime dependencies (always import shared deps from here). |
| 20 | +- **`deps_test.ts`** — Centralized test-only dependencies. |
| 21 | +- **`mod.ts`** — Public entry point that re-exports the full public API. |
| 22 | +- **`types.ts`** — Shared TypeScript types and interfaces. |
| 23 | +- **`examples/`** — Example usage scripts (not published). |
| 24 | +- **`fixtures/`** — Test fixtures (not published). |
| 25 | +- **`docs/`** — Documentation site source (not published). |
| 26 | + |
| 27 | +## Development Commands |
| 28 | + |
| 29 | +All commands use the [Deno](https://deno.com/) toolchain (no `npm` or build step needed). |
| 30 | + |
| 31 | +| Task | Command | |
| 32 | +|---|---| |
| 33 | +| Run tests | `deno task test` | |
| 34 | +| Run tests with coverage | `deno task test:coverage` | |
| 35 | +| Generate lcov report | `deno task coverage` | |
| 36 | +| Format code | `deno fmt` | |
| 37 | +| Check formatting | `deno fmt --check` | |
| 38 | +| Lint code | `deno lint` | |
| 39 | + |
| 40 | +## Coding Conventions |
| 41 | + |
| 42 | +- **Language**: TypeScript, targeting Deno-first with cross-runtime support (Node.js, Bun). |
| 43 | +- **Copyright header**: Every source file begins with: |
| 44 | + ```ts |
| 45 | + // Copyright 2018-2025 the oak authors. All rights reserved. MIT license. |
| 46 | + ``` |
| 47 | +- **Imports**: Use relative imports with `.ts` extensions (e.g., `import { foo } from "./bar.ts"`). |
| 48 | + Shared dependencies are imported via `deps.ts`; test-only dependencies via `deps_test.ts`. |
| 49 | +- **JSDoc**: Public APIs are documented with JSDoc. Module-level doc comments end with a `@module` tag. |
| 50 | +- **Formatting**: Enforced by `deno fmt`. Do not manually adjust whitespace or indentation. |
| 51 | +- **Linting**: Enforced by `deno lint`. The `no-import-prefix` rule is disabled (see `deno.json`). |
| 52 | +- **Tests**: Co-located `*.test.ts` files. Use `assertEquals`, `assertStrictEquals`, and |
| 53 | + `assertRejects` from `deps_test.ts`. Mock helpers are defined locally within test files. |
| 54 | +- **Error handling**: Use the `errors` object from `deps.ts` for HTTP error classes. |
| 55 | +- **Exports**: All public symbols are re-exported from `mod.ts`. The `deno.json` |
| 56 | + `exports` field also defines the package entry points for JSR publishing. |
0 commit comments