From 48f4ec6cd26ede818243a04bf167a85adc23157a Mon Sep 17 00:00:00 2001 From: James Date: Thu, 27 Mar 2025 23:02:50 +0000 Subject: [PATCH 1/3] fix: yarn v4 not passing args to wrangler correctly --- .changeset/brave-snakes-roll.md | 5 ++++ .../cloudflare/src/cli/utils/run-wrangler.ts | 26 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 .changeset/brave-snakes-roll.md diff --git a/.changeset/brave-snakes-roll.md b/.changeset/brave-snakes-roll.md new file mode 100644 index 00000000..475fcc4d --- /dev/null +++ b/.changeset/brave-snakes-roll.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +fix: yarn v4 not passing args to wrangler correctly diff --git a/packages/cloudflare/src/cli/utils/run-wrangler.ts b/packages/cloudflare/src/cli/utils/run-wrangler.ts index 10a7afb8..c4f5d269 100644 --- a/packages/cloudflare/src/cli/utils/run-wrangler.ts +++ b/packages/cloudflare/src/cli/utils/run-wrangler.ts @@ -1,6 +1,9 @@ import { spawnSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import path from "node:path"; import type { BuildOptions } from "@opennextjs/aws/build/helper.js"; +import { compareSemver } from "@opennextjs/aws/build/helper.js"; import logger from "@opennextjs/aws/logger.js"; export type WranglerTarget = "local" | "remote"; @@ -12,18 +15,37 @@ type WranglerOptions = { logging?: "all" | "error"; }; +/** + * Checks the package.json `packageManager` field to determine whether yarn modern is used. + * + * @param options Build options. + * @returns Whether yarn modern is used. + */ +function isYarnModern(options: BuildOptions) { + const packageJson: { packageManager?: string } = JSON.parse( + readFileSync(path.join(options.monorepoRoot, "package.json"), "utf-8") + ); + + if (!packageJson.packageManager?.startsWith("yarn")) return false; + + const [, version] = packageJson.packageManager.split("@"); + if (!version) return false; + + return compareSemver(version, ">=", "4.0.0"); +} + /** * Prepends CLI flags with `--` so that certain package managers can pass args through to wrangler * properly. * - * npm and yarn require `--` to be used, while pnpm and bun require that it is not used. + * npm and yarn classic require `--` to be used, while pnpm and bun require that it is not used. * * @param options Build options. * @param args CLI args. * @returns Arguments with a passthrough flag injected when needed. */ function injectPassthroughFlagForArgs(options: BuildOptions, args: string[]) { - if (options.packager !== "npm" && options.packager !== "yarn") { + if (options.packager !== "npm" && (options.packager !== "yarn" || isYarnModern(options))) { return args; } From cb7319fe0c5d9e4644da0d5214fb19b585e38891 Mon Sep 17 00:00:00 2001 From: James Anderson Date: Fri, 28 Mar 2025 11:16:40 +0000 Subject: [PATCH 2/3] Update packages/cloudflare/src/cli/utils/run-wrangler.ts Co-authored-by: Victor Berchet --- packages/cloudflare/src/cli/utils/run-wrangler.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/cloudflare/src/cli/utils/run-wrangler.ts b/packages/cloudflare/src/cli/utils/run-wrangler.ts index c4f5d269..a8595c8c 100644 --- a/packages/cloudflare/src/cli/utils/run-wrangler.ts +++ b/packages/cloudflare/src/cli/utils/run-wrangler.ts @@ -28,10 +28,7 @@ function isYarnModern(options: BuildOptions) { if (!packageJson.packageManager?.startsWith("yarn")) return false; - const [, version] = packageJson.packageManager.split("@"); - if (!version) return false; - - return compareSemver(version, ">=", "4.0.0"); + return version ? compareSemver(version, ">=", "4.0.0") : false; } /** From 61ba700949258cddb2c8c97570b2301d301f43ee Mon Sep 17 00:00:00 2001 From: James Anderson Date: Fri, 28 Mar 2025 11:19:37 +0000 Subject: [PATCH 3/3] Update packages/cloudflare/src/cli/utils/run-wrangler.ts --- packages/cloudflare/src/cli/utils/run-wrangler.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cloudflare/src/cli/utils/run-wrangler.ts b/packages/cloudflare/src/cli/utils/run-wrangler.ts index a8595c8c..2f213c67 100644 --- a/packages/cloudflare/src/cli/utils/run-wrangler.ts +++ b/packages/cloudflare/src/cli/utils/run-wrangler.ts @@ -28,6 +28,7 @@ function isYarnModern(options: BuildOptions) { if (!packageJson.packageManager?.startsWith("yarn")) return false; + const [, version] = packageJson.packageManager.split("@"); return version ? compareSemver(version, ">=", "4.0.0") : false; }