Skip to content

Commit 02a672e

Browse files
mrbbotpetebacondarwin
authored andcommittedMay 17, 2023
[wrangler] feature: enable persistent storage in local mode by default (#3188)
* feature: enable persistent storage in local mode by default Wrangler will now persist local KV, R2, D1, Cache and Durable Object data in the `.wrangler` folder, by default, between reloads. This persistence directory can be customised with the `--persist-to` flag. The `--persist` flag has been removed, as this is now the default behaviour. * fixup! feature: enable persistent storage in local mode by default Make change for Pages too

File tree

6 files changed

+16
-45
lines changed

6 files changed

+16
-45
lines changed
 

‎.changeset/moody-ducks-pull.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"wrangler": major
3+
---
4+
5+
feature: enable persistent storage in local mode by default
6+
7+
Wrangler will now persist local KV, R2, D1, Cache and Durable Object data
8+
in the `.wrangler` folder, by default, between reloads. This persistence
9+
directory can be customised with the `--persist-to` flag. The `--persist` flag
10+
has been removed, as this is now the default behaviour.

‎packages/wrangler/src/__tests__/dev.test.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1257,8 +1257,7 @@ describe("wrangler dev", () => {
12571257
--experimental-local-remote-kv Read/write KV data from/to real namespaces on the Cloudflare network [boolean] [default: false]
12581258
--minify Minify the script [boolean]
12591259
--node-compat Enable Node.js compatibility [boolean]
1260-
--persist Enable persistence for local mode, using default path: .wrangler/state [boolean]
1261-
--persist-to Specify directory to use for local persistence (implies --persist) [string]
1260+
--persist-to Specify directory to use for local persistence (defaults to .wrangler/state) [string]
12621261
--live-reload Auto reload HTML pages when change is detected in local mode [boolean]
12631262
--test-scheduled Test scheduled events by visiting /__scheduled in browser [boolean] [default: false]
12641263
--log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"] [default: \\"log\\"]",

‎packages/wrangler/src/d1/execute.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,7 @@ async function executeLocally({
236236
);
237237
}
238238

239-
const persistencePath = getLocalPersistencePath(
240-
persistTo,
241-
true,
242-
config.configPath
243-
);
239+
const persistencePath = getLocalPersistencePath(persistTo, config.configPath);
244240

245241
const dbDir = path.join(persistencePath, "d1");
246242
const dbPath = path.join(dbDir, `${localDB.binding}.sqlite3`);

‎packages/wrangler/src/dev.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,9 @@ export function devOptions(yargs: CommonYargsArgv) {
240240
deprecated: true,
241241
hidden: true,
242242
})
243-
.option("persist", {
244-
describe:
245-
"Enable persistence for local mode, using default path: .wrangler/state",
246-
type: "boolean",
247-
})
248243
.option("persist-to", {
249244
describe:
250-
"Specify directory to use for local persistence (implies --persist)",
245+
"Specify directory to use for local persistence (defaults to .wrangler/state)",
251246
type: "string",
252247
requiresArg: true,
253248
})
@@ -792,7 +787,6 @@ async function validateDevServerSettings(
792787

793788
const localPersistencePath = getLocalPersistencePath(
794789
args.persistTo,
795-
Boolean(args.persist),
796790
config.configPath
797791
);
798792

‎packages/wrangler/src/dev/get-local-persistence-path.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,25 @@ import path from "node:path";
22

33
export function getLocalPersistencePath(
44
persistTo: string | undefined,
5-
doPersist: true,
65
configPath: string | undefined
76
): string;
87

98
export function getLocalPersistencePath(
109
persistTo: string | undefined,
11-
doPersist: boolean,
1210
configPath: string | undefined
1311
): string | null;
1412

1513
export function getLocalPersistencePath(
1614
persistTo: string | undefined,
17-
doPersist: boolean,
1815
configPath: string | undefined
1916
) {
2017
return persistTo
2118
? // If path specified, always treat it as relative to cwd()
2219
path.resolve(process.cwd(), persistTo)
23-
: doPersist
24-
? // If just flagged on, treat it as relative to wrangler.toml,
20+
: // Otherwise, treat it as relative to wrangler.toml,
2521
// if one can be found, otherwise cwd()
2622
path.resolve(
2723
configPath ? path.dirname(configPath) : process.cwd(),
2824
".wrangler/state"
29-
)
30-
: null;
25+
);
3126
}

‎packages/wrangler/src/pages/dev.ts

+1-24
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,9 @@ export function Options(yargs: CommonYargsArgv) {
126126
describe: "Protocol to listen to requests on, defaults to http.",
127127
choices: ["http", "https"] as const,
128128
},
129-
"experimental-enable-local-persistence": {
130-
describe:
131-
"Enable persistence for local mode (deprecated, use --persist)",
132-
type: "boolean",
133-
deprecated: true,
134-
hidden: true,
135-
},
136-
persist: {
137-
describe:
138-
"Enable persistence for local mode, using default path: .wrangler/state",
139-
type: "boolean",
140-
},
141129
"persist-to": {
142130
describe:
143-
"Specify directory to use for local persistence (implies --persist)",
131+
"Specify directory to use for local persistence (defaults to .wrangler/state)",
144132
type: "string",
145133
requiresArg: true,
146134
},
@@ -187,8 +175,6 @@ export const Handler = async ({
187175
r2: r2s = [],
188176
liveReload,
189177
localProtocol,
190-
experimentalEnableLocalPersistence,
191-
persist,
192178
persistTo,
193179
nodeCompat: legacyNodeCompat,
194180
experimentalLocal,
@@ -243,14 +229,6 @@ export const Handler = async ({
243229
compatibilityDate = currentDate;
244230
}
245231

246-
if (experimentalEnableLocalPersistence) {
247-
logger.warn(
248-
`--experimental-enable-local-persistence is deprecated.\n` +
249-
`Move any existing data to .wrangler/state and use --persist, or\n` +
250-
`use --persist-to=./wrangler-local-state to keep using the old path.`
251-
);
252-
}
253-
254232
let scriptReadyResolve: () => void;
255233
const scriptReadyPromise = new Promise<void>(
256234
(promiseResolve) => (scriptReadyResolve = promiseResolve)
@@ -579,7 +557,6 @@ export const Handler = async ({
579557
]
580558
: undefined,
581559
bundle: enableBundling,
582-
persist,
583560
persistTo,
584561
inspect: undefined,
585562
logLevel,

0 commit comments

Comments
 (0)
Please sign in to comment.