install-deps-postmerge

Install package.json dependencies whenever needed after a git merge

Usage no npm install needed!

<script type="module">
  import installDepsPostmerge from 'https://cdn.skypack.dev/install-deps-postmerge';
</script>

README

install-deps-postmerge

Script for installing dependencies using npm or yarn as a postmerge git-hook.

Install

yarn add -D install-deps-postmerge

What does this module do?

This script will git a list of files by running:

git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD

It will take the results and check if package.json, package-lock.json, or yarn.lock is listed.

If any of those files is found, the script will intelligently pick the correct client (based on which lockfile changed and falling back to yarn-or-npm) to install the dependencies.

How do I use it in my project?

It can be used as part of a postmerge npm script alongside 'husky' for githook integrations:

{
  ...
  "husky": {
    "hooks": {
      "post-merge": "install-deps-postmerge"
    }
  },
  "devDependencies": {
    "husky": "latest",
    "install-deps-postmerge": "latest"
  }
}

Alternatively, if you do not want to use 'husky', the script can be added as a command in the .git/hooks/post-merge file:

# abbreviated command "idpm"
npm run -s idpm
# or
yarn -s idpm

Requirements

  • node: >=10