diff --git a/README.md b/README.md index 73ff199..d9599e3 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,15 @@ Just use `npm install -g bundle-phobia-cli` and you're good to go! ## Usage -Once installed you will have access to different executables: -- `bundle-phobia`: to query package size. - Just invoke it with a list of package names and some options. -- `bundle-phobia-install`: to conditionally install package if weight constraint are respected. This is a wrapper on `npm install` +Once installed you will have access a single executable `bundle-phobia` (aliased to `bundle-phobia-cli` for `npx usage`), with two commands: +- `stats` to query package size. This is the default command, just invoke it with a list of package names and some options. + ``` + $ bundle-phobia lodash react + ``` +- `install`: to conditionally install package if weight constraint are respected. This is a wrapper on `npm install` + ``` + $ bundle-phobia install lodash react + ``` Note that you can specify a version along with the package range such as an instance exact version `lodash@4.12.0` or range version `ora@^3.0.0`. @@ -63,18 +68,20 @@ Usage: bundle-phobia [other-package-names...] Options: --version Show version number [boolean] - --package, -p Provide a package.json to read dependencies [string] - --range, -r Get a range of version (0 for all, 8 by default) [number] - --json, -j Output json rather than a formater string [boolean] - --size, -s Output just the module size [boolean] - --gzip-size, -g Output just the module gzip size [boolean] - --dependencies, -d Output just the number of dependencies [boolean] - --self Output bundle-phobia stats [boolean] + -p, --package Provide a package.json to read dependencies [string] + -r, --range Get a range of version (0 for all, 8 by default) [number] + -j, --json Output json rather than a formater string [boolean] + -s, --size Output just the module size [boolean] + -g, --gzip-size Output just the module gzip size [boolean] + -d, --dependencies Output just the number of dependencies [boolean] + -x, --fail-fast Stop on first error [boolean] + -1, --serial Run requests serially [boolean] + --self Output bundle-phobia stats [boolean] -h, --help Show help [boolean] ``` -#### `bundle-phobia-install` +#### `bundle-phobia install` -`bundle-phobia-install` offer three kind of flags: +`bundle-phobia install` offer three kind of flags: - flags to specify the size constraints - flags to specify behavior when constraints are not respected - npm install flags to control it's behavior @@ -108,11 +115,15 @@ Usage: bundle-phobia-install [other-package-names...] Options: --version Show version number [boolean] - --warn, -w Install despite of negative check but warn about + -w, --warn Install despite of negative check but warn about predicate violation [boolean] - --interactive, -i Ask for override in case of predicate violation [boolean] - --max-size, -m Size threeshold of individual library to install [string] - --max-gzip-size, -M Gzip Size threeshold of individual library to install + -i, --interactive Ask for override in case of predicate violation [boolean] + -m, --max-size Size threeshold of individual library to install [string] + -M, --max-gzip-size Gzip Size threeshold of individual library to install [string] + -o, --max-overall-size Overall size threeshold of dependencies [string] + -O, --max-overall-gzip-size Overall Gzip size threeshold of dependencies + [string] + -x, --fail-fast Stop on first error [boolean] -h, --help Show help [boolean] ``` diff --git a/index-install.js b/index-install.js deleted file mode 100755 index cad2614..0000000 --- a/index-install.js +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env node - -const updateNotifier = require('update-notifier'); -const c = require('chalk'); -const {argv} = require('yargs') - .parserConfiguration({ - 'short-option-groups': true, - 'camel-case-expansion': false, - 'dot-notation': false, - 'parse-numbers': true, - 'boolean-negation': false - }) - .usage('Usage: $0 [other-package-names...]') - .describe('warn', 'Install despite of negative check but warn about predicate violation') - .alias('warn', 'w') - .boolean('warn') // no force, use npm instead ;) - .describe('interactive', 'Ask for override in case of predicate violation') - .alias('interactive', 'i') - .boolean('interactive') - .describe('max-size', 'Size threeshold of individual library to install') - .alias('max-size', 'm') - .string('max-size') - .describe('max-gzip-size', 'Gzip Size threeshold of individual library to install') - .alias('max-gzip-size', 'M') - .string('max-gzip-size') - .describe('max-overall-size', 'Overall size threeshold of dependencies') - .alias('max-overall-size', 'o') - .string('max-overall-size') - .describe('max-overall-gzip-size', 'Overall Gzip size threeshold of dependencies') - .alias('max-overall-gzip-size', 'O') - .string('max-overall-gzip-size') - .describe('fail-fast', 'Stop on first error') - .alias('fail-fast', 'x') - // List of npm install flags - .boolean([ - 's', - 'S', - 'save', - 'P', - 'save-prod', - 'D', - 'save-dev', - 'O', - 'save-optional', - 'E', - 'save-exact', - '-B', - 'save-bundle', - 'no-save', - 'dry-run', - '-x', - '--fail-fast' - ]) - .help('h') - .alias('h', 'help') - .pkgConf('bundle-phobia'); -const pkg = require('./package'); - -const {main} = require('./src/install'); - -if (!module.parent) { - /* eslint-disable no-console */ - main({argv}).catch(err => { - console.log(c.red.bold('bundle-phobia-install failed: ') + err.message); - process.exit(1); - }); - updateNotifier({pkg}).notify(); -} diff --git a/index.js b/index.js deleted file mode 100644 index c62e151..0000000 --- a/index.js +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env node - -const updateNotifier = require('update-notifier'); -const c = require('chalk'); -const {argv} = require('yargs') - .parserConfiguration({ - 'short-option-groups': true, - 'camel-case-expansion': false, - 'dot-notation': false, - 'parse-numbers': true, - 'boolean-negation': false - }) - .usage('Usage: $0 [other-package-names...]') - .describe('package', 'Provide a package.json to read dependencies') - .alias('package', 'p') - .string('package') - .describe('range', 'Get a range of version (0 for all, 8 by default)') - .alias('range', 'r') - .number('range') - .describe('json', 'Output json rather than a formater string') - .alias('json', 'j') - .boolean('j') - .describe('size', 'Output just the module size') - .alias('size', 's') - .boolean('s') - .describe('gzip-size', 'Output just the module gzip size') - .alias('gzip-size', 'g') - .boolean('g') - .describe('dependencies', 'Output just the number of dependencies') - .alias('dependencies', 'd') - .boolean('d') - .describe('fail-fast', 'Stop on first error') - .alias('fail-fast', 'x') - .default('fail-fast', false) - .boolean('x') - .describe('serial', 'Run requests serially') - .alias('serial', '1') - .boolean('serial') - .describe('self', 'Output bundle-phobia stats') - .boolean('self') - .help('h') - .alias('h', 'help') - .pkgConf('bundle-phobia'); -const pkg = require('./package'); - -const {main} = require('./src/core'); - -if (!module.parent) { - /* eslint-disable no-console */ - main({argv}).catch(err => { - console.log(c.red.bold('bundle-phobia failed: ') + err.message); - process.exit(1); - }); - updateNotifier({pkg}).notify(); -} diff --git a/main.js b/main.js new file mode 100644 index 0000000..ba741cb --- /dev/null +++ b/main.js @@ -0,0 +1,140 @@ +#!/usr/bin/env node + +const updateNotifier = require('update-notifier'); +const c = require('chalk'); +const Yargs = require('yargs'); +const yargs = require('yargs'); + +const STATS_OPTIONS = { + package: { + alias: 'p', + string: true, + describe: 'Provide a package.json to read dependencies' + }, + range: { + alias: 'r', + number: true, + describe: 'Get a range of version (0 for all, 8 by default)' + }, + json: { + alias: 'j', + boolean: true, + describe: 'Output json rather than a formater string' + }, + size: { + alias: 's', + boolean: true, + describe: 'Output just the module size' + }, + 'gzip-size': { + alias: 'g', + boolean: true, + describe: 'Output just the module gzip size' + }, + dependencies: { + alias: 'd', + boolean: true, + describe: 'Output just the number of dependencies' + }, + 'fail-fast': { + alias: 'x', + boolean: true, + default: false, + describe: 'Stop on first error' + }, + serial: { + alias: '1', + boolean: true, + describe: 'Run requests serially' + }, + self: { + boolean: true, + describe: 'Output bundle-phobia stats' + }, + help: { + alias: 'h', + describe: 'Show help' + } +}; +const INSTALL_OPTIONS = { + warn: { + describe: 'Install despite of negative check but warn about predicate violation', + alias: 'w', + boolean: true + }, + interactive: { + describe: 'Ask for override in case of predicate violation', + alias: 'i', + boolean: true + }, + 'max-size': { + describe: 'Size threeshold of individual library to install', + alias: 'm', + string: true + }, + 'max-gzip-size': { + describe: 'Gzip Size threeshold of individual library to install', + alias: 'M', + string: true + }, + 'max-overall-size': { + describe: 'Overall size threeshold of dependencies', + alias: 'o', + string: true + }, + 'max-overall-gzip-size': { + describe: 'Overall Gzip size threeshold of dependencies', + alias: 'O', + string: true + }, + 'fail-fast': { + describe: 'Stop on first error', + alias: 'x', + boolean: true + } +}; + +const yargsParser = Yargs.scriptName('bundle-phobia') + .parserConfiguration({ + 'short-option-groups': true, + 'camel-case-expansion': false, + 'dot-notation': false, + 'parse-numbers': true, + 'boolean-negation': false + }) + .usage('Bundle Phobia: Find the cost of adding a npm package to your bundle') + .example('$0 lodash chalk', 'Get stats for a list of packages') + .example('$0 install lodash chalk', 'Conditionaly install packages') + .command( + 'install', + 'Perform install if specified size constraints are met', + yargs => yargs.options(INSTALL_OPTIONS), + argv => + require('./src/install') + .main({argv}) + .catch(err => { + console.log(c.red.bold(`bundle-phobia-install failed: `) + err.message); + yargs.exit(1, err); + }) + ) + .command( + ['$0', 'stats', 'package-stats'], + 'Get the stats of given package from bundlephobia.com', + yargs => yargs.options(STATS_OPTIONS), + argv => + require('./src/core') + .main({argv}) + .catch(err => { + console.log(c.red.bold(`bundle-phobia failed: `) + err.message); + yargs.exit(1, err); + }) + ) + .showHelpOnFail(false) + .alias('h', 'help') + .pkgConf('bundle-phobia'); + +if (!module.parent) { + yargsParser.parse(process.argv.slice(2)).argv; + const pkg = require('./package'); + updateNotifier({pkg}).notify(); +} diff --git a/package-lock.json b/package-lock.json index 244ef41..07c3383 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,11 +19,11 @@ "read-pkg-up": "^7.0.1", "resolve-package-json": "^1.4.0", "update-notifier": "^4.1.3", - "yargs": "^15.4.1" + "yargs": "^17.7.2" }, "bin": { - "bundle-phobia": "index.js", - "bundle-phobia-install": "index-install.js" + "bundle-phobia": "main.js", + "bundle-phobia-cli": "main.js" }, "devDependencies": { "@-k/eslint-plugin": "^0.4.1", @@ -32,7 +32,7 @@ "eslint": "^7.32.0", "nyc": "^15.1.0", "strip-ansi": "^6.0.1", - "yargs-parser": "^18.1.3" + "yargs-parser": "^21.1.1" }, "engines": { "node": ">=16.13" @@ -2509,13 +2509,16 @@ "integrity": "sha512-cHFF3C3XZ6ED7f22wAgvjnnVj5A+sXEYf7D5GCRmDUaH6D0QNnu3ZclUhSd1AoMyzgSN3IlyhI75q85onuIq3g==" }, "node_modules/cliui": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", - "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", "dependencies": { "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^6.2.0" + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" } }, "node_modules/clone": { @@ -2770,6 +2773,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -3202,7 +3206,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", - "dev": true, "engines": { "node": ">=6" } @@ -6269,6 +6272,26 @@ "node": ">=8.9" } }, + "node_modules/nyc/node_modules/camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/nyc/node_modules/cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + } + }, "node_modules/nyc/node_modules/p-map": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/p-map/-/p-map-3.0.0.tgz", @@ -6305,6 +6328,61 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/nyc/node_modules/wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/nyc/node_modules/y18n": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", + "dev": true + }, + "node_modules/nyc/node_modules/yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "dev": true, + "dependencies": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/nyc/node_modules/yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "dev": true, + "dependencies": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -7348,7 +7426,8 @@ "node_modules/require-main-filename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", - "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", + "dev": true }, "node_modules/require-precompiled": { "version": "0.1.0", @@ -7612,7 +7691,8 @@ "node_modules/set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "dev": true }, "node_modules/set-function-length": { "version": "1.1.1", @@ -8704,7 +8784,8 @@ "node_modules/which-module": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.1.tgz", - "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==" + "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==", + "dev": true }, "node_modules/which-typed-array": { "version": "1.1.13", @@ -8737,16 +8818,19 @@ } }, "node_modules/wrap-ansi": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", - "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" }, "engines": { - "node": ">=8" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, "node_modules/wrappy": { @@ -8783,9 +8867,12 @@ } }, "node_modules/y18n": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", - "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "engines": { + "node": ">=10" + } }, "node_modules/yallist": { "version": "3.1.1", @@ -8794,44 +8881,28 @@ "dev": true }, "node_modules/yargs": { - "version": "15.4.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", - "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", "dependencies": { - "cliui": "^6.0.0", - "decamelize": "^1.2.0", - "find-up": "^4.1.0", - "get-caller-file": "^2.0.1", + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", - "require-main-filename": "^2.0.0", - "set-blocking": "^2.0.0", - "string-width": "^4.2.0", - "which-module": "^2.0.0", - "y18n": "^4.0.0", - "yargs-parser": "^18.1.2" + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" }, "engines": { - "node": ">=8" + "node": ">=12" } }, "node_modules/yargs-parser": { - "version": "18.1.3", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", - "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", - "dependencies": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/yargs-parser/node_modules/camelcase": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", "engines": { - "node": ">=6" + "node": ">=12" } } }, @@ -10699,13 +10770,13 @@ "integrity": "sha512-cHFF3C3XZ6ED7f22wAgvjnnVj5A+sXEYf7D5GCRmDUaH6D0QNnu3ZclUhSd1AoMyzgSN3IlyhI75q85onuIq3g==" }, "cliui": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", - "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", "requires": { "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^6.2.0" + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" } }, "clone": { @@ -10904,7 +10975,8 @@ "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==" + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", + "dev": true }, "decamelize-keys": { "version": "1.1.1", @@ -11246,8 +11318,7 @@ "escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", - "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", - "dev": true + "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==" }, "escape-goat": { "version": "2.1.1", @@ -13541,6 +13612,23 @@ "yargs": "^15.0.2" }, "dependencies": { + "camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "dev": true + }, + "cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "dev": true, + "requires": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + } + }, "p-map": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/p-map/-/p-map-3.0.0.tgz", @@ -13564,6 +13652,52 @@ "requires": { "glob": "^7.1.3" } + }, + "wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dev": true, + "requires": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + } + }, + "y18n": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", + "dev": true + }, + "yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "dev": true, + "requires": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + } + }, + "yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "dev": true, + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } } } }, @@ -14320,7 +14454,8 @@ "require-main-filename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", - "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", + "dev": true }, "require-precompiled": { "version": "0.1.0", @@ -14516,7 +14651,8 @@ "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "dev": true }, "set-function-length": { "version": "1.1.1", @@ -15361,7 +15497,8 @@ "which-module": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.1.tgz", - "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==" + "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==", + "dev": true }, "which-typed-array": { "version": "1.1.13", @@ -15385,9 +15522,9 @@ } }, "wrap-ansi": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", - "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "requires": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", @@ -15422,9 +15559,9 @@ "dev": true }, "y18n": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", - "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==" }, "yallist": { "version": "3.1.1", @@ -15433,38 +15570,23 @@ "dev": true }, "yargs": { - "version": "15.4.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", - "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", "requires": { - "cliui": "^6.0.0", - "decamelize": "^1.2.0", - "find-up": "^4.1.0", - "get-caller-file": "^2.0.1", + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", - "require-main-filename": "^2.0.0", - "set-blocking": "^2.0.0", - "string-width": "^4.2.0", - "which-module": "^2.0.0", - "y18n": "^4.0.0", - "yargs-parser": "^18.1.2" + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" } }, "yargs-parser": { - "version": "18.1.3", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", - "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", - "requires": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - }, - "dependencies": { - "camelcase": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" - } - } + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==" } } } diff --git a/package.json b/package.json index c897108..995d02a 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "Cli for the node BundlePhobia Service", "main": "src/index.js", "bin": { - "bundle-phobia": "index.js", - "bundle-phobia-install": "index-install.js" + "bundle-phobia": "main.js", + "bundle-phobia-cli": "main.js" }, "engines": { "node": ">=16.13" @@ -48,7 +48,7 @@ "read-pkg-up": "^7.0.1", "resolve-package-json": "^1.4.0", "update-notifier": "^4.1.3", - "yargs": "^15.4.1" + "yargs": "^17.7.2" }, "devDependencies": { "@-k/eslint-plugin": "^0.4.1", @@ -57,7 +57,7 @@ "eslint": "^7.32.0", "nyc": "^15.1.0", "strip-ansi": "^6.0.1", - "yargs-parser": "^18.1.3" + "yargs-parser": "^21.1.1" }, "ava": { "files": [ diff --git a/src/core.js b/src/core.js index 891d31d..9b15615 100644 --- a/src/core.js +++ b/src/core.js @@ -13,9 +13,11 @@ const fakeSpinner = require('./fake-spinner'); const getPackages = async argv => { const range = argv.range || (argv.range === undefined ? null : -1); if ('range' in argv && 'r' in argv) return getPackageVersionList(argv._[0], range || 8); - if ('package' in argv && 'p' in argv) return getPackagesFromPackageJson(argv.package); + if (argv.self) return ['bundle-phobia-cli']; + if (('package' in argv && 'p' in argv) || _.isEmpty(argv._)) + return getPackagesFromPackageJson(argv.package || '.'); // !FIXME: this adress 56, implicit default folder - return argv.self ? ['bundle-phobia-cli'] : argv._; + return argv._; }; const isSingleOutput = argv => @@ -38,10 +40,13 @@ const main = async ({argv, stream = process.stdout}) => { const spinner = Spinner({stream}); const packages = await getPackages(argv).catch(err => { - const paquage = argv._[0] || 'packages from packages.json'; + // !FIXME: check the error handling message? + const paquage = argv._[0] || `packages from ${argv.package || 'package.json'}`; + /* if (spinnerActivated) spinner.fail(c.red(`resolving ${c.bold.underline(paquage)} failed: `) + err.message); - const wrapError = new Error(`${paquage}: ${err.message}`); + */ + const wrapError = new Error(`${paquage}: ${err.message}`); // FIXME: reword wrapError.error = err; throw wrapError; }); diff --git a/test/e2e/install-safetynet.sh b/test/e2e/install-safetynet.sh index 8e8c6df..f8251cc 100755 --- a/test/e2e/install-safetynet.sh +++ b/test/e2e/install-safetynet.sh @@ -21,7 +21,7 @@ cat > $E2E_FOLDER/tmp/expected_output < $output_file 2> $output_file.err) +(cd $sandbox && node ../../../../main install $args > $output_file 2> $output_file.err) status_code=$? set -e head -6 $output_file > $output_file.head diff --git a/test/e2e/status-safetynet.sh b/test/e2e/status-safetynet.sh index d4bc8bf..789c5b1 100755 --- a/test/e2e/status-safetynet.sh +++ b/test/e2e/status-safetynet.sh @@ -1,13 +1,13 @@ #!/bin/bash set -e -diff <(node index.js lodash@4.12) \ +diff <(node main.js lodash@4.12) \ <(echo "- Fetching stats for package lodash@4.12 ℹ lodash (4.12.0) has 0 dependencies for a weight of 63.65KB (22.11KB gzipped)") for pattern in lodash react bluebird; do - [[ $(node index.js lodash bluebird react | grep lodash | wc -l) -eq 2 ]] + [[ $(node main.js lodash bluebird react | grep lodash | wc -l) -eq 2 ]] # one occurence for report, one other for progress done -[[ $(node index.js lodash bluebird react | grep total | wc -l) -eq 1 ]] -[[ $(node index.js lodash bluebird react | grep weight | wc -l) -eq 4 ]] +[[ $(node main.js lodash bluebird react | grep total | wc -l) -eq 1 ]] +[[ $(node main.js lodash bluebird react | grep weight | wc -l) -eq 4 ]]