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

Commit c4d0719

Browse files
committed
Only inherit persistence options from parent to mounts if defined
`kv_persist`, `cache_persist` and `durable_objects_persist` options set in mounted workers' `wrangler.toml` files are now respected.
1 parent c1a0946 commit c4d0719

File tree

3 files changed

+251
-135
lines changed

3 files changed

+251
-135
lines changed

packages/core/src/index.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -435,22 +435,38 @@ export class MiniflareCore<
435435
const mounts = options.CorePlugin
436436
.mounts as MiniflareCoreOptions<Plugins>["mounts"];
437437
if (mounts) {
438-
const defaultMountOptions = {
439-
// Copy watch option
440-
watch: this.#watching || undefined,
441-
// Copy storage persistence options, we want mounted workers to share
442-
// the same underlying storage for shared namespaces.
443-
// (this tight coupling makes me sad)
444-
kvPersist: resolveStoragePersist(rootPath, options.KVPlugin?.kvPersist),
445-
cachePersist: resolveStoragePersist(
446-
rootPath,
447-
options.CachePlugin?.cachePersist
448-
),
449-
durableObjectsPersist: resolveStoragePersist(
450-
rootPath,
451-
options.DurableObjectsPlugin?.durableObjectsPersist
452-
),
453-
};
438+
// Always copy watch option
439+
const defaultMountOptions: {
440+
watch?: boolean;
441+
kvPersist?: boolean | string;
442+
cachePersist?: boolean | string;
443+
durableObjectsPersist?: boolean | string;
444+
} = { watch: this.#watching || undefined };
445+
446+
// Copy defined storage persistence options, we want mounted workers to
447+
// share the same underlying storage for shared namespaces.
448+
// (this tight coupling makes me sad)
449+
const kvPersist = resolveStoragePersist(
450+
rootPath,
451+
options.KVPlugin?.kvPersist
452+
);
453+
const cachePersist = resolveStoragePersist(
454+
rootPath,
455+
options.CachePlugin?.cachePersist
456+
);
457+
const durableObjectsPersist = resolveStoragePersist(
458+
rootPath,
459+
options.DurableObjectsPlugin?.durableObjectsPersist
460+
);
461+
if (kvPersist !== undefined) {
462+
defaultMountOptions.kvPersist = kvPersist;
463+
}
464+
if (cachePersist !== undefined) {
465+
defaultMountOptions.cachePersist = cachePersist;
466+
}
467+
if (durableObjectsPersist !== undefined) {
468+
defaultMountOptions.durableObjectsPersist = durableObjectsPersist;
469+
}
454470

455471
// Create new and update existing mounts
456472
for (const [name, rawOptions] of Object.entries(mounts)) {

0 commit comments

Comments
 (0)