Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions .yarn/versions/bcd19e09.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
releases:
"@yarnpkg/cli": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
35 changes: 18 additions & 17 deletions packages/yarnpkg-cli/sources/lib.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Configuration, CommandContext, PluginConfiguration, TelemetryManager, semverUtils, miscUtils, YarnVersion} from '@yarnpkg/core';
import {PortablePath, npath, ppath, xfs} from '@yarnpkg/fslib';
import {execFileSync, type SpawnSyncReturns} from 'child_process';
import {isCI} from 'ci-info';
import {Cli, UsageError} from 'clipanion';
import Module from 'module';

import {pluginCommands} from './pluginCommands';
import {getPluginConfiguration} from './tools/getPluginConfiguration';
Expand Down Expand Up @@ -61,30 +61,31 @@ async function getCoreConfiguration({selfPath, pluginConfiguration}: {selfPath:
});
}

// We load the binary into the current process,
// while making it think it was spawned.
function runYarnPath(cli: YarnCli, argv: Array<string>, {yarnPath}: {yarnPath: PortablePath}) {
if (!xfs.existsSync(yarnPath)) {
(cli.error(new Error(`The "yarn-path" option has been set, but the specified location doesn't exist (${yarnPath}).`)));
return 1;
}

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.
});
const binPath = npath.fromPortablePath(yarnPath);

const yarnPathExecOptions = {
stdio: `inherit`,
env: {
...process.env,
YARN_IGNORE_PATH: `1`,
},
} as const;
process.env.YARN_IGNORE_PATH = `1`;

try {
execFileSync(process.execPath, [npath.fromPortablePath(yarnPath), ...argv], yarnPathExecOptions);
} catch (err) {
return (err as SpawnSyncReturns<void>).status ?? 1;
}
process.argv = [
process.execPath,
binPath,
...argv,
];
process.execArgv = [];

// Unset the mainModule and let Node.js set it when needed.
process.mainModule = undefined;

// Use nextTick to unwind the stack, and consequently remove this binary from
// the stack trace of the next binary.
process.nextTick(Module.runMain, binPath);

return 0;
}
Expand Down