Skip to content

Latest commit

 

History

History
58 lines (41 loc) · 1.96 KB

bulk-updating-outdated-npm-packages.md

File metadata and controls

58 lines (41 loc) · 1.96 KB

Updating Outdated npm Packages with pnpm

This command sequence updates all outdated npm packages in a project to their latest versions using pnpm. Below is a breakdown of each part of the command:

npm outdated | cut -d" " -f1 | tail -n +2 | sed 's/$/@latest/' | xargs pnpm i

Command Breakdown

npm outdated

  • Lists all the dependencies that are outdated in your project.
  • Outputs details such as the current version, wanted version, and latest version available for each package.

cut -d" " -f1

  • cut is used to extract specific fields from each line of input.
  • -d" " sets the delimiter to a space character.
  • -f1 extracts the first field, which is the package name.

tail -n +2

  • tail outputs the last part of files.
  • -n +2 tells tail to start from the second line, skipping the header line from npm outdated.

sed 's/$/@latest/'

  • sed is a stream editor for parsing and transforming text.
  • s/$/@latest/ substitutes the end of each line ($) with @latest, appending @latest to each package name.

xargs pnpm i

  • xargs builds and executes command lines from standard input.
  • pnpm i (or pnpm install) is the pnpm command to install packages.
  • xargs takes the list of packages generated by the previous commands and runs pnpm i for each one, installing the latest version of each outdated package.

Example

Consider a project with the following outdated packages:

$ npm outdated
Package  Current  Wanted  Latest  Location
lodash    4.17.15  4.17.21  4.17.21  myproject
express   4.17.1   4.17.1   4.18.2   myproject

Running the command:

npm outdated | cut -d" " -f1 | tail -n +2 | sed 's/$/@latest/' | xargs pnpm i

Will install the latest versions of lodash and express:

pnpm i lodash@latest express@latest

This updates lodash to 4.17.21 and express to 4.18.2.

This command sequence is a convenient way to update all outdated packages in your project to their latest versions.