Socket
Socket
Sign inDemoInstall

husky

Package Overview
Dependencies
Maintainers
1
Versions
214
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 1.0.0-rc.2 to 1.0.0-rc.3

4

CHANGELOG.md
# CHANGELOG
## 1.0.0-rc.3
* Re-introduce subdirectory support
## 1.0.0-rc.2

@@ -4,0 +8,0 @@

52

docs.md

@@ -21,3 +21,4 @@ # Documentation

If you have a multi-package repository:
If you have a multi-package repository, it's recommended to use tools like [lerna](https://github.com/lerna/lerna) and have `husky` installed ONLY in the root `package.json` to act as the source of truth.
Generally speaking, you should avoid defining `husky` in multiple `package.json`, as each package would overwrite previous `husky` installations.

@@ -28,3 +29,3 @@ ```sh

├── .git
├── package.json 🐶 # add husky here
├── package.json 🐶 # Add husky here
└── packages

@@ -39,5 +40,4 @@ ├── A

It's recommended to use tools like [lerna](https://github.com/lerna/lerna) and have `husky` installed in the root `package.json`:
```json
```js
// root/package.json
{

@@ -54,42 +54,2 @@ "private": true,

}
```
## Sub-directory package
If your project is in a sub-directory, create a root `package.json`, run `npm install husky --save-dev` and edit `package.json` to configure `husky`:
```sh
.
└── root
├── .git
├── package.json 🐶 # add husky here
└── subdirectory
└── package.json
```
```js
// Create root/package.json
{
"private": true,
"devDependencies": {
"husky": "..."
},
"husky": {
"hooks": {
"pre-commit": "cd subproject && npm test"
}
}
}
```
One of the downside of this approach is that you'll have to run `npm install` in `project` and `subproject`. If you only have one package and you're __not publishing it__, you can do the following to ensure that `husky` is also installed when you run `npm install` in your subdirectory:
```js
// root/subdirectory/package.json
{
"private": true,
"scripts": {
"postinstall": "cd .. && npm install"
}
}
```
```

@@ -0,0 +0,0 @@ "use strict";

@@ -21,3 +21,3 @@ "use strict";

if (action === 'install') {
_1.install(gitDir, huskyDir, isCI);
_1.install(gitDir, huskyDir, undefined, isCI);
}

@@ -24,0 +24,0 @@ else {

@@ -10,16 +10,22 @@ "use strict";

exports.huskyIdentifier = '# husky';
function default_1(userDir,
// Additional params used for testing
requireRunNodePath, platform) {
if (requireRunNodePath === void 0) {
// Additional params used for testing
requireRunNodePath = require.resolve('.bin/run-node'); }
if (platform === void 0) { platform = os.platform(); }
var runNodePath = slash(path.relative(userDir, requireRunNodePath));
/**
* @param rootDir - e.g. /home/typicode/project/
* @param huskyDir - e.g. /home/typicode/project/node_modules/husky/
* @param requireRunNodePath - path to run-node resolved by require e.g. /home/typicode/project/node_modules/.bin/run-node
* @param platform - platform husky installer is running on (used to produce win32 specific script)
*/
function default_1(rootDir, huskyDir, requireRunNodePath,
// Additional param used for testing only
platform) {
if (platform === void 0) {
// Additional param used for testing only
platform = os.platform(); }
var runNodePath = slash(path.relative(rootDir, requireRunNodePath));
// On Windows do not rely on run-node
var node = platform === 'win32' ? 'node' : runNodePath;
var version = JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf-8')).version;
var script = slash(path.join(path.relative(rootDir, huskyDir), 'lib/runner/bin'));
var template = fs.readFileSync(path.join(__dirname, '../../templates/hook.sh'), 'utf-8');
return pupa(template, { huskyIdentifier: exports.huskyIdentifier, node: node, platform: platform, version: version });
return pupa(template, { huskyIdentifier: exports.huskyIdentifier, node: node, platform: platform, script: script, version: version });
}
exports.default = default_1;

@@ -77,2 +77,14 @@ "use strict";

}
// This prevents the case where someone would want to debug a node_module that has
// husky as devDependency and run npm install from node_modules directory
function isInNodeModules(dir) {
// INIT_CWD holds the full path you were in when you ran npm install (supported also by yarn and pnpm)
// See https://docs.npmjs.com/cli/run-script
if (process.env.INIT_CWD &&
process.env.INIT_CWD.indexOf('node_modules') !== -1) {
return true;
}
// Old technique
return (dir.match(/node_modules/g) || []).length > 1;
}
function getHooks(gitDir) {

@@ -82,6 +94,18 @@ var gitHooksDir = path.join(gitDir, 'hooks');

}
function install(gitDir, huskyDir, isCI) {
/**
* @param gitDir - e.g. /home/typicode/project/.git/
* @param huskyDir - e.g. /home/typicode/project/node_modules/husky/
* @param requireRunNodePath - path to run-node resolved by require e.g. /home/typicode/project/node_modules/.bin/run-node
* @param isCI - true if running in CI
*/
function install(gitDir, huskyDir, requireRunNodePath, isCI) {
if (requireRunNodePath === void 0) { requireRunNodePath = require.resolve('.bin/run-node'); }
console.log('husky > setting up git hooks');
var userDir = pkgDir.sync(path.join(huskyDir, '..'));
var conf = getConf_1.default(userDir);
// Git repo root directory e.g. /home/typicode/project/
var rootDir = path.join(gitDir, '..');
// First directory containing user's package.json
var userPkgDir = pkgDir.sync(path.join(huskyDir, '..'));
// Get conf from package.json or .huskyrc
var conf = getConf_1.default(userPkgDir);
// Checks
if (process.env.HUSKY_SKIP_INSTALL === 'true') {

@@ -95,13 +119,11 @@ console.log("HUSKY_SKIP_INSTALL environment variable is set to 'true',", 'skipping Git hooks installation.');

}
if (userDir === null) {
if (userPkgDir === null) {
console.log("Can't find package.json, skipping Git hooks installation.");
return;
}
if (path.join(userDir, '.git') !== gitDir) {
console.log("Expecting package.json to be at the same level as .git, skipping Git hooks installation.");
console.log("gitDir: " + gitDir);
console.log("userDir: " + userDir);
if (isInNodeModules(huskyDir)) {
console.log('Trying to install from node_modules directory, skipping Git hooks installation.');
return;
}
if (!fs.existsSync(path.join(userDir, '.git/hooks'))) {
if (!fs.existsSync(path.join(rootDir, '.git/hooks'))) {
console.log("Can't find .git/hooks directory. You can try to fix this error by creating it manually.");

@@ -113,3 +135,3 @@ console.log('Skipping Git hooks installation.');

var hooks = getHooks(gitDir);
var script = getScript_1.default(userDir);
var script = getScript_1.default(rootDir, huskyDir, requireRunNodePath);
createHooks(hooks, script);

@@ -122,9 +144,11 @@ console.log("husky > done");

var userDir = pkgDir.sync(path.join(huskyDir, '..'));
if (path.join(userDir, '.git') === gitDir) {
// Remove hooks
var hooks = getHooks(gitDir);
removeHooks(hooks);
if (isInNodeModules(huskyDir)) {
console.log('Trying to uninstall from node_modules directory, skipping Git hooks uninstallation.');
return;
}
// Remove hooks
var hooks = getHooks(gitDir);
removeHooks(hooks);
console.log('husky > done');
}
exports.uninstall = uninstall;

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -6,5 +6,8 @@ "use strict";

var getConf_1 = require("../getConf");
function default_1(_a, _b) {
var _c = _a[2], hookName = _c === void 0 ? '' : _c;
var _d = (_b === void 0 ? {} : _b).cwd, cwd = _d === void 0 ? process.cwd() : _d;
/**
* @param argv - process.argv
*/
function default_1(_a) {
var scriptPath = _a[1], _b = _a[2], hookName = _b === void 0 ? '' : _b;
var cwd = scriptPath.split('node_modules')[0];
var pkg = readPkg.sync(cwd);

@@ -11,0 +14,0 @@ var config = getConf_1.default(cwd);

@@ -0,0 +0,0 @@ "use strict";

{
"name": "husky",
"version": "1.0.0-rc.2",
"version": "1.0.0-rc.3",
"description": "Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...)",

@@ -15,3 +15,3 @@ "bin": {

"preuninstall": "node lib/installer/bin uninstall",
"devinstall": "npm run build && npm run install -- node_modules/husky && node scripts/dev",
"devinstall": "npm run build && npm run install -- node_modules/husky && node scripts/dev-fix-paths",
"devuninstall": "npm run build && npm run preuninstall -- node_modules/husky",

@@ -18,0 +18,0 @@ "build": "del-cli lib && tsc",

@@ -1,2 +0,2 @@

# husky [![](https://img.shields.io/npm/dm/husky.svg?style=flat)](https://www.npmjs.org/package/husky) [![Mac/Linux Build Status](https://img.shields.io/travis/typicode/husky/dev.svg?label=Mac%20OSX%20%26%20Linux)](https://travis-ci.org/typicode/husky) [![Windows Build status](https://img.shields.io/appveyor/ci/typicode/husky/dev.svg?label=Windows)](https://ci.appveyor.com/project/typicode/husky/dev/master)
# husky [![](https://img.shields.io/npm/dm/husky.svg?style=flat)](https://www.npmjs.org/package/husky) [![Mac/Linux Build Status](https://img.shields.io/travis/typicode/husky/dev.svg?label=Mac%20OSX%20%26%20Linux)](https://travis-ci.org/typicode/husky) [![Windows Build status](https://img.shields.io/appveyor/ci/typicode/husky/dev.svg?label=Windows)](https://ci.appveyor.com/project/typicode/husky/dev)

@@ -32,6 +32,4 @@ > Git hooks made easy

_By default, husky expects your project's `package.json` and your `.git` directory to be at the same level. It can be configured to support monorepos or sub-directories._
Check [documentation](https://github.com/typicode/husky/blob/dev/docs.md) for more.
Check [documentation](docs.md) for more.
## Uninstall

@@ -38,0 +36,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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