@amiram/smart-update v1.0.3
smart-update
Update npm packages after git merge/pull only if dependencies were changed.
Background
Many projects use husky to update node_modules after getting changes from git. This way you can be sure that your node_modules are updated if a team member changed dependecies.
The simple way to do it is:
1. npm i husky --save-dev
2. Add scripts in package.json
- Do
git pull
orgit merge [branch]
This may slow down your git commands a little bit. However, imagine you have many repos and you want to update all of them, this might take a huge amount of time.
A possible solution is to check if the package.json file has changed. You can do it with a simple shell script. The problem with this solution is that package.json might changed but not the dependencies in it. The most common change is the version which can be change in any ci build.
The best solution - check dependencies
This package is comparing the dependencies and devDependencies parts inside current and previous package.json (before the git command) and run npm update
only if something has changed.
Command git diff-tree
is used to get both versions of package.json.
Usage
The steps are almost identical to the ones above:
npm i husky @amiram/smart-update --save-dev
Add scripts in package.json
Do
git pull
orgit merge [branch]
Now there are 3 possible scenarios:
- package.json wasn't changed. Output:
- package.json was changed but dependencies or devDependencies weren't. Output:
dependencies or devDependencies were changed. Output:
important: the package is also checking the versions of the dependencies, so npm update may run even if the total amount of dependencies in the output looks equal but the versions are different.