Skip to content

Commit

Permalink
feat: (resolves #320) disable persistence by default
Browse files Browse the repository at this point in the history
feat: Added —experimental-enable-local-persistence flag to turn back on
chore: added project-level .prettierrc, otherwise system-wide settings cause massive diffs
chore: added changeset
  • Loading branch information
geelen committed Jan 28, 2022
1 parent 53c6318 commit f4a3c9c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .changeset/two-coins-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"wrangler": patch
---

fix: disable local persistence by default & add `--experimental-enable-local-persistence` flag

BREAKING CHANGE:

When running `dev` locally any data stored in KV, Durable Objects or the cache are no longer persisted between sessions by default.

To turn this back on add the `--experimental-enable-local-persistence` at the command line.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 80,
"singleQuote": false,
"semi": true
}
2 changes: 2 additions & 0 deletions packages/wrangler/src/__tests__/dev.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function renderDev({
compatibilityFlags,
usageModel,
buildCommand = {},
enableLocalPersistence = false,
}: Partial<DevProps>) {
return render(
<Dev
Expand All @@ -62,6 +63,7 @@ function renderDev({
compatibilityFlags={compatibilityFlags}
usageModel={usageModel}
bindings={bindings}
enableLocalPersistence={enableLocalPersistence}
/>
);
}
11 changes: 8 additions & 3 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type DevProps = {
initialMode: "local" | "remote";
jsxFactory: undefined | string;
jsxFragment: undefined | string;
enableLocalPersistence: boolean;
bindings: CfWorkerInit["bindings"];
public: undefined | string;
assetPaths: undefined | AssetPaths;
Expand Down Expand Up @@ -102,6 +103,7 @@ function Dev(props: DevProps): JSX.Element {
site={props.assetPaths}
public={props.public}
port={port}
enableLocalPersistence={props.enableLocalPersistence}
/>
) : (
<Remote
Expand Down Expand Up @@ -184,13 +186,15 @@ function Local(props: {
public: undefined | string;
site: undefined | AssetPaths;
port: number;
enableLocalPersistence: boolean;
}) {
const { inspectorUrl } = useLocalWorker({
name: props.name,
bundle: props.bundle,
format: props.format,
bindings: props.bindings,
port: props.port,
enableLocalPersistence: props.enableLocalPersistence,
});
useInspector({ inspectorUrl, port: 9229, logToTerminal: false });
return null;
Expand All @@ -202,6 +206,7 @@ function useLocalWorker(props: {
format: CfScriptFormat;
bindings: CfWorkerInit["bindings"];
port: number;
enableLocalPersistence: boolean;
}) {
// TODO: pass vars via command line
const { bundle, format, bindings, port } = props;
Expand Down Expand Up @@ -238,9 +243,9 @@ function useLocalWorker(props: {
path.join(__dirname, "../miniflare-config-stubs/package.empty.json"),
"--port",
port.toString(),
"--kv-persist",
"--cache-persist",
"--do-persist",
...(props.enableLocalPersistence
? ["--kv-persist", "--cache-persist", "--do-persist"]
: []),
...Object.entries(bindings.vars || {}).flatMap(([key, value]) => {
return ["--binding", `${key}=${value}`];
}),
Expand Down
7 changes: 7 additions & 0 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ export async function main(argv: string[]): Promise<void> {
.option("jsx-fragment", {
describe: "The function that is called for each JSX fragment",
type: "string",
})
.option("experimental-enable-local-persistence", {
describe: "Enable persistence for this session (only for local mode)",
type: "boolean",
});
},
async (args) => {
Expand Down Expand Up @@ -608,6 +612,9 @@ export async function main(argv: string[]): Promise<void> {
initialMode={args.local ? "local" : "remote"}
jsxFactory={args["jsx-factory"] || envRootObj?.jsx_factory}
jsxFragment={args["jsx-fragment"] || envRootObj?.jsx_fragment}
enableLocalPersistence={
args["experimental-enable-local-persistence"] || false
}
accountId={config.account_id}
assetPaths={getAssetPaths(
config,
Expand Down

0 comments on commit f4a3c9c

Please sign in to comment.