Skip to content

Commit c23f464

Browse files
committed
address comments
1 parent b059227 commit c23f464

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

packages/wrangler/src/deployment-bundle/bindings.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,6 @@ class R2Handler extends ProvisionResourceHandler<"r2_bucket", CfR2Bucket> {
170170
return this.binding.bucket_name as string;
171171
}
172172

173-
override inherit(): void {
174-
if (!this.binding.bucket_name) {
175-
this.binding.bucket_name = INHERIT_SYMBOL;
176-
}
177-
}
178-
179173
async create(name: string) {
180174
await createR2Bucket(
181175
this.complianceConfig,
@@ -193,6 +187,21 @@ class R2Handler extends ProvisionResourceHandler<"r2_bucket", CfR2Bucket> {
193187
) {
194188
super("r2_bucket", binding, "bucket_name", complianceConfig, accountId);
195189
}
190+
191+
/**
192+
* Inheriting an R2 binding replaces the id property (bucket_name for R2) with the inheritance symbol.
193+
* This works when deploying (and is appropriate for all other binding types), but it means that the
194+
* bucket_name for an R2 bucket is not displayed when deploying. As such, only use the inheritance symbol
195+
* if the R2 binding has no `bucket_name`.
196+
*/
197+
override inherit(): void {
198+
this.binding.bucket_name ??= INHERIT_SYMBOL;
199+
}
200+
201+
/**
202+
* R2 bindings can be inherited if the binding name and jusrisdiction match.
203+
* Additionally, if the user has specified a bucket_name in config, make sure that matches
204+
*/
196205
canInherit(settings: Settings | undefined): boolean {
197206
return !!settings?.bindings.find(
198207
(existing) =>
@@ -457,11 +466,11 @@ export async function provisionBindings(
457466
);
458467

459468
if (pendingResources.length > 0) {
460-
if (!config.configPath) {
461-
throw new UserError(
462-
"Provisioning resources is not supported without a config file"
463-
);
464-
}
469+
assert(
470+
config.configPath,
471+
"Provisioning resources is not possible without a config file"
472+
);
473+
465474
if (!isLegacyEnv(config)) {
466475
throw new UserError(
467476
"Provisioning resources is not supported with a service environment"
@@ -498,7 +507,6 @@ export async function provisionBindings(
498507
patch[resource.resourceType] = config[resource.resourceType].map(
499508
(binding) => {
500509
if (binding.binding === resource.binding) {
501-
// Using an early return here would be nicer but makes TS blow up
502510
binding = resource.handler.binding;
503511
}
504512

@@ -523,9 +531,8 @@ export async function provisionBindings(
523531
"Your Worker was deployed with provisioned resources. We've written the IDs of these resources to your config file, which you can choose to save or discard—either way future deploys will continue to work."
524532
);
525533
} catch (e) {
526-
if (e instanceof PatchConfigError) {
527-
// no-op — if the user is using TOML config we can't update it.
528-
} else {
534+
// no-op — if the user is using TOML config we can't update it.
535+
if (!(e instanceof PatchConfigError)) {
529536
throw e;
530537
}
531538
}

packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ export function createWorkerUploadForm(
286286
// is inheritable or requires provisioning (since that would require hitting the API).
287287
// As such, _assume_ any undefined IDs are inheritable when doing a dry run.
288288
// When this Worker is actually deployed, some may be provisioned at the point of deploy
289-
if (options?.dryRun && id === undefined) {
290-
id = INHERIT_SYMBOL;
289+
if (options?.dryRun) {
290+
id ??= INHERIT_SYMBOL;
291291
}
292292

293293
if (id === undefined) {
@@ -368,8 +368,8 @@ export function createWorkerUploadForm(
368368

369369
bindings.r2_buckets?.forEach(
370370
({ binding, bucket_name, jurisdiction, raw }) => {
371-
if (options?.dryRun && bucket_name === undefined) {
372-
bucket_name = INHERIT_SYMBOL;
371+
if (options?.dryRun) {
372+
bucket_name ??= INHERIT_SYMBOL;
373373
}
374374
if (bucket_name === undefined) {
375375
throw new UserError(
@@ -396,8 +396,8 @@ export function createWorkerUploadForm(
396396

397397
bindings.d1_databases?.forEach(
398398
({ binding, database_id, database_internal_env, raw }) => {
399-
if (options?.dryRun && database_id === undefined) {
400-
database_id = INHERIT_SYMBOL;
399+
if (options?.dryRun) {
400+
database_id ??= INHERIT_SYMBOL;
401401
}
402402
if (database_id === undefined) {
403403
throw new UserError(

0 commit comments

Comments
 (0)