Ignore a specific package while installing depende

2020-02-11 06:55发布

I have a node package react-native-push-notification for which i have made some changes in the packages to fulfil my requirement. But every time i do a npm install the new (original package without my changes) package overlaps with my current package.

Is there any way i can restrict npm install to ignore my modified package? And also i want to push this package to git.

Any lead will be highly appreciated.

3条回答
来,给爷笑一个
2楼-- · 2020-02-11 07:32

If I understand you correctly you have made some changes to the already existing node package react-native-push-notification and you would rather use your own version of it than the original.

You have a couple of options:

  • In package.json change react-native-push-notification to point to your git repo (e.g. your fork on github). This is not ideal since it makes semver problematic. But it works.
  • Rename your fork of the package and use that directly from npm. E.g. rename to react-native-push-notification2 or even better, use a scoped package name e.g. @yournick/react-native-push-notification and publish that to npm. Change your package.json to use this package instead.
  • Convince the authors of the original package to incorporate your changes. This is the ideal solution, but might be difficult to get your patch merged etc.
查看更多
不美不萌又怎样
3楼-- · 2020-02-11 07:39

The best way to handle this would be to fork the repo https://help.github.com/articles/fork-a-repo/.

This way, you have control of the contents of the package.

Then update your package.json with your repo address.

I also would recommend not pushing your packages to Git. Packages are already under version control (in their own repo) and pushing to Git just bloats your repo for no reason.

查看更多
爷的心禁止访问
4楼-- · 2020-02-11 07:52

patch-package is exactly what you're looking for: https://github.com/ds300/patch-package

It will preserve your changes even after running npm install.

查看更多
登录 后发表回答