Created
October 8, 2019 17:51
-
-
Save ThisIsMissEm/eeb9b3e0fb2e8b211a0bfb1641d9b876 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env node | |
/** | |
* This file does not use typescript as it's run before you've necessarily run `yarn install` | |
* As such, we can only use built-in modules here. | |
*/ | |
function main() { | |
let [ | |
// Arguments from the githook: https://git-scm.com/docs/githooks#_post_checkout | |
prevHead, | |
head, | |
isFileCheckout | |
] = process.env.HUSKY_GIT_PARAMS.split(' ', 3); | |
// we're doing `git checkout foo.js` so don't run: | |
if (isFileCheckout === '0') { | |
return; | |
} | |
const diffArgs = [prevHead, head, '--', 'package.json']; | |
const args = ['diff', '--exit-code', '--quiet', ...diffArgs]; | |
const result = require('child_process').spawnSync('git', args, { | |
encoding: 'utf8' | |
}); | |
if (result.status === 1) { | |
console.log(` | |
⚠️ package.json was changed! You may wish to run: | |
$ yarn install | |
You can see the changes with: | |
$ git diff ${diffArgs.join(' ')} | |
`); | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment