Skip to content

Commit bbd5bfb

Browse files
committed
Adds Corepack integration
1 parent 953c8b6 commit bbd5bfb

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/cli/commands/init.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,38 @@ export const shouldRunInCurrentCwd = true;
3030

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

3435
if (installVersion) {
35-
const lockfilePath = path.resolve(config.cwd, 'yarn.lock');
36-
if (!await fs.exists(lockfilePath)) {
37-
await fs.writeFile(lockfilePath, '');
38-
}
39-
await child.spawn(NODE_BIN_PATH, [process.argv[1], 'policies', 'set-version', installVersion, '--silent'], {
40-
stdio: 'inherit',
41-
cwd: config.cwd,
42-
});
43-
await child.spawn(
44-
NODE_BIN_PATH,
45-
[process.argv[1], 'init', ...(flags.yes ? ['-y'] : []), ...(flags.private ? ['-p'] : [])],
46-
{
36+
if (flags[`2`] && process.env.COREPACK_ROOT) {
37+
await child.spawn(
38+
NODE_BIN_PATH,
39+
[
40+
path.join(process.env.COREPACK_ROOT, 'dist/corepack.js'),
41+
`yarn@${flags.install || `stable`}`,
42+
`init`,
43+
...forwardedArgs,
44+
`--install=self`,
45+
],
46+
{
47+
stdio: 'inherit',
48+
cwd: config.cwd,
49+
},
50+
);
51+
} else {
52+
const lockfilePath = path.resolve(config.cwd, 'yarn.lock');
53+
if (!await fs.exists(lockfilePath)) {
54+
await fs.writeFile(lockfilePath, '');
55+
}
56+
await child.spawn(NODE_BIN_PATH, [process.argv[1], 'policies', 'set-version', installVersion, '--silent'], {
4757
stdio: 'inherit',
4858
cwd: config.cwd,
49-
},
50-
);
59+
});
60+
await child.spawn(NODE_BIN_PATH, [process.argv[1], 'init', ...forwardedArgs], {
61+
stdio: 'inherit',
62+
cwd: config.cwd,
63+
});
64+
}
5165
return;
5266
}
5367

0 commit comments

Comments
 (0)