Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#! /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