# 🚧 Changelog ## 2.14.4 ### Fixes - Re-release of `2.14.3` to fix release issues ## 2.14.3 ### Fixes - Bump undici version from 5.28.3 to 5.28.4. Thanks [@italopiresshopify](https://github.com/italopiresshopify) for [the PR](https://github.com/cloudflare/miniflare/pull/773). - Bump undici to 5.28.3 to fix CVE-2024-24758. Thanks [@vavsab](https://github.com/vavsab) for [the PR](https://github.com/cloudflare/miniflare/pull/758). - Fix `body.cancel()` throwing `undefined`. Thanks [@jahands](https://github.com/jahands) for [the PR](https://github.com/cloudflare/miniflare/pull/757). ## 2.14.2 ### Fixes - Throw errors when calling `Body#formData()` with malformed form data. Thanks [@b-marques](https://github.com/b-marques) for [the PR](https://github.com/cloudflare/miniflare/pull/711). - Use `scriptPath` as the file path for the script if set. Thanks [@frandiox](https://github.com/frandiox) for [the PR](https://github.com/cloudflare/miniflare/pull/736). - Ensure `vitest-environment-miniflare` works with Node 21. Closes [issue #732](https://github.com/cloudflare/miniflare/issues/732), thanks [@jkeys089](https://github.com/jkeys089) for [the PR](https://github.com/cloudflare/miniflare/pull/734). - Ensure `waitUntil()`s added inside `waitUntil()` callbacks are waited on. Closes [issue #605](https://github.com/cloudflare/miniflare/issues/605), thanks [@hansottowirtz](https://github.com/hansottowirtz) for [the PR](https://github.com/cloudflare/miniflare/pull/606). - Bump `undici` to `5.82.2`, addressing [low severity `npm audit` warning](https://github.com/advisories/GHSA-wqq4-5wpv-mx2g). Closes [issues #607](https://github.com/cloudflare/miniflare/issues/607) and [#738](https://github.com/cloudflare/miniflare/issues/738), thanks [@hansottowirtz](https://github.com/hansottowirtz) and [@mm-jpoole](https://github.com/mm-jpoole). ## 2.14.1 ### Fixes - Allow `vitest-environment-miniflare` to be used with `vitest@0.34.0` and above. Closes [issue #645](https://github.com/cloudflare/miniflare/issues/645), thanks [@AdiRishi](https://github.com/AdiRishi), and [@Averethel](https://github.com/Averethel) for [the PR](https://github.com/cloudflare/miniflare/pull/661). - Allow responses with `429` and `503` status codes to be cached. Closes [issue #82](https://github.com/cloudflare/miniflare/issues/82), thanks [@haus](https://github.com/haus) and [@rdaniels6813](https://github.com/rdaniels6813) for [the PR](https://github.com/cloudflare/miniflare/pull/669). - Avoid self-imports in `@miniflare/core` package. Closes [issue #663](https://github.com/cloudflare/miniflare/issues/663), thanks [@ajwootto](https://github.com/ajwootto) for [the PR](https://github.com/cloudflare/miniflare/pull/664). ## 2.14.0 ### Features - Add support for the [`Ed25519` algorithm](https://github.com/cloudflare/workerd/pull/500) and mark `X448`/`Ed448` algorithms as unsupported. Thanks [@panva](https://github.com/panva) for [`jose`'s comprehensive test suite](https://github.com/panva/jose/tree/main/tap). - Add `ExecutionContext` as a global _value_ to Miniflare's unit testing environments' global types. Miniflare injects the `ExecutionContext` class into testing environments, so they can be constructed and passed to imported module event handlers. This change ensures `new ExecutionContext()` isn't a type error. - Allow `wrangler.toml` `build.watch_dir` to be an array of directories. Thanks [@sj-e2digital](https://github.com/sj-e2digital) for [the PR](https://github.com/cloudflare/miniflare/issues/557). ### Fixes - Ensure queue consumers are registered when using Miniflare's unit testing environments. - Fix crash when calling `Miniflare#reload()` with queue consumers set. Closes [issue #560](https://github.com/cloudflare/miniflare/issues/560), thanks [@calebmer](https://github.com/calebmer). - Add `@miniflare/core` as a dependency of `@miniflare/r2`. Closes [issue #559](https://github.com/cloudflare/miniflare/issues/559), thanks [@calebmer](https://github.com/calebmer). - Update `@miniflare/d1` `README` with new API ## 2.13.0 ### Features - Add support for `DurableObjectNamespace#jurisdiction()` method. Note the passed `jurisdiction` is validated but otherwise ignored. IDs generated by sub-namespaces in different jurisdictions will be the same. Thanks [@DaniFoldi](https://github.com/DaniFoldi) for [the PR](https://github.com/cloudflare/miniflare/pull/540). - Add support for the non-standard `crypto.subtle.timingSafeEqual()` function. Thanks [@DaniFoldi](https://github.com/DaniFoldi) for [the PR](https://github.com/cloudflare/miniflare/pull/542). - Remove requirement for `experimental` compatibility flag alongside `nodejs_compat` to use `node:assert`, `node:buffer` and `node:util` modules. Closes [issue #547](https://github.com/cloudflare/miniflare/issues/547), thanks [@Skye-31](https://github.com/Skye-31) and [@DaniFoldi](https://github.com/DaniFoldi) for [the PR](https://github.com/cloudflare/miniflare/pull/548). ### Fixes - Fix binding of `?N` parameters in D1 prepared statements. Closes issues [#504](https://github.com/cloudflare/miniflare/issues/504), [#526](https://github.com/cloudflare/miniflare/issues/526), [cloudflare/workers-sdk#2811](https://github.com/cloudflare/workers-sdk/issues/2811) and [cloudflare/workers-sdk#2887](https://github.com/cloudflare/workers-sdk/issues/2887). Thanks [@ruslantalpa](https://github.com/ruslantalpa) and [@maurerbot](https://github.com/maurerbot). - Fix cloning of `Response`s constructed with byte streams. Notably, byte streams are returned from lots of Workers runtime APIs (e.g. KV, R2) to support BYOB reads. Closes [issue #527](https://github.com/cloudflare/miniflare/issues/527), thanks [@cwkang1998](https://github.com/cwkang1998). - Copy `Content-Length` from `Request`/`Response` `body` streams when constructing a new `Request`/`Response` or calling `fetch`. Closes [issue #522](https://github.com/cloudflare/miniflare/issues/522), thanks [@notorca](https://github.com/notorca). ## 2.12.2 ### Fixes - Fix detection of read-only D1 SQL statements in Jest. Closes [issue #529](https://github.com/cloudflare/miniflare/issues/529), thanks [@jschlesser](https://github.com/jschlesser) for [the PR](https://github.com/cloudflare/miniflare/pull/533). ## 2.12.1 ### ⚠️ Security Update ### Fixes - Bump `undici` to `5.20.0`, addressing [GHSA-5r9g-qh6m-jxff](https://github.com/advisories/GHSA-5r9g-qh6m-jxff) and [GHSA-r6ch-mqf9-qc9w](https://github.com/advisories/GHSA-r6ch-mqf9-qc9w). Thanks [@WalshyDev](https://github.com/WalshyDev) and [@Cherry](https://github.com/Cherry) for [the PR](https://github.com/cloudflare/miniflare/pull/510). - Ensure global uniqueness of Durable Objects across mounts. Previously, it was possible to have multiple Durable Object instances with the same ID if they were created from different mounts. Closes [#461](https://github.com/cloudflare/miniflare/issues/461), thanks [@Finistere](https://github.com/Finistere). - Return a `R2MultipartUpload` instead of a `Promise` from `R2Bucket#resumeMultipartUpload()`. Thanks [@notorca](https://github.com/notorca) for [the PR](https://github.com/cloudflare/miniflare/pull/505). - Copy known-lengths from `FixedLengthStream`s and `Request`/`Response` `body` streams when calling `ReadableStream#tee()`. Closes [issue #506](https://github.com/cloudflare/miniflare/issues/506), thanks [@notorca](https://github.com/notorca). ## 2.12.0 ### Features - Add support for R2 multipart upload bindings. - Add support for dynamic `import()`s. Closes [issue #456](https://github.com/cloudflare/miniflare/issues/456), thanks [@calebmer](https://github.com/calebmer). - Add support for the [`new WebSocket()` constructor](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket). This is an alternative standard API to `fetch`-with-`Upgrade: websocket` for creating WebSocket clients. - Add support for the `nodejs_compat` compatibility flag, specifically the `node:assert`, `node:async_hooks`, `node:buffer`, `node:events`, and `node:util` modules. For now, the `experimental` compatibility flag must also be enabled to use `node:assert`, `node:buffer` or `node:events`. Thanks [@GregBrimble](https://github.com/GregBrimble) for [the PR](https://github.com/cloudflare/miniflare/pull/478). - Extract out types for test environment global helper functions. Add either `jest-environment-miniflare/globals` or `vitest-environment-miniflare/globals` to your `tsconfig.json`'s `types` array to include them. Closes [issue #94](https://github.com/cloudflare/miniflare/issues/94), thanks [@ryan-mars](https://github.com/ryan-mars). ```jsonc // tsconfig.json { "compilerOptions": { // ... "types": [ "@cloudflare/workers-types", // For Jest... "jest", "jest-environment-miniflare/globals" // ...or for Vitest "vitest-environment-miniflare/globals" ] } } ``` - Allow direct access to Durable Object instances inside testing environments. Thanks [@cdrx](https://github.com/cdrx) for [the PR](https://github.com/cloudflare/miniflare/pull/385). See [🀹 Jest Environment](https://miniflare.dev/testing/jest#constructing-durable-objects-directly) or [⚑️ Vitest Environment](https://miniflare.dev/testing/vitest#constructing-durable-objects-directly) for more details. - Forward `/cdn-cgi/scripts/*` to Cloudflare. This allows scripts such as `rocket-loader.min.js` to be loaded during development. Closes [issue #421](https://github.com/cloudflare/miniflare/issues/421), thanks [@jstevans](https://github.com/jstevans) for [the PR](https://github.com/cloudflare/miniflare/pull/422) - Implement `structuredClone` `transfer` option for Node.js versions below 17. Note Miniflare's minimum supported Node.js version is still 16.13.0. - Set default-on date for `streams_enable_constructors` and `transformstream_enable_standard_constructor` compatibility flags to `2022-11-30`. - Add support for the `DurableObjectStorage#sync()` method. See [cloudflare/workerd#87](https://github.com/cloudflare/workerd/pull/87) for details. - Accept [multiple keys in `R2Bucket#delete()`](https://community.cloudflare.com/t/2022-9-16-workers-runtime-release-notes/420496). Closes [issue #420](https://github.com/cloudflare/miniflare/issues/420), thanks [@TateB](https://github.com/TateB). - Implement the [`r2_list_honor_include`](https://developers.cloudflare.com/workers/platform/compatibility-dates/#r2-bucket-list-respects-the-include-option) compatibility flag. - Add support for the [HTTP `Range` header](https://community.cloudflare.com/t/2022-8-12-workers-runtime-release-notes/410873) to `R2Bucket#get()`. - Add support for [R2 `SHA-*` checksums](https://community.cloudflare.com/t/2022-9-16-workers-runtime-release-notes/420496), and return these from `R2Bucket#{get,head}`. - Implement the [`export_commonjs_default`/`export_commonjs_namespace`](https://developers.cloudflare.com/workers/platform/compatibility-dates/#commonjs-modules-do-not-export-a-module-namespace) compatibility flags. Note Miniflare previously implemented `export_commonjs_default` behaviour for `CommonJS` modules, but `export_commonjs_namespace` behaviour for all other types. This change switches everything to the correct `export_commonjs_default` by default, but allows old behaviour to be enabled by setting `export_commonjs_namespace`. - Add support for `D1Database#dump()` - Add support for `meta.{last_row_id,changes}` properties on D1 responses ### Fixes - Fix request body type when mocking fetch requests in testing environments with `getMiniflareFetchMock()` and via the `fetchMock` option. Thanks [@robertcepa](https://github.com/robertcepa) for [the PR](https://github.com/cloudflare/miniflare/pull/423). - Respect the `maxBatchSize` setting of queue consumers. Thanks [@a-robinson](https://github.com/a-robinson) for [the PR](https://github.com/cloudflare/miniflare/pull/450). - Fix `jest-environment-miniflare`'s `homepage` URL. Thanks [@aaharu](https://github.com/aaharu) for [the PR](https://github.com/cloudflare/miniflare/pull/451). - Fix typo in R2 documentation. Thanks [@aarhus](https://github.com/aarhus) for [the PR](https://github.com/cloudflare/miniflare/pull/452). - Rename queue producer binding class to `WorkerQueue`, matching the name in the real runtime. This will enable [`workers-rs`](https://github.com/cloudflare/workers-rs) to provide queue bindings. Thanks [@zebp](https://github.com/zebp) for [the PR](https://github.com/cloudflare/miniflare/pull/455). - Reset internal body stream when cloning `Request`s and `Response`s. This ensures both clones' bodies can be read. Thanks [@DSergiu](https://github.com/DSergiu) for [the PR](https://github.com/cloudflare/miniflare/pull/449). - Bump `npx-import` to `1.1.4`, fixing `require is not defined` error when using D1. Closes [issue #400](https://github.com/cloudflare/miniflare/issues/400), thanks [@tgriesser](https://github.com/tgriesser) and [@geelen](https://github.com/geelen). - Bump `undici` to `5.11.0`, allowing third-party `FormData`/`Blob` `Request`/`Response` bodies. Closes [issue #351](https://github.com/cloudflare/miniflare/issues/351), thanks [@yusefnapora](https://github.com/yusefnapora). - Get `CryptoKey` class from global scope if available. Fixes `'instanceof' is not an object` error in Node.js 19 and above. Closes [issue #457](https://github.com/cloudflare/miniflare/issues/457), thanks [@edevil](https://github.com/edevil) and [@panva](https://github.com/panva). - Bump `better-sqlite3` to `8.0.1`, adding support for Node.js 19. - Coerce R2 keys to `string`s. - Fix return type of `D1PreparedStatement#raw()`. Closes [issue cloudflare/workers-sdk#2238](https://github.com/cloudflare/workers-sdk/issues/2238), thanks [@repository](https://github.com/repository) for [the PR](https://github.com/cloudflare/miniflare/pull/474). - Throw when calling `D1PreparedStatement#run()` with statements that return data. Closes [issue #441](https://github.com/cloudflare/miniflare/issues/441), thanks [@AlexBlokh](https://github.com/AlexBlokh). - Fix D1 response envelope format. Closes issues [#442](https://github.com/cloudflare/miniflare/issues/442) and [cloudflare/workers-sdk#2504](https://github.com/cloudflare/workers-sdk/issues/2504), thanks [@jiripospisil](https://github.com/jiripospisil) and [@demosjarco](https://github.com/demosjarco). - Fix binding/return of `BLOB`-typed values in D1 operations. Closes [cloudflare/workers-sdk#2527](https://github.com/cloudflare/workers-sdk/issues/2527), thanks [@JoshVazq](https://github.com/JoshVazq). - Ensure `D1Database#{batch,exec}()` statements are executed in an implicit transaction. Closes [issue #484](https://github.com/cloudflare/miniflare/issues/484), thanks [@anthonymclaughlin](https://github.com/anthonymclaughlin). - Ensure only first statements are executed when calling `D1PreparedStatement#{first,run,all,raw}()` - Throw an error when KV expiration values exceed 32-bit signed integer bounds. Closes [issue #485](https://github.com/cloudflare/miniflare/issues/485), thanks [@huw](https://github.com/huw) for [the PR](https://github.com/cloudflare/miniflare/pull/487). - Pass through WebSocket abnormal closure code. Closes [issue #465](https://github.com/cloudflare/miniflare/issues/465), thanks [@yw662](https://github.com/yw662). ## 2.11.0 ### Features - Add support for dead-letter queues. Thanks [@jbw1991](https://github.com/jbw1991) for [the PR](https://github.com/cloudflare/miniflare/pull/411). - Add `getMiniflareDurableObjectIds()` global function to Miniflare's Jest/Vitest environments for listing active Durable Objects. Calling `getMiniflareDurableObjectIds("TEST_OBJECT")` will return a `Promise` that resolves to an array of active `DurableObjectId`s for the `TEST_OBJECT` namespace. Closes [issue #384](https://github.com/cloudflare/miniflare/issues/384), thanks [@DaniFoldi](https://github.com/DaniFoldi) for [the PR](https://github.com/cloudflare/miniflare/pull/413). ### Fixes - Strip quotes from R2 `onlyIf` header values. Closes [issue #402](https://github.com/cloudflare/miniflare/issues/402), thanks [@vincentbernat](https://github.com/vincentbernat) and [@CraigglesO](https://github.com/CraigglesO) for [the PR](https://github.com/cloudflare/miniflare/pull/403). - Disable `r2Persist` option in Miniflare's Jest/Vitest environments. Thanks [@hanford](https://github.com/hanford) for [the PR](https://github.com/cloudflare/miniflare/pull/414). ## 2.10.0 ### Features - Add support for `TextEncoderStream`/`TextDecoderStream`. Closes [issue #389](https://github.com/cloudflare/miniflare/issues/389), thanks [@vlovich](https://github.com/vlovich). ### Fixes - Fix reporting of server port when using `--port=0`. Closes [issue #381](https://github.com/cloudflare/miniflare/issues/381), thanks [@GregBrimble](https://github.com/GregBrimble) for [the PR](https://github.com/cloudflare/miniflare/pull/382). - Return Durable Object `get()`s in lexicographic order. Closes [issue #393](https://github.com/cloudflare/miniflare/issues/393), thanks [@vlovich](https://github.com/vlovich). - Add missing `@miniflare/r2` dependency to `@miniflare/shared-test-environment` package. Thanks [@askoufis](https://github.com/askoufis) for [the PR](https://github.com/cloudflare/miniflare/pull/394). - Return correct `Content-Length` from `Cache#match()` partial responses. Closes [issue #406](https://github.com/cloudflare/miniflare/issues/406). Thanks [@notorca](https://github.com/notorca) for [the PR](https://github.com/cloudflare/miniflare/pull/405). - Fix links in Vitest test environment docs. Thanks [@eadmundo](https://github.com/eadmundo) for [the PR](https://github.com/cloudflare/miniflare/pull/404). ## 2.9.0 ### Features - πŸ’Ύ **Add support for D1. Closes [issue #277](https://github.com/cloudflare/miniflare/issues/277), thanks [@geelen](https://github.com/geelen) for [the PR](https://github.com/cloudflare/miniflare/pull/329).** Docs coming soonβ„’... πŸ‘€ - πŸšͺ **Add `getMiniflareDurableObjectState()` and `runWithMiniflareDurableObjectGates()` functions** to the Jest/Vitest environments. This allows you to construct and call instance methods of Durable Objects directly, without having to fetch through a stub. Closes [issue #157](https://github.com/cloudflare/miniflare/issues/157), thanks [@jorroll](https://github.com/jorroll). ```js // Durable Object class, would probably come from an import class Counter { constructor(state) { this.storage = state.storage; } async fetch() { const count = ((await this.storage.get("count")) ?? 0) + 1; void this.storage.put("count", count); return new Response(String(count)); } } const env = getMiniflareBindings(); // Use standard Durable Object bindings to generate IDs const id = env.COUNTER.newUniqueId(); // Get DurableObjectState, and seed data const state = await getMiniflareDurableObjectState(id); await state.storage.put("count", 3); // Construct object directly const object = new Counter(state, env); // Call instance method directly, closing input gate, // and waiting for output gate to open const res = await runWithMiniflareDurableObjectGates(state, () => object.fetch(new Request("http://localhost/")) ); expect(await res.text()).toBe("4"); ``` - πŸ₯· Don't construct corresponding Durable Object instance when calling `Miniflare#getDurableObjectStorage()`. This allows you to seed data _before_ your Durable Object's constructor is invoked. Closes [issue #300](https://github.com/cloudflare/miniflare/issues/300), thanks [@spigaz](https://github.com/spigaz). - β˜‘οΈ **Add support for `WebSocket#readyState`** and `WebSocket.READY_STATE_{CONNECTING,OPEN,CLOSING,CLOSED}` constants. Note these constant names intentionally deviate from [the spec](https://websockets.spec.whatwg.org/#interface-definition) to match the Workers runtime. - πŸ“œ **Add persistent history to the REPL.** This respects the `MINIFLARE_REPL_HISTORY`, `MINIFLARE_REPL_HISTORY_SIZE`, and `MINIFLARE_REPL_MODE` environment variables [based on Node's](https://nodejs.org/api/repl.html#environment-variable-options). - πŸ’΅ **Add support for `Range`, `If-Modified-Since` and `If-None-Match` headers** on `Request`s to `Cache#match`. Closes [issue #246](https://github.com/cloudflare/miniflare/issues/246). ### Fixes - Don't wait for `waitUntil` `Promise`s to resolve before opening WebSocket connections - Allow WebSockets to be `close()`d on receiving a `close` event. Closes [issue #331](https://github.com/cloudflare/miniflare/issues/331), thanks [@awthwathje](https://github.com/awthwathje). - Ensure calling `WebSocket#close()` before returning a WebSocket response sends the correct close code and reason. - Fix delivery of incoming `WebSocket` `error` events - Ensure only scheduled Durable Object alarms are flushed. Previously, flushing all alarms would attempt to execute the `alarm` handler of every constructed Durable Object instance, even if that instance hadn't scheduled an alarm, or didn't have an `alarm` handler. - Delay scheduled missed alarms. Previously, if Durable Object persistence was enabled, and an alarm should've executed when Miniflare wasn't running, Miniflare may have crashed on startup. Closes [issue #359](https://github.com/cloudflare/miniflare/issues/359), thanks [@AlCalzone](https://github.com/AlCalzone). - Allow empty-chunk writes to `IdentityTransformStream`. Closes [issue #374](https://github.com/cloudflare/miniflare/issues/374), thanks [@cdloh](https://github.com/cdloh). - Don't hang when fetching from Durable Objects with fake-timers installed. Closes [issue #190](https://github.com/cloudflare/miniflare/issues/190), thanks [@vlovich](https://github.com/vlovich). - Match unimplemented `Request`/`Response` properties with the Workers runtime. Specifically, throw unimplemented errors when attempting to access `Request#{context,mode,credentials,integrity,cache}` and `Response#{type,useFinalUrl}`. - Discard `Content-Length: NaN` headers as a temporary workaround until [cloudflare/kv-asset-handler#295](https://github.com/cloudflare/kv-asset-handler/pull/295) is released. Closes [honojs/hono#520](https://github.com/honojs/hono/issues/520), thanks [@Cherry](https://github.com/Cherry). - Return byte streams when `tee()`ing byte streams to match the behaviour of the Workers runtime. Closes [issues #317](https://github.com/cloudflare/miniflare/issues/317) and [#375](https://github.com/cloudflare/miniflare/issues/375). - Throw `TypeError` when calling `Fetcher#fetch` with an illegal this to match the behaviour of the Workers runtime. ## 2.8.2 ### Fixes - Allow WebSocket client connection errors to be caught. Closes [issue #229](https://github.com/cloudflare/miniflare/issues/229), thanks [@viorel-d](https://github.com/viorel-d). - Return `Response`s with immutable headers from `cache.match`s. Closes [issue #365](https://github.com/cloudflare/miniflare/issues/365), thanks [@AlCalzone](https://github.com/AlCalzone). - Ensure `request.cf.clientAcceptEncoding` is always a `string`. Closes [issue #362](https://github.com/cloudflare/miniflare/issues/362), thanks [@GregBrimble](https://github.com/GregBrimble). ## 2.8.1 ### Fixes - Add missing `@miniflare/queues` dependencies. Closes [issue #360](https://github.com/cloudflare/miniflare/issues/360), thanks [@AlCalzone](https://github.com/AlCalzone) for [the PR](https://github.com/cloudflare/miniflare/pull/361). - Fix support for queues in Jest/Vitest testing environments ## 2.8.0 ### Features - ⚑️ Add **custom Vitest testing environment**. This behaves almost identically to the Jest environment. However, isolated storage must be installed manually in each test file. Call the `setupMiniflareIsolatedStorage()` global function and use the returned `describe` function instead of the regular `describe`/`suite` functions imported from `vitest`. See [⚑️ Vitest Environment](https://miniflare.dev/testing/vitest) for more details. - 🌐 **Populate Workers Sites `__STATIC_CONTENT_MANIFEST`** with site files instead of an empty object. Miniflare will still disable caching of Workers Sites files to ensure the most up-to-date files are always returned. Closes [issues #233](https://github.com/cloudflare/miniflare/issues/233), [#326](https://github.com/cloudflare/miniflare/issues/326) and [cloudflare/wrangler2#1632](https://github.com/cloudflare/wrangler2/issues/1632). Thanks [@ItalyPaleAle](https://github.com/ItalyPaleAle), [@Skye-31](https://github.com/Skye-31), [@CraigglesO](https://github.com/CraigglesO), [@Hexstream](https://github.com/Hexstream) and [@PolariTOON](https://github.com/PolariTOON). - ⏱ **Add global `getMiniflareWaitUntil()` method** and `ExecutionContext` class to the Jest and Vitest testing environments. This can be used to `await` the results of `waitUntil`ed `Promise`s in tests. See [🀹️ Jest Environment](https://miniflare.dev/testing/jest#waiting-for-waituntiled-promises) and [⚑️ Vitest Environment](https://miniflare.dev/testing/vitest#waiting-for-waituntiled-promises) for more details. Closes [issue #202](https://github.com/cloudflare/miniflare/issues/202), thanks [@jamesarosen](https://github.com/jamesarosen) and [@CraigglesO](https://github.com/CraigglesO) for [the PR](https://github.com/cloudflare/miniflare/pull/345). - ⏳ Match Web Streams implementations with Workers runtime, closes issue [#168](https://github.com/cloudflare/miniflare/issues/168), thanks [@leviwolfe](https://github.com/leviwolfe): - Add support for the non-standard [`IdentityTransformStream`](https://developers.cloudflare.com/workers/runtime-apis/streams/transformstream/#identitytransformstream) class. - Add support for the **`streams_enable_constructors` compatibility flag**. `ReadableStream` and `WritableStream` constructors will throw unless this flag is enabled. `ReadableByteStreamController`, `ReadableStreamBYOBRequest`, `ReadableStreamDefaultController` and `WritableStreamDefaultController` will only be included in the sandbox if this flag is enabled. - Add support for the **`transformstream_enable_standard_constructor` compatibility flag**. `TransformStream` will behave like `IdentityTransformStream` if this isn't enabled, ignoring custom transformers. If `transformstream_enable_standard_constructor` is set, but `streams_enable_constructors` isn't, the `TransformStream` constructor will throw. `TransformStreamDefaultController` will only be included in the sandbox if both flags are enabled. - Add support for BYOB reads to the non-standard [`FixedLengthStream`](https://developers.cloudflare.com/workers/runtime-apis/streams/transformstream/#fixedlengthstream) class. - πŸ‡¬πŸ‡§ Add support for **Queues**. Docs coming soonβ„’... πŸ‘€ - πŸ™‰ Allow calls to `addEventListener`, `removeEventListener` and `dispatchEvent` in modules mode. Please note, calling `addEventListener` with a special event type (e.g. `fetch`, `scheduled`) will log a warning prompting you to use the `export default` syntax. Closes [issue #207](https://github.com/cloudflare/miniflare/issues/207), thanks [@Electroid](https://github.com/Electroid). - 🍟 Add experimental and highly-inaccurate request CPU time measurements. These are not representative of deployed worker performance, should only be used for relative comparisons, and may be removed in the future. Enable measurements with the `--inaccurate-cpu`/`[miniflare] inaccurate_cpu`/`inaccurateCpu` option. Closes [issue #161](https://github.com/cloudflare/miniflare/issues/161). Thanks [@alexandernst](https://github.com/alexandernst) and [@y21](https://github.com/y21). - πŸ¦„ Automatically enable watch mode when `live_reload = true` is set in `wrangler.toml`. ### Fixes - Return `Response`s with immutable headers from `fetch`es to Durable Objects and service bindings. Closes [issue #346](https://github.com/cloudflare/miniflare/issues/346), thanks [@Cherry](https://github.com/Cherry). - Fix `CryptoKey#algorithm.name` property of `NODE-ED25519` keys. Closes [issue panva/jose#446](https://github.com/panva/jose/issues/446), thanks [@ItalyPaleAle](https://github.com/ItalyPaleAle). - Disable automatic insertion of `Sec-WebSocket-Protocol` header. Closes [issue #179](https://github.com/cloudflare/miniflare/issues/179), thanks [@aboodman](https://github.com/aboodman) and [@grgbkr](https://github.com/grgbkr). - Return `Content-Length` header is custom `Content-Encoding` is specified. Closes [issue #313](https://github.com/cloudflare/miniflare/issues/313), thanks [@vlovich](https://github.com/vlovich). - Require `"automatic"` instead of `"auto"` for the `encodeBody` option when constructing `Request`s. Closes [issue #357](https://github.com/cloudflare/miniflare/issues/357), thanks [@GregBrimble](https://github.com/GregBrimble) for [the PR](https://github.com/cloudflare/miniflare/pull/358). - Remove `request.cf.cacheTtl`/`request.cf.cacheTtlByStatus` support from the Cache API to match the behaviour of the Workers runtime, which only supports `request.cf.cacheKey`. ## 2.7.1 ### Fixes - Ensure initialisation is complete before tear down in `Miniflare#dispose()`. Closes [issue #341](https://github.com/cloudflare/miniflare/issues/341), thanks [@vlovich](https://github.com/vlovich). - Ensure `DurableObjectTransaction` operations are executed in program order. Closes [issue #344](https://github.com/cloudflare/miniflare/issues/344), thanks [@vlovich](https://github.com/vlovich). ## 2.7.0 > ⚠️ **Miniflare's minimum supported Node.js version is now `16.13.0`.** This > was the first LTS release of Node.js 16. > > We recommend you use the latest Node.js version if possible, as Cloudflare > Workers use a very up-to-date version of V8. Consider using a Node.js version > manager such as https://volta.sh/ or https://github.com/nvm-sh/nvm. ### Features - πŸŽ‰ Add support for easily **mocking outbound `fetch` requests**. See [πŸ•Έ Web Standards](https://miniflare.dev/core/standards#mocking-outbound-fetch-requests) for more details. Closes [issue #162](https://github.com/cloudflare/miniflare/issues/162), thanks [@william1616](https://github.com/william1616) for [the PR](https://github.com/cloudflare/miniflare/pull/293). ```js test("mocks fetch", async () => { // Get correctly set up `MockAgent` const fetchMock = getMiniflareFetchMock(); // Throw when no matching mocked request is found fetchMock.disableNetConnect(); // Mock request to https://example.com/thing const origin = fetchMock.get("https://example.com"); origin .intercept({ method: "GET", path: "/thing" }) .reply(200, "Mocked response!"); const res = await fetch("https://example.com/thing"); const text = await res.text(); expect(text).toBe("Mocked response!"); }); ``` - 🚽 Add support to immediately invoke _("flush")_ scheduled Durable Object alarms in the [🀹 Jest Environment](https://miniflare.dev/testing/jest). Closes [issue #322](https://github.com/cloudflare/miniflare/issues/322), thanks [@robertcepa](https://github.com/robertcepa) and [@CraigglesO](https://github.com/CraigglesO) for [the PR](https://github.com/cloudflare/miniflare/pull/324). ```js test("flushes alarms", async () => { // Get Durable Object stub const env = getMiniflareBindings(); const id = env.TEST_OBJECT.newUniqueId(); const stub = env.TEST_OBJECT.get(id); // Schedule Durable Object alarm await stub.fetch("http://localhost/"); // Flush all alarms... await flushMiniflareDurableObjectAlarms(); // ...or specify an array of `DurableObjectId`s to flush await flushMiniflareDurableObjectAlarms([id]); }); ``` - πŸͺ£ Add support for R2 bucket bindings to the [🀹 Jest Environment](https://miniflare.dev/testing/jest). Closes [issue #305](https://github.com/cloudflare/miniflare/issues/305), thanks [@Cerberus](https://github.com/Cerberus) for [the PR](https://github.com/cloudflare/miniflare/pull/306). - 2️⃣ Add support for Wrangler 2's `routes` property. Closes [issue #254](https://github.com/cloudflare/miniflare/issues/254), thanks [@jrencz](https://github.com/jrencz) for [the PR](https://github.com/cloudflare/miniflare/pull/307). - ⚠️ Upgrade [`undici`](https://github.com/nodejs/undici) to [`5.9.1`](https://github.com/nodejs/undici/releases/tag/v5.9.1). Thanks [@yusukebe](https://github.com/yusukebe) and [@cameron-robey](https://github.com/cameron-robey) for [the](https://github.com/cloudflare/miniflare/pull/320) [PRs](https://github.com/cloudflare/miniflare/pull/333). ### Fixes - Return custom `Content-Encoding`s, closes [issue #312](https://github.com/cloudflare/miniflare/issues/312), thanks [@vlovich](https://github.com/vlovich). - Fix reading symlinked files from Miniflare's file-system storage. Closes [issue #318](https://github.com/cloudflare/miniflare/issues/318), thanks [@CraigglesO](https://github.com/CraigglesO) for [the PR](https://github.com/cloudflare/miniflare/pull/319). - Display all accessible addresses when listening on host `0.0.0.0`. Closes [issue cloudflare/wrangler2#1652](https://github.com/cloudflare/wrangler2/issues/1652), thanks [@Skye-31](https://github.com/Skye-31) for [the PR](https://github.com/cloudflare/miniflare/pull/332). - Fix unbounded recursion when calling `Date.now()`/`new Date()` without `--actual-time` flag. Closes [issue #314](https://github.com/cloudflare/miniflare/issues/314), thanks [@WalshyDev](https://github.com/WalshyDev) and [@AggressivelyMeows](https://github.com/AggressivelyMeows). - Preserve full path in `File#name` field. Thanks [@yusefnapora](https://github.com/yusefnapora) for [the PR](https://github.com/cloudflare/miniflare/pull/309). - Change underlying glob matching implementation to `picomatch`. Closes [issue #244](https://github.com/cloudflare/miniflare/issues/244), thanks [@jed](https://github.com/jed) and [@cometkim](https://github.com/cometkim) for [the PR](https://github.com/cloudflare/miniflare/pull/316). - Fix `NotSupportedError` when using the `NODE-ED25519` algorithm in recent versions of Node.js. Closes [issue #310](https://github.com/cloudflare/miniflare/issues/310), thanks [@yusefnapora](https://github.com/yusefnapora) for [the PR](https://github.com/cloudflare/miniflare/pull/311). ## 2.6.0 ### Features - πŸͺ£ **Add support for R2 bucket bindings.** Closes [issue #276](https://github.com/cloudflare/miniflare/issues/276), thank you so much [@CraigglesO](https://github.com/CraigglesO) for [the _massive_ PR](https://github.com/cloudflare/miniflare/pull/289). - Add support for [`navigator.userAgent`](https://developers.cloudflare.com/workers/platform/compatibility-dates#global-navigator). Closes [issue #209](https://github.com/cloudflare/miniflare/issues/209), thanks [@Electroid](https://github.com/Electroid). - Return fixed time from `new Date()`/`Date.now()`, unless the `--actual-time`/`actualTime: true` option is set, to match [the behaviour the Workers runtime](https://developers.cloudflare.com/workers/learning/security-model/#step-1-disallow-timers-and-multi-threading). Closes [issue #225](https://github.com/cloudflare/miniflare/issues/225), thanks [@ItalyPaleAle](https://github.com/ItalyPaleAle). - Add support for [`(De)CompressionStream`](https://developer.mozilla.org/en-US/docs/Web/API/Compression_Streams_API). Closes [issue #206](https://github.com/cloudflare/miniflare/issues/206), thanks [@Electroid](https://github.com/Electroid). - Add an interactive REPL via the `--repl` flag. Any other flag can be passed too, and options will automatically be loaded from `wrangler.toml` files. Specifying a script is optional when `--repl` is enabled. The REPL can also be started programmatically via the `Miniflare#startREPL()` method. See []() for more details. Thanks [@threepointone](https://github.com/threepointone) for the idea over at [cloudflare/wrangler2#1263](https://github.com/cloudflare/wrangler2/issues/1263). ### Fixes - Load service bindings from `services` instead of `experimental_services`, and use `binding` instead of `name` for the binding name. Thanks [@jrencz](https://github.com/jrencz) for [the PR](https://github.com/cloudflare/miniflare/pull/302). [issue #280](https://github.com/cloudflare/miniflare/issues/280). - Log warning instead of error when fetching `Request#cf` object fails. Closes [issue #224](https://github.com/cloudflare/miniflare/issues/224), thanks [@threepointone](https://github.com/threepointone). - Increase the subrequest limit for `unbound` workers from 50 to 1000, and limit the number of calls to internal APIs such as KV/Durable Object to 1000. Closes [issue #274](https://github.com/cloudflare/miniflare/issues/274), thanks [@isaac-mcfadyen](https://github.com/isaac-mcfadyen). - Fix logging of accessible hosts in Node.js 18 - Remove `name` from `DurableObjectId`s in `DurableObjectState` to match the behaviour of the Workers runtime. Closes [issue #219](https://github.com/cloudflare/miniflare/issues/219). - Allow failure WebSocket upgrade responses. Closes [issue #174](https://github.com/cloudflare/miniflare/issues/174), thanks [@jinjor](https://github.com/jinjor). - Correctly handle internationalised domain names in routes. Closes [issue #186](https://github.com/cloudflare/miniflare/issues/186), thanks [@dsod](https://github.com/dsod). - Improve the error message when Durable Object bindings are missing a script to mention mounting. Closes [issue #221](https://github.com/cloudflare/miniflare/issues/221), thanks [@konsumer](https://github.com/konsumer). - Allow WebSockets to be closed without a status code. Closes [issue #284](https://github.com/cloudflare/miniflare/issues/284), thanks [@hansottowirtz](https://github.com/hansottowirtz). - Allow Durable Object alarms to be scheduled less than 30 seconds in the future. Closes [issue #290](https://github.com/cloudflare/miniflare/issues/290), thanks [@wighawag](https://github.com/wighawag) and [@CraigglesO](https://github.com/CraigglesO) for [the PR](https://github.com/cloudflare/miniflare/pull/294). - Fix `DurableObjectStorage#list()` when alarms are scheduled. Closes [issue #297](https://github.com/cloudflare/miniflare/issues/297), thanks [@evanderkoogh](https://github.com/evanderkoogh) and [@CraigglesO](https://github.com/CraigglesO) for [the PR](https://github.com/cloudflare/miniflare/pull/298). ## 2.5.1 ### ⚠️ Security Update - Upgrade `undici` to `5.5.1`, addressing [GHSA-pgw7-wx7w-2w33](https://github.com/advisories/GHSA-pgw7-wx7w-2w33) - Upgrade `node-forge` to `1.3.1`, addressing [GHSA-2r2c-g63r-vccr](https://github.com/advisories/GHSA-2r2c-g63r-vccr), [GHSA-x4jg-mjrx-434g](https://github.com/advisories/GHSA-x4jg-mjrx-434g) and [GHSA-cfm4-qjh2-4765](https://github.com/advisories/GHSA-cfm4-qjh2-4765) - Upgrade `minimist` to `1.2.6`, addressing [GHSA-xvch-5gv4-984h](https://github.com/advisories/GHSA-xvch-5gv4-984h) ## 2.5.0 ### Features - ⏰ Add support for [**Durable Object alarms**](https://developers.cloudflare.com/workers/learning/using-durable-objects/#alarms-in-durable-objects). Thanks [@CraigglesO](https://github.com/CraigglesO) for [the PR](#257). - Add support for `URLPattern`. Closes [issue #199](https://github.com/cloudflare/miniflare/issues/199), thanks [@Electroid](https://github.com/Electroid) and [@tom-sherman](https://github.com/tom-sherman) for [the PR](https://github.com/cloudflare/miniflare/pull/260). - Add support for the [`Response.json()`](https://community.cloudflare.com/t/2022-5-26-workers-runtime-release-notes/386584) static method. Closes [issue #272](https://github.com/cloudflare/miniflare/issues/272), thanks [@Cherry](https://github.com/Cherry). - Add support for the [`startAfter`](https://developers.cloudflare.com/workers/runtime-apis/durable-objects#methods) Durable Object `list()` option. Closes [issue #266](https://github.com/cloudflare/miniflare/issues/266), thanks [@vlovich](https://github.com/vlovich). - Add support for Jest 28 and custom [export conditions](https://nodejs.org/api/packages.html#conditional-exports). By default, the Miniflare Jest environment will use the `worker` condition, followed by `browser`. Closes issues [#249](https://github.com/cloudflare/miniflare/issues/249) and [#255](https://github.com/cloudflare/miniflare/issues/255), thanks [@awwong1](https://github.com/awwong1) and [@SupremeTechnopriest](https://github.com/SupremeTechnopriest). ### Fixes - Fixed issue where `403 Forbidden` responses were returned when a site behind Cloudflare was set as the upstream. Closes [issue #237](https://github.com/cloudflare/miniflare/issues/237), thanks [@james-maher](https://github.com/james-maher) for [the PR](https://github.com/cloudflare/miniflare/pull/238). - Respect `env_path` option in `wrangler.toml` when using mounts or the Miniflare Jest environment. Closes [issue #240](https://github.com/cloudflare/miniflare/issues/240), thanks [@bkniffler](https://github.com/bkniffler). - Fix cases where BYOB readers didn't notice the end of the stream. Closes [issue #192](https://github.com/cloudflare/miniflare/issues/192), thanks [@vlovich](https://github.com/vlovich) for [the PR](https://github.com/cloudflare/miniflare/pull/194). - Wait for unawaited writes within a Durable Object transaction before attempting to commit. Closes [issue #250](https://github.com/cloudflare/miniflare/issues/250), thanks [@vlovich](https://github.com/vlovich). - Correctly bind `this` in `crypto` and `crypto.subtle`. Closes [issue #256](https://github.com/cloudflare/miniflare/issues/256), thanks [@lmcarreiro](https://github.com/lmcarreiro) and [@awwong1](https://github.com/awwong1) for [the PR](https://github.com/cloudflare/miniflare/pull/259/). - Bump `busboy` to resolve a [security issue](https://github.com/advisories/GHSA-wm7h-9275-46v2). Closes [issue #267](https://github.com/cloudflare/miniflare/issues/267), thanks [@grempe](https://github.com/grempe) and [@Cherry](https://github.com/Cherry) for [the PR](https://github.com/cloudflare/miniflare/pull/269/). - Set incoming `Accept-Encoding` headers to `gzip` and put actual client encodings in `request.cf.clientAcceptEncoding` to match the behaviour of the Workers runtime. Closes [issue #180](https://github.com/cloudflare/miniflare/issues/180), thanks [@evanderkoogh](https://github.com/evanderkoogh) and [@leader22](https://github.com/leader22) for [the PR](https://github.com/cloudflare/miniflare/pull/213/). - [Remove restriction](https://community.cloudflare.com/t/2022-2-25-workers-runtime-release-notes/360450) on supported `TextDecoder` encodings. Closes [issue #212](https://github.com/cloudflare/miniflare/issues/212). - Make `headers` on returned `fetch` `Response`s immutable. Closes [issue #242](https://github.com/cloudflare/miniflare/issues/242), thanks [@nickreese](https://github.com/nickreese). - Use lexicographic ordering for KV/Durable Object `list()`s. Closes [issue #235](https://github.com/cloudflare/miniflare/issues/235), thanks [@vlovich](https://github.com/vlovich). - Re-export `Request`, `RequestInfo`, `RequestInit` and `Response` from `miniflare`. Closes [issue #258](https://github.com/cloudflare/miniflare/issues/258), thanks [@ajwootto](https://github.com/ajwootto). - Add `jest-environment-miniflare`'s missing `dependencies`. Thanks [@BasixKOR](https://github.com/BasixKOR) for [the PR](https://github.com/cloudflare/miniflare/pull/195). ## 2.4.0 ### Features - Add support for `[text_blobs]`. Closes [issue #211](https://github.com/cloudflare/miniflare/issues/211), thanks [@caass](https://github.com/caass) for [the PR](https://github.com/cloudflare/miniflare/pull/228). - Add support for `[data_blobs]`. Closes [issue #231](https://github.com/cloudflare/miniflare/issues/231), thanks [@threepointone](https://github.com/threepointone) for [the PR](https://github.com/cloudflare/miniflare/pull/232). - Do not display the pretty error page when making requests with `curl`. Closes [issue #198](https://github.com/cloudflare/miniflare/issues/198), thanks [@GregBrimble](https://github.com/GregBrimble) for [the PR](https://github.com/cloudflare/miniflare/pull/210). ### Fixes - Pass correctly-typed value to `webcrypto.getRandomValues()`. Closes [issue #188](https://github.com/cloudflare/miniflare/issues/188), thanks [@vlovich](https://github.com/vlovich). - Fix `fetch` with `Content-Length: 0` header. Closes [issue #193](https://github.com/cloudflare/miniflare/issues/193), thanks [@orls](https://github.com/orls) for [the PR](https://github.com/cloudflare/miniflare/pull/204). - Bind `this` to `webcrypto` methods, fixing `crypto.getRandomValues()` and `crypto.subtle.generateKey()`. Thanks [@szkl](https://github.com/szkl) for [the PR](https://github.com/cloudflare/miniflare/pull/216). ## 2.3.0 ### Features - Route `/cdn-cgi/mf/scheduled` requests based on mount routes. Closes [issue #163](https://github.com/cloudflare/miniflare/issues/163), thanks [@jed](https://github.com/jed). - Add clear error if a Durable Object class is missing a `fetch` handler. Closes [issue #164](https://github.com/cloudflare/miniflare/issues/164), thanks [@aboodman](https://github.com/aboodman). - Upgrade [`undici`](https://github.com/nodejs/undici) to [`4.13.0`](https://github.com/nodejs/undici/releases/tag/v4.13.0) ### Fixes - Fix `instanceof` when subclassing `Error`. Subclasses of `Error` were previously treated as `Error`s themselves in `instanceof` checks. Closes [issue #159](https://github.com/cloudflare/miniflare/issues/159), thanks [@valeriangalliat](https://github.com/valeriangalliat). - Return `null` bodies when `fetch`ing `Response`s with a null status. Closes [issue #165](https://github.com/cloudflare/miniflare/issues/165), thanks [@lukaszczerpak](https://github.com/lukaszczerpak) for reporting this and [@GregBrimble](https://github.com/GregBrimble) for [the PR](https://github.com/cloudflare/miniflare/pull/172). - Clone `ArrayBuffer` bodies when constructing `Request`/`Response`s. Closes [issue #171](https://github.com/cloudflare/miniflare/issues/171), thanks [@segator](https://github.com/segator) and [@leader22](https://github.com/leader22). - Watch `index.js` by default in `type = "webpack"` projects - Throw `TypeError`s instead of `string`s on `HTMLRewriter` parser errors - Disable nested mounts via `Miniflare#getMount().setOptions()` ## 2.2.0 ### Features - Add support for the `HTMLRewriter` [`Element#onEndTag(handler)`](https://github.com/cloudflare/workers-types/blob/17d21e9ae7cfee0c5d6ca4bf247978e5618c0386/index.d.ts#L466-L474) [method](https://community.cloudflare.com/t/2022-01-17-workers-runtime-release-notes/346596) - Add support for the [`html_rewriter_treats_esi_include_as_void_tag`](https://developers.cloudflare.com/workers/platform/compatibility-dates#htmlrewriter-handling-of-esiinclude) compatibility flag - Make the error message when attempting to import Node.js built-in modules more helpful ### Fixes - Fix `instanceof` checks with `null` values. Closes issues [#152](https://github.com/cloudflare/miniflare/issues/152) and [#154](https://github.com/cloudflare/miniflare/issues/154). Thanks [@Cerberus](https://github.com/Cerberus) for [the PR](https://github.com/cloudflare/miniflare/pull/155), and [@bduff9](https://github.com/bduff9), [@huw](https://github.com/huw) & [@g45t345rt](https://github.com/g45t345rt) for reporting this. - Fix subdirectory watching on Linux. Closes [issue #153](https://github.com/cloudflare/miniflare/issues/153), thanks [@huw](https://github.com/huw) for reporting this. - Throw a `TypeError` instead of a `string` when the parameter passed to a `HTMLRewriter` handler is used outside the handler ## 2.1.0 ### Features - Allow multiple build watch paths to be set in `wrangler.toml` files. Use the `[miniflare] build_watch_dirs` option. Note this gets merged with the regular `[build] watch_dir` option: ```toml [build] watch_dir = "src1" [miniflare] build_watch_dirs = ["src2", "src3"] ``` - WebSocket handshake headers are now included in responses from the HTTP server and WebSocket upgrade `fetch`es. Closes [issue #151](https://github.com/cloudflare/miniflare/issues/151), thanks [@jed](https://github.com/jed). ### Fixes - Allow Miniflare to be installed with [Yarn PnP](https://yarnpkg.com/features/pnp). Closes [issue #144](https://github.com/cloudflare/miniflare/issues/144), thanks [@lookfirst](https://github.com/lookfirst), [@merceyz](https://github.com/merceyz), and [@DJtheRedstoner](https://github.com/DJtheRedstoner). - Use the actual body length for the `Content-Length` header in HTTP server responses, instead of the value provided in the `Response` constructor. Closes [issue #148](https://github.com/cloudflare/miniflare/issues/148), thanks [@lukaszczerpak](https://github.com/lukaszczerpak). - Don't rewrite the `Host` header to match the upstream URL. Closes [issue #149](https://github.com/cloudflare/miniflare/issues/149), thanks [@hansede](https://github.com/hansede). - Bump dependencies, fixing `npm audit` warnings. Thanks [@leader22](https://github.com/leader22) for [the PR](https://github.com/cloudflare/miniflare/pull/150). - Make `instanceof` spec-compliant, ensuring checks like `Object instanceof Object` succeed. This particular check was used by Lodash's `_.isPlainObject()` method, which is internally called by `_.merge()`, causing unexpected results. - Make the unimplemented `Response#type` property non-enumerable - Copy header guard when `clone()`ing `Request`s, ensuring `Request`s with immutable headers still have immutable headers when `clone()`ed - Fix race conditions in file-system watcher ## 2.0.0 Miniflare 2 has been completely redesigned from version 1 with 3 primary design goals: 1. πŸ“š **Modular:** Miniflare 2 splits Workers components (KV, Durable Objects, etc.) into **separate packages** (`@miniflare/kv`, `@miniflare/durable-objects`, etc.) that you can import separately for testing. 2. ✨ **Lightweight:** Miniflare 1 included [122 third-party packages](http://npm.anvaka.com/#/view/2d/miniflare) with a total install size of `88MB`. Miniflare 2 reduces this to **24 packages and `6MB`** by leveraging features included with Node.js 16. 3. βœ… **Accurate:** Miniflare 2 more accurately replicates the quirks and thrown errors of the real Workers runtime, so you'll know before you deploy if things are going to break. Check out the [migration guide](https://miniflare.dev/get-started/migrating) if you're upgrading from version 1. ### Notable Changes - ✳️ Node.js 16.7.0 is now the minimum required version - 🀹 Added a custom Jest test environment, allowing you to run unit tests in the Miniflare sandbox, with isolated storage for each test - πŸ”Œ Added support for running multiple workers in the same Miniflare instance - ⚑️ Added a live reload feature (`--live-reload`) that automatically refreshes your browser when your worker reloads - πŸšͺ Added Durable Object input and output gates, and write coalescing - πŸ›‘ Added the `DurableObjectState#blockConcurrencyWhile(callback)` method - πŸ“… Added support for compatibility dates and flags: `durable_object_fetch_requires_full_url`, `fetch_refuses_unknown_protocols`, `formdata_parser_supports_files` - πŸ“š Added a proper CommonJS module loader - πŸ—Ί Automatically fetch the incoming `Request#cf` object from a trusted Cloudflare endpoint - 🎲 Added support for `crypto.randomUUID()` - πŸ” Added support for the `NODE-ED25519` algorithm - βœ‰οΈ Added support for sending/receiving binary WebSocket messages ### Breaking Changes - **Node.js 16.7.0 is now the minimum required version.** You should use the latest Node.js version if possible, as Cloudflare Workers use a very up-to-date version of V8. Consider using a Node.js version manager such as or . - Changed the storage format for Durable Objects and cached responses. If you're using file-system or Redis storage, you'll need to delete these directories/namespaces. - Changed the Durable Object ID format to include a hash of the object name. Durable Object IDs generated in Miniflare 1 cannot be used with Miniflare 2. - Correctly implement the Durable Object `script_name` option. In Miniflare 1, this incorrectly expected a script path instead of a script name. This now relies on mounting the other worker. See [πŸ“Œ Durable Objects](https://miniflare.dev/storage/durable-objects#using-a-class-exported-by-another-script) for more details. - Removed the non-standard `DurableObjectStub#storage()` method. To access Durable Object storage outside a worker, use the new `Miniflare#getDurableObjectStorage(id)` method, passing a `DurableObjectId` obtained from a stub. See [πŸ“Œ Durable Objects](https://miniflare.dev/storage/durable-objects#manipulating-outside-workers) for more details. - Renamed the `--disable-cache`/`disableCache: true` option to `--no-cache`/`cache: false` - Renamed the `--disable-updater` option to `--no-update-check` - When using the API, `wrangler.toml`, `package.json` and `.env` are no longer automatically loaded from their default locations. To re-enable this behaviour, set these options to `true`: ```js const mf = new Miniflare({ wranglerConfigPath: true, packagePath: true, envPath: true, }); ``` - Replaced the `ConsoleLog` class with the `Log` class from `@miniflare/shared`. You can construct this with a `LogLevel` to control how much information is logged to the console: ```js import { Miniflare, Log, LogLevel } from "miniflare"; const mf = new Miniflare({ log: new Log(LogLevel.DEBUG), }); ``` - Load WASM bindings from the standard `wasm_modules` `wrangler.toml` key instead of `miniflare.wasm_bindings`. ```toml --- filename: wrangler.toml --- [miniflare] wasm_bindings = [ { name = "MODULE1", path="module1.wasm" }, { name = "MODULE2", path="module2.wasm" } ] ``` ...should now be... ```toml --- filename: wrangler.toml --- [wasm_modules] MODULE1 = "module1.wasm" MODULE2 = "module2.wasm" ``` - Renamed the `buildWatchPath` option to `buildWatchPaths`. This is now an array of string paths to watch as opposed to a single string. - Replaced the `Miniflare#reloadOptions()` method with the `Miniflare#reload()` and `Miniflare#setOptions({ ... })` methods. `reload()` will reload options from `wrangler.toml` (useful if not watching), and `setOptions()` accepts the same options object as the `new Miniflare` constructor, applies those options, then reloads the worker. - Replaced the `Miniflare#getCache()` method the `Miniflare#getCaches()` method. This returns the global `caches` object. See [✨ Cache ](https://miniflare.dev/storage/cache#manipulating-outside-workers). - `Miniflare#createServer()` now always returns a `Promise` which you must await to get a `http.Server`/`https.Server` instance. You may want to check out the new `Miniflare#startServer()` method which automatically starts a server using the configured `host` and `port`. - Redis support is no longer included by default. If you're persisting KV, Durable Objects or cached responses in Redis, you must install the `@miniflare/storage-redis` optional peer dependency. - Replaced how Miniflare sanitises file paths for file-system storage so namespace separators (`/`, `\`, `:` and `|`) now create new directories. - The result of `Miniflare#dispatchScheduled` will no longer include `undefined` if a module scheduled handler doesn't return a value ### Features and Fixes **Cache:** - Added support for `cf.cacheKey`, `cf.cacheTtl` and `cf.cacheTtlByStatus` on `Request`. Closes [issue #37](https://github.com/cloudflare/miniflare/issues/37), thanks [@cdloh](https://github.com/cdloh). - Added the `CF-Cache-Status: HIT` header to matched `Response`s - Log warning when trying to use cache with `workers_dev = true` in `wrangler.toml`. Cache operations are a no-op on `workers.dev` subdomains. - Throw errors when trying to cache Web Socket, non-`GET`, `206 Partial Content`, or `Vary: *` responses - Throw an error when trying to `open` a cache with a name longer than `1024` characters **CLI:** - Separated command line options into sections - Validate types of all command line options **Core:** - **Added support for running multiple workers** in the same Miniflare instance. See [πŸ”Œ Multiple Workers](https://miniflare.dev/core/mount) for more details. - **Added support for compatibility dates and flags**, specifically the flags `durable_object_fetch_requires_full_url`, `fetch_refuses_unknown_protocols`, **`formdata_parser_supports_files`** are now supported. This feature is exposed under the `--compat-date` and `--compat-flag` CLI options, in addition to the standard keys in `wrangler.toml`. Closes [issue #48](https://github.com/cloudflare/miniflare/issues/48), thanks [@PaganMuffin](https://github.com/PaganMuffin). See [πŸ“… Compatibility Dates](https://miniflare.dev/core/compatibility) for more details. - **Added a proper CommonJS module loader.** Workers built with Webpack will be more likely to work with Miniflare now. Closes [issue #44](https://github.com/cloudflare/miniflare/issues/44), thanks [@TimTinkers](https://github.com/TimTinkers). - Don't crash on unhandled promise rejections when using the CLI. Instead, log them. Closes [issue #115](https://github.com/cloudflare/miniflare/issues/115), thanks [@togglydev](https://github.com/togglydev). - Limit the number of [subrequests](https://developers.cloudflare.com/workers/platform/limits#subrequests) to 50, [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 `--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 worker's script - Only rebuild parts of the sandbox that need to change when options are updated - Added a new reload event to `Miniflare` instances that is dispatched whenever the worker reloads: ```js const mf = new Miniflare({ ... }); mf.addEventListener("reload", (event) => { console.log("Worker reloaded!"); }); ``` - Added a new `Miniflare#getGlobalScope()` method for getting the global scope of the Miniflare sandbox. This allows you to access and manipulate the Miniflare environment whilst your worker is running without reloading it. Closes [issue #38](https://github.com/cloudflare/miniflare/issues/38), thanks [@cdloh](https://github.com/cdloh). - Added a new `Miniflare#startScheduler()` method that starts a CRON scheduler that dispatches `scheduled` events according to CRON expressions in options - Miniflare-added `CF-*` headers are now included in the HTML error response - Updated build script to use ES module exports of dependencies where possible. Thanks [@lukeed](https://github.com/lukeed) for the [PR](https://github.com/cloudflare/miniflare/pull/77). **Bindings:** - Added `--global KEY=VALUE`/`globals: { KEY: "value" }` option for binding arbitrary values to the global scope. This behaves exactly like the `--binding`/`bindings: { ... }` option, but always binds to the global scope, even in modules mode. - Added a new global variable `MINIFLARE` to the Miniflare sandbox, which will always have the value `true` when your script is running within Miniflare - Miniflare now stringifies all environment variables from `wrangler.toml`. Closes [issue #50](https://github.com/cloudflare/miniflare/issues/50), thanks [@ozburo](https://github.com/ozburo). - Adds **highly experimental** support for [service bindings](https://blog.cloudflare.com/introducing-worker-services/#services-can-talk-to-each-other). This is primarily meant for internal testing, and users outside the beta can't deploy workers using this feature yet, but feel free to play around with them locally and let us know what you think in the [Cloudflare Workers Discord server](https://discord.gg/cloudflaredev). To enable these, mount your service (so Miniflare knows where to find it) then add the binding. Note the bound service name must match the mounted name: ```sh $ miniflare --mount auth=./auth --service AUTH_SERVICE=auth # or -S ``` ```toml # wrangler.toml experimental_services = [ # Note environment is currently ignored { name = "AUTH_SERVICE", service = "auth", environment = "production" } ] [miniflare.mounts] auth = "./auth" ``` ```js const mf = new Miniflare({ mounts: { auth: "./auth" }, serviceBindings: { AUTH_SERVICE: "auth" }, }); ``` ...then to use the service binding: ```js export default { async fetch(request, env, ctx) { const res = await env.AUTH_SERVICE.fetch("..."); // ... }, }; ``` If `./auth/wrangler.toml` contains its own service bindings, those services must also be mounted in the **root** worker (i.e. in `wrangler.toml` not `./auth/wrangler.toml`). Nested mounts are not supported. **Builds:** - When running your worker's build script, Miniflare will set the environment variable `MINIFLARE=1`. Closes [issue #65](https://github.com/cloudflare/miniflare/issues/65), thanks [@maraisr](https://github.com/maraisr). - Added an alias, `-B`, for the `--build-command` option - Multiple build watch paths can now be specified. If any of them change, your worker will rebuild and reload. - Pass the `--env` flag to `wrangler build` when `--wrangler-env` is set for `type = "webpack"`/`"rust"` builds - Fixed an issue where workers would not rebuild if the build watch path started with `./`. Closes [issue #53](https://github.com/cloudflare/miniflare/issues/53), thanks [@janat08](https://github.com/janat08). **Standards:** - **Added support for [`crypto.randomUUID()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID)** - **Added support for [`structuredClone`](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone)**. Note the `transfer` option is only supported on Node.js >= 17. - **Added support for [`queueMicrotask`](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask)** - **Added support for the `NODE-ED25519` algorithm** to `crypto.subtle.sign()` and `crypto.subtle.verify()` - Added support for `AbortSignal.timeout()` - Added support for `crypto.DigestStream` - Added support for `scheduler.wait()` - Added support for `FixedLengthStream`. Closes [issue #123](https://github.com/cloudflare/miniflare/issues/123), thanks [@vlovich](https://github.com/vlovich). - Throw an error when attempting to create a new `TextDecoder` with a non-UTF-8 encoding - Throw errors when attempting to use `FetchEvent`/`ScheduledEvent` methods with incorrectly bound `this` - Throw errors when attempting to call `respondWith()` twice, or after the `fetch` handler has finished executing synchronously. Closes [issue #63](https://github.com/cloudflare/miniflare/issues/63), thanks [@Kikobeats](https://github.com/Kikobeats). - Added support for the `unhandledrejection` and `rejectionhandled` events - Throw an error (with a suggested fix) when trying to access an `env` binding globally in modules mode - Throw errors when trying to use `addEventListener()`, `removeEventListener()` and `dispatchEvent()` globals in modules mode - Split the `FetchError: No fetch handler responded and unable to proxy request to upstream?` error into more specific errors with suggested fixes - Added the [non-standard `Headers#getAll()` method](https://developers.cloudflare.com/workers/runtime-apis/headers#differences). This can only be used with the `Set-Cookie` header. - Switch to a [more spec-compliant `fetch` implementation](https://github.com/nodejs/undici/), and get `crypto`, `EventTarget` and Web Streams from Node.js. Closes [issues #56](https://github.com/cloudflare/miniflare/issues/56) and [#59](https://github.com/cloudflare/miniflare/issues/59), thanks [@jasnell](https://github.com/jasnell), [@jonathannorris](https://github.com/jonathannorris) and [@SupremeTechnopriest](https://github.com/SupremeTechnopriest). - Added support for the [`Response#encodeBody` property](https://developers.cloudflare.com/workers/runtime-apis/response#properties). If this is omitted or set to `auto`, `Response`s with a `Content-Encoding` header that includes `gzip`, `deflate` or `br` will be automatically encoded. Closes [issue #72](https://github.com/cloudflare/miniflare/issues/72), thanks [@SupremeTechnopriest](https://github.com/SupremeTechnopriest). - Return a non-`opaque` `Response` containing headers when fetching with a `redirect` mode set to `manual` in response to a redirect, closes [issue #133](https://github.com/cloudflare/miniflare/issues/133), thanks [@hansede](https://github.com/hansede), [@vzaramel](https://github.com/vzaramel) and [@hnrqer](https://github.com/hnrqer). - Set the `redirect` mode of incoming requests to `manual`, matching the [behaviour of the Workers runtime](https://developers.cloudflare.com/workers/runtime-apis/request#requestinit) - Remove extra headers not sent by Cloudflare Workers with `fetch` requests. Closes [issue #139](https://github.com/cloudflare/miniflare/issues/139), thanks [@dfcowell](https://github.com/dfcowell). - `Request`/`Response` `body`s are now byte streams, allowing them to be read with bring-your-own-buffer readers - Throw an error when attempting to construct a WebSocket response with a status other than `101` - Throw an error when attempting to clone a WebSocket response - Added support for the non-standard `ReadableStreamBYOBReader#readAtLeast(size, buffer)` method - Include `File` in the Miniflare sandbox. Closes [issue #66](https://github.com/cloudflare/miniflare/issues/66), thanks [@tranzium](https://github.com/tranzium). **Durable Objects:** - **Added input and output gates** for ensuring consistency without explicit transactions - **Added write coalescing** for `put`/`delete` without interleaving `await`s for automatic atomic writes - Added the `DurableObjectState#blockConcurrencyWhile(callback)` method. This prevents new `fetch` events being delivered to your object whilst the callback runs. Closes [issue #45](https://github.com/cloudflare/miniflare/issues/45), thanks [@gmencz](https://github.com/gmencz). - Added the `DurableObjectId#equals(id)` method for comparing if 2 Durable Object IDs have the same hex-ID - Automatically resolve relative URLs passed to `DurableObjectStub#fetch(input, init?)` against `https://fast-host`. Closes [issue #27](https://github.com/cloudflare/miniflare/issues/27), thanks [@halzy](https://github.com/halzy). - Throw an error if the string passed to `DurableObjectNamespace#idFromString(hexId)` is not 64 hex digits - Throw an error if the hex-ID passed to `DurableObjectNamespace#idFromString(hexId)` is for a different Durable Object - Throw an error if the ID passed to `DurableObjectNamespace#get(id)` is for a different Durable Object - Throw an error when keys are greater than `2KiB` or `undefined` - Throw an error when values are greater than `128KiB` - Throw an error when attempting to `get`, `put` or `delete` more than `128` keys, or when attempting to modify more than `128` keys in a transaction - Throw an error when attempting to `put` an `undefined` value - Throw an error when attempting to list keys with a negative `limit` - Throw an error when attempting to perform an operation in a rolledback transaction or in a transaction that has already committed - Throw an error when attempting to call `deleteAll()` in a transaction - Throw an error when a Durable Object `fetch` handler doesn't return a `Response` - Use the same V8 serialization as Cloudflare Workers to store values - Fixed an issue where keys added in a transaction callback were not reported as deleted in the same transaction - Fixed an issue where keys added in a transaction callback were not included in the list of keys in the same transaction **HTMLRewriter:** - Remove `Content-Length` header from `HTMLRewriter` transformed `Response`s - Don't start transforming until transformed `Response` body is needed - Throw an error when attempting to transform body streams containing non-ArrayBuffer/ArrayBufferView chunks **HTTP Server:** - **Added a live reload feature**, that automatically refreshes your browser when your worker reloads. For this to work, pass the `--live-reload` option, and return an HTML response containing a `` tag with the `Content-Type` set to `text/html`. See [⚑️ Live Reload](https://miniflare.dev/developing/live-reload) for more details. ```js addEventListener("fetch", (event) => { const body = `

Try update me!

`; const res = new Response(body, { headers: { "Content-Type": "text/html; charset=utf-8" }, }); event.respondWith(res); }); ``` - Added `--open`/`-O` option that automatically opens your browser once your worker is running. You can optionally specify a different URL to open with `--open https://example.com`. Closes [issue #121](https://github.com/cloudflare/miniflare/issues/121), thanks [@third774](https://github.com/third774) for the suggestion. - **Automatically fetch the incoming `Request#cf` object** from a trusted Cloudflare endpoint, so the values are the same as you'd get for real. Closes [issue #61](https://github.com/cloudflare/miniflare/issues/61), thanks [@aaronsdevera](https://github.com/aaronsdevera) and [@Electroid](https://github.com/Electroid). - Added a `metaProvider` option that allows you fetch metadata for an incoming `Request`: ```js const mf = new Miniflare({ async metaProvider(req) { return { forwardedProto: req.headers["X-Forwarded-Proto"], realIp: req.headers["X-Forwarded-For"], cf: { // Could get these from a geo-IP database colo: "SFO", country: "US", // ... }, }; }, }); ``` - Split out the Node request to `Request` object conversion logic into a `convertNodeRequest(req, meta?)` function. You can import this from `@miniflare/http-server`. - Only return a pretty-error page when the request `Accept` header includes `text/html` - Added a new `Miniflare#startServer(options?)` method that starts an HTTP server using the configured `port` and `host`. `options` can be a `http.ServerOptions` or `https.ServerOptions` object. Closes [issue #39](https://github.com/cloudflare/miniflare/issues/39), thanks [@amlwwalker](https://github.com/amlwwalker) - Include a default `Content-Type` header of `text/plain` in `Response`s. Closes [issue #57](https://github.com/cloudflare/miniflare/issues/57), thanks [@Rysertio](https://github.com/Rysertio). **Jest Environment:** - Added a custom Jest test environment, allowing you to run unit tests in the Miniflare sandbox, with isolated storage for each test. See [🀹 Jest Environment](https://miniflare.dev/testing/jest) for more details. **KV:** - Throw an error when keys are empty, `.`, `..`, `undefined`, or greater than `512B` when UTF-8 encoded - Throw an error when values are greater than `25MiB` - Throw an error when metadata is greater than `1KiB` - Throw an error when the `cacheTtl` option is less than `60s` - Throw an error when `expirationTtl` is non-numeric, less than or equal 0, or less than `60s` - Throw an error when `expiration` is non-numeric, less than or equal the current time, or less than `60s` in the future - Throw an error when the `limit` passed to `KVNamespace#list()` is non-numeric, less than or equal `0`, or greater than `1000` **Scheduler:** - Moved the `/.mf/scheduled` endpoint for triggering scheduled events to `/cdn-cgi/mf/scheduled`. Closes [issue #42](https://github.com/cloudflare/miniflare/issues/42), thanks [@ObsidianMinor](https://github.com/ObsidianMinor). - Switched the CRON validation and scheduling package from [`node-cron`](https://www.npmjs.com/package/node-cron) to [`cron-schedule`](https://www.npmjs.com/package/cron-schedule). This improves error messages for invalid CRON expressions, and removes a transitive dependency on `moment-timezone`, reducing the installation size by 5MB. **Workers Sites:** - Added support for the new `__STATIC_CONTENT_MANIFEST` text module allowing you to use Workers Sites in modules mode **Web Sockets:** - Added support for **sending/receiving binary messages**. Closes [issue #67](https://github.com/cloudflare/miniflare/issues/67), thanks [@NostalgiaRunner](https://github.com/NostalgiaRunner). - Removed the `WebSocket#readyState` property. Closes [issue #47](https://github.com/cloudflare/miniflare/issues/47), thanks [@aboodman](https://github.com/aboodman). - Wait for worker response before opening WebSocket in client, closes [issue #88](https://github.com/cloudflare/miniflare/issues/88), thanks [@TimTinkers](https://github.com/TimTinkers). - `http` and `https` protocols are now required for WebSocket upgrades via `fetch` as per the workers runtime - Throw an error when attempting to use a `WebSocket` in a `Response` that has already been used - Throw an error when attempting to use a `WebSocket` in a `Response` after calling `accept()` on it - Throw an error when attempting to construct a `WebSocket` using the `WebSocket` constructor - Throw an error when attempting to call `WebSocket#send()` or `WebSocket#close()` without first calling `accept()`. Closes [issue #43](https://github.com/cloudflare/miniflare/issues/43), thanks [@aboodman](https://github.com/aboodman). - Throw an error when attempting to call `WebSocket#send()` after calling `close()` - Throw an error when attempting to call `WebSocket#close()` on an already closed WebSocket - Throw an error when attempting to call `WebSocket#close()` with an invalid close code - Make WebSocket event constructors more spec-compliant ## 1.4.1 ### Fixes - Fixed linking of modules with cyclic imports, allowing [new Rust workers](https://blog.cloudflare.com/workers-rust-sdk/) to be run with Miniflare. Closes [issue #41](https://github.com/cloudflare/miniflare/issues/41), thanks [@nuvanti](https://github.com/nuvanti). - Fixed handling of `ArrayBufferView`s as `Response` bodies ## 1.4.0 ### Features - Added `Event` and `EventTarget` to the sandbox. The global scope and `WebSocket` now inherit from `EventTarget` so `removeEventListener` is now supported. Closes [issue #18](https://github.com/cloudflare/miniflare/issues/18), thanks [@jayphelps](https://github.com/jayphelps). - Added workers' uncompressed size to logs, closes [issue #23](https://github.com/cloudflare/miniflare/issues/23), thanks [@ItsWendell](https://github.com/ItsWendell) - Switch to lighter dependencies, thanks [@lukeed](https://github.com/lukeed). There's still lots of work to do here for the next major release. ### Fixes - Require the `GET` method for WebSocket upgrades, closes [issue #25](https://github.com/cloudflare/miniflare/issues/25), thanks [@ItsWendell](https://github.com/ItsWendell) - Added `WebSocket` to the sandbox, closes [issue #30](https://github.com/cloudflare/miniflare/issues/30), thanks [@ItsWendell](https://github.com/ItsWendell). Note you still need to use `WebSocketPair` and `fetch` to set up WebSocket connections. See [βœ‰οΈ WebSockets](https://miniflare.dev/core/web-sockets) for more details. - Fixed caching with `URL` request keys, closes [issue #33](https://github.com/cloudflare/miniflare/issues/33), thanks [@TimTinkers](https://github.com/TimTinkers) - Disable the watcher whilst rebuilding, closes [issue #34](https://github.com/cloudflare/miniflare/issues/34), thanks [@TimTinkers](https://github.com/TimTinkers) ## 1.3.3 ### Features - Added an option to disable default and named caches. When disabled, the caches will still be available in the sandbox, they just won't cache anything. Thanks [@frandiox](https://github.com/frandiox) for the suggestion. See [✨ Cache](https://miniflare.dev/storage/cache#disabling) for more details. - Added the corresponding `wrangler.toml` key for the `--disable-updater` flag: `miniflare.disable_updater` ### Fixes - Fixed the `package.json` file path the update checker checked against ## 1.3.2 ### Features - Responses are now streamed when using the built-in HTTP(S) server - Return values of Durable Object transaction closures are now propagated as the return value of the `transaction` call ### Fixes - Upgraded [`html-rewriter-wasm`](https://github.com/mrbbot/html-rewriter-wasm) to version `0.3.2`, fixing `async` handler support, closes [`html-rewriter-wasm` issue #1](https://github.com/mrbbot/html-rewriter-wasm/issues/1) ## 1.3.1 ### Fixes - Upgraded [`html-rewriter-wasm`](https://github.com/mrbbot/html-rewriter-wasm) to version `0.3.1`, fixing the return type of `Element.attributes` ## 1.3.0 ### Features - Switched to a [`lol-html`](https://github.com/cloudflare/lol-html)-based WebAssembly implementation of `HTMLRewriter` for a more accurate simulation of the real Workers environment. See [πŸ“„ HTMLRewriter](https://miniflare.dev/core/html-rewriter) for more details. - Added HTTPS support for local development, thanks [@RichiCoder1](https://github.com/RichiCoder1) for the [suggestion (#12)](https://github.com/cloudflare/miniflare/issues/12). See [πŸ’» Using the CLI](https://miniflare.dev/get-started/cli#https-server) and [🧰 Using the API](https://miniflare.dev/get-started/api#https-server) for more details. - When using the CLI, the `--watch` flag is now assumed if `--build-watch-path` is set, thanks [@evanderkoogh](https://github.com/evanderkoogh) for the [PR (#8)](https://github.com/cloudflare/miniflare/pull/8) - Added source maps to `CommonJS` module transformation ### Fixes - Switched to real values for the `cf` property, thanks [@chase](https://github.com/chase) for the [PR (#11)](https://github.com/cloudflare/miniflare/pull/11) - Upgraded the TOML parser to support dotted keys, thanks [@leader22](https://github.com/leader22) for the [PR (#13)](https://github.com/cloudflare/miniflare/pull/13) - Added `CryptoKey` to the sandbox, thanks [@mosch](https://github.com/mosch) for the [PR (#14)](https://github.com/cloudflare/miniflare/pull/14) ## 1.2.0 ### Features - Added **Redis** persistence support for [πŸ“¦ KV](https://miniflare.dev/storage/kv#persistence), [✨ Cache](https://miniflare.dev/storage/cache#persistence) and [πŸ“Œ Durable Objects](https://miniflare.dev/storage/durable-objects#persistence) - Added support for loading scripts from `package.json`, closes [issue #7](https://github.com/cloudflare/miniflare/issues/7). See [πŸ’» Using the CLI](https://miniflare.dev/get-started/cli#script-requirement) and [⚑️ Developing with esbuild](https://miniflare.dev/developing/esbuild#dependencies) for more details. - Added `FormData` to the sandbox, closes [issue #6](https://github.com/cloudflare/miniflare/issues/6) - Added an automatic update checker. See [πŸ’» Using the CLI](https://miniflare.dev/get-started/cli#update-checker) for more details. - [πŸ“š Modules](https://miniflare.dev/core/modules) mode is now always enabled when specifying [πŸ“Œ Durable Objects](https://miniflare.dev/storage/durable-objects##objects) bindings ### Fixes - Fixed **Windows** support, closes [issue #10](https://github.com/cloudflare/miniflare/issues/10) - Fixed issue where scripts were not reloaded correctly when editing script path in `wrangler.toml`. Scripts are now always reloaded on options change. `Miniflare.reloadScript()` is now deprecated. You should use `Miniflare.reloadOptions()` instead. ## 1.1.0 ### Features - Added support for namespaced caches with `caches.open`. See [✨ Cache](https://miniflare.dev/storage/cache) for more details. ## 1.0.1 ### Fixes - Fixed `/usr/bin/env: 'node --experimental-vm-modules': No such file or directory` error when running the CLI in Linux. See [πŸ’» Using the CLI](https://miniflare.dev/get-started/cli#usage) for more details. ## 1.0.0 ### Breaking Changes - The first and only argument to the `Miniflare` constructor is now an object. Scripts should be specified via the `script` option for strings and the `scriptPath` option for files: ```js // Previous version import vm from "vm"; import { Miniflare } from "miniflare"; const mf1 = new Miniflare( new vm.Script(`addEventListener("fetch", (event) => { ... })`), { kvPersist: true } ); const mf2 = new Miniflare("script.js", { kvPersist: true }); ``` ```js // New version import { Miniflare } from "miniflare"; const mf1 = new Miniflare({ script: `addEventListener("fetch", (event) => { ... })`, kvPersist: true, }); const mf2 = new Miniflare({ scriptPath: "script.js", kvPersist: true, }); ``` - The `Miniflare.getNamespace` method has been renamed to `Miniflare.getKVNamespace` - Logged errors will now throw a `MiniflareError` if no log is provided - When using file system KV persistence, key names are now sanitised to replace special characters such as `:`, `/`, and `\`. Reading keys containing these characters may now return `null` if a value was stored in the previous version. ### Features - Added support for [πŸ“š Modules](https://miniflare.dev/core/modules) (requires `--experimental-vm-modules` flag) - Added support for [πŸ“Œ Durable Objects](https://miniflare.dev/storage/durable-objects) - Added support for [βœ‰οΈ Web Sockets](https://miniflare.dev/core/web-sockets) (client and server) - Added support for [πŸ›  Builds](https://miniflare.dev/developing/builds) (custom builds and `webpack`/`rust` Wrangler builds) - Added support for [βš™οΈ WebAssembly](https://miniflare.dev/core/web-assembly) - Added support for [πŸ“„ HTMLRewriter](https://miniflare.dev/core/html-rewriter) - Made CLI `script` parameter optional, it can now be inferred in some cases from `wrangler.toml` - Added `host` option (`--host`/`-H` flag) for restricting hosts the HTTP server listens on - Added `Miniflare.dispose` method for cleaning up file watcher - Added [`CF-*` headers](https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers-) and [`cf` object](https://developers.cloudflare.com/workers/runtime-apis/request#incomingrequestcfproperties) to HTTP server requests - Added `cron` property to [⏰ Scheduled Events](https://miniflare.dev/core/scheduled) - Added manual triggering for [⏰ Scheduled Events](https://miniflare.dev/core/scheduled) via `/.mf/scheduled` HTTP endpoint - Added pretty error page powered by [Youch](https://github.com/poppinss/youch) - Added many more tests ### Fixes - Fixed error if options object (containing `type` and `cacheTtl` properties) passed as second parameter to KV `get` method, closes [issue #3](https://github.com/cloudflare/miniflare/issues/3) - Fixed error if `ArrayBuffer` passed as `data` to `crypto.subtle.digest("md5", data)` - Fixed handling of `ignoreMethod` option for `Cache` `match` and `delete` - Disabled edge caching when using Workers Sites, files are now always loaded from disk - Provided `Set` and `WeakSet` from Miniflare's realm to sandbox, removing `Promise`, so `(async () => {})() instanceof Promise` evaluates to `true` ## 0.1.1 ### Fixes - Depend on `@mrbbot/node-fetch` from npm instead of GitHub, closes [issue #2](https://github.com/cloudflare/miniflare/issues/2) ## 0.1.0 Initial Release ### Features - Added support for [πŸ“¨ Fetch Events](https://miniflare.dev/core/fetch) - Added support for [⏰ Scheduled Events](https://miniflare.dev/core/scheduled) - Added support for [πŸ”‘ Variables and Secrets](https://miniflare.dev/core/variables-secrets) - Added support for [πŸ“¦ KV](https://miniflare.dev/storage/kv) - Added support for [✨ Cache](https://miniflare.dev/storage/cache) - Added support for [🌐 Workers Sites](https://miniflare.dev/storage/sites) - Added support for [πŸ—Ί Source Maps](https://miniflare.dev/developing/source-maps)