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

Commit a57b936

Browse files
committed
Bump versions to 2.0.0-rc.5, update CHANGELOG.md and docs
1 parent a22663f commit a57b936

File tree

29 files changed

+476
-288
lines changed

29 files changed

+476
-288
lines changed

docs/CHANGELOG.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,37 @@ if you're upgrading from version 1.
184184
[as per the Workers runtime](https://developers.cloudflare.com/workers/platform/limits#account-plan-limits).
185185
Closes [issue #117](https://github.com/cloudflare/miniflare/issues/117),
186186
thanks [@leader22](https://github.com/leader22) for the suggestion.
187+
- To match the behaviour of the Workers runtime, some functionality, such as
188+
asynchronous I/O (`fetch`, Cache API, KV), timeouts (`setTimeout`,
189+
`setInterval`), and generating cryptographically-secure random values
190+
(`crypto.getRandomValues`, `crypto.subtle.generateKey`), can now only be
191+
performed while handling a request.
192+
193+
This behaviour can be disabled by setting the
194+
`--global-async-io`/`globalAsyncIO`, `--global-timers`/`globalTimers` and
195+
`--global-random`/`globalRandom` options respectively, which may be useful for
196+
tests or libraries that need async I/O for setup during local development.
197+
Note the Miniflare Jest environment automatically enables these options.
198+
199+
KV namespaces and caches returned from `Miniflare#getKVNamespace()` and
200+
`getCaches()` are unaffected by this change, so they can still be used in
201+
tests without setting any additional options.
202+
203+
- To match the behaviour of the Workers runtime, Miniflare now enforces
204+
recursion depth limits. Durable Object `fetch`es can recurse up to 16 times,
205+
and service bindings can recurse up to 32 times. This means if a Durable
206+
Object fetch triggers another Durable Object fetch, and so on 16 times, an
207+
error will be thrown.
187208
- Incoming request headers are now immutable. Closes
188209
[issue #36](https://github.com/cloudflare/miniflare/issues/36), thanks
189210
[@grahamlyons](https://github.com/grahamlyons).
190211
- Disabled dynamic WebAssembly compilation in the Miniflare sandbox
191-
- Fixed `instanceof` on primitives such as `Object`, `Array`, `Promise`, etc.
192-
from outside the Miniflare sandbox. This makes it much easier to run Rust
193-
workers in Miniflare, as `wasm-bindgen` frequently generates this code.
212+
- Added a new `--proxy-primitive`/`proxyPrimitiveInstanceOf: true` option. If
213+
set, `instanceof` checks on primitives such as `Object`, `Array`, `Promise`,
214+
etc. from outside the Miniflare sandbox will pass. This makes it much easier
215+
to run Rust workers in Miniflare, as `wasm-bindgen` frequently generates this
216+
code. Beware enabling this option will cause `Object` `constructor`/prototype
217+
checks to fail.
194218
- Added a new `--verbose`/`verbose: true` option that enables verbose logging
195219
with more debugging information
196220
- Throw a more helpful error with suggested fixes when Miniflare can't find your

docs/src/content/core/mount.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ $ miniflare --mount api=./api --mount site=./site@dev
4545
---
4646
filename: wrangler.toml
4747
---
48+
# Paths resolved relative to wrangler.toml's directory
4849
[miniflare.mounts]
4950
api = "./api"
5051
site = "./site@dev"
@@ -75,7 +76,8 @@ the `watch` option) is copied to mounted workers.
7576

7677
When using the API, you can instead configure the mounted workers using the same
7778
options as the `new Miniflare` constructor. Note that nested `mounts` are not
78-
supported: 🙃
79+
supported, but all mounts are automatically accessible to all other mounts (e.g.
80+
for use in Durable Object bindings).
7981

8082
```js
8183
const mf = new Miniflare({
@@ -131,6 +133,33 @@ const mf = new Miniflare({
131133
});
132134
```
133135

136+
The parent worker is always used as a fallback if no mounts' routes match. If
137+
the parent worker has a `name` set, and it has more specific routes than other
138+
mounts, they'll be used instead.
139+
140+
<ConfigTabs>
141+
142+
```sh
143+
$ miniflare --name worker --route http://127.0.0.1/parent*
144+
```
145+
146+
```toml
147+
---
148+
filename: wrangler.toml
149+
---
150+
name = "worker"
151+
route = "http://127.0.0.1/parent*"
152+
```
153+
154+
```js
155+
const mf = new Miniflare({
156+
name: "worker",
157+
routes: ["http://127.0.0.1/parent*"],
158+
});
159+
```
160+
161+
</ConfigTabs>
162+
134163
When using the CLI with hostnames that aren't `localhost` or `127.0.0.1`, you
135164
may need to edit your computer's `hosts` file, so those hostnames resolve to
136165
`localhost`. On Linux and macOS, this is usually at `/etc/hosts`. On Windows,

docs/src/content/core/standards.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,57 @@ Like the real workers runtime, Miniflare limits you to
4545
[50 subrequests per request](https://developers.cloudflare.com/workers/platform/limits#account-plan-limits).
4646
Each call to `fetch()`, each URL in a redirect chain, and each call to a Cache
4747
API method (`put()`/`match()`/`delete()`) counts as a subrequest.
48+
49+
If needed, the subrequest limit to be customised using the
50+
`MINIFLARE_SUBREQUEST_LIMIT` environment variable. Setting this to a negative
51+
number disables the limit. Setting this to 0 disables subrequests.
52+
53+
```sh
54+
$ MINIFLARE_SUBREQUEST_LIMIT=100 miniflare
55+
```
56+
57+
## Global Functionality Limits
58+
59+
To match the behaviour of the Workers runtime, some functionality, such as
60+
asynchronous I/O (`fetch`, Cache API, KV), timeouts (`setTimeout`,
61+
`setInterval`), and generating cryptographically-secure random values
62+
(`crypto.getRandomValues`, `crypto.subtle.generateKey`), can only be performed
63+
while handling a request, not in the global scope.
64+
65+
This behaviour can be disabled by setting the `globalAsyncIO`, `globalTimers`
66+
and `globalRandom` options respectively, which may be useful for tests or
67+
libraries that need async I/O for setup during local development. Note that the
68+
Miniflare [🤹 Jest Environment](/testing/jest) automatically enables these
69+
options.
70+
71+
import ConfigTabs from "../components/mdx/config-tabs";
72+
73+
<ConfigTabs>
74+
75+
```sh
76+
$ miniflare --global-async-io --global-timers --global-random
77+
```
78+
79+
```toml
80+
---
81+
filename: wrangler.toml
82+
---
83+
[miniflare]
84+
global_async_io = true
85+
global_timers = true
86+
glboal_random = true
87+
```
88+
89+
```js
90+
const mf = new Miniflare({
91+
globalAsyncIO: true,
92+
globalTimers: true,
93+
globalRandom: true,
94+
});
95+
```
96+
97+
</ConfigTabs>
98+
99+
KV namespaces and caches returned from `Miniflare#getKVNamespace()` and
100+
`Miniflare#getCaches()` are unaffected by this limit, so they can still be used
101+
in tests without setting any additional options.

docs/src/content/core/web-assembly.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,59 @@ export default {
8484
};
8585
```
8686

87+
## `instanceof` Checks
88+
89+
When accessing JavaScript objects from WebAssembly, glue code (what
90+
`wasm-bingen` generates) often needs to check values' types using `instanceof`.
91+
Due to how Miniflare works, these checks will fail for primitive classes like
92+
`Object` if values are created outside the Miniflare sandbox (in a different
93+
JavaScript realm). For example,
94+
`caches.default.match("https://miniflare.dev") instanceof Object` will always be
95+
`false` even if the request is cached, since the returned `Response` object is
96+
created outside the sandbox. To fix this, enable the `proxyPrimitiveInstanceOf`
97+
option:
98+
99+
<ConfigTabs>
100+
101+
```sh
102+
$ miniflare --proxy-primitive
103+
```
104+
105+
```toml
106+
---
107+
filename: wrangler.toml
108+
---
109+
[miniflare]
110+
proxy_primitive_instanceof = true
111+
```
112+
113+
```js
114+
const mf = new Miniflare({
115+
proxyPrimitiveInstanceOf: true,
116+
});
117+
```
118+
119+
</ConfigTabs>
120+
121+
This proxies `instanceof` checks for primitive classes, so they succeed
122+
regardless of the realm the object is created in. See
123+
[this comment](https://github.com/cloudflare/miniflare/blob/720794accee7582b01e849182244a65ce60c9d60/packages/core/src/plugins/core.ts#L487-L555)
124+
for more details.
125+
126+
<Aside type="warning" header="Warning">
127+
128+
Enabling this option will cause primitive class `constructor` and `prototype`
129+
checks to fail:
130+
131+
```js
132+
{}.constructor === Object; // false
133+
Object.getPrototypeOf({}) === Object.prototype; // false
134+
```
135+
136+
</Aside>
137+
87138
## Rust Wrangler Builds
88139

89140
When using [Rust Wrangler Builds](/developing/builds#rust), `wasm` is
90-
automatically bound to your compiled WebAssembly module.
141+
automatically bound to your compiled WebAssembly module. The
142+
`proxyPrimitiveInstanceOf` option is also automatically enabled.

docs/src/content/get-started/api.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,19 @@ const mf = new Miniflare({
399399
rootPath: "./site", // Path to resolve files relative to
400400
scriptPath: "./index.js", // Resolved as ./site/index.js
401401
sitePath: "./public", // Resolved as ./site/public
402-
routes: ["site.mf/*"], // Route requests matching site.mf/* to this worker
402+
routes: ["*site.mf/*"], // Route requests matching *site.mf/* to this worker
403403
},
404404
},
405+
name: "worker", // Name of service
406+
routes: ["*site.mf/parent"], // Route requests matching *site.mf/parent to parent over mounts
407+
408+
logUnhandledRejections: true, // Log unhandled promise rejections instead of crashing
409+
410+
globalAsyncIO: true, // Allow async I/O outside handlers
411+
globalTimers: true, // Allow setting timers outside handlers
412+
globalRandom: true, // Allow secure random generation outside handlers
413+
414+
proxyPrimitiveInstanceOf: true, // Proxy primitives' instanceof (for WebAssembly/Rust development)
405415

406416
host: "127.0.0.1", // Host for HTTP(S) server to listen on
407417
port: 8787, // Port for HTTP(S) server to listen on

docs/src/content/get-started/cli.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,18 @@ Core Options:
241241
--(no-)update-check Enable update checker (enabled by default) [boolean]
242242
--root Path to resolve files relative to [string]
243243
--mount Mount additional named workers [array:NAME=PATH[@ENV]]
244+
--name Name of service [string]
245+
--route Route to respond with this worker on [array]
246+
--global-async-io Allow async I/O outside handlers [boolean]
247+
--global-timers Allow setting timers outside handlers [boolean]
248+
--global-random Allow secure random generation outside [boolean]
249+
handlers
250+
--proxy-primitive Proxy primitives' instanceof (for WASM) [boolean]
244251
245252
HTTP Options:
246253
-H, --host Host for HTTP(S) server to listen on [string]
247254
-p, --port Port for HTTP(S) server to listen on [number]
255+
-O, --open Automatically open browser to URL [boolean/string]
248256
--https Enable self-signed HTTPS (with [boolean/string]
249257
optional cert path)
250258
--https-key Path to PEM SSL key [string]

docs/src/content/storage/durable-objects.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Like the real Workers runtime, Miniflare will throw errors when:
127127
- Attempting to perform an operation in a rolledback transaction or in a
128128
transaction that has already committed
129129
- Attempting to call `deleteAll()` in a transaction
130+
- Attempting to recurse more than 16 levels deep with Durable Object `fetch`es
130131

131132
## Manipulating Outside Workers
132133

@@ -256,6 +257,9 @@ const mf = new Miniflare({
256257

257258
</ConfigTabs>
258259

260+
Mounted workers can access Durable Objects declared in other mounts or the
261+
parent worker, assuming it has a `name` set.
262+
259263
## Internal Details
260264

261265
Durable Object instances are only unique within the same `Miniflare` instance.

0 commit comments

Comments
 (0)