This content originally appeared on DEV Community and was authored by matoruru
The command is:
node -e "console.log(Object.keys(require('./package.json').peerDependencies).join(' '))" | xargs yarn add
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"
}
}
We'll see one by one:
-
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' }
-
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' ]
-
join
method joins the elements with the given string.
> [ 'react', 'react-dom' ].join(' ') 'react react-dom'
-
node -e
evaluates the given script.
$ node -e "console.log('react react-dom')" 'react react-dom'
-
Pass it to the
yarn add
withxargs
.
$ node -e "console.log('react react-dom')" | xargs yarn add yarn add v1.22.5 [1/4] Resolving packages... [2/4] Fetching packages... [########------------------
Done ?
This content originally appeared on DEV Community and was authored by matoruru
matoruru | Sciencx (2021-04-08T20:39:05+00:00) One-liner to install peerDependencies. Retrieved from https://www.scien.cx/2021/04/08/one-liner-to-install-peerdependencies/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.