From 6d51e2fd00d13fb73a31b212bb7cbc856888984a Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Sat, 6 Jul 2024 12:41:32 +0000 Subject: [PATCH 1/3] fix(yarnpkg-cli): properly handle missing physicalPath in runBinary --- packages/yarnpkg-cli/sources/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yarnpkg-cli/sources/main.ts b/packages/yarnpkg-cli/sources/main.ts index bbab63f49fb6..0fd86b74aaed 100644 --- a/packages/yarnpkg-cli/sources/main.ts +++ b/packages/yarnpkg-cli/sources/main.ts @@ -25,7 +25,7 @@ function runBinary(path: PortablePath) { }, }); } else { - execFileSync(physicalPath, process.argv.slice(2), { + execFileSync(process.execPath, process.argv.slice(2), { stdio: `inherit`, env: { ...process.env, From 4f8417e722c75335ef24c0a43367178893f0f6c9 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Sat, 6 Jul 2024 20:27:14 +0000 Subject: [PATCH 2/3] fix: remove duplicate error handling; return potential non-number exit codes as 1 --- packages/yarnpkg-cli/sources/main.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/yarnpkg-cli/sources/main.ts b/packages/yarnpkg-cli/sources/main.ts index 0fd86b74aaed..e38678f9a602 100644 --- a/packages/yarnpkg-cli/sources/main.ts +++ b/packages/yarnpkg-cli/sources/main.ts @@ -10,6 +10,13 @@ import {pluginCommands} function runBinary(path: PortablePath) { const physicalPath = npath.fromPortablePath(path); + if (!physicalPath) { + throw Object.assign( + new Error(`runBinary ${path} ENOENT`), + {code: `ENOENT`, errno: -2}, + ); + } + process.on(`SIGINT`, () => { // We don't want SIGINT to kill our process; we want it to kill the // innermost process, whose end will cause our own to exit. @@ -99,14 +106,16 @@ export async function main({binaryVersion, pluginConfiguration}: {binaryVersion: await exec(cli); return; } else if (yarnPath !== null && !ignorePath) { - if (!xfs.existsSync(yarnPath)) { - process.stdout.write(cli.error(new Error(`The "yarn-path" option has been set (in ${configuration.sources.get(`yarnPath`)}), but the specified location doesn't exist (${yarnPath}).`))); - process.exitCode = 1; - } else { - try { - runBinary(yarnPath); - } catch (error) { - process.exitCode = error.code || 1; + try { + runBinary(yarnPath); + } catch (error) { + if (error.code === `ENOENT`) + process.stdout.write(cli.error(new Error(`The "yarn-path" option has been set (in ${configuration.sources.get(`yarnPath`)}), but the specified location doesn't exist (${yarnPath}).`))); + + if (typeof error.code === `number`) { + process.exitCode = error.code; + } else { + process.exitCode = 1; } } } else { From 2ee671f10417cbd28bd48ac66040f639745a008e Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Sat, 6 Jul 2024 20:35:51 +0000 Subject: [PATCH 3/3] chore: remove dead code --- packages/yarnpkg-cli/sources/main.ts | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/packages/yarnpkg-cli/sources/main.ts b/packages/yarnpkg-cli/sources/main.ts index e38678f9a602..88220b340f9d 100644 --- a/packages/yarnpkg-cli/sources/main.ts +++ b/packages/yarnpkg-cli/sources/main.ts @@ -22,25 +22,14 @@ function runBinary(path: PortablePath) { // innermost process, whose end will cause our own to exit. }); - if (physicalPath) { - execFileSync(process.execPath, [physicalPath, ...process.argv.slice(2)], { - stdio: `inherit`, - env: { - ...process.env, - YARN_IGNORE_PATH: `1`, - YARN_IGNORE_CWD: `1`, - }, - }); - } else { - execFileSync(process.execPath, process.argv.slice(2), { - stdio: `inherit`, - env: { - ...process.env, - YARN_IGNORE_PATH: `1`, - YARN_IGNORE_CWD: `1`, - }, - }); - } + execFileSync(process.execPath, [physicalPath, ...process.argv.slice(2)], { + stdio: `inherit`, + env: { + ...process.env, + YARN_IGNORE_PATH: `1`, + YARN_IGNORE_CWD: `1`, + }, + }); } export async function main({binaryVersion, pluginConfiguration}: {binaryVersion: string, pluginConfiguration: PluginConfiguration}) {