From a986f19f2d7989639524f9fd73761ea69aef4f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20F=C3=B6ldi?= Date: Thu, 7 Sep 2023 17:34:27 +0200 Subject: [PATCH] Don't throw for missing preview ids in local dev mode (#3901) * Don't throw for preview ids in local dev * Add changeset * These are used now, no underscore --- .changeset/bright-badgers-sit.md | 5 +++++ packages/wrangler/src/dev.tsx | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 .changeset/bright-badgers-sit.md diff --git a/.changeset/bright-badgers-sit.md b/.changeset/bright-badgers-sit.md new file mode 100644 index 000000000000..2113d8abe71c --- /dev/null +++ b/.changeset/bright-badgers-sit.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Only require preview_id and preview_bucket_name in remote dev mode diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index d603e7622cd8..a3270f0bcc2d 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -844,14 +844,14 @@ function getBindings( const bindings = { kv_namespaces: [ ...(configParam.kv_namespaces || []).map( - ({ binding, preview_id, id: _id }) => { - // In `dev`, we make folks use a separate kv namespace called + ({ binding, preview_id, id }) => { + // In remote `dev`, we make folks use a separate kv namespace called // `preview_id` instead of `id` so that they don't // break production data. So here we check that a `preview_id` // has actually been configured. // This whole block of code will be obsoleted in the future // when we have copy-on-write for previews on edge workers. - if (!preview_id) { + if (!preview_id && !local) { // TODO: This error has to be a _lot_ better, ideally just asking // to create a preview namespace for the user automatically throw new Error( @@ -860,7 +860,7 @@ function getBindings( } return { binding, - id: preview_id, + id: preview_id ?? id, }; } ), @@ -889,17 +889,17 @@ function getBindings( ], r2_buckets: [ ...(configParam.r2_buckets?.map( - ({ binding, preview_bucket_name, bucket_name: _bucket_name }) => { + ({ binding, preview_bucket_name, bucket_name }) => { // same idea as kv namespace preview id, // same copy-on-write TODO - if (!preview_bucket_name) { + if (!preview_bucket_name && !local) { throw new Error( `In development, you should use a separate r2 bucket than the one you'd use in production. Please create a new r2 bucket with "wrangler r2 bucket create " and add its name as preview_bucket_name to the r2_buckets "${binding}" in your wrangler.toml` ); } return { binding, - bucket_name: preview_bucket_name, + bucket_name: preview_bucket_name ?? bucket_name, }; } ) || []),