diff --git a/main.js b/main.js index ba741cb..8596ef4 100644 --- a/main.js +++ b/main.js @@ -106,7 +106,7 @@ const yargsParser = Yargs.scriptName('bundle-phobia') .example('$0 lodash chalk', 'Get stats for a list of packages') .example('$0 install lodash chalk', 'Conditionaly install packages') .command( - 'install', + 'install ', 'Perform install if specified size constraints are met', yargs => yargs.options(INSTALL_OPTIONS), argv => diff --git a/src/install.js b/src/install.js index fb4be9d..66878cd 100644 --- a/src/install.js +++ b/src/install.js @@ -17,6 +17,7 @@ const { const DEFAULT_MAX_SIZE = '100kB'; const BUNLE_PHOBIA_ARGS = [ + 'packages', 'i', 'interactive', '$0', @@ -47,7 +48,7 @@ const npmOptionsFromArgv = argv => { const installCommandArgs = argv => { const options = npmOptionsFromArgv(argv); - return ['install', ...argv._, ...options]; + return ['install', ...argv.packages, ...options]; }; const getSizePredicate = (argv, defaultSize, packageConfig) => { @@ -108,8 +109,8 @@ const main = async ({ } }; const currentPkg = readPkg(); - const packages = argv._; - if (_.isEmpty(packages)) throw new Error('No packages to install was given'); + const {packages} = argv; + if (_.isEmpty(argv.packages)) throw new Error('No packages to install was given'); const pluralSuffix = _.size(packages) > 1 ? 's' : ''; const performInstall = () => diff --git a/test/e2e/install-safetynet.sh b/test/e2e/install-safetynet.sh index f8251cc..04de3ca 100755 --- a/test/e2e/install-safetynet.sh +++ b/test/e2e/install-safetynet.sh @@ -51,8 +51,7 @@ fi node_major=$(node <<< "console.log(process.versions.node.split('.')[0])") case $node_major in - 8|10|12|14) expected_add_message="added [1-2] packages? from [1-9] contributors? and audited [1-6] packages? in";; - 16|18|20) expected_add_message="added [1-2] packages?, and audited [1-6] packages?";; + 16|18|20) expected_add_message="added [1-3] packages?, and audited [1-6] packages?";; *) expected_add_message="><"; echo "No expected message for this major version";; esac diff --git a/test/integration/install.integration.test.js b/test/integration/install.integration.test.js index 84abeb1..e823261 100644 --- a/test/integration/install.integration.test.js +++ b/test/integration/install.integration.test.js @@ -9,7 +9,7 @@ test('install just a single package and fail', async t => { const spawn = fakeSpawn(); try { await main({ - argv: {_: ['lodash@4.12.0']}, + argv: {packages: ['lodash@4.12.0']}, stream, spawn, defaultMaxSize, @@ -36,7 +36,7 @@ test('install just a single package and succeed', async t => { const spawn = fakeSpawn(); // await main({ - argv: {_: ['bytes@3.0.0']}, + argv: {packages: ['bytes@3.0.0']}, stream, spawn, defaultMaxSize, @@ -59,7 +59,7 @@ test('install just a single package and just warn', async t => { const stream = fakeStream(); const spawn = fakeSpawn(); await main({ - argv: {_: ['lodash@4.12.0'], w: true, warn: true, 'save-dev': true}, + argv: {packages: ['lodash@4.12.0'], w: true, warn: true, 'save-dev': true}, stream, spawn, defaultMaxSize, @@ -84,7 +84,7 @@ test('ask to install a package and accept', async t => { const spawn = fakeSpawn(); const prompt = fakePrompt(); await main({ - argv: {_: ['lodash@4.12.0'], i: true, interactive: true}, + argv: {packages: ['lodash@4.12.0'], i: true, interactive: true}, stream, spawn, prompt, @@ -109,7 +109,7 @@ test('ask to install a package and deny', async t => { const spawn = fakeSpawn(); const prompt = fakePrompt(false); await main({ - argv: {_: ['lodash@4.12.0'], i: true, interactive: true}, + argv: {packages: ['lodash@4.12.0'], i: true, interactive: true}, stream, spawn, prompt, @@ -135,7 +135,7 @@ test('try to install package that does not exist', async t => { const spawn = fakeSpawn(); try { await main({ - argv: {_: ['no-sorry-but-i-do-not-exist']}, + argv: {packages: ['no-sorry-but-i-do-not-exist']}, stream, spawn, defaultMaxSize, @@ -156,7 +156,7 @@ test('install just a single package on empty package with global config and succ const spawn = fakeSpawn(); await main({ - argv: {_: ['bytes@3.0.0']}, + argv: {packages: ['bytes@3.0.0']}, stream, spawn, defaultMaxSize,