Skip to content

Commit

Permalink
feat: (resolves #320) disable persistence by default (adding --enable…
Browse files Browse the repository at this point in the history
…-persistence flag to turn back on)
  • Loading branch information
geelen committed Jan 27, 2022
1 parent 53c6318 commit 4bcb4a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 10 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;
enablePersistence: 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}
enablePersistence={props.enablePersistence}
/>
) : (
<Remote
Expand Down Expand Up @@ -184,13 +186,15 @@ function Local(props: {
public: undefined | string;
site: undefined | AssetPaths;
port: number;
enablePersistence: boolean;
}) {
const { inspectorUrl } = useLocalWorker({
name: props.name,
bundle: props.bundle,
format: props.format,
bindings: props.bindings,
port: props.port,
enablePersistence: props.enablePersistence,
});
useInspector({ inspectorUrl, port: 9229, logToTerminal: false });
return null;
Expand All @@ -202,6 +206,7 @@ function useLocalWorker(props: {
format: CfScriptFormat;
bindings: CfWorkerInit["bindings"];
port: number;
enablePersistence: boolean;
}) {
// TODO: pass vars via command line
const { bundle, format, bindings, port } = props;
Expand Down Expand Up @@ -238,9 +243,11 @@ function useLocalWorker(props: {
path.join(__dirname, "../miniflare-config-stubs/package.empty.json"),
"--port",
port.toString(),
"--kv-persist",
"--cache-persist",
"--do-persist",
...(props.enablePersistence ? [
"--kv-persist",
"--cache-persist",
"--do-persist",
] : []),
...Object.entries(bindings.vars || {}).flatMap(([key, value]) => {
return ["--binding", `${key}=${value}`];
}),
Expand Down
5 changes: 5 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("enable-persistence", {
describe: "Enable persistence for this session (only for local mode)",
type: "boolean",
});
},
async (args) => {
Expand Down Expand Up @@ -608,6 +612,7 @@ 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}
enablePersistence={args["enable-persistence"] || false}
accountId={config.account_id}
assetPaths={getAssetPaths(
config,
Expand Down

0 comments on commit 4bcb4a3

Please sign in to comment.