1
1
import { spawnSync } from "node:child_process" ;
2
+ import { readFileSync } from "node:fs" ;
3
+ import path from "node:path" ;
2
4
3
5
import type { BuildOptions } from "@opennextjs/aws/build/helper.js" ;
6
+ import { compareSemver } from "@opennextjs/aws/build/helper.js" ;
4
7
import logger from "@opennextjs/aws/logger.js" ;
5
8
6
9
export type WranglerTarget = "local" | "remote" ;
@@ -12,18 +15,35 @@ type WranglerOptions = {
12
15
logging ?: "all" | "error" ;
13
16
} ;
14
17
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
+
15
35
/**
16
36
* Prepends CLI flags with `--` so that certain package managers can pass args through to wrangler
17
37
* properly.
18
38
*
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.
20
40
*
21
41
* @param options Build options.
22
42
* @param args CLI args.
23
43
* @returns Arguments with a passthrough flag injected when needed.
24
44
*/
25
45
function injectPassthroughFlagForArgs ( options : BuildOptions , args : string [ ] ) {
26
- if ( options . packager !== "npm" && options . packager !== "yarn" ) {
46
+ if ( options . packager !== "npm" && ( options . packager !== "yarn" || isYarnModern ( options ) ) ) {
27
47
return args ;
28
48
}
29
49
0 commit comments