Skip to content

hint-test/test-peerdeps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Test 3rd party tools to install direct peerDependencies libraries

npm prior to v7, will not install plugin's peerDependencies automatically. In order to properly maintain the plugin, like compile and publish, you will need a way to install these peerDeps in your dev env. (This may not be an issue to Monorepo)

npm v7 fixed the issue perfectly, so you don't need this topic anymore.

Instruction

Actually there are 2 ways to handle this issue:

  1. Just add these peerDependencies to devDependencies to fit the dev env.
    Just these 'devDeps' are not real 'devDeps'.

  2. Use prepare script to let NPM to install these 'additional' deps via 3rd party tools, right after npm install, which is this topic talks about.

"prepare": "npm-install-peers"

About prepare, please see NPM life-cycle-scripts.

Test

Test Design
react-share has a peerDependencies of react
file-loader has a peerDependencies of webpack
Use react-share as peerDependencies and file-loader as dependencies

Check Point

  1. Can install direct peerDependencies
  2. Can install peerDependencies of the dependencies
  3. Can install peerDependencies of the peerDependencies
  4. Can install peerDependencies of the devDependencies
  5. Install modifies package.json, package-lock.json

Tools

npm-install-peers

https://www.npmjs.com/package/npm-install-peers https://www.npmjs.com/package/npm-install-peers

  "scripts": {
    "prepare": "npm-install-peers"
  },

install-peers-cli

https://www.npmjs.com/package/install-peers-cli https://www.npmjs.com/package/install-peers-cli

  "scripts": {
    "prepare": "install-peers"
  },

@team-griffin/install-self-peers

https://www.npmjs.com/package/@team-griffin/install-self-peers https://www.npmjs.com/package/@team-griffin/install-self-peers

  "scripts": {
    "prepare": "install-self-peers --npm -- --ignore-scripts"
  },

Test Result

Run: npm install

npm-install-peers install-peers-cli @team-griffin/install-self-peers
Windows: (1) (2) (3)
macOS (1) (1) (3)

Note:

  1. All tools just only install direct peerDependencies, they don't install peerDependencies of the devDependencies, peerDependencies and devDependencies.
  2. Known issue, see alexindigo/install-peers-cli#12
  3. It adds the "peerDependencies" to "dependencies", thus package.json get updated, no good.

So, prefer to use npm-install-peers, and it is also the most popular one.

Disadvantage

Go with prepare script, peerDependencies will be re-installed every time you run npm install, which will slow down the install task.
The best choice is to upgrade to npm v7. ^_^

About

Test 3rd Party Tools to install direct `peerDependencies`

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published