Skip to content

Commit

Permalink
fix(create): make --packageManager flag work (#3498)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgred committed Jul 3, 2022
1 parent 463d4e7 commit cd3db48
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/create/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ function main(argv, error = console.error, log = console.log) {
}

// Which package manager will be used in the new project
const pkgMgr = args['packageManager'] || detectRunningUnderYarn() ? 'yarn' : 'npm';
let pkgMgr = args['packageManager'];

if (!pkgMgr) {
pkgMgr = detectRunningUnderYarn() ? 'yarn' : 'npm';
} else if(pkgMgr !== 'yarn' && pkgMgr !== 'npm') {
error('Please select between \'yarn\' and \'npm\' when providing --packageManager');
usage(error);
return 1;
}

log_verbose('Running with', process.argv);
log_verbose('Environment', process.env);
Expand Down
10 changes: 10 additions & 0 deletions packages/create/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ wkspContent = read('default_to_yarn/WORKSPACE');
if (wkspContent.indexOf('yarn_install(') < 0) {
fail('should use yarn by default');
}

exitCode = main(['use_npm_with_yarn', '--packageManager=npm']);
if (exitCode != 0) fail('should be success');
wkspContent = read('use_npm_with_yarn/WORKSPACE');
if (wkspContent.indexOf('npm_install(') < 0) {
fail('should use npm as selected');
}

exitCode = main(['neither_yarn_nor_npm', '--packageManager=foo']);
if (exitCode != 1) fail('should exit 1 when selecting neither \'yarn\' nor \'npm\'');
// TODO: run bazel in the new directory to verify a build works

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

0 comments on commit cd3db48

Please sign in to comment.