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

Commit cb4ae22

Browse files
committed
Prepare for 1.2.0 release: bump version and add docs
1 parent dda8fb2 commit cb4ae22

File tree

12 files changed

+136
-48
lines changed

12 files changed

+136
-48
lines changed

CHANGELOG.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
# 🚧 Changelog
22

3+
## 1.2.0
4+
5+
### Features
6+
7+
- Added **Redis** persistence support for
8+
[📦 KV](https://miniflare.dev/kv.html#persistence),
9+
[✨ Cache](https://miniflare.dev/cache.html#persistence) and
10+
[📌 Durable Objects](https://miniflare.dev/durable-objects.html#persistence)
11+
- Added support for loading scripts from `package.json`, closes
12+
[issue #7](https://github.com/mrbbot/miniflare/issues/7). See
13+
[💻 Using the CLI](https://miniflare.dev/cli.html#script-requirement) and
14+
[⚡️ Developing with esbuild](https://miniflare.dev/recipes/esbuild.html#dependencies)
15+
for more details.
16+
- Added `FormData` to the sandbox, closes
17+
[issue #6](https://github.com/mrbbot/miniflare/issues/6)
18+
- Added an automatic update checker. See
19+
[💻 Using the CLI](https://miniflare.dev/cli.html#update-checker) for more
20+
details.
21+
- [📚 Modules](https://miniflare.dev/modules.html) mode is now always enabled
22+
when specifying
23+
[📌 Durable Objects](https://miniflare.dev/durable-objects.html##objects)
24+
bindings
25+
26+
### Fixes
27+
28+
- Fixed **Windows** support, closes
29+
[issue #10](https://github.com/mrbbot/miniflare/issues/10)
30+
- Fixed issue where scripts were not reloaded correctly when editing script path
31+
in `wrangler.toml`. Scripts are now always reloaded on options change.
32+
`Miniflare.reloadScript()` is now deprecated. You should use
33+
`Miniflare.reloadOptions()` instead.
34+
335
## 1.1.0
436

537
### Features
@@ -98,7 +130,7 @@
98130
- Fixed handling of `ignoreMethod` option for `Cache` `match` and `delete`
99131
- Disabled edge caching when using Workers Sites, files are now always loaded
100132
from disk
101-
- Provide `Set` and `WeakSet` from Miniflare's realm to sandbox, removing
133+
- Provided `Set` and `WeakSet` from Miniflare's realm to sandbox, removing
102134
`Promise`, so `(async () => {})() instanceof Promise` evaluates to `true`
103135

104136
## 0.1.1

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ $ miniflare worker.js --watch --debug
5151
[mf:dbg] - Scripts: worker.js
5252
[mf:dbg] Reloading worker.js...
5353
[mf:inf] Worker reloaded!
54-
[mf:dbg] Watching .env, worker.js, wrangler.toml...
54+
[mf:dbg] Watching .env, package.json, worker.js, wrangler.toml...
5555
[mf:inf] Listening on :8787
5656
[mf:inf] - http://127.0.0.1:8787
5757
```
@@ -85,6 +85,7 @@ Options:
8585
-d, --debug Log debug messages [boolean]
8686
-c, --wrangler-config Path to wrangler.toml [string]
8787
--wrangler-env Environment in wrangler.toml to use [string]
88+
--package Path to package.json [string]
8889
-m, --modules Enable modules [boolean]
8990
--modules-rule Modules import rule (TYPE=GLOB) [array]
9091
--build-command Command to build project [string]
@@ -105,6 +106,7 @@ Options:
105106
-e, --env Path to .env file [string]
106107
-b, --binding Bind variable/secret (KEY=VALUE) [array]
107108
--wasm WASM module to bind (NAME=PATH) [array]
109+
--disable-updater Disable update checker [boolean]
108110
```
109111

110112
## Acknowledgements

docs/api.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ The [Guide](/fetch.html) goes into more detail on configuring specific features.
4343

4444
<!--prettier-ignore-start-->
4545
::: warning
46-
Like the CLI, the API will automatically load `.env` and `wrangler.toml` files
46+
Like the CLI, the API will automatically load `.env`, `package.json` and `wrangler.toml` files
4747
in the current working directory. This may lead to unexpected results. You can
48-
disable this by setting `envPath` and `wranglerConfigPath` options to paths of
48+
disable this by setting `envPath`, `packagePath` and `wranglerConfigPath` options to paths of
4949
empty files:
5050

5151
```js
5252
const mf = new Miniflare({
5353
envPath: ".env.empty",
54+
packagePath: "package.empty.json", // Containing empty object: {}
5455
wranglerConfigPath: "wrangler.empty.toml"
5556
});
5657
```
@@ -72,7 +73,7 @@ const mf = new Miniflare({
7273
});
7374
```
7475

75-
### Watching and Reloading
76+
### Watching, Reloading and Disposing
7677

7778
You can watch scripts, `.env` files and `wrangler.toml` files with the `watch`
7879
option. When this is enabled, you must `dispose` of the watcher when you're done
@@ -86,13 +87,14 @@ const mf = new Miniflare({
8687
await mf.dispose();
8788
```
8889

90+
You must also `dispose` if you're persisting KV, cache, or Durable Object data
91+
in Redis to close opened connections.
92+
8993
You can also manually reload scripts (main and Durable Object's) and options
90-
(`.env` and `wrangler.toml`) too with `reloadScript` and `reloadOptions`.
91-
Reloading scripts implicitly reloads options too:
94+
(`.env` and `wrangler.toml`) too with `reloadOptions`:
9295

9396
```js
9497
const mf = new Miniflare({ ... });
95-
await mf.reloadScript();
9698
await mf.reloadOptions();
9799
```
98100

docs/cache.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,36 @@ await caches.open("cache_name");
2727

2828
By default, cached data is stored in memory. It will persist between reloads,
2929
but not CLI invocations or different `Miniflare` instances. To enable
30-
persistence to the file system, specify the cache persistence option:
30+
persistence to the file system or Redis, specify the cache persistence option:
3131

3232
```shell
3333
$ miniflare --cache-persist # Defaults to ./mf/cache
3434
$ miniflare --cache-persist ./data/ # Custom path
35+
$ miniflare --cache-persist redis://localhost:6379 # Redis server
3536
```
3637

3738
```toml
3839
# wrangler.toml
3940
[miniflare]
4041
cache_persist = true # Defaults to ./mf/cache
4142
cache_persist = "./data/" # Custom path
43+
cache_persist = "redis://localhost:6379" # Redis server
4244
```
4345

4446
```js
4547
const mf = new Miniflare({
4648
cachePersist: true, // Defaults to ./mf/cache
4749
cachePersist: "./data", // Custom path
50+
cachePersist: "redis://localhost:6379", // Redis server
4851
});
4952
```
5053

51-
Each namespace will get its own directory within the cache persistence
52-
directory.
54+
When using the file system, each namespace will get its own directory within the
55+
cache persistence directory.
56+
57+
When using Redis, each key will be prefixed with the namespace. If you're using
58+
this with the API, make sure you call `dispose` on your `Miniflare` instance to
59+
close database connections.
5360

5461
## Manipulating Outside Workers
5562

docs/cli.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,6 @@ See [🛠 Builds](/builds.html) for more details.
4545
:::
4646
<!--prettier-ignore-end-->
4747

48-
<!--prettier-ignore-start-->
49-
::: warning
50-
[📚 Modules](/modules.html) support currently requires the
51-
`--experimental-vm-modules` flag. This is enabled by default, but requires the
52-
`-S` flag of `/usr/bin/env`. If your operating system doesn't support the `-S`
53-
flag (e.g. Ubuntu 18.04), you can run the following instead:
54-
55-
```shell
56-
$ node --experimental-vm-modules ./node_modules/.bin/miniflare worker.js
57-
```
58-
:::
59-
<!--prettier-ignore-end-->
60-
6148
### Watching and Debugging
6249

6350
Add `--watch`/`-w` and `--debug`/`-d` flags to reload the worker whenever
@@ -70,16 +57,16 @@ $ miniflare worker.js --watch --debug
7057
[mf:dbg] - Scripts: worker.js
7158
[mf:dbg] Reloading worker.js...
7259
[mf:inf] Worker reloaded!
73-
[mf:dbg] Watching .env, worker.js, wrangler.toml...
60+
[mf:dbg] Watching .env, package.json, worker.js, wrangler.toml...
7461
[mf:inf] Listening on :8787
7562
[mf:inf] - http://127.0.0.1:8787
7663
```
7764

7865
### Configuration Autoloading
7966

80-
Note that `.env` and `wrangler.toml` files are also being watched. These files
81-
are always loaded automatically and configure your worker's environment in
82-
addition to the CLI flags. See the
67+
Note that `.env`, `package.json` and `wrangler.toml` files are also being
68+
watched. These files are always loaded automatically and configure your worker's
69+
environment in addition to the CLI flags. See the
8370
[Wrangler Configuration](#wrangler-configuration) reference below for more
8471
details, but as an example, with the following `wrangler.toml` file and
8572
`worker.js` files:
@@ -106,14 +93,34 @@ $ miniflare worker.js --wrangler-config wrangler.other.toml
10693
### Script Requirement
10794

10895
The only required option is the script to run. This can either be passed as a
109-
command line argument as we've been doing so far, or in a `wrangler.toml` file:
96+
command line argument as we've been doing so far, in a `wrangler.toml` file or
97+
in a `package.json` file. The command line argument takes priority, then the
98+
script in `wrangler.toml`, then the `main` or `module` field in `package.json`
99+
(depending on whether `modules` support is enabled):
110100

111101
```toml
102+
# wrangler.toml
112103
[build.upload]
113104
dir = "" # Defaults to "dist"
114105
main = "./worker.js"
115106
```
116107

108+
```json
109+
// package.json
110+
{
111+
"main": "worker.js", // "service-worker" format
112+
"module": "worker.mjs" // "modules" format
113+
}
114+
```
115+
116+
### Update Checker
117+
118+
The CLI includes an automatic update checker that looks for new versions of
119+
Miniflare once a day. As Cloudflare are always improving and tweaking workers,
120+
you should aim to install these promptly for improved compatibility with the
121+
real workers environment. You can disable this with the `--disable-updater`
122+
flag.
123+
117124
## Reference
118125

119126
### Flags
@@ -129,6 +136,7 @@ Options:
129136
-d, --debug Log debug messages [boolean]
130137
-c, --wrangler-config Path to wrangler.toml [string]
131138
--wrangler-env Environment in wrangler.toml to use [string]
139+
--package Path to package.json [string]
132140
-m, --modules Enable modules [boolean]
133141
--modules-rule Modules import rule (TYPE=GLOB) [array]
134142
--build-command Command to build project [string]
@@ -149,6 +157,7 @@ Options:
149157
-e, --env Path to .env file [string]
150158
-b, --binding Bind variable/secret (KEY=VALUE) [array]
151159
--wasm WASM module to bind (NAME=PATH) [array]
160+
--disable-updater Disable update checker [boolean]
152161
```
153162

154163
### Wrangler Configuration

docs/durable-objects.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,40 +48,47 @@ const mf = new Miniflare({
4848
```
4949

5050
<!--prettier-ignore-start-->
51-
::: warning
52-
Durable Objects require the `modules` option to be enabled. This is enabled
53-
automatically if Durable Object bindings are specified in `wrangler.toml`.
54-
See [📚 Modules](/modules.html) for more details.
51+
::: tip
52+
The `modules` option is automatically enabled when specifying Durable Object
53+
bindings. See [📚 Modules](/modules.html) for more details.
5554
:::
5655
<!--prettier-ignore-end-->
5756

5857
## Persistence
5958

6059
By default, Durable Object data is stored in memory. It will persist between
6160
reloads, but not CLI invocations or different `Miniflare` instances. To enable
62-
persistence to the file system, specify the Durable Object persistence option:
61+
persistence to the file system or Redis, specify the Durable Object persistence
62+
option:
6363

6464
```shell
6565
$ miniflare --do-persist # Defaults to ./mf/do
6666
$ miniflare --do-persist ./data/ # Custom path
67+
$ miniflare --do-persist redis://localhost:6379 # Redis server
6768
```
6869

6970
```toml
7071
# wrangler.toml
7172
[miniflare]
7273
durable_objects_persist = true # Defaults to ./mf/do
7374
durable_objects_persist = "./data/" # Custom path
75+
durable_objects_persist = "redis://localhost:6379" # Redis server
7476
```
7577

7678
```js
7779
const mf = new Miniflare({
7880
durableObjectsPersist: true, // Defaults to ./mf/do
7981
durableObjectsPersist: "./data", // Custom path
82+
durableObjectsPersist: "redis://localhost:6379", // Redis server
8083
});
8184
```
8285

83-
Each object instance will get its own directory within the Durable Object
84-
persistence directory.
86+
When using the file system, each object instance will get its own directory
87+
within the Durable Object persistence directory.
88+
89+
When using Redis, each key will be prefixed with the object name and instance.
90+
If you're using this with the API, make sure you call `dispose` on your
91+
`Miniflare` instance to close database connections.
8592

8693
## Manipulating Outside Workers
8794

docs/fetch.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ console.log(waitUntil[0]); // 1
8181
console.log(waitUntil[1]); // "2"
8282
```
8383

84+
When using the API to dispatch events, you are responsible for adding
85+
[`CF-*` headers](https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers-)
86+
and the
87+
[`cf` object](https://developers.cloudflare.com/workers/runtime-apis/request#incomingrequestcfproperties).
88+
This lets you control their values for testing:
89+
90+
```js
91+
const res = await mf.dispatchFetch("http://localhost:8787", {
92+
headers: {
93+
"CF-IPCountry": "GB",
94+
},
95+
cf: {
96+
country: "GB",
97+
},
98+
});
99+
```
100+
84101
## Upstream
85102

86103
Miniflare will call each `fetch` listener until a response is returned. If no

docs/kv.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,39 @@ user's computer) so it doesn't really mean anything.
5050

5151
By default, KV data is stored in memory. It will persist between reloads, but
5252
not CLI invocations or different `Miniflare` instances. To enable persistence to
53-
the file system, specify the KV persistence option:
53+
the file system or Redis, specify the KV persistence option:
5454

5555
```shell
5656
$ miniflare --kv-persist # Defaults to ./mf/kv
5757
$ miniflare --kv-persist ./data/ # Custom path
58+
$ miniflare --kv-persist redis://localhost:6379 # Redis server
5859
```
5960

6061
```toml
6162
# wrangler.toml
6263
[miniflare]
6364
kv_persist = true # Defaults to ./mf/kv
6465
kv_persist = "./data/" # Custom path
66+
kv_persist = "redis://localhost:6379" # Redis server
6567
```
6668

6769
```js
6870
const mf = new Miniflare({
6971
kvPersist: true, // Defaults to ./mf/kv
7072
kvPersist: "./data", // Custom path
73+
kvPersist: "redis://localhost:6379", // Redis server
7174
});
7275
```
7376

74-
Each namespace will get its own directory within the KV persistence directory.
75-
Key names are sanitised before data is read/written. Metadata is stored in files
76-
with a `.meta.json` suffix. These also contain original key names, so they can
77-
be returned when listing keys.
77+
When using the file system, each namespace will get its own directory within the
78+
KV persistence directory. Key names are sanitised before data is read/written.
79+
Metadata is stored in files with a `.meta.json` suffix. These also contain
80+
original key names, so they can be returned when listing keys.
81+
82+
When using Redis, each key will be prefixed with the namespace and `:value:`.
83+
Metadata will be prefixed with the namespace and `:meta:`. If you're using this
84+
with the API, make sure you call `dispose` on your `Miniflare` instance to close
85+
database connections.
7886

7987
## Manipulating Outside Workers
8088

docs/recipes/esbuild.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ $ npm init -y
1515
$ npm install -D esbuild miniflare
1616
```
1717

18-
Update the `scripts` field in `package.json` to the following:
18+
Update the `main` and `scripts` fields in `package.json` to the following:
1919

2020
```json
2121
{
22-
...
22+
...,
23+
"main": "./dist/index.js",
2324
"scripts": {
2425
"build": "esbuild --bundle --sourcemap --outdir=dist ./src/index.js",
2526
"dev": "miniflare --watch --debug"
@@ -47,7 +48,6 @@ kv_namespaces = [
4748
command = "npm run build"
4849
[build.upload]
4950
format = "service-worker"
50-
main = "./index.js"
5151
```
5252

5353
## Worker Script

0 commit comments

Comments
 (0)