Repository navigation
Conversation
ascorbic
left a comment
There was a problem hiding this comment.
Thanks for your patience here! This is a good approach, I just have a few comments before it can be merged
| let bucketName = args["blobs-bucket-name"]; | ||
| if (!bucketName) { | ||
| if (nonInteractive) { | ||
| bucketName = "pds-blobs"; | ||
| } else { | ||
| const result = await p.text({ | ||
| message: "Blobs bucket name (must be unique in your Cloudflare account):", | ||
| placeholder: "pds-blobs", | ||
| defaultValue: "pds-blobs", | ||
| }); | ||
| if (p.isCancel(result)) { | ||
| p.cancel("Cancelled"); | ||
| process.exit(0); | ||
| } | ||
| bucketName = result; |
There was a problem hiding this comment.
The name needs validating before it goes into the config. Running the built CLI with --blobs-bucket-name 'My_Bucket"x' exits 0 and writes "bucket_name": "My_Bucket"x", which is invalid JSONC. Uppercase or underscores give valid JSON that then fails at deploy.
R2's rules are 3–63 characters, lowercase letters, digits and hyphens, with no leading or trailing hyphen. Could you add a validate to the p.text prompt and an error exit when the flag value fails the same check? A test for the rejected case would be good too.
| let bucketName = args["blobs-bucket-name"]; | ||
| if (!bucketName) { | ||
| if (nonInteractive) { | ||
| bucketName = "pds-blobs"; |
There was a problem hiding this comment.
With pds-blobs as the default, a second PDS created with --yes (or by pressing enter at the prompt) gets the same bucket as the first, and wrangler binds to the existing one without complaint. Blob keys are prefixed with the DID so nothing gets overwritten, but it isn't the per-instance default #107 is after.
How about defaulting to ${projectName}-blobs, here and in the prompt's placeholder/defaultValue? pds init can rename the worker afterwards so the two can still differ, but it's a much better starting point.
| "blobs-bucket-name": { | ||
| type: "string", | ||
| description: "Cloudflare R2 bucket name for blobs", | ||
| required: false, |
There was a problem hiding this comment.
Nit: required: false is the default in citty, so this can go.
| p.cancel("Cancelled"); | ||
| process.exit(0); | ||
| } | ||
| bucketName = result; |
There was a problem hiding this comment.
Nit: the folder-name prompt above does result || "my-pds". Clack's defaultValue covers the empty case, but matching that pattern keeps the two prompts consistent.
| // Uploads are staged under `<did>/staged/` until a record references | ||
| // them. Add a lifecycle rule to expire abandoned uploads, e.g.: | ||
| // wrangler r2 bucket lifecycle add pds-blobs --prefix "<did>/staged/" --expire-days 7 | ||
| // wrangler r2 bucket lifecycle add <bucket-name> --prefix "<did>/staged/" --expire-days 7 |
There was a problem hiding this comment.
replaceInFile uses replaceAll, so you can use {{blobsBucketName}} here as well and the generated command stays copy-pasteable.
| expect(wrangler).toContain('"my-custom-bucket"'); | ||
| }); | ||
|
|
||
| it("leaves no unreplaced placeholders in wrangler.jsonc", () => { |
There was a problem hiding this comment.
This reads the directory created by the "default bucket name" test, so it fails when run on its own. Could you move the not.toContain("{{") assertion into that test?
|
|
||
| - Not authenticated. Run `pnpm wrangler login`. | ||
| - The R2 bucket name is taken (R2 bucket names are global). Edit `wrangler.jsonc` to use a different name. | ||
| - The R2 bucket name is taken (R2 bucket names must be unique within an account). Edit `wrangler.jsonc` to use a different name. |
There was a problem hiding this comment.
You're right that names are per-account, thanks for catching that. It does mean this cause no longer applies though: if the name already exists in your own account, wrangler binds to that bucket and the deploy succeeds. The failure people can actually hit is an invalid name, so I'd reword this to something like:
| - The R2 bucket name is taken (R2 bucket names must be unique within an account). Edit `wrangler.jsonc` to use a different name. | |
| - The R2 bucket name is invalid. Names must be 3–63 characters of lowercase letters, digits and hyphens, and cannot start or end with a hyphen. Edit `wrangler.jsonc` to fix it. |
| ``` | ||
|
|
||
| The `binding` is what the Worker uses (`env.BLOBS`). The `bucket_name` is the R2 bucket — bucket names are global across all of Cloudflare. Pick a unique name. | ||
| The `binding` is what the Worker uses (`env.BLOBS`). The `bucket_name` is the R2 bucket which must be unique to your account but (unlike some other blog storage services) do not need to be globally unique. The `create-pds` CLI prompts you for this and will write it to this file, otherwise just provide one here if you're managing the `wrangler.jsonc` manually. |
There was a problem hiding this comment.
There's a typo ("blog storage") and the sentence has drifted a bit. Suggested wording:
| The `binding` is what the Worker uses (`env.BLOBS`). The `bucket_name` is the R2 bucket which must be unique to your account but (unlike some other blog storage services) do not need to be globally unique. The `create-pds` CLI prompts you for this and will write it to this file, otherwise just provide one here if you're managing the `wrangler.jsonc` manually. | |
| The `binding` is what the Worker uses (`env.BLOBS`). The `bucket_name` is the R2 bucket. Bucket names are unique within your Cloudflare account, so two PDSes with the same `bucket_name` share one bucket. The `create-pds` CLI asks for the name and writes it here. |
Closes #107
In contrast to #201 I added the bucket naming to the
create-pdsCLI's variables here. I think the auto-naming convention ofwrangleris useful but for the reasons mentioned in that PR's discussion I think this use case might not be a good one for it.Docs
I updated a few places in the docs that reference buckets. Most notably was a change only indirectly related to my code change. There were two places that mentioned that bucket names must be globally unique. I don't believe that's the case with Cloudflare's buckets (although it definitely is the case with other cloud provider bucket implementations).
create-pdsI added an optional CLI arg for
--blobs-bucket-namewhich effectively defaults topds-blobsalthough to allow for the "should we prompt" logic I didn't usecitty's default option and instead followed the pattern ofprojectName. I think write that to thewrangler.jsoncafter copying it over from the template directory following thepackage.jsonpattern.Tests
I added a few tests but not sure how you will feel about the basic string-matching of the assertions. Open to other ideas.
Changeset
I've never managed or contributed to a monorepo that uses that so hopefully I got that right!