Skip to content

Commit

Permalink
feat: support configurable persistDir
Browse files Browse the repository at this point in the history
resolves #7
  • Loading branch information
pi0 committed Mar 8, 2024
1 parent 45ad7d2 commit 725fd42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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", {
Expand Down

1 comment on commit 725fd42

@miaobuao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, bro :)

Please sign in to comment.