@@ -30,24 +30,38 @@ export const shouldRunInCurrentCwd = true;
30
30
31
31
export async function run ( config : Config , reporter : Reporter , flags : Object , args : Array < string > ) : Promise < void > {
32
32
const installVersion = flags [ `2` ] ? `berry` : flags . install ;
33
+ const forwardedArgs = process . argv . slice ( process . argv . indexOf ( 'init' , 2 ) + 1 ) ;
33
34
34
35
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' ] , {
47
57
stdio : 'inherit' ,
48
58
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
+ }
51
65
return ;
52
66
}
53
67
0 commit comments