better-install v0.1.0
Better Install
Automatically install TypeScript @types.
Inspired by @yarnpkg/plugin-typescript but works with yarn@1, yarn@2, pnpm and npm.
- Install
- Configure
- Add Packages
- Install All Packages
- Add devDependency
- CLI Options
- As a Global Bin - Install All Packages - Select a Package Manager - Project or User Config
- MonoRepo Projects
Install
yarn
yarn add -D better-installpnpm
pnpm add -D better-installnpm
npm install -D better-installConfigure
package.json
{
"scripts": {
"bi": "better-install"
}
}:star: When running
better-installas annpmscript, it will use the package manager that invokes the script to run all commands, e.g.,yarn bi lodashusesyarnto installlodashand@types/lodash.
Add Packages
The format for installing packages is
<PACKAGE_MANAGER> bi [PACKAGES...] [OPTIONS]yarn
yarn bi lodash yargs-parser minimist-options argvilleInstall lodash, yargs-parser and minimist-options as a prod dependencies and corresponding @types/ as a devDependencies using yarn.
:fire:
better-installinstalls@types/packages if the dependency does not contain atypesortypingsfield in package.json or an index.d.ts file in the package root.minimist-optionsincludes a default declaration file, index.d.ts, in the package root but does not specify atypesor atypingsfield within the package.json file. This is enough forbetter-installto know thatminimist-optionscomes bundled with types and therefore will skip installing@types/minimist-options.better-installchecks fortypes,typingsand index.d.ts the same as TypeScript.Like
minimist-options,argvillecomes bundled withtypesand therforebetter-installskips installing@types/argville.:star:
better-installsupports bothyarn@1andyarn@2.:thumbsup:
better-installalso supports locating and installing@types/for scoped packages.
pnpm
pnpm bi -- lodash yargs-parser minimist-options argvillenpm
npm run bi -- lodash yargs-parser minimist-options argvilleInstall All Packages
Run better-install without any args to install all packages listed in package.json and corresponding @types/.
# with yarn
yarn bi
# OR pnpm
pnpm bi
# OR npm
npm run biAdd devDependency
better-install passes all unknown cli flags to the underlying package manager. To install dev dependencies simply pass the dev flag for the appropriate package manager.
# with yarn
yarn bi -D lodash
# OR pnpm
pnpm bi -D lodash
# OR npm
npm run bi --save-dev lodashInstalls lodash and @types/lodash as devDependencies.
CLI Options
Run yarn bi --help (or with pnpm or npm) to view a full list of options.
:warning: better-install passes unknown flags to the underlying package manager. For example,
bi lodash -Dsends the -D flag to the package manager and therfore installslodashand@types/lodashas devDependencies (@typesare always installed as devDependencies).
As a Global Bin
May also install better-install globally
# with yarn
yarn add better-install -g
# OR pnpm
pnpm add better-install -g
# OR npm
npm add better-install -gExposes two bins, better-install and, for convenience, bi.
Install All Packages
biInstalls all packages listed in \/package.json.
Select a Package Manager
As a global bin, better-install uses npm by default. Override this using the --pm option.
# install all package.json dependencies and @types with yarn
bi --pm yarn
# add lodash and @types/lodash with pnpm
bi lodash --pm pnpm
# add lodash and @types/lodash as devDependencies with npm
bi lodash -D --pm npm
# Same as
bi lodash -DProject or User Config
better-install loads configuration from project level .npmrc config files, /path/to/project/.npmrc, and user level .npmrc config files, ~/.npmrc. Instead of always passing --pm to better-install, one can define the pm key once within an .npmrc file.
# /path/to/project/.npmrc
pm=yarnNow bi commands within /path/to/project will use yarn instead of npm. Can still override this using the --pm flag.
MonoRepo Projects
better-install supports yarn workspaces and pnpm workspaces.
yarn
// package.json
{
"private": true,
"workspaces": ["packages/*"]
}Then use the -f,--filter flag to glob
yarn bi lodash --filter packages/sub-pkg
# Or with globbing
yarn bi lodash -f packages/*The -f,--filter flag also supports globbing for the package name.
yarn bi lodash -f @pkg-name/sub-pkg
# Or with globbing
yarn bi lodash -f @pkg-name/*pnpm
# pnpm-workspace.yaml
packages:
- packages/*pnpm bi lodash -f @pkg-name/*