Thank you for your interest in contributing to @supabase/middleware! This document provides guidelines and instructions for contributing to the project.
- Getting Started
- Development Setup
- Development Workflow
- Testing
- Code Style
- Writing a middleware
- Submitting Changes
- Release Process
- Questions?
- License
Check the open issues for something to work on, or open one to discuss a bug or feature before sending a PR.
- Node.js: 22.x or higher
- pnpm
-
Fork and clone the repository:
git clone https://github.com/YOUR_USERNAME/middleware.git cd middleware -
Install dependencies:
pnpm install
-
Build the project to verify setup:
pnpm build
Build the library for distribution:
pnpm buildWatch mode for development (rebuilds on file changes):
pnpm devFormat all code using Prettier:
pnpm format # write
pnpm format:check # verify only — this is what CI runsCI fails on unformatted files, so run pnpm format before pushing. Generated
files are excluded in .prettierignore: the lockfiles and
CHANGELOG.md, which release-please owns. Build output (dist, api-docs) is
already covered because Prettier reads .gitignore as well.
pnpm testWatch mode:
pnpm test:watchCI also runs pipeline from the built dist on Deno, Bun, and Cloudflare's workerd. Those jobs check runtime detection, environment resolution, and that the host's platform argument never reaches ctx. The fixtures live in test/runtimes/ and import the built output, so build first.
pnpm build
pnpm test:deno # needs Deno 2.x
pnpm test:bun # needs Bun
pnpm test:workers # workerd through @cloudflare/vitest-pool-workers; the fixture installs its own vitestAfter the build, CI loads the published entrypoints in plain Node, checks the type exports with attw, and dry-runs a JSR publish. All three run locally:
pnpm build
pnpm smoke # every entrypoint loads in raw Node
pnpm check-exports # arethetypeswrong against the packed tarball
pnpm dlx jsr@0.14.3 publish --dry-run --allow-dirty # slow types and the jsr.json payloadpnpm lint # check
pnpm lint:fix # fix
pnpm typecheck # tsc --noEmitpnpm typecheck runs the repo's own TypeScript. Consumers may be on an older
one, so CI also checks both published artifacts against the minimum version
the README claims — currently 5.4, because the types use NoInfer:
pnpm typecheck:min # src/**/*.ts — what JSR ships
pnpm typecheck:consumer # dist/*.d.ts — what npm ships (run pnpm build first)Both use the tsc pinned in test/ts-floor, which is also
where the consumer fixture lives. Below the floor the interesting failure is not
a different error but a missing one — collision detection goes quiet and a
duplicate key compiles — so the fixture pins its negative cases with
@ts-expect-error and fails on the unused directive.
If a change needs a newer TypeScript, raising the floor is deliberate: bump
typescript in test/ts-floor/package.json and the Requirements section of the
root README in the same commit.
The full authoring guide — defineMiddleware, request-side and generator forms, tests, publishing, and composing alongside the built-in entries — is in docs/authoring-guide.md. The composition primitives (ctx shape, conflict & prerequisite enforcement, the response seam) are documented in src/core/README.md, with feature-flag and cors as worked examples.
Your middleware is its own package. This repository ships the composition primitives and two worked examples (cors and feature-flag) and takes no new middleware; the authoring guide's Where it lives section covers the options. Middleware Supabase maintains lives in @supabase/server; to propose one, open an issue there.
To change one of the two built-ins, see src/middleware/README.md for the directory layout and subpath wiring.
This project follows Conventional Commits. Format:
<type>(<scope>): <description>
[optional body]
[optional footer]
Types: feat, fix, docs, test, chore, refactor, perf, ci, build
Breaking changes: use feat!: / fix!:, or include BREAKING CHANGE: in the commit footer.
Examples:
feat(cors): support wildcard subdomain origins
fix(pipeline): preserve ctx ordering across generator seams
docs: clarify prerequisite enforcement-
Create a branch from
main:git checkout -b feat/my-feature
-
Make your changes, following the guidelines above.
-
Commit using conventional commit format.
-
Push to your fork and open a Pull Request with:
- A clear title following conventional commit format
- A description of what changed and why
- A reference to any related issue (e.g., "Fixes #123")
-
Respond to feedback — maintainers may request changes.
- Keep PRs focused — one feature or fix per PR.
- Update documentation if you change public APIs.
- Add tests for new functionality.
- Ensure all CI checks pass.
Releases are automated with release-please. Versions and CHANGELOG.md come from the conventional commit history, so no PR edits either by hand.
- Commits land on
mainwith conventional commit messages (see above). - release-please opens or updates a release PR that bumps the version in
package.jsonandjsr.jsonand writes the changelog entry. - While that PR is open, every push to
mainpublishes a release candidate to npm as<next version>-rc.<run>under thercdist-tag, with a matching GitHub pre-release. Install it withnpm install @supabase/middleware@rc. - A maintainer merges the release PR. The workflow publishes the release to npm under
latestwith provenance through OIDC trusted publishing, then to JSR. JSR has no pre-release channel, so only real releases go there, and a JSR failure never blocks the npm release.
release-please derives the bump from the commit types since the last release:
- Breaking change (
feat!:,fix!:, or aBREAKING CHANGE:footer): major bump feat:: minor bumpfix:: patch bump
docs:, test:, and chore: commits do not trigger a release on their own. A Release-As: x.y.z footer on any commit pins the next release to that version.
Every pull request publishes a preview build through pkg.pr.new when it is opened, on each push, and when a label is added. The install command lands as a comment on the PR, so a change can be tried before it merges.
- Open an issue for bugs or feature requests.
- Check existing issues and PRs before creating new ones.
By contributing to @supabase/middleware, you agree that your contributions will be licensed under the MIT License.