-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Allow hooks to be written as TypeScript files instead of shell commands, leveraging Deno's native TypeScript support for type-safe, composable hooks.
Motivation
Current hooks are shell commands which limits:
- Type safety
- Code reuse and composition
- Access to Deno APIs
- Debugging capabilities
- IDE support
Proposed Solution
Support TypeScript files as hook implementations:
// .deno-hooks/pre-commit.ts
import type { HookContext, HookResult } from "jsr:@theswanfactory/deno-hooks";
export default async function(ctx: HookContext): Promise<HookResult> {
const files = ctx.files.filter(f => f.endsWith('.ts'));
for (const file of files) {
const content = await Deno.readTextFile(file);
if (content.includes('console.log')) {
return {
success: false,
message: `Found console.log in ${file}`,
};
}
}
return { success: true };
}Configuration:
hooks:
pre-commit:
- id: no-console-log
run: .deno-hooks/pre-commit.ts
pass_filenames: trueBenefits
- ✅ Type-safe hooks with full IDE support
- ✅ Access to all Deno APIs (fs, network, subprocess, etc.)
- ✅ Composable - import utilities and JSR packages
- ✅ Debuggable with Deno's debugger
- ✅ Impossible in Husky/pre-commit - unique to Deno
Implementation
- Detect
.tsfiles inrunfield - Use dynamic import to load TypeScript hooks
- Pass standardized
HookContextobject - Validate return type matches
HookResult
Files to modify:
src/executor.ts- Add TypeScript hook executionsrc/hook.ts- ExportHookContextandHookResulttypes
Priority
HIGH - Game-changing feature that differentiates from Node.js alternatives
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request