Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/brave-snakes-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

fix: yarn v4 not passing args to wrangler correctly
26 changes: 24 additions & 2 deletions packages/cloudflare/src/cli/utils/run-wrangler.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
}

Expand Down