For example.I installed a module in the node_modules. if i change that module, updating node_module will update all modules.What is the usual practice
In summary, you install the package and add a postinstall
script to your package.json file that calls patch-package:
"scripts": {
"postinstall": "patch-package"
}
Modify the package directly in /node_modules
and then call patch-package
on the package you just modified:
npx patch-package <package_name>
This will create a local directory called /patches
with a diff (or patch) file inside for that package. Commit that folder in with your repo.
Now whenever you run npm install
, the postinstall
script will also run and apply the /patches
that you committed to that package
First, We call it Package
instead of Module
, Why? because search results on Google are much more accurate when you use that word
Second, to update a specific package use npm update {package name}
Third, you don't change the code of other packages, you can only either install
, update
, or delete
the package. there's this option to override it but it's only possible if the package owner allows overrides.
I decided to update my answer due to the discussion below.
since I have put in mind that you are a beginner and are not entirely sure how to update code or override package code, or maybe even if it's a good idea to change package code, I have given you an unclear answer.
and since the other answer are telling you to use patch-package
then I'm here to tell you that you can fork that package. and install that package from your fork. here's how you do it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.