Skip to content

Commit 45c8578

Browse files
committed
fix(hooks): update prepare script to link husky directory correctly
1 parent 1ebb86d commit 45c8578

File tree

9 files changed

+4088
-35
lines changed

9 files changed

+4088
-35
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ __pycache__/
88
tests/*/
99
!tests/.gitignore
1010
node_modules
11+
/.husky
12+
/.eslintcache

booster/.husky/commit-msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ cd "$ROOT_DIR"
1212
HOOK="$CWD/commit-msg.ts"
1313

1414
# Use the generic runner script to execute the TypeScript hook
15-
exec "$CWD/shared/runner.sh" pnpm zx $HOOK "$@"
15+
exec "$CWD/shared/runner.sh" zx $HOOK "$@"

booster/.husky/commit-msg.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* - SKIP_COMMITMSG=1: Skip the entire commit-msg hook
1313
* - GIT_HOOKS_VERBOSE=1: Enable verbose output for debugging
1414
*/
15-
import { fs } from 'zx'
15+
import { fs, path } from 'zx'
16+
import { fileURLToPath } from 'url'
1617
import validateBranchNameConfig from '../validate-branch-name.config.cjs'
1718
import { getCurrentBranch, GitHook, log, runHook, runTool, runWithRunner } from './shared/index.ts'
1819

@@ -117,11 +118,7 @@ function extractTicketId(branchName: string, config: BranchConfig): string | nul
117118
* Validate branch name using validate-branch-name tool
118119
*/
119120
async function validateBranchName(branchName: string): Promise<boolean> {
120-
const binPath = './node_modules/.bin/validate-branch-name'
121-
if (!(await fs.pathExists(binPath))) {
122-
log.error('validate-branch-name not found in node_modules/.bin/')
123-
return false
124-
}
121+
const binPath = 'validate-branch-name'
125122

126123
return await runTool('Branch Name', 'Validating branch name...', async () => {
127124
try {
@@ -147,14 +144,14 @@ async function validateBranchName(branchName: string): Promise<boolean> {
147144
* Lint commit message using commitlint
148145
*/
149146
async function lintCommitMessage(commitFile: string): Promise<boolean> {
150-
const binPath = './node_modules/.bin/commitlint'
151-
if (!(await fs.pathExists(binPath))) {
152-
log.error('commitlint not found in node_modules/.bin/')
153-
return false
154-
}
147+
const binPath = 'commitlint'
148+
149+
const __filename = fileURLToPath(import.meta.url)
150+
const scriptDir = path.dirname(__filename)
151+
const configPath = path.resolve(scriptDir, '../commitlint.config.ts')
155152

156153
return await runTool('Commitlint', 'Validating commit message format...', async () => {
157-
await runWithRunner([binPath, '--edit', commitFile])
154+
await runWithRunner([binPath, '--config', configPath, '--edit', commitFile])
158155
})
159156
}
160157

@@ -214,7 +211,6 @@ async function appendTicketFooter(commitFile: string): Promise<boolean> {
214211
return false
215212
}
216213
}
217-
218214
await runHook(GitHook.CommitMsg, async () => {
219215
const [commitFile] = process.argv.slice(3) // Skip node, script, and hook args
220216

booster/.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ cd "$ROOT_DIR"
1212
HOOK="$CWD/pre-commit.ts"
1313

1414
# Use the generic runner script to execute the TypeScript hook
15-
exec "$CWD/shared/runner.sh" pnpm zx $HOOK "$@"
15+
exec "$CWD/shared/runner.sh" zx $HOOK "$@"

booster/.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ cd "$ROOT_DIR"
1212
HOOK="$CWD/pre-push.ts"
1313

1414
# Use the generic runner script to execute the TypeScript hook
15-
exec "$CWD/shared/runner.sh" pnpm zx $HOOK "$@"
15+
exec "$CWD/shared/runner.sh" zx $HOOK "$@"

booster/.husky/shared/runner.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@
66
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
77
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
88

9+
# Resolve the real path of the script to find the booster root (where dependencies are)
10+
REAL_SCRIPT_PATH=$(realpath "${BASH_SOURCE[0]}")
11+
REAL_SCRIPT_DIR="$(dirname "$REAL_SCRIPT_PATH")"
12+
BOOSTER_ROOT="$(cd "$REAL_SCRIPT_DIR/../.." && pwd)"
13+
14+
# If running via symlink (PROJECT_ROOT != BOOSTER_ROOT), add booster dependencies to PATH
15+
if [ "$PROJECT_ROOT" != "$BOOSTER_ROOT" ]; then
16+
export PATH="$BOOSTER_ROOT/node_modules/.bin:$BOOSTER_ROOT/vendor/bin:$PATH"
17+
export NODE_PATH="$BOOSTER_ROOT/node_modules:$NODE_PATH"
18+
fi
19+
920
# Change to project root to ensure context is correct
1021
cd "$PROJECT_ROOT" || exit 1
1122

1223
# Load mise if available to ensure pnpm is found
1324
if command -v mise &> /dev/null; then
14-
eval "$(mise activate bash)"
25+
eval "$(mise activate bash)"
1526
fi
1627

1728
# Main execution

booster/.husky/shared/workflow.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { $, fs, which } from 'zx'
1+
import { $, which } from 'zx'
22
import { formatDuration, initEnvironment, isSkipped, log, runWithRunner } from './core.ts'
33
import { shouldSkipDuringMerge, stageFiles } from './git.ts'
44
import { GitHook, type ToolConfig } from './types.ts'
@@ -40,12 +40,6 @@ export async function runTool(
4040
}
4141
}
4242

43-
function getBinPath(tool: ToolConfig): string {
44-
if (tool.type === 'node') return `./node_modules/.bin/${tool.command}`
45-
if (tool.type === 'php') return `./vendor/bin/${tool.command}`
46-
return tool.command
47-
}
48-
4943
/**
5044
* Run all configured quality tools on the provided files
5145
*
@@ -77,18 +71,14 @@ export async function runQualityTools(files: string[], tools: ToolConfig[]): Pro
7771
if (filesToRun.length === 0) continue
7872

7973
// Check binary existence
80-
const binPath = getBinPath(tool)
74+
const binPath = tool.command
8175
let exists = false
8276

83-
if (tool.type === 'system') {
84-
try {
85-
await which(binPath)
86-
exists = true
87-
} catch {
88-
exists = false
89-
}
90-
} else {
91-
exists = await fs.pathExists(binPath)
77+
try {
78+
await which(binPath)
79+
exists = true
80+
} catch {
81+
exists = false
9282
}
9383

9484
if (!exists) {

0 commit comments

Comments
 (0)