Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.x fix import fallback #6385

Open
wants to merge 3 commits into
base: cherry-pick/next-release
Choose a base branch
from
Open
Changes from all commits
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
52 changes: 25 additions & 27 deletions packages/yarnpkg-cli/sources/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,26 @@ 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`, () => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate but it seems like this is never restored after execution of the binary?

// 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.
});

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(physicalPath, 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}) {
Expand Down Expand Up @@ -99,14 +95,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;
Comment on lines +98 to +107
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the path is set and is truthy but the file doesn't exist this wont throw the same error it did before.

Copy link
Author

@legobeat legobeat Jul 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exit code before was a non-number string. This is not valid. Do we actually want to preserve that behavior?

For string type, only integer strings (e.g.,'1') are allowed

https://nodejs.org/api/process.html#processexitcode_1

Copy link
Author

@legobeat legobeat Jul 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I put this here specifically for consistency with old behavior - otherwise using error.errno, ie -2 would have seemed appropriate)

}
}
} else {
Expand Down
Loading