“This is the 9th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”
Hello, I’m Shanyue.
The version number of NPM is Semver specification, which consists of [Major, minor, patch]
- Major: When you send an API that contains Breaking Change
- Minor: When you add a backward-compatible feature
- Patch: When you fix a backward compatibility Bug
Suppose the react version is 17.0.1. What should we do if we want to upgrade to 17.0.2?
- "react" : "17.0.1",
+ "react" : "17.0.2",
Copy the code
Automatic discovery update
The last thing you want to do to upgrade the version number is manually change it in package.json.
- "react" : "17.0.1",
+ "react" : "17.0.2",
Copy the code
After all, you can’t manually discover all the packages that need to be updated.
At this point, the package to be updated can be found by means of NPM outdated.
Using NPM outdated, you can also list the documents whose package is to be updated.
$NPM outdated -l Package Current Wanted Latest Location 可 by Package Type homepage.next/bundle-Analyzer 10.2.0 10.2.3 12.0.3 node_modules / @ next/bundle - analyzer app dependencies at https://github.com/vercel/next.js#readme
@types/lodash 4.14.169 4.14.176 4.14.176 node_modules/@types/lodash app dependencies https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/lodash
Copy the code
Automatically updates the version number
Using NPM outdated, you can find packages that need to be upgraded, but you still need to manually change the version number in package.json to upgrade.
NPM check-updates is a more powerful tool than NPM outdated.
Npm-check-updates -u automatically rewrites the version number to be updated in package.json.
Upgrade the [minor] minor version, which may cause a Break Change, but only the latest patch version can be upgraded.
$ npx npm-check-updates --target patch
Copy the code
A little advice
- When the major version number of a library is updated, do not immediately update it, because it is easy to stumble. You can try to update the new function after several patch versions
- When you encounter a major update, read the documentation of ChangeLog, upgrade instructions, and test and audit more