diff --git a/package.json b/package.json index 9c4347a5b..8757a3a52 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.5.0", "description": "Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...)", "bin": { + "husky-run": "./run.js", "husky-upgrade": "./lib/upgrader/bin.js" }, "engines": { diff --git a/src/installer/__tests__/__snapshots__/getScript.ts.snap b/src/installer/__tests__/__snapshots__/getScript.ts.snap index 56628aa9c..03dbe76dd 100644 --- a/src/installer/__tests__/__snapshots__/getScript.ts.snap +++ b/src/installer/__tests__/__snapshots__/getScript.ts.snap @@ -30,23 +30,28 @@ if [ \\"\${HUSKY_SKIP_HOOKS}\\" = \\"true\\" ] || [ \\"\${HUSKY_SKIP_HOOKS}\\" = exit 0 fi - -if ! command -v node >/dev/null 2>&1; then - echo \\"Info: can't find node in PATH, trying to find a node binary on your system\\" -fi - -if [ -f \\"$scriptPath\\" ]; then - # if [ -t 1 ]; then - # exec < /dev/tty - # fi - if [ -f ~/.huskyrc ]; then - debug \\"source ~/.huskyrc\\" - . ~/.huskyrc - fi - node_modules/run-node/run-node \\"$scriptPath\\" $hookName \\"$gitParams\\" +if [ \\"\${HUSKY_USE_YARN}\\" = \\"true\\" ] || [ \\"\${HUSKY_USE_YARN}\\" = \\"1\\" ]; then + debug \\"calling husky through Yarn\\" + yarn husky-run $hookName \\"$gitParams\\" else - echo \\"Can't find Husky, skipping $hookName hook\\" - echo \\"You can reinstall it using 'npm install husky --save-dev' or delete this hook\\" + + if ! command -v node >/dev/null 2>&1; then + echo \\"Info: can't find node in PATH, trying to find a node binary on your system\\" + fi + + if [ -f \\"$scriptPath\\" ]; then + # if [ -t 1 ]; then + # exec < /dev/tty + # fi + if [ -f ~/.huskyrc ]; then + debug \\"source ~/.huskyrc\\" + . ~/.huskyrc + fi + node_modules/run-node/run-node \\"$scriptPath\\" $hookName \\"$gitParams\\" + else + echo \\"Can't find Husky, skipping $hookName hook\\" + echo \\"You can reinstall it using 'npm install husky --save-dev' or delete this hook\\" + fi fi " `; @@ -81,19 +86,24 @@ if [ \\"\${HUSKY_SKIP_HOOKS}\\" = \\"true\\" ] || [ \\"\${HUSKY_SKIP_HOOKS}\\" = exit 0 fi - -if [ -f \\"$scriptPath\\" ]; then - # if [ -t 1 ]; then - # exec < /dev/tty - # fi - if [ -f ~/.huskyrc ]; then - debug \\"source ~/.huskyrc\\" - . ~/.huskyrc - fi - node \\"$scriptPath\\" $hookName \\"$gitParams\\" +if [ \\"\${HUSKY_USE_YARN}\\" = \\"true\\" ] || [ \\"\${HUSKY_USE_YARN}\\" = \\"1\\" ]; then + debug \\"calling husky through Yarn\\" + yarn husky-run $hookName \\"$gitParams\\" else - echo \\"Can't find Husky, skipping $hookName hook\\" - echo \\"You can reinstall it using 'npm install husky --save-dev' or delete this hook\\" + + if [ -f \\"$scriptPath\\" ]; then + # if [ -t 1 ]; then + # exec < /dev/tty + # fi + if [ -f ~/.huskyrc ]; then + debug \\"source ~/.huskyrc\\" + . ~/.huskyrc + fi + node \\"$scriptPath\\" $hookName \\"$gitParams\\" + else + echo \\"Can't find Husky, skipping $hookName hook\\" + echo \\"You can reinstall it using 'npm install husky --save-dev' or delete this hook\\" + fi fi " `; diff --git a/src/installer/getScript.ts b/src/installer/getScript.ts index 3ba200191..270bfceec 100644 --- a/src/installer/getScript.ts +++ b/src/installer/getScript.ts @@ -59,27 +59,32 @@ if [ "$\{HUSKY_SKIP_HOOKS}" = "true" ] || [ "$\{HUSKY_SKIP_HOOKS}" = "1" ]; then exit 0 fi -${ - platform === 'win32' - ? '' - : ` -if ! command -v node >/dev/null 2>&1; then - echo "Info: can't find node in PATH, trying to find a node binary on your system" -fi -` -} -if [ -f "$scriptPath" ]; then - # if [ -t 1 ]; then - # exec < /dev/tty - # fi - if [ -f ${huskyrc} ]; then - debug "source ${huskyrc}" - . ${huskyrc} - fi - ${node} "$scriptPath" $hookName "$gitParams" +if [ "$\{HUSKY_USE_YARN}" = "true" ] || [ "$\{HUSKY_USE_YARN}" = "1" ]; then + debug "calling husky through Yarn" + yarn husky-run $hookName "$gitParams" else - echo "Can't find Husky, skipping $hookName hook" - echo "You can reinstall it using 'npm install husky --save-dev' or delete this hook" + ${ + platform === 'win32' + ? '' + : ` + if ! command -v node >/dev/null 2>&1; then + echo "Info: can't find node in PATH, trying to find a node binary on your system" + fi + ` + } + if [ -f "$scriptPath" ]; then + # if [ -t 1 ]; then + # exec < /dev/tty + # fi + if [ -f ${huskyrc} ]; then + debug "source ${huskyrc}" + . ${huskyrc} + fi + ${node} "$scriptPath" $hookName "$gitParams" + else + echo "Can't find Husky, skipping $hookName hook" + echo "You can reinstall it using 'npm install husky --save-dev' or delete this hook" + fi fi `