How to update specific sub-package version by using npm

白昼怎懂夜的黑 提交于 2020-01-03 01:46:05

问题


I had checked global package minimatch for gulp

$ npm list -g minimatch

+-- gulp@3.9.1
| `-- vinyl-fs@0.3.14
|   +-- glob-stream@3.1.18
|   | +-- glob@4.5.3
|   | | `-- minimatch@2.0.10  deduped
|   | `-- minimatch@2.0.10
|   `-- glob-watcher@0.0.6
|     `-- gaze@0.5.2
|       `-- globule@0.1.0
|         +-- glob@3.1.21
|         | `-- minimatch@0.2.14  deduped
|         `-- minimatch@0.2.14

Now, i wanted to update all minimatch versions from specific gulp package (all minimatch@0.2.14 and minimatch@3.04) to latest version.

Is their any command in npm that updates my existing package dependencies?


回答1:


Here is my solution, you can create symbolic link for minimatch package by using

npm ln
npm link (in package dir)
npm link [<@scope>/]<pkg>[@<version>]

here is link for more explanation https://docs.npmjs.com/cli/link

I think you must not update them manually, because if something comes up wrong, you will have to delete everything and install again. it there are some migration issue disturbing you then try.

npm audit [--json|--parseable]
npm audit fix [--force|--package-lock-only|--dry-run|--production|--only=dev]

here is documentation https://docs.npmjs.com/cli/link




回答2:


You can't and you shouldn't update subpackages (packages used as dependencies for other packages).

Node modules are designed to contain all dependencies with specified versions inside the node_modules, in order to avoid problems with new updates. Let's say your minimatch@3.0.4 introduces some new features, now glob@4.5.3 might stop working, and in turn gulp@3.9.1 might stop working as well.

You should either:

Update to a new gulp version without worrying about minimatch

npm update gulp

or use the latest version of minimatch directly, using

npm install minimatch

If however you really want to perform the operation for whatever reason, you could try the following ugly hack:

  • install minimatch somewhere in a random location with npm install minimatch@3.0.4
  • go to the node_modules folder in this location and copy the minimatch folder
  • find your gulp installation folder (this may depend on your system, C:\Users\user\AppData\Roaming\npm\node_modules\gulp on Windows or /usr/lib/node_modules/gulp/ on Linux)
  • search for minimatch inside the gulp installation folder (find . | grep minimatch)
  • replace all the found minimatch folders with the one you just installed in the random location

At this point gulp should use the updated minimatch, although npm list will still display the old version number.
Again, this is highly not recommended and only provided for the sake of answering the question.



来源:https://stackoverflow.com/questions/52966789/how-to-update-specific-sub-package-version-by-using-npm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!