Skip to content

Commit efdba4f

Browse files
docs(miniflare): add description for defaultPersistRoot (#9372)
* chore: fix typo in changeset * docs: add description for defaultPersistRoot * fix path * Apply suggestions from code review Co-authored-by: James Opstad <[email protected]> * Update packages/miniflare/README.md --------- Co-authored-by: James Opstad <[email protected]>
1 parent adc4941 commit efdba4f

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

.changeset/blue-streets-thank.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Add a new `defaultPersistRoot` option to control where plugins persist data when
88
// Before this change / No `defaultPersistRoot`
99
new Miniflare({
1010
kvPersist: undefined, // → "/(tmp)/kv"
11-
d1Persist: true, // → "/.mf/d1"
12-
r2Persist: false, // → "/(tmp)/d1"
11+
d1Persist: true, // → "$PWD/.mf/d1"
12+
r2Persist: false, // → "/(tmp)/r2"
1313
cachePersist: "/my-cache", // → "/my-cache"
1414
});
1515

@@ -18,7 +18,7 @@ new Miniflare({
1818
defaultPersistRoot: "/storage",
1919
kvPersist: undefined, // → "/storage/kv"
2020
d1Persist: true, // → "/storage/d1"
21-
r2Persist: false, // → "/(tmp)/d1"
21+
r2Persist: false, // → "/(tmp)/r2"
2222
cachePersist: "/my-cache", // → "/my-cache"
2323
});
2424
```

packages/miniflare/README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,13 @@ modules.
107107

108108
Represents where data should be persisted, if anywhere.
109109

110-
- If this is `undefined` or `false`, data will be stored in-memory and only
110+
- If this is `undefined`, it defaults to `true` if `defaultPersistRoot` is set
111+
or otherwise defaults to `false`.
112+
- If this is`false`, data will be stored in-memory and only
111113
persist between `Miniflare#setOptions()` calls, not restarts nor
112114
`new Miniflare` instances.
113-
- If this is `true`, data will be stored on the file-system, in the `$PWD/.mf`
114-
directory.
115+
- If this is `true`, data will be stored in a subdirectory of the `defaultPersistRoot` path if `defaultPersistRoot` is set
116+
or otherwise will be stored in a subdirectory of `$PWD/.mf`.
115117
- If this looks like a URL, then:
116118
- If the protocol is `memory:`, data will be stored in-memory as above.
117119
- If the protocol is `file:`, data will be stored on the file-system, in the
@@ -490,6 +492,29 @@ parameter in module format Workers.
490492
as deployed Workers. If no routes match, Miniflare will fallback to the Worker
491493
defined first.
492494

495+
- `defaultPersistRoot?: string`
496+
497+
Specifies the default directory where Miniflare will write persisted data when persistence is enabled.
498+
499+
```js
500+
// Without `defaultPersistRoot`
501+
new Miniflare({
502+
kvPersist: undefined, // → "/(tmp)/kv"
503+
d1Persist: true, // → "$PWD/.mf/d1"
504+
r2Persist: false, // → "/(tmp)/r2"
505+
cachePersist: "/my-cache", // → "/my-cache"
506+
});
507+
508+
// With `defaultPersistRoot`
509+
new Miniflare({
510+
defaultPersistRoot: "/storage",
511+
kvPersist: undefined, // → "/storage/kv"
512+
d1Persist: true, // → "/storage/d1"
513+
r2Persist: false, // → "/(tmp)/r2"
514+
cachePersist: "/my-cache", // → "/my-cache"
515+
});
516+
```
517+
493518
#### Cache
494519

495520
- `cache?: boolean`

0 commit comments

Comments
 (0)