Skip to content

Commit

Permalink
adds an optional settings to use Yarn to run Husky (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis authored and typicode committed Jun 26, 2019
1 parent f7029a1 commit 449a615
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 48 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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": {
Expand Down
66 changes: 38 additions & 28 deletions src/installer/__tests__/__snapshots__/getScript.ts.snap
Expand Up @@ -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
"
`;
Expand Down Expand Up @@ -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
"
`;
45 changes: 25 additions & 20 deletions src/installer/getScript.ts
Expand Up @@ -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
`

Expand Down

0 comments on commit 449a615

Please sign in to comment.