NPM updates dependency packages in three ways
1. Use basic commands
- View the global installation package
npm list -g --depth 0
Copy the code
- Viewing the Installation Package
packageName
Latest version information
npm view | info packageName version
Copy the code
- View the remote installation package
packageName
Release information for all releases of
npm view | info packageName versions
Copy the code
- Check for outdated installation packages
npm outdated [packageName]
Copy the code
Version Information
Package Displays the Package name. If –long / -l is used, the package belongs to Dependencies or devDependency
Current Current dependency package installation version
Wanted The latest version number that can be updated according to package.json package version prefix rules
Latest package version number (by default, this is the Latest, depending on the developer’s package management regime)
Location is the Location of the dependency package in the dependency tree
Package font color meaning
-
Red package.json dependencies with updatable package version prefix rules
-
Yellow package.json dependencies with package version prefix rules that cannot be updated
Dependent version cognition
The dependency packages of the project are generally saved in package.json file, and the corresponding version number is in the form of mojor.minor.patch
Major means a major API change that is not compatible (major)
Minor represents backward compatible functional changes (minor)
Patch stands for backward compatible bug fixes (patched)
Meaning of the prefix of the version number of the dependent package
-
* Matches the latest major version dependency package
-
^ Matches the latest minor version of the dependency package, eg: 1.1.0 can be updated to match all 1.x.x packages, not to match 2.x.x
-
~ Matches the latest patch version dependency packages, eg: 1.1.0 can update all packages that match 1.1.x, but not 1.2.x
-
No prefix indicates a fixed version number, and the version will not be updated to match any other version. [Need to manually change package version of package.json]
Second, the NPM update
- Update specified dependency packages
major
Bit updates are sometimes required inpackage.json
Manually change the corresponding version number of the dependency package in the update.- -S
dependencies
Dependency installation (–save) in production environment, default installation - -D
devDependencies
Dependency installation in development environment (–save-dev)
- -S
npm update packageName (-D | -S)
Copy the code
Differences between NPM I and NPM Update
The following description:
package
Indicates that package.json depends on a version management filelock
Package-lock. json locks dependent version files
lock
File exists
-
NPM I will be installed according to the corresponding package version of Lock and will not be automatically upgraded
- Manual changes
package
Corresponding package,lock
Will be in accordance with thepackage
Prefix version specification updated to the latest version,package
The version is manual
- Manual changes
-
NPM update is installed to the latest version according to the package version prefix upgrade specification
package
According to the latest version of the prefix specification andlock
The same will not change, the different will change.lock
The corresponding package version number in
lock
File does not exist
-
NPM I is installed to the latest version of package.json according to the package version prefix upgrade specification
package.json
Still the prefix specification version numberpackage-lock.json
Upgrade to the latest version according to the version prefix specification
-
NPM UPDATE is similar to NPM I
- But ignore
devDependencies
The corresponding package under update installation - added
-D
Before the update is installeddependencies
Under the premise of the update installationdevDependencies
Below the corresponding dependency packages
- But ignore
Third, NPM – check – updates
- The global installation depends on nPm-check-update
npm install npm-check-update -g
Copy the code
- Check updatable modules
Ncu or NPM - check - updateCopy the code
- Update updatable modules [It is not recommended to update all updatable dependencies at once] (updates include updates to the major bit)
ncu -u [packageName]
Copy the code
Fourth, NPM – check
- The global installation depends on NPm-check
npm install npm-check -g
Copy the code
- View information about updatable packages
npm-check
Copy the code
- Select and update the corresponding dependency package
npm-check -u
Copy the code
Five, the difference between the three methods
The difference between:
npm update
npm update [packageName]
Will update synchronouslypackage-lock.json
The version of the corresponding package in the file, no need to reinstall the NPM package
NPM – check – updates and NPM – check
-
The two are basically the same, but there are some differences in some forms of interaction during the update process
-
Update the updatable installation package in package.json file, but not the version of the corresponding package in the corresponding package-lock.json file
-
Dependencies need to be reinstalled using the following command:
rm -rf package-lock.json && npm i
Copy the code
Refer to the link
-
How do I update dependencies in package.json
-
Install, update, and delete NPM dependencies
-
[NPM module management advanced – NPm-check + CNPM build package update environment]