Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

husky

Package Overview
Dependencies
Maintainers
1
Versions
215
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

husky - npm Package Compare versions

Comparing version 6.0.0 to 8.0.3

husky.sh

51

lib/bin.js
#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const _1 = require("./");
function readPkg() {
return JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8'));
}
const pkg = readPkg();
const [, , cmd, ...args] = process.argv;
function version() {
console.log(pkg.version);
}
function help() {
console.log(`Usage
const p = require("path");
const h = require("./");
function help(code) {
console.log(`Usage:
husky install [dir] (default: .husky)
husky uninstall
husky set|add <file> [cmd]`);
process.exit(code);
}
function misuse() {
help();
process.exit(2);
}
const [, , cmd, ...args] = process.argv;
const ln = args.length;
const [x, y] = args;
const hook = (fn) => () => !ln || ln > 2 ? help(2) : fn(x, y);
const cmds = {
install(dir) {
args.length > 1 ? misuse() : _1.install(dir);
},
uninstall: _1.uninstall,
set(...args) {
args.length === 0 || args.length > 2 ? misuse() : _1.set(args[0], args[1]);
},
add(...args) {
args.length === 0 || args.length > 2 ? misuse() : _1.add(args[0], args[1]);
},
'--version': version,
'-v': version,
install: () => (ln > 1 ? help(2) : h.install(x)),
uninstall: h.uninstall,
set: hook(h.set),
add: hook(h.add),
['-v']: () => console.log(require(p.join(__dirname, '../package.json')).version),
};
cmds[cmd] ? cmds[cmd](...args) : help();
try {
cmds[cmd] ? cmds[cmd]() : help(0);
}
catch (e) {
console.error(e instanceof Error ? `husky - ${e.message}` : e);
process.exit(1);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.uninstall = exports.add = exports.set = exports.install = void 0;
const cp = require("child_process");
const fs = require("fs");
const cp = require("child_process");
const path = require("path");
function l(msg) {
console.log(`husky - ${msg}`);
}
const p = require("path");
const l = (msg) => console.log(`husky - ${msg}`);
const git = (args) => cp.spawnSync('git', args, { stdio: 'inherit' });
function install(dir = '.husky') {
if (cp.spawnSync('git', ['rev-parse']).status !== 0) {
l('not a Git repository, skipping hooks installation');
if (process.env.HUSKY === '0') {
l('HUSKY env variable is set to 0, skipping install');
return;
}
if (git(['rev-parse']).status !== 0) {
l(`git command not found, skipping install`);
return;
}
const url = 'https://typicode.github.io/husky/#/?id=custom-directory';
if (!path.resolve(process.cwd(), dir).startsWith(process.cwd())) {
if (!p.resolve(process.cwd(), dir).startsWith(process.cwd())) {
throw new Error(`.. not allowed (see ${url})`);

@@ -23,6 +26,6 @@ }

try {
fs.mkdirSync(path.join(dir, '_'), { recursive: true });
fs.writeFileSync(path.join(dir, '.gitignore'), '_\n');
fs.copyFileSync(path.join(__dirname, 'husky.sh'), path.join(dir, '_/husky.sh'));
const { error } = cp.spawnSync('git', ['config', 'core.hooksPath', dir]);
fs.mkdirSync(p.join(dir, '_'), { recursive: true });
fs.writeFileSync(p.join(dir, '_/.gitignore'), '*');
fs.copyFileSync(p.join(__dirname, '../husky.sh'), p.join(dir, '_/husky.sh'));
const { error } = git(['config', 'core.hooksPath', dir]);
if (error) {

@@ -40,8 +43,8 @@ throw error;

function set(file, cmd) {
const dir = path.dirname(file);
const dir = p.dirname(file);
if (!fs.existsSync(dir)) {
throw new Error(`can't create hook, ${dir} directory doesn't exist (try running husky install)`);
}
fs.writeFileSync(file, `#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
fs.writeFileSync(file, `#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

@@ -64,6 +67,4 @@ ${cmd}

function uninstall() {
cp.spawnSync('git', ['config', '--unset', 'core.hooksPath'], {
stdio: 'inherit',
});
git(['config', '--unset', 'core.hooksPath']);
}
exports.uninstall = uninstall;
{
"name": "husky",
"version": "6.0.0",
"version": "8.0.3",
"description": "Modern native Git hooks made easy",
"bin": "lib/bin.js",
"main": "lib/index.js",
"files": [
"lib"
],
"keywords": [

@@ -15,8 +10,32 @@ "git",

],
"author": "Typicode <typicode@gmail.com>",
"license": "MIT",
"homepage": "https://typicode.github.io/husky",
"repository": "github:typicode/husky",
"repository": "typicode/husky",
"funding": "https://github.com/sponsors/typicode",
"gitHead": "cb4e3b913e2d8963af3179650ed550d3a0e210f5"
"license": "MIT",
"author": "Typicode <typicode@gmail.com>",
"bin": "lib/bin.js",
"main": "lib/index.js",
"files": [
"lib",
"husky.sh"
],
"scripts": {
"build": "tsc",
"test": "sh test/all.sh",
"lint": "eslint src --ext .ts",
"serve": "docsify serve docs",
"prepare": "npm run build && node lib/bin install"
},
"devDependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@tsconfig/node14": "^1.0.3",
"@types/node": "^18.11.18",
"@typicode/eslint-config": "^1.1.0",
"docsify-cli": "^4.4.4",
"typescript": "^4.9.4"
},
"engines": {
"node": ">=14"
}
}
# husky
[![Open Collective](https://opencollective.com/husky/all/badge.svg?label=financial+contributors)](https://opencollective.com/husky)
> Modern native Git hooks made easy

@@ -9,2 +7,8 @@

# Install
```
npm install husky --save-dev
```
# Usage

@@ -15,3 +19,4 @@

```sh
npm set-script prepare "husky install" && npm run prepare
npm pkg set scripts.prepare="husky install"
npm run prepare
```

@@ -23,2 +28,3 @@

npx husky add .husky/pre-commit "npm test"
git add .husky/pre-commit
```

@@ -29,3 +35,4 @@

```sh
$ git commit -m "Keep calm and commit"
git commit -m "Keep calm and commit"
# `npm test` will run
```

@@ -36,7 +43,1 @@

https://typicode.github.io/husky
__Important__ upgrading from v4 to v6 requires additional steps, please see the docs.
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc