better-install
v0.1.0
Published
Automatically install typescript types when installing or adding dependencies.
Downloads
7
Maintainers
Readme
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
- MonoRepo Projects
Install
yarn
yarn add -D better-install
pnpm
pnpm add -D better-install
npm
npm install -D better-install
Configure
package.json
{
"scripts": {
"bi": "better-install"
}
}
:star: When running
better-install
as annpm
script, it will use the package manager that invokes the script to run all commands, e.g.,yarn bi lodash
usesyarn
to installlodash
and@types/lodash
.
Add Packages
The format for installing packages is
<PACKAGE_MANAGER> bi [PACKAGES...] [OPTIONS]
yarn
yarn bi lodash yargs-parser minimist-options argville
Install lodash
, yargs-parser
and minimist-options
as a prod dependencies and corresponding @types/
as a devDependencies using yarn
.
:fire:
better-install
installs@types/
packages if the dependency does not contain atypes
ortypings
field in package.json or an index.d.ts file in the package root.minimist-options
includes a default declaration file, index.d.ts, in the package root but does not specify atypes
or atypings
field within the package.json file. This is enough forbetter-install
to know thatminimist-options
comes bundled with types and therefore will skip installing@types/minimist-options
.better-install
checks fortypes
,typings
and index.d.ts the same as TypeScript.Like
minimist-options
,argville
comes bundled withtypes
and therforebetter-install
skips installing@types/argville
.
:star:
better-install
supports bothyarn@1
andyarn@2
.
:thumbsup:
better-install
also supports locating and installing@types/
for scoped packages.
pnpm
pnpm bi -- lodash yargs-parser minimist-options argville
npm
npm run bi -- lodash yargs-parser minimist-options argville
Install 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 bi
Add 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 lodash
Installs 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 -D
sends the -D flag to the package manager and therfore installslodash
and@types/lodash
as devDependencies (@types
are 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 -g
Exposes two bins, better-install
and, for convenience, bi
.
Install All Packages
bi
Installs all packages listed in <CWD>/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 -D
Project 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=yarn
Now 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/*