Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cloudflare/miniflare
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: aa80286020dbaf9aa78aeb5a3734161532ab3427
Choose a base ref
...
head repository: cloudflare/miniflare
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b25cfe22d0af3777ef521466016d476caf5ce14f
Choose a head ref
Loading
Showing 427 changed files with 27,581 additions and 53,508 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist
packages/miniflare/src/runtime/config/workerd.*
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
22 changes: 11 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ name: Test

on:
push:
branches: [master]
branches: [master, tre]
pull_request:
branches: [master]
branches: [master, tre]

jobs:
test:
@@ -18,14 +18,14 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node: [16.13.0, 18.x]
os: [ubuntu-latest, macos-latest, windows-latest]
node: [16.13.0, latest]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: npm ci
@@ -35,11 +35,11 @@ jobs:
name: "Lint & Type Check"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 18.x
uses: actions/setup-node@v2
- uses: actions/checkout@v3
- name: Use Node.js LTS
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: lts/*
- run: npm ci
- run: npm run lint
- run: npm run types:build
- run: npm run types:bundle
1 change: 0 additions & 1 deletion README.md

This file was deleted.

177 changes: 177 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# 🔥 Miniflare

**Miniflare** is a simulator for developing and testing
[**Cloudflare Workers**](https://workers.cloudflare.com/).

- 🎉 **Fun:** develop workers easily with detailed logging, file watching and
pretty error pages supporting source maps.
- 🔋 **Full-featured:** supports most Workers features, including KV, Durable
Objects, WebSockets, modules and more.
-**Fully-local:** test and develop Workers without an internet connection.
Reload code on change quickly.

It's an alternative to `wrangler dev`, written in TypeScript, that runs your
workers in a sandbox implementing Workers' runtime APIs.

**See <https://miniflare.dev> for more detailed documentation.**

## Features

- 📨 Fetch Events (with HTTP(S) server and manual dispatch)
- ⏰ Scheduled Events (with cron triggering and manual dispatch)
- 🔑 Variables and Secrets with `.env` Files
- 📚 Modules Support
- 📦 KV (with optional persistence)
- 🪣 R2 (with optional persistence)
- ✨ Cache (with optional persistence)
- 📌 Durable Objects (with optional persistence)
- 🌐 Workers Sites
- ✉️ WebSockets
- 🛠 Custom & Wrangler Builds Support
- ⚙️ WebAssembly Support
- 🗺 Source Map Support
- 🕸 Web Standards: Base64, Timers, Fetch, Encoding, URL, Streams, Crypto
- 📄 HTMLRewriter
- ⚡️ Live Reload on File Changes
- 📅 Compatibility Dates/Flags Support
- 🔌 Multiple Workers Support
- 🤹 Custom Jest Environment (with isolated per-test storage)
- 💪 Written in TypeScript

## Install

Miniflare is installed using npm:

```sh
$ npm install -g miniflare # either globally..
$ npm install -D miniflare # ...or as a dev dependency
```

## Using the CLI

```sh
$ miniflare worker.js --watch --debug
[mf:dbg] Options:
[mf:dbg] - Scripts: worker.js
[mf:dbg] Reloading worker.js...
[mf:inf] Worker reloaded! (97B)
[mf:dbg] Watching .env, package.json, worker.js, wrangler.toml...
[mf:inf] Listening on :8787
[mf:inf] - http://127.0.0.1:8787
```

## Using the API

```js
import { Miniflare } from "miniflare";

const mf = new Miniflare({
script: `
addEventListener("fetch", (event) => {
event.respondWith(new Response("Hello Miniflare!"));
});
`,
});
const res = await mf.dispatchFetch("http://localhost:8787/");
console.log(await res.text()); // Hello Miniflare!
```

## CLI Reference

```
Usage: miniflare [script] [options]
Core Options:
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
-c, --wrangler-config Path to wrangler.toml [string]
--wrangler-env Environment in wrangler.toml to use [string]
--package Path to package.json [string]
-m, --modules Enable modules [boolean]
--modules-rule Modules import rule [array:TYPE=GLOB]
--compat-date Opt into backwards-incompatible changes from [string]
--compat-flag Control specific backwards-incompatible changes [array]
--usage-model Usage model (bundled by default) [string]
-u, --upstream URL of upstream origin [string]
-w, --watch Watch files for changes [boolean]
-d, --debug Enable debug logging [boolean]
-V, --verbose Enable verbose logging [boolean]
--(no-)update-check Enable update checker (enabled by default) [boolean]
--repl Enable interactive REPL [boolean]
--root Path to resolve files relative to [string]
--mount Mount additional named workers [array:NAME=PATH[@ENV]]
--name Name of service [string]
--route Route to respond with this worker on [array]
--global-async-io Allow async I/O outside handlers [boolean]
--global-timers Allow setting timers outside handlers [boolean]
--global-random Allow secure random generation outside handlers [boolean]
--actual-time Always return correct time from Date methods [boolean]
HTTP Options:
-H, --host Host for HTTP(S) server to listen on [string]
-p, --port Port for HTTP(S) server to listen on [number]
-O, --open Automatically open browser to URL [boolean/string]
--https Enable self-signed HTTPS (with optional cert path) [boolean/string]
--https-key Path to PEM SSL key [string]
--https-cert Path to PEM SSL cert chain [string]
--https-ca Path to SSL trusted CA certs [string]
--https-pfx Path to PFX/PKCS12 SSL key/cert chain [string]
--https-passphrase Passphrase to decrypt SSL files [string]
--(no-)cf-fetch Path for cached Request cf object from Cloudflare [boolean/string]
--live-reload Reload HTML pages whenever worker is reloaded [boolean]
Scheduler Options:
-t, --cron CRON expression for triggering scheduled events [array]
Build Options:
-B, --build-command Command to build project [string]
--build-base-path Working directory for build command [string]
--build-watch-path Directory to watch for rebuilding on changes [array]
KV Options:
-k, --kv KV namespace to bind [array]
--kv-persist Persist KV data (to optional path) [boolean/string]
R2 Options:
-r, --r2 R2 bucket to bind [array]
--r2-persist Persist R2 data (to optional path) [boolean/string]
Durable Objects Options:
-o, --do Durable Object to bind [array:NAME=CLASS[@MOUNT]]
--do-persist Persist Durable Object data (to optional path) [boolean/string]
--(no-)do-alarms Enable Durable Object alarms (enabled by default) [boolean]
Cache Options:
--(no-)cache Enable default/named caches (enabled by default) [boolean]
--cache-persist Persist cached data (to optional path) [boolean/string]
Sites Options:
-s, --site Path to serve Workers Site files from [string]
--site-include Glob pattern of site files to serve [array]
--site-exclude Glob pattern of site files not to serve [array]
Bindings Options:
-e, --env Path to .env file [string]
-b, --binding Binds variable/secret to environment [array:KEY=VALUE]
--global Binds variable/secret to global scope [array:KEY=VALUE]
--wasm WASM module to bind [array:NAME=PATH]
--text-blob Text blob to bind [array:NAME=PATH]
--data-blob Data blob to bind [array:NAME=PATH]
-S, --service Mounted service to bind [array:NAME=MOUNT[@ENV]]
```

## Acknowledgements

Miniflare was created by [Brendan Coll](https://github.com/mrbbot).

Many thanks to
[dollarshaveclub/cloudworker](https://github.com/dollarshaveclub/cloudworker)
and
[gja/cloudflare-worker-local](https://github.com/gja/cloudflare-worker-local)
for inspiration.

Durable Object's transactions are implemented using Optimistic Concurrency
Control (OCC) as described in
["On optimistic methods for concurrency control." ACM Transactions on Database Systems](https://dl.acm.org/doi/10.1145/319566.319567).
Thanks to [Alistair O'Brien](https://github.com/johnyob) for helping the
Miniflare creator understand this.
6 changes: 2 additions & 4 deletions ava.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspector from "inspector";
import { pkgsList } from "./scripts/common.mjs";

const rewritePaths = Object.fromEntries(
@@ -8,12 +9,9 @@ const rewritePaths = Object.fromEntries(
);

export default {
nonSemVerExperiments: {
nextGenConfig: true,
},
files: ["packages/*/test/**/*.spec.ts"],
timeout: "5m",
nodeArguments: ["--no-warnings", "--experimental-vm-modules"],
workerThreads: inspector.url() === undefined,
typescript: {
compile: false,
rewritePaths,
Loading