Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C3: Fixing double prompt for ts during hello world worker creation #4088

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eighty-plums-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

Fixes an issue where users were prompted for TypeScript twice during worker creation
14 changes: 7 additions & 7 deletions packages/create-cloudflare/src/workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export const runWorkersGenerator = async (args: C3Args) => {
args,
};

ctx.args.ts = await processArgument<boolean>(ctx.args, "ts", {
Copy link
Contributor

@RamIdeas RamIdeas Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either processArgument should handle assigning the args.x value, ie:

Suggested change
ctx.args.ts = await processArgument<boolean>(ctx.args, "ts", {
await processArgument<boolean>(ctx.args, "ts", {

or the pattern should be to call it with args.x ??=, ie:

Suggested change
ctx.args.ts = await processArgument<boolean>(ctx.args, "ts", {
ctx.args.ts ??= await processArgument<boolean>(ctx.args, "ts", {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agreed this feels a little unwieldy still.

One of the important things processArgument does is render the submit state of the prompt for the question, so a user would see yes Typescript even if they passed the --ts flag. That's why ctx.args.ts ??= await processArgument<boolean>(ctx.args, "ts", { wouldn't work, since we do need it to evaluate.

I like the first alternative though. I'll make a separate PR to refactor this into an in-place operation instead of returning a value that we re-assign to the same object.

type: "confirm",
question: "Do you want to use TypeScript?",
label: "typescript",
defaultValue: C3_DEFAULTS.ts,
});

await copyFiles(ctx);
await copyExistingWorkerFiles(ctx);
await updateFiles(ctx);
Expand All @@ -53,13 +60,6 @@ export const runWorkersGenerator = async (args: C3Args) => {
};

async function getTemplate(ctx: Context) {
ctx.args.ts = await processArgument<boolean>(ctx.args, "ts", {
type: "confirm",
question: "Do you want to use TypeScript?",
label: "typescript",
defaultValue: C3_DEFAULTS.ts,
});

const preexisting = ctx.args.type === "pre-existing";
const template = preexisting ? "hello-world" : ctx.args.type;
const path = resolve(
Expand Down
Loading