From 725fd425154c9e4a3eec54cf1d57b0be15f05e1d Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 8 Mar 2024 14:37:57 +0100 Subject: [PATCH] feat: support configurable `persistDir` resolves #7 --- README.md | 6 ++++++ src/index.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e8573b..ecbb6d1 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,12 @@ This module automatically finds the closest [`wrangler.toml`](https://developers Data is persisted `.wrangler/state/v3` directory. On first use of the module, it will be automatically added to the `.gitignore` file. +You can configure additional options using `cloudflareDev: { }` in `nitro.config` or `nitro: { cloudflareDev: {} }` in `nuxt.config`. + +### Available options + +- `persistDir`: Sets the persist dir (default `.wrangler/state/v3`) + ## Development - Clone this repository diff --git a/src/index.ts b/src/index.ts index cb49136..8ad858b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,14 @@ import { findFile } from "pkg-types"; export {} from "./types"; +declare module "nitropack" { + interface NitroOptions { + cloudflareDev?: { + persistDir?: string; + }; + } +} + async function nitroModule(nitro: Nitro) { if (!nitro.options.dev) { return; // Production doesn't need this @@ -20,7 +28,7 @@ async function nitroModule(nitro: Nitro) { }).catch(() => undefined); // Resolve the persist dir - const persistDir = resolve(nitro.options.rootDir, ".wrangler/state/v3"); + const persistDir = resolve(nitro.options.rootDir, nitro.options.cloudflareDev?.persistDir || ".wrangler/state/v3"); // Add `.wrnagle/state/v3` to `.gitignore` const gitIgnorePath = await findFile(".gitignore", {