Skip to content

Commit

Permalink
Adds Corepack integration
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis committed Jul 5, 2021
1 parent 953c8b6 commit bbd5bfb
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/cli/commands/init.js
Expand Up @@ -30,24 +30,38 @@ export const shouldRunInCurrentCwd = true;

export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
const installVersion = flags[`2`] ? `berry` : flags.install;
const forwardedArgs = process.argv.slice(process.argv.indexOf('init', 2) + 1);

if (installVersion) {
const lockfilePath = path.resolve(config.cwd, 'yarn.lock');
if (!await fs.exists(lockfilePath)) {
await fs.writeFile(lockfilePath, '');
}
await child.spawn(NODE_BIN_PATH, [process.argv[1], 'policies', 'set-version', installVersion, '--silent'], {
stdio: 'inherit',
cwd: config.cwd,
});
await child.spawn(
NODE_BIN_PATH,
[process.argv[1], 'init', ...(flags.yes ? ['-y'] : []), ...(flags.private ? ['-p'] : [])],
{
if (flags[`2`] && process.env.COREPACK_ROOT) {
await child.spawn(
NODE_BIN_PATH,
[
path.join(process.env.COREPACK_ROOT, 'dist/corepack.js'),
`yarn@${flags.install || `stable`}`,
`init`,
...forwardedArgs,
`--install=self`,
],
{
stdio: 'inherit',
cwd: config.cwd,
},
);
} else {
const lockfilePath = path.resolve(config.cwd, 'yarn.lock');
if (!await fs.exists(lockfilePath)) {
await fs.writeFile(lockfilePath, '');
}
await child.spawn(NODE_BIN_PATH, [process.argv[1], 'policies', 'set-version', installVersion, '--silent'], {
stdio: 'inherit',
cwd: config.cwd,
},
);
});
await child.spawn(NODE_BIN_PATH, [process.argv[1], 'init', ...forwardedArgs], {
stdio: 'inherit',
cwd: config.cwd,
});
}
return;
}

Expand Down

0 comments on commit bbd5bfb

Please sign in to comment.