2017/01/09

How to update npm modules

So, when was the last time you have been updated your npm modules?
After I have been updated for few of machines, I believe it is quite useful and necessary for me to record steps for doing so to save my life. Here we go.

1. Get a list of outdated packages

npm provides a useful command for us to do so. Below is an example for listing global modules which are outdated. Of cause, you can run that in your local project once you got the idea.
$ npm -g outdated
Package                 Current  Wanted  Latest  Location
eslint                   3.12.2  3.13.0  3.13.0  /opt/local/lib > eslint
eslint-config-airbnb     13.0.0  14.0.0  14.0.0  /opt/local/lib > eslint-config-airbnb
eslint-plugin-jsx-a11y    2.2.3   3.0.2   3.0.2  /opt/local/lib > eslint-plugin-jsx-a11y
eslint-plugin-react       6.8.0   6.9.0   6.9.0  /opt/local/lib > eslint-plugin-react
npm                     2.15.11   4.0.5   4.0.5  /opt/local/lib > npm
Here is the documentation about npm outdated. Briefly speaking, you should take care versions in the middle column.
NOTE:
  • Current column shows versions you own now.
  • Wanted column shows latest versions you can get after considering your package dependencies
  • Latest column shows the latest available version from corresponding projects

2. Update the npm modules

As my npm is managed by macport, I will let macport to upgrade my npm.
$ sudo port upgrade outdated
Install rest of the modules by specifying name and version together.
$ sudo npm -g install eslint@3.13.0 eslint-config-airbnb@14.0.0 eslint-plugin-jsx-a11y@3.0.2 eslint-plugin-react@6.9.0
NOTE:
  • My global modules requires a root privilege
Sometime, there are warnings about mismatched dependencies.
npm WARN eslint-config-airbnb@14.0.0 requires a peer of eslint@^3.13.0 but none was installed.
npm WARN eslint-config-airbnb@14.0.0 requires a peer of eslint-plugin-import@^2.2.0 but none was installed.
npm WARN eslint-config-airbnb-base@11.0.1 requires a peer of eslint@^3.13.0 but none was installed.
npm WARN eslint-config-airbnb-base@11.0.1 requires a peer of eslint-plugin-import@^2.2.0 but none was installed.
npm WARN eslint-plugin-jsx-a11y@3.0.2 requires a peer of eslint@^2.10.2 || 3.x but none was installed.
npm WARN eslint-plugin-react@6.9.0 requires a peer of eslint@^2.0.0 || ^3.0.0 but none was installed.
Don’t be afraid. Make sure they are really a problem first.
$ npm -g list
If you can read those warnings again, they are really problems. Semver explains syntax in the version, for example ^, x etc. I really suggest you to go through that article before solving the warnings.
Basically, they are talking about version mismatched. Take a serious look and install the required packages and problems will be solved.

3. End

You can double check the modules by calling npm outdated again and see whether there are missing modules.
In my opinion, the troublesome parts are resolving versions between packages. This is a smooth and easy process after resolving them.

4. More about npm’s dependencies

Actually, I have posted a question about missing dependencies in StackOverflow here. There are links for you to further study npm’s dependencies. (Hopefully, :D)

5. Search with semver

The best way to know whether the semver includes certain version is testing.
For example, I would like to know how many versions can be search for eslint with ^3.17.x
mondwan@mondwan-All-Series:~/Documents/git/abc$ npm -g view eslint@^3.17.x | grep ^eslint
eslint@3.17.0  
eslint@3.17.1

Change logs

  • 2017-03-14: Add a command for searching package’s version
  • 2017-03-11: Add a reference from StackOverflow

沒有留言:

張貼留言