Skip to content

Commit cd3db48

Browse files
authored
fix(create): make --packageManager flag work (#3498)
1 parent 463d4e7 commit cd3db48

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎packages/create/index.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ function main(argv, error = console.error, log = console.log) {
7575
}
7676

7777
// Which package manager will be used in the new project
78-
constpkgMgr=args['packageManager']||detectRunningUnderYarn() ? 'yarn' : 'npm';
78+
letpkgMgr=args['packageManager'];
79+
80+
if(!pkgMgr){
81+
pkgMgr=detectRunningUnderYarn() ? 'yarn' : 'npm';
82+
}elseif(pkgMgr!=='yarn'&&pkgMgr!=='npm'){
83+
error('Please select between \'yarn\' and \'npm\' when providing --packageManager');
84+
usage(error);
85+
return1;
86+
}
7987

8088
log_verbose('Running with',process.argv);
8189
log_verbose('Environment',process.env);

‎packages/create/test.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ wkspContent = read('default_to_yarn/WORKSPACE');
7070
if(wkspContent.indexOf('yarn_install(')<0){
7171
fail('should use yarn by default');
7272
}
73+
74+
exitCode=main(['use_npm_with_yarn','--packageManager=npm']);
75+
if(exitCode!=0)fail('should be success');
76+
wkspContent=read('use_npm_with_yarn/WORKSPACE');
77+
if(wkspContent.indexOf('npm_install(')<0){
78+
fail('should use npm as selected');
79+
}
80+
81+
exitCode=main(['neither_yarn_nor_npm','--packageManager=foo']);
82+
if(exitCode!=1)fail('should exit 1 when selecting neither \'yarn\' nor \'npm\'');
7383
// TODO: run bazel in the new directory to verify a build works
7484

7585
exitCode=main(['--typescript','with_ts'],captureError);

0 commit comments

Comments
 (0)