Package Exports
- git-pull-run
Readme
Run Commands on Changes after Git Pull
Automatically run commands like npm install when fetching changes from git, but only if certain files have changed.
Why?
For more information, please refer to my: Automatically Install NPM Dependencies on Git Pull
Install
npm install --save-dev git-pull-runCommand Line Options
> npx git-pull-run --help
Usage: git-pull-run [options]
Options:
-V --version output the version number
-p, --pattern <glob> pattern to match files (required)
-c, --command <command> execute shell command for each matched file (default: "")
-s, --script <script> execute npm script for each matched file (default: "")
-d, --debug print additional debug information (default: false)
-h, --help display help for command--pattern <glob>: Required glob pattern to detect if certain files have changed on the remote repository when pulling changes. Each changed file (including path from root) is matched against this pattern.- uses micromatch internally and supports all matching features like wildcards, negation, extglobs and more.
--command <command>: Command to execute on the shell for each changed file that matches thepattern. The command is going to be executed inside the directory of the changed file.- uses execa internally with the
cwdoption set as directory of the matched file.
- uses execa internally with the
--script <script>: NPM script to execute on the shell for each changed file that matches thepattern. Same as option--command "npm run <script>". The script is going to be executed inside the directory of the changed file.--debug: Run in debug mode and print additional information about the changed files and commands and scripts that are being executed.
Usage
Run npm install when package-lock.json changes
post-merge git hook with Husky:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# matches only the package-lock.json inside project directory
npx git-pull-run -p 'package-lock.json' -c 'npm install'Run npm install when in a multi-package monorepo
post-merge git hook with Husky:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# assumes monorepo structure with multiple packages in directory /packages
# matches any of these package-lock.json
npx git-pull-run -p 'packages/*/package-lock.json' -c 'npm install'FAQ
Match package.json or package-lock.json?
The package.json contains the semver versions of each package whereas the package-lock.json contains the exactly installed version of each package. See But what the hell is package-lock.json? for more information.
Run npm install or npm ci?
Discussion on: But what the hell is package-lock.json?:
npm installdoes not ignorepackage.jsonversions, nor does it ignore thepackage-lock.json. What it does is verify that thepackage.jsonandpackage-lock.jsoncorrespond to each other. That is, if the semver versions described inpackage.jsonfit with the locked versions inpackage-lock.json,npm installwill use the latter completely, just likenpm ciwould.Now, if you change
package.jsonsuch that the versions inpackage-lock.jsonare no longer valid, yournpm installwill be treated as if you'd donenpm install some-pkg@x.y.z, where x.y.z is the new version in thepackage.jsonfor some-package.