Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-tools): bump husky #423

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .config/husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commit message lint
yarn commit message lint
5 changes: 1 addition & 4 deletions .config/husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commit staged
yarn commit staged
5 changes: 1 addition & 4 deletions .config/husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commit message $@
yarn commit message $@
8 changes: 4 additions & 4 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
1,022 changes: 487 additions & 535 deletions .yarn/releases/yarn.cjs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ __metadata:
"@yarnpkg/fslib": "npm:3.1.0"
clipanion: "npm:4.0.0-rc.3"
deepmerge: "npm:4.3.1"
husky: "npm:8.0.3"
husky: "npm:9.1.6"
semver: "npm:7.6.3"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -8824,12 +8824,12 @@ __metadata:
languageName: node
linkType: hard

"husky@npm:8.0.3":
version: 8.0.3
resolution: "husky@npm:8.0.3"
"husky@npm:9.1.6":
version: 9.1.6
resolution: "husky@npm:9.1.6"
bin:
husky: lib/bin.js
checksum: 10/b754cf70fdc97c3b60fec5b80056b9c11436464953b1691bf2b5dcf0081fb6685d2c5f47abb8b2b1c49f504aabea5321fdd6496f8b755d9f6e7525a493406abb
husky: bin.js
checksum: 10/421ccd8850378231aaefd70dbe9e4f1549b84ffe3a6897f93a202242bbc04e48bd498169aef43849411105d9fcf7c192b757d42661e28d06b934a609a4eb8771
languageName: node
linkType: hard

Expand Down
1,022 changes: 487 additions & 535 deletions yarn/cli/dist/yarn.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion yarn/plugin-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@atls/config-typescript": "workspace:*",
"clipanion": "4.0.0-rc.3",
"deepmerge": "4.3.1",
"husky": "8.0.3",
"husky": "9.1.6",
"semver": "7.6.3"
},
"devDependencies": {
Expand Down
93 changes: 16 additions & 77 deletions yarn/plugin-tools/src/hooks/after-all-installed.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,7 @@ import { platform } from 'node:os'
import { ppath } from '@yarnpkg/fslib'
import { xfs } from '@yarnpkg/fslib'

const husky = `#!/usr/bin/env sh
if [ -z "$husky_skip_init" ]; then
debug() {
if [ "$HUSKY_DEBUG" = "1" ]; then
echo "husky (debug) - $1"
fi
}

readonly hook_name="$(basename -- "$0")"
debug "starting $hook_name..."

if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi

for file in "$XDG_CONFIG_HOME/husky/init.sh" "$HOME/.config/husky/init.sh" "$HOME/.huskyrc.sh"; do
if [ -f "$file" ]; then
debug "sourcing $file"
. "$file"
break
fi
done

readonly husky_skip_init=1
export husky_skip_init

if [ "$(basename -- "$SHELL")" = "zsh" ]; then
zsh --emulate sh -e "$0" "$@"
else
sh -e "$0" "$@"
fi
exitCode="$?"

if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
fi

if [ $exitCode = 127 ]; then
echo "husky - command not found in PATH=$PATH"
fi

exit $exitCode
fi
`

const hook = (command: string): string =>
`#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

${command}
`
const hook = (command: string): string => `${command}`

const git = (args: Array<string>): SpawnSyncReturns<string> =>
spawnSync('git', args, { encoding: 'utf-8' })
Expand All @@ -74,35 +23,25 @@ const hooksExists = (): boolean => {
}

export const afterAllInstalled = async (project: Project): Promise<void> => {
if (platform() === 'darwin') {
const target = ppath.join(project.cwd, '.config/husky')

if (!hooksExists()) {
await xfs.mkdirPromise(ppath.join(target, '_'), { recursive: true })
await xfs.writeFilePromise(ppath.join(target, '_/.gitignore'), '*')
await xfs.writeFilePromise(ppath.join(target, '_/husky.sh'), husky)
const target = ppath.join(project.cwd, '.config/husky')

await xfs.writeFilePromise(
ppath.join(target, 'commit-msg'),
hook('yarn commit message lint'),
{ mode: 0o755 }
)
await xfs.writeFilePromise(ppath.join(target, 'commit-msg'), hook('yarn commit message lint'), {
mode: 0o755,
})

await xfs.writeFilePromise(ppath.join(target, 'pre-commit'), hook('yarn commit staged'), {
mode: 0o755,
})
await xfs.writeFilePromise(ppath.join(target, 'pre-commit'), hook('yarn commit staged'), {
mode: 0o755,
})

await xfs.writeFilePromise(
ppath.join(target, 'prepare-commit-msg'),
hook('yarn commit message $@'),
{ mode: 0o755 }
)
await xfs.writeFilePromise(
ppath.join(target, 'prepare-commit-msg'),
hook('yarn commit message $@'),
{ mode: 0o755 }
)

const { error } = git(['config', 'core.hooksPath', target])
const { error } = git(['config', 'core.hooksPath', target])

if (error) {
throw error
}
}
if (error) {
throw error
}
}
Loading