DEV Community

matoruru
matoruru

Posted on • Edited on

3 2

One-liner to install peerDependencies

Here it is:

node -e "console.log(Object.keys(require('./package.json').peerDependencies).join(' '))" | xargs yarn add
Enter fullscreen mode Exit fullscreen mode

How it works

Let's say we have peerDependencies in our package.json like this:

    ...
  },
  "peerDependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  }
}
Enter fullscreen mode Exit fullscreen mode

We'll see one by one:

  1. Load the package.json and get the peerDependencies.

    Welcome to Node.js v15.14.0.
    > require('./package.json').peerDependencies
    { react: '^17.0.2', 'react-dom': '^17.0.2' }
    
  2. Object.keys function collects the keys of the object and put them together in the array.

    Welcome to Node.js v15.14.0.
    > Object.keys({ react: '^17.0.2', 'react-dom': '^17.0.2' })
    [ 'react', 'react-dom' ]
    
  3. join method joins the elements with the given string.

    > [ 'react', 'react-dom' ].join(' ')
    'react react-dom'
    
  4. node -e evaluates the given script.

    $ node -e "console.log('react react-dom')"
    'react react-dom'
    
  5. Pass it to the yarn add with xargs.

    $ node -e "console.log('react react-dom')" | xargs yarn add
    yarn add v1.22.5
    [1/4] Resolving packages...
    [2/4] Fetching packages...
    [########------------------
    

Done 🥳

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (1)

Collapse
 
shinbobbu profile image
shinbobbu

thank you, great job 🥳

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs