Skip to content

Commit

Permalink
Bump versions to 2.0.0-rc.5, update CHANGELOG.md and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbbot committed Jan 7, 2022
1 parent 4e78e33 commit e534706
Show file tree
Hide file tree
Showing 29 changed files with 476 additions and 288 deletions.
30 changes: 27 additions & 3 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,37 @@ if you're upgrading from version 1.
[as per the Workers runtime](https://developers.cloudflare.com/workers/platform/limits#account-plan-limits).
Closes [issue #117](https://github.com/cloudflare/miniflare/issues/117),
thanks [@leader22](https://github.com/leader22) for the suggestion.
- To match the behaviour of the Workers runtime, some functionality, such as
asynchronous I/O (`fetch`, Cache API, KV), timeouts (`setTimeout`,
`setInterval`), and generating cryptographically-secure random values
(`crypto.getRandomValues`, `crypto.subtle.generateKey`), can now only be
performed while handling a request.

This behaviour can be disabled by setting the
`--global-async-io`/`globalAsyncIO`, `--global-timers`/`globalTimers` and
`--global-random`/`globalRandom` options respectively, which may be useful for
tests or libraries that need async I/O for setup during local development.
Note the Miniflare Jest environment automatically enables these options.

KV namespaces and caches returned from `Miniflare#getKVNamespace()` and
`getCaches()` are unaffected by this change, so they can still be used in
tests without setting any additional options.

- To match the behaviour of the Workers runtime, Miniflare now enforces
recursion depth limits. Durable Object `fetch`es can recurse up to 16 times,
and service bindings can recurse up to 32 times. This means if a Durable
Object fetch triggers another Durable Object fetch, and so on 16 times, an
error will be thrown.
- Incoming request headers are now immutable. Closes
[issue #36](https://github.com/cloudflare/miniflare/issues/36), thanks
[@grahamlyons](https://github.com/grahamlyons).
- Disabled dynamic WebAssembly compilation in the Miniflare sandbox
- Fixed `instanceof` on primitives such as `Object`, `Array`, `Promise`, etc.
from outside the Miniflare sandbox. This makes it much easier to run Rust
workers in Miniflare, as `wasm-bindgen` frequently generates this code.
- Added a new `--proxy-primitive`/`proxyPrimitiveInstanceOf: true` option. If
set, `instanceof` checks on primitives such as `Object`, `Array`, `Promise`,
etc. from outside the Miniflare sandbox will pass. This makes it much easier
to run Rust workers in Miniflare, as `wasm-bindgen` frequently generates this
code. Beware enabling this option will cause `Object` `constructor`/prototype
checks to fail.
- Added a new `--verbose`/`verbose: true` option that enables verbose logging
with more debugging information
- Throw a more helpful error with suggested fixes when Miniflare can't find your
Expand Down
31 changes: 30 additions & 1 deletion docs/src/content/core/mount.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ $ miniflare --mount api=./api --mount site=./site@dev
---
filename: wrangler.toml
---
# Paths resolved relative to wrangler.toml's directory
[miniflare.mounts]
api = "./api"
site = "./site@dev"
Expand Down Expand Up @@ -75,7 +76,8 @@ the `watch` option) is copied to mounted workers.

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

```js
const mf = new Miniflare({
Expand Down Expand Up @@ -131,6 +133,33 @@ const mf = new Miniflare({
});
```

The parent worker is always used as a fallback if no mounts' routes match. If
the parent worker has a `name` set, and it has more specific routes than other
mounts, they'll be used instead.

<ConfigTabs>

```sh
$ miniflare --name worker --route http://127.0.0.1/parent*
```

```toml
---
filename: wrangler.toml
---
name = "worker"
route = "http://127.0.0.1/parent*"
```

```js
const mf = new Miniflare({
name: "worker",
routes: ["http://127.0.0.1/parent*"],
});
```

</ConfigTabs>

When using the CLI with hostnames that aren't `localhost` or `127.0.0.1`, you
may need to edit your computer's `hosts` file, so those hostnames resolve to
`localhost`. On Linux and macOS, this is usually at `/etc/hosts`. On Windows,
Expand Down
54 changes: 54 additions & 0 deletions docs/src/content/core/standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,57 @@ Like the real workers runtime, Miniflare limits you to
[50 subrequests per request](https://developers.cloudflare.com/workers/platform/limits#account-plan-limits).
Each call to `fetch()`, each URL in a redirect chain, and each call to a Cache
API method (`put()`/`match()`/`delete()`) counts as a subrequest.

If needed, the subrequest limit to be customised using the
`MINIFLARE_SUBREQUEST_LIMIT` environment variable. Setting this to a negative
number disables the limit. Setting this to 0 disables subrequests.

```sh
$ MINIFLARE_SUBREQUEST_LIMIT=100 miniflare
```

## Global Functionality Limits

To match the behaviour of the Workers runtime, some functionality, such as
asynchronous I/O (`fetch`, Cache API, KV), timeouts (`setTimeout`,
`setInterval`), and generating cryptographically-secure random values
(`crypto.getRandomValues`, `crypto.subtle.generateKey`), can only be performed
while handling a request, not in the global scope.

This behaviour can be disabled by setting the `globalAsyncIO`, `globalTimers`
and `globalRandom` options respectively, which may be useful for tests or
libraries that need async I/O for setup during local development. Note that the
Miniflare [🤹 Jest Environment](/testing/jest) automatically enables these
options.

import ConfigTabs from "../components/mdx/config-tabs";

<ConfigTabs>

```sh
$ miniflare --global-async-io --global-timers --global-random
```

```toml
---
filename: wrangler.toml
---
[miniflare]
global_async_io = true
global_timers = true
glboal_random = true
```

```js
const mf = new Miniflare({
globalAsyncIO: true,
globalTimers: true,
globalRandom: true,
});
```

</ConfigTabs>

KV namespaces and caches returned from `Miniflare#getKVNamespace()` and
`Miniflare#getCaches()` are unaffected by this limit, so they can still be used
in tests without setting any additional options.
54 changes: 53 additions & 1 deletion docs/src/content/core/web-assembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,59 @@ export default {
};
```

## `instanceof` Checks

When accessing JavaScript objects from WebAssembly, glue code (what
`wasm-bingen` generates) often needs to check values' types using `instanceof`.
Due to how Miniflare works, these checks will fail for primitive classes like
`Object` if values are created outside the Miniflare sandbox (in a different
JavaScript realm). For example,
`caches.default.match("https://miniflare.dev") instanceof Object` will always be
`false` even if the request is cached, since the returned `Response` object is
created outside the sandbox. To fix this, enable the `proxyPrimitiveInstanceOf`
option:

<ConfigTabs>

```sh
$ miniflare --proxy-primitive
```

```toml
---
filename: wrangler.toml
---
[miniflare]
proxy_primitive_instanceof = true
```

```js
const mf = new Miniflare({
proxyPrimitiveInstanceOf: true,
});
```

</ConfigTabs>

This proxies `instanceof` checks for primitive classes, so they succeed
regardless of the realm the object is created in. See
[this comment](https://github.com/cloudflare/miniflare/blob/720794accee7582b01e849182244a65ce60c9d60/packages/core/src/plugins/core.ts#L487-L555)
for more details.

<Aside type="warning" header="Warning">

Enabling this option will cause primitive class `constructor` and `prototype`
checks to fail:

```js
{}.constructor === Object; // false
Object.getPrototypeOf({}) === Object.prototype; // false
```

</Aside>

## Rust Wrangler Builds

When using [Rust Wrangler Builds](/developing/builds#rust), `wasm` is
automatically bound to your compiled WebAssembly module.
automatically bound to your compiled WebAssembly module. The
`proxyPrimitiveInstanceOf` option is also automatically enabled.
12 changes: 11 additions & 1 deletion docs/src/content/get-started/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,19 @@ const mf = new Miniflare({
rootPath: "./site", // Path to resolve files relative to
scriptPath: "./index.js", // Resolved as ./site/index.js
sitePath: "./public", // Resolved as ./site/public
routes: ["site.mf/*"], // Route requests matching site.mf/* to this worker
routes: ["*site.mf/*"], // Route requests matching *site.mf/* to this worker
},
},
name: "worker", // Name of service
routes: ["*site.mf/parent"], // Route requests matching *site.mf/parent to parent over mounts

logUnhandledRejections: true, // Log unhandled promise rejections instead of crashing

globalAsyncIO: true, // Allow async I/O outside handlers
globalTimers: true, // Allow setting timers outside handlers
globalRandom: true, // Allow secure random generation outside handlers

proxyPrimitiveInstanceOf: true, // Proxy primitives' instanceof (for WebAssembly/Rust development)

host: "127.0.0.1", // Host for HTTP(S) server to listen on
port: 8787, // Port for HTTP(S) server to listen on
Expand Down
8 changes: 8 additions & 0 deletions docs/src/content/get-started/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,18 @@ Core Options:
--(no-)update-check Enable update checker (enabled by default) [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 [boolean]
handlers
--proxy-primitive Proxy primitives' instanceof (for WASM) [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 [boolean/string]
optional cert path)
--https-key Path to PEM SSL key [string]
Expand Down
4 changes: 4 additions & 0 deletions docs/src/content/storage/durable-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Like the real Workers runtime, Miniflare will throw errors when:
- Attempting to perform an operation in a rolledback transaction or in a
transaction that has already committed
- Attempting to call `deleteAll()` in a transaction
- Attempting to recurse more than 16 levels deep with Durable Object `fetch`es

## Manipulating Outside Workers

Expand Down Expand Up @@ -256,6 +257,9 @@ const mf = new Miniflare({

</ConfigTabs>

Mounted workers can access Durable Objects declared in other mounts or the
parent worker, assuming it has a `name` set.

## Internal Details

Durable Object instances are only unique within the same `Miniflare` instance.
Expand Down
Loading

0 comments on commit e534706

Please sign in to comment.