Skip to content

Commit

Permalink
fix: using regex to determine yarn version to account for newer relea…
Browse files Browse the repository at this point in the history
…ses of yarn (i.e. yarn 3). fixes: electron-userland#6069
  • Loading branch information
mmaietta committed Jul 19, 2021
1 parent daeb56d commit b913b84
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/app-builder-lib/src/util/yarn.ts
Expand Up @@ -74,6 +74,15 @@ export function getGypEnv(frameworkInfo: DesktopFrameworkInfo, platform: NodeJS.
}
}

function checkYarnBerry () {
const npmUserAgent = process.env["npm_config_user_agent"] || ''
const regex = /yarn\/(\d+)\./gm;

const yarnVersionMatch = regex.exec(npmUserAgent);
const yarnMajorVersion = Number(yarnVersionMatch?.[1] ?? 0)
return yarnMajorVersion >= 2;
}

function installDependencies(appDir: string, options: RebuildOptions): Promise<any> {
const platform = options.platform || process.platform
const arch = options.arch || process.arch
Expand All @@ -82,9 +91,8 @@ function installDependencies(appDir: string, options: RebuildOptions): Promise<a
log.info({ platform, arch, appDir }, `installing production dependencies`)
let execPath = process.env.npm_execpath || process.env.NPM_CLI_JS
const execArgs = ["install"]
const npmUserAgent = process.env["npm_config_user_agent"]
const isYarn2 = npmUserAgent != null && npmUserAgent.startsWith("yarn/2.")
if (!isYarn2) {
const isYarnBerry = checkYarnBerry()
if (!isYarnBerry) {
if (process.env.NPM_NO_BIN_LINKS === "true") {
execArgs.push("--no-bin-links")
}
Expand All @@ -97,7 +105,7 @@ function installDependencies(appDir: string, options: RebuildOptions): Promise<a

if (execPath == null) {
execPath = getPackageToolPath()
} else if (!isYarn2) {
} else if (!isYarnBerry) {
execArgs.unshift(execPath)
execPath = process.env.npm_node_execpath || process.env.NODE_EXE || "node"
}
Expand Down

0 comments on commit b913b84

Please sign in to comment.