Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

install-peerdeps

nathanhleung173kMIT3.0.7

CLI to automatically install peerDeps

install, peerdeps, automatically, yarn, npm, airbnb, eslint

readme

install-peerdeps

As seen on the README of Airbnb's ESLint config!

Disclaimer: Airbnb is not affiliated with, and does not endorse, this CLI tool

GitHub Actions Workflow Status Libraries.io dependency status for GitHub repo

npm total downloads npm monthly downloads GitHub stars

Node version npm version GitHub license

💻 Quickly install an npm package and its peer dependencies automatically, using npm, Yarn, or pnpm.

Starting with npm v3.0, peer dependencies are not automatically installed on npm install, and it can be a hassle to install them all manually. The install-peerdeps tool makes the process fast and easy.

Also works with Yarn (with the --yarn flag) and pnpm (with the --pnpm flag).

Quick Start

cd my-project-directory

npx install-peerdeps <package>[@<version>]

# If you're using yarn
yarn dlx install-peerdeps --yarn <package>[@<version>]

# If you're using pnpm
pnpm dlx install-peerdeps --pnpm <package>[@<version>]

The specified package along with its peer dependencies will be installed.

Why

It's true that on Linux you can run something like this to automatically install peerDeps (taken from Airbnb's eslint config repo):

(
  export PKG=eslint-config-airbnb;
  npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
)

However, the above solution is hard to remember, and doesn't work on Windows. This tool aims to solve both of these problems.

Usage

Usage: install-peerdeps <package>[@<version>], default version is 'latest'

Installs the specified package along with correct peerDeps.

Options:
  -V, --version                    output the version number
  -D                               Install the package as a devDependency (alias for `-d`)
  -d, --dev                        Install the package as a devDependency
  -g, --global                     Install the package globally
  -o, --only-peers                 Install only peerDependencies of the package
  -S, --silent                     If using npm, don't save in package.json
  -Y, --yarn                       Install with Yarn
  -P, --pnpm                       Install with pnpm
  -n, --no-registry                Do not use a remote registry to find dependencies list
  --dry-run                        Do not install packages, but show the install command that will be run
  -x, --extra-args "<extra_args>"  Extra arguments to pass through to the underlying package manager
  -h, --help                       output usage information

Extra Arguments

Only core npm, Yarn, and pnpm arguments relating to package installation are officially provided by install-peerdeps. However, if you'd like to pass through additional arguments, you may do so with --extra-args. Here's how you'd install a package into a Yarn-workspace-enabled repository:

install-peerdeps <package> --dev -Y --extra-args "-W"

Here's how you'd use --extra-args to pass a custom npm config option (in this case, disabling strict-ssl when accessing a custom registry over HTTPS):

install-peerdeps <package> --extra-args "--strict-ssl false"

Examples

Basic Peer Dependency Installation

eslint-config-airbnb requires quite a few peer dependencies. Here's what you'd do to install them all:

install-peerdeps eslint-config-airbnb --dev

install-peerdeps will automatically detect whether you're using Yarn. If you are, it'll prompt you as to whether you want to use Yarn or npm to install the packages.

# If you're using npm
npm install eslint-config-airbnb@18.2.1 eslint@^7.2.0 eslint-plugin-import@^2.22.1 eslint-plugin-jsx-a11y@^6.4.1 eslint-plugin-react@^7.21.5 eslint-plugin-react-hooks@^1.7.0 --save-dev

# If you're using yarn
yarn add eslint-config-airbnb@18.2.1 eslint@^7.2.0 eslint-plugin-import@^2.22.1 eslint-plugin-jsx-a11y@^6.4.1 eslint-plugin-react@^7.21.5 eslint-plugin-react-hooks@^1.7.0 --dev

Installing a Different Version Tag

If you'd like to install a different version of a package than the latest (the default), simply specify the version like so:

install-peerdeps @angular/core@next

The tool will automatically install the version corresponding to the tag, as well as its peer dependencies:

Installing peerdeps for @angular/core@next.
yarn add @angular/core@11.2.0-next.0 rxjs@^6.5.3 zone.js@^0.11.3 --dev

Contributing

See CONTRIBUTING.md

License

MIT

changelog

3.0.7

  • Fixes #142 - issue when installing packages with a version range that npm info returns an array for
  • Merges #256 - replace cli-color with picocolors
  • Merges #221 - fix parsing of --no-registry option

3.0.6

  • Fixes NPM install broken by new Yarn code path (npm npm info is not a valid npm command)

3.0.5

  • Merges #255 - fix wrong info command in Yarn >1, resolving #215, #249, maybe #171, #193, and #228

3.0.4

  • Merges #254 - update call to spawn due to Node.js security, resolving #252

3.0.3

  • Reverts quotes around package name

3.0.2

  • Merges #126 - don't coerce version strings to semver, quote package names

3.0.1

  • Merges #124 - add .cmd suffix to spawned commands on windows

3.0.0

  • Merges #85 by @amclin - use package manager to get info, resolving #72 and #73

2.0.3

  • Merges #88 by @cdierkens - set the default registry to the official registry.npmjs.org, resolving #87

2.0.2

  • Merges #66 by @marlonicus - fix installation not starting after package manager confirmation, resolving #70

2.0.1

2.0.0

  • Bumps dependencies
  • Drops support for Node.js below version 8

1.11.0

  • Resolves #47 - support pnpm
  • Merges #51 by @jaredly - allow installation from linked modules/GitHub, resolving #44
  • Merges #50 by @vladimyr - support both -D & -d flags for dev mode
  • Merges #49 by @AndreGeng - make sure registry option is passed through, resolving #48

1.10.2

  • Fixes #43 - check to see if --extra-args is undefined before appending to cli command

1.10.1

  • Fixes #31 - use semver to handle version ranges with spaces

1.10.0

  • Addresses #41 - allow extra arguments to be passed with --extra-args flag

1.9.0

  • Merges #32 by @nandub - add --proxy flag
  • Merges #38 by @gwicksted - add --global flag

1.8.0

  • Merges #29 by @ljharb - convert tests to Tape

1.7.1

  • Allows Node.js 0.10 test failure due to Jest incompatibility
  • Inlines has-yarn for compatibility with earlier Node versions

1.7.0

  • Fixes #25 - allow version number ranges to be installed
  • Fixes #24 - allow extra args to be passed through with --

1.6.0

  • Merges #23 - add option to pass Auth header to install private packages

1.5.0

  • Fixes #16 - remove trailing slash from registry URI if present
  • Addresses #21 - target older Node (v0.10)

1.4.1

  • Merges #18 - update the argument parsing regular expression to account for periods in the package name

1.4.0

  • Adds --registry option to specify custom/private package registry
  • Fixes #12 - fix version regular expression to allow dashes in the version name (i.e. packages like `bootstrap@4.0.0-beta` are now installable)
  • Fixes #3 - proxy environments are now supported (Node.js native http.request([options]) does not seem to support proxy environments; migrated to request/request)
  • Migrates from babel-preset-latest to babel-preset-env targeting Node.js >4.0.0
  • Replaces Airbnb formatting rules with prettier and eslint --fix workflow

1.3.0

  • Merges pull request #15 from @brucewpaul - add the explicit --no-save option when using NPM (NPM v5 defaults to --save)
  • Updates README with build badges, add CONTRIBUTING.md and ROADMAP.md
  • Increases test coverage - added tests for #15 and #10
  • Adds --dry-run option for testing

1.2.0

  • Merges pull request #10 from @okonet - allow installation of only peers instead of peers and package too

1.1.3

  • Starts changelog
  • Merges pull request #4 from @lancefisher - handle ranges of peer dependencies