Skip to content

Commit 96efdc1

Browse files
james-elicxvicb
andauthored
fix: yarn v4 not passing args to wrangler correctly (#512)
* fix: yarn v4 not passing args to wrangler correctly * Update packages/cloudflare/src/cli/utils/run-wrangler.ts Co-authored-by: Victor Berchet <[email protected]> * Update packages/cloudflare/src/cli/utils/run-wrangler.ts --------- Co-authored-by: Victor Berchet <[email protected]>
1 parent c195019 commit 96efdc1

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

.changeset/brave-snakes-roll.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix: yarn v4 not passing args to wrangler correctly

packages/cloudflare/src/cli/utils/run-wrangler.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { spawnSync } from "node:child_process";
2+
import { readFileSync } from "node:fs";
3+
import path from "node:path";
24

35
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
6+
import { compareSemver } from "@opennextjs/aws/build/helper.js";
47
import logger from "@opennextjs/aws/logger.js";
58

69
export type WranglerTarget = "local" | "remote";
@@ -12,18 +15,35 @@ type WranglerOptions = {
1215
logging?: "all" | "error";
1316
};
1417

18+
/**
19+
* Checks the package.json `packageManager` field to determine whether yarn modern is used.
20+
*
21+
* @param options Build options.
22+
* @returns Whether yarn modern is used.
23+
*/
24+
function isYarnModern(options: BuildOptions) {
25+
const packageJson: { packageManager?: string } = JSON.parse(
26+
readFileSync(path.join(options.monorepoRoot, "package.json"), "utf-8")
27+
);
28+
29+
if (!packageJson.packageManager?.startsWith("yarn")) return false;
30+
31+
const [, version] = packageJson.packageManager.split("@");
32+
return version ? compareSemver(version, ">=", "4.0.0") : false;
33+
}
34+
1535
/**
1636
* Prepends CLI flags with `--` so that certain package managers can pass args through to wrangler
1737
* properly.
1838
*
19-
* npm and yarn require `--` to be used, while pnpm and bun require that it is not used.
39+
* npm and yarn classic require `--` to be used, while pnpm and bun require that it is not used.
2040
*
2141
* @param options Build options.
2242
* @param args CLI args.
2343
* @returns Arguments with a passthrough flag injected when needed.
2444
*/
2545
function injectPassthroughFlagForArgs(options: BuildOptions, args: string[]) {
26-
if (options.packager !== "npm" && options.packager !== "yarn") {
46+
if (options.packager !== "npm" && (options.packager !== "yarn" || isYarnModern(options))) {
2747
return args;
2848
}
2949

0 commit comments

Comments
 (0)