'How can I version bump all my dependencies?

Having yarn outdated is quite informative but I'd like to avoid running over package by package doing yarn upgrade.

From yarn's documentation, just yarn upgrade without arguments is said to upgrade all dependencies but there's no change in my project's package.json and yarn outdated shows the same packages versions than before.

Is there some command or argument that just bumps all my dependencies?

If not, is the practice discouraged in some way?



Solution 1:[1]

You can update your packages to the latest version specified in the package.json using yarn upgrade without any args.

This is taken from the docs:

yarn upgrade

This command updates all dependencies to their latest version based on the version range specified in the package.json file. The yarn.lock file will be recreated as well.

This will only update packages that are allowed to be upgraded in the package.json e.g. using ^ (e.g. ^0.13.0 would update to version 0.14.0 if it exists). This will not update your package.json file, but it will update the yarn.lock.

If you want to update dependencies in to the latest version you can use the package npm-check-updates which will update your package.json:

$ yarn global add npm-check-updates
$ npm-check-updates -u
$ yarn upgrade

Solution 2:[2]

Upgrade all packages to latest version

yarn upgrade --latest

Solution 3:[3]

just run yarn upgrade-interactive --latest and select packages you want to update using space button and press the enter to update.

Solution 4:[4]

If your dependencies are using a range version ("^x.x.x", "~x.x.x", etc), your package.json won't be updated if the latest version also match that range, only your yarn.lock.

If you want your package.json to be updated:

  1. Change all your dependencies to a fixed version ("x.x.x")
  2. Run yarn to update the yarn.lock
  3. Run yarn upgrade-interactive and select all dependencies you want to upgrade

Now both your yarn.lock and package.json will reflect the exact latest versions.

Solution 5:[5]

Answer for users of Yarn v2 and above.

Import the interactive-tools plugin:

$ yarn plugin import interactive-tools

And run it like this:

$ yarn upgrade-interactive

Note that this will also modify the semvers in your package.json.

Solution 6:[6]

I always follow the official documentation for it :)

yarn add --dev yarn-upgrade-all

src: https://yarnpkg.com/package/yarn-upgrade-all

Solution 7:[7]

You could also copy your dependecies to a typescript or javascript playground and use Object.entries(obj).reduce((xs, x) => ${xs} ${x[0] }, "yarn add") to generate the command containing all of the packages inside your package.json.

Example

let obj = {
    "@types/react": "^16.3.18",
    "@types/react-dom": "^16.0.6",
    "awesome-typescript-loader": "^5.1.0",
    "babel-polyfill": "^6.26.0",
    "del": "2.2.2",
    "es-cookie": "^1.2.0",
    "es6-promise": "4.1.1",
    "gulp": "^4.0.2",
    "gulp-autoprefixer": "^3.1.1",
    "gulp-clean-css": "^3.0.2",
    "gulp-concat": "^2.6.1",
    "gulp-if": "^2.0.2",
    "gulp-jshint": "^2.0.4",
    "gulp-merge-media-queries": "0.2.1",
    "gulp-rename": "^1.2.2",
    "gulp-rev-all": "^0.9.7",
    "gulp-sass": "^3.1.0",
    "gulp-uglify": "^2.0.1",
    "jshint": "^2.9.4",
    "node-promise": "^0.5.12",
    "react": "^16.4.1",
    "react-dom": "^16.4.1",
    "require-dir": "^0.3.2",
    "run-sequence": "1.2.2",
    "source-map-loader": "^0.2.3",
    "typescript": "^2.9.2",
    "webpack": "^4.12.0",
    "webpack-cli": "^3.0.8",
    "webpack-log": "^1.2.0"
  }

  let res = Object.entries(obj).reduce((xs, x) => `${xs} ${x[0] }`, "yarn add")

  console.log(res)

Output:

yarn add @types/react @types/react-dom awesome-typescript-loader babel-polyfill del es-cookie es6-promise gulp gulp-autoprefixer gulp-clean-css gulp-concat gulp-if gulp-jshint gulp-merge-media-queries gulp-rename gulp-rev-all gulp-sass gulp-uglify jshint node-promise react react-dom require-dir run-sequence source-map-loader typescript webpack webpack-cli webpack-log

I use this playground to quickly generate the command. It is also usefull to quickly generate code from json objects.

https://www.typescriptlang.org/play?ssl=35&ssc=19&pln=1&pc=1#code/DYUwLgBA9gRgVhAvBA3gKApiAiAAmATwAcQBnAegCcQBDAYzGwC4cA9ARgDYA6AZm-YAObABoMWPIRIVq9MAFoAJlAC2zNl24AGbp1HjM2GgHcyqkPKlk6lAJZEFwKDUUhK67KwCsA7fqw4MDQwIMDyRFDABABmtsDAHqw8AEw8Wv4Srgks2MnceckZhmTydFBQANa2IIns+X5iAdhknOGUqrakNTkALL7sRTgA5gCuwESJfTqFjRKj4-I0I2BQRNSxAB5uifx1A7OG80SloDQAdqWkpDva+YPYR6VQZ3Q0jDmseTz7BsNjx7Zook8tN7o84KQABa2M7vNgg7g9MH-eQqNxDCxoxS2GjyACOIzc1WuOWmAmRC2oZxoaNq9RmvweKOoADdFvFEjoAJzcADsFOOpBoVxudXSBz+CxGQ2AgIIwNuPyaEOhsIVPKREuwZygrjaHS6nO4PnYDKasgYtR4fSVEgtCmUag+mht92oBNs1CUnqN-DNdpGFy6BJAL26ODqBXupCgI0odExNGOThc2w+ZN49yspBs9jhnjyPP9hlMMCI9AqkwEIPupfLdAqJ1sNx0wi1dYr8icQzpNfEAF80OJQJBqKQkBAAPLwEAMbihsB2MgAClgcAAlNxqIoRgnl8uNqQRBANuukAA+CAAAwAJChD-2IHeNgBtLQAXQg-avx+wBBolBnBALiKNg65DpgZRnDGoDcN2y5juuQA

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 user2210411
Solution 3 Nux
Solution 4 Bruno Lemos
Solution 5
Solution 6 Sodhi saab
Solution 7 OCP30pt1c1l1l43-X1z17