I couldn't find a npm
command to update a subset of my dependencies to their latest version based on a name pattern, so here's a one-liner to do it with pipes and awk
(to be modified for your needs).
In this example, I want to update all the dependencies containing the string "babel".
npm outdated |awk 'BEGIN{OFS="@"} $1 ~ /babel/ { print $1, "latest" }'| xargs npm install
Explanation of each command
npm outdated
lists your outdated dependencies.
awk
:
-
BEGIN{OFS="@"}
sets@
as the output field separator (will be used byprint
) -
$1 ~ /babel/
will match the lines containing "babel" in their first column -
{ print $1, "latest" }
will output each selected lines concatenated with "latest" (using "@" as theOFS
)
xargs npm install
will give the output of awk
as input arguments to npm install
, like so : npm install dependency1@latest dependency2@latest ...
Tweak it
The beauty of the command line: you could tweak this for different dependency managers, such as Composer for PHP.
Top comments (0)