Skip to content

Commit

Permalink
C3: Turn auto-update back on (#4136)
Browse files Browse the repository at this point in the history
* C3: Turn auto-update back on

* Fix hardcoded npx call in workers

* Only prepend  to npm create
  • Loading branch information
jculvey committed Oct 12, 2023
1 parent 2a0eefd commit 0f043a1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-cycles-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": minor
---

Fixes an issue that was causing the auto-update check not to run
8 changes: 7 additions & 1 deletion packages/create-cloudflare/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ const isUpdateAvailable = async () => {
// Spawn a separate process running the most recent version of c3
export const runLatest = async () => {
const args = process.argv.slice(2);
await runCommand(`${npm} create cloudflare@latest ${args.join(" ")}`);

// the parsing logic of `npm create` requires `--` to be supplied
// before any flags intended for the target command.
const argString =
npm === "npm" ? `-- ${args.join(" ")}` : `${args.join(" ")}`;

await runCommand(`${npm} create cloudflare@latest ${argString}`);
};

// Entrypoint to c3
Expand Down
6 changes: 6 additions & 0 deletions packages/create-cloudflare/src/helpers/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export const parseArgs = async (argv: string[]): Promise<Partial<C3Args>> => {
alias: "y",
type: "boolean",
})
.option("auto-update", {
type: "boolean",
default: C3_DEFAULTS.autoUpdate,
description:
"Automatically uses the latest version of `create-cloudflare`. Set --no-auto-update to disable",
})
.option("wrangler-defaults", { type: "boolean", hidden: true })
.version(version)
// note: we use strictOptions since `strict()` seems not to handle `positional`s correctly
Expand Down
5 changes: 4 additions & 1 deletion packages/create-cloudflare/src/workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
npmInstall,
runCommand,
} from "helpers/command";
import { detectPackageManager } from "helpers/packages";
import {
chooseAccount,
gitCommit,
Expand All @@ -34,6 +35,8 @@ import {
} from "./common";
import type { C3Args, PagesGeneratorContext as Context } from "types";

const { dlx } = detectPackageManager();

export const runWorkersGenerator = async (args: C3Args) => {
const { name, path } = setupProjectDirectory(args);

Expand Down Expand Up @@ -120,7 +123,7 @@ async function copyExistingWorkerFiles(ctx: Context) {
join(tmpdir(), "c3-wrangler-init--from-dash-")
);
await runCommand(
`npx wrangler@3 init --from-dash ${ctx.args.existingScript} -y --no-delegate-c3`,
`${dlx} wrangler@3 init --from-dash ${ctx.args.existingScript} -y --no-delegate-c3`,
{
silent: true,
cwd: tempdir, // use a tempdir because we don't want all the files
Expand Down

0 comments on commit 0f043a1

Please sign in to comment.