Git hooks management tool forked from husky with improved monorepo support
npx @tessl/cli install tessl/npm-yorkie@2.0.0Yorkie is a Git hooks management tool that provides an easy way to configure and manage Git hooks in JavaScript projects. It's a fork of husky with specific improvements for monorepo environments, prioritizing package.json files located next to .git directories and using a cleaner gitHooks configuration format.
npm install yorkieYorkie primarily works through npm lifecycle hooks and provides programmatic access to its core functions:
const installFrom = require('yorkie/src/install');
const uninstallFrom = require('yorkie/src/uninstall');Utilities can be imported individually:
const findHooksDir = require('yorkie/src/utils/find-hooks-dir');
const findParent = require('yorkie/src/utils/find-parent');
const getHookScript = require('yorkie/src/utils/get-hook-script');
const { huskyOrYorkie, ghooks, preCommit } = require('yorkie/src/utils/is');Configure Git hooks in your package.json using the gitHooks field:
{
"name": "my-project",
"scripts": {
"test": "jest",
"lint": "eslint ."
},
"gitHooks": {
"pre-commit": "npm run lint",
"pre-push": "npm test",
"commit-msg": "commitizen --cz-conventional-changelog"
},
"devDependencies": {
"yorkie": "^2.0.0"
}
}Yorkie automatically installs Git hooks when the package is installed:
npm install yorkie
# Git hooks are automatically set up during installationControl yorkie's behavior with environment variables:
# Skip installation in CI environments (overrides default CI detection)
export YORKIE_IGNORE_CI=1
# Skip installation entirely during npm install
export YORKIE_SKIP_INSTALL=1
# Legacy husky compatibility: skip installation in CI
export HUSKY_IGNORE_CI=1
# Legacy husky compatibility: skip installation entirely
export HUSKY_SKIP_INSTALL=1Environment Variable Behavior:
is-ci package and skips installation by defaultYORKIE_IGNORE_CI=1 or HUSKY_IGNORE_CI=1 to force installation in CI environmentsYORKIE_SKIP_INSTALL=1 or HUSKY_SKIP_INSTALL=1 to completely bypass hook installationAutomatically installs Git hooks for all supported hook types during npm package installation.
/**
* Install Git hooks from a yorkie dependency directory
* @param {string} depDir - Path to the yorkie dependency directory
*/
function installFrom(depDir);Supported Git Hooks:
applypatch-msg, pre-applypatch, post-applypatchpre-commit, prepare-commit-msg, commit-msg, post-commitpre-rebase, post-checkout, post-mergepre-push, pre-receive, update, post-receive, post-updatepush-to-checkout, pre-auto-gc, post-rewrite, sendemail-validateRemoves yorkie-managed Git hooks during package uninstallation.
/**
* Uninstall Git hooks from a yorkie directory
* @param {string} huskyDir - Path to the yorkie directory
*/
function uninstallFrom(huskyDir);The runner executes Git hook commands defined in package.json. This is automatically invoked by installed Git hooks and is not intended for direct programmatic use.
Runner Process (src/runner.js - executable script):
gitHooks fieldNote: The runner is an executable Node.js script, not a module that exports functions for programmatic use.
Utilities for finding Git and package directories in complex project structures.
/**
* Find the Git hooks directory for a given project directory
* @param {string} dir - Project directory to search from
* @returns {string|undefined} Path to .git/hooks directory or undefined if not found
*/
function findHooksDir(dir);
/**
* Find parent directory containing a specific file or directory
* @param {string} currentDir - Starting directory for search
* @param {string} name - Name of file/directory to find
* @returns {string|undefined} Absolute path to parent directory or undefined if not found
*/
function findParent(currentDir, name);Generates shell scripts for Git hooks with platform-specific Node.js environment setup.
/**
* Generate a complete shell script for a Git hook
* @param {string} hookName - Name of the Git hook (e.g., 'pre-commit')
* @param {string} relativePath - Relative path from Git root to package.json
* @param {string} runnerPath - Path to yorkie's runner.js
* @returns {string} Complete shell script content
*/
function getHookScript(hookName, relativePath, runnerPath);Generated Script Features:
GIT_PARAMS environment variableUtilities for detecting existing Git hook managers to handle migration scenarios.
/**
* Check if a hook file was created by husky or yorkie
* @param {string} filename - Path to hook file
* @returns {boolean} true if created by husky/yorkie
*/
function huskyOrYorkie(filename);
/**
* Check if a hook file was created by ghooks
* @param {string} filename - Path to hook file
* @returns {boolean} true if created by ghooks
*/
function ghooks(filename);
/**
* Check if a hook file was created by pre-commit
* @param {string} filename - Path to hook file
* @returns {boolean} true if created by pre-commit
*/
function preCommit(filename);Yorkie follows a simple architecture designed for reliability and monorepo compatibility:
bin/install.jssrc/install.js analyzes project structure.git/hooks/pre-commit)src/runner.js reads package.json gitHooks configurationYorkie handles several error scenarios gracefully:
Yorkie addresses specific limitations in husky for monorepo environments:
gitHooks object instead of npm script names