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

simple-git-hooks

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-git-hooks - npm Package Compare versions

Comparing version 2.8.1 to 2.9.0

LICENSE.txt

4

cli.js
#!/usr/bin/env node
/**
* A CLI tool to change the git hooks to commands from config
*/
const {setHooksFromConfig} = require('./simple-git-hooks')

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

12

package.json
{
"name": "simple-git-hooks",
"version": "2.8.1",
"version": "2.9.0",
"description": "A simple, zero dependency tool for setting up git hooks for small projects",

@@ -8,6 +8,2 @@ "author": "Mikhail Gorbunov <toplenboren@gmail.com> (toplenboren.github.io)",

"bin": "./cli.js",
"scripts": {
"postinstall": "node ./postinstall.js",
"uninstall": "node ./uninstall.js"
},
"keywords": [

@@ -22,3 +18,7 @@ "pre-commit",

"license": "MIT",
"repository": "toplenboren/simple-git-hooks"
"repository": "toplenboren/simple-git-hooks",
"scripts": {
"postinstall": "node ./postinstall.js",
"uninstall": "node ./uninstall.js"
}
}

@@ -5,127 +5,2 @@ # simple-git-hooks

- Zero dependency
- Small configuration (1 object in package.json)
- Lightweight:
## Usage
### Add simple-git-hooks to the project
1. Install simple-git-hooks as a dev dependency:
```sh
npm install simple-git-hooks --save-dev
```
2. Add `simple-git-hooks` to your `package.json`. Fill it with git hooks and the corresponding commands.
For example:
```jsonc
{
"simple-git-hooks": {
"pre-commit": "npx lint-staged",
"pre-push": "cd ../../ && npm run format",
// All unused hooks will be removed automatically by default
// but you can use the `preserveUnused` option like following to prevent this behavior
// if you'd prefer preserve all unused hooks
"preserveUnused": true,
// if you'd prefer preserve specific unused hooks
"preserveUnused": ["commit-msg"]
}
}
```
This configuration is going to run all linters on every `commit` and formatter on `push`.
> There are more ways to configure the package. Check out [Additional configuration options](#additional-configuration-options).
3. Run the CLI script to update the git hooks with the commands from the config:
```sh
# [Optional] These 2 steps can be skipped for non-husky users
git config core.hooksPath .git/hooks/
rm -rf .git/hooks
# Update ./git/hooks
npx simple-git-hooks
```
Now all the git hooks are created.
### Update git hooks command
1. Change the configuration.
2. Run `npx simple-git-hooks` **from the root of your project**.
Note for **yarn2** users: Please run `yarn dlx simple-git-hooks` instead of the command above. More info on [dlx](https://yarnpkg.com/cli/dlx)
Note that you should manually run `npx simple-git-hooks` **every time you change a command**.
### Additional configuration options
You can also add a `.simple-git-hooks.cjs`, `.simple-git-hooks.js`, `simple-git-hooks.cjs`, `simple-git-hooks.js`, `.simple-git-hooks.json` or `simple-git-hooks.json` file to the project and write the configuration inside it.
This way `simple-git-hooks` configuration in `package.json` will not take effect any more.
`.simple-git-hooks.cjs`, `.simple-git-hooks.js` or `simple-git-hooks.cjs`, `simple-git-hooks.js` should look like the following.
```js
module.exports = {
"pre-commit": "npx lint-staged",
"pre-push": "cd ../../ && npm run format",
};
```
`.simple-git-hooks.json` or `simple-git-hooks.json` should look like the following.
```json
{
"pre-commit": "npx lint-staged",
"pre-push": "cd ../../ && npm run format"
}
```
If you need to have multiple configuration files or just your-own configuration file, you install hooks manually from it by `npx simple-git-hooks ./my-config.js`.
### Uninstall simple-git-hooks
> Uninstallation will remove all the existing git hooks.
```sh
npm uninstall simple-git-hooks
```
## Common issues
### When migrating from `husky` git hooks are not running
**Why is this happening?**
Husky might change the `core.gitHooks` value to `.husky`, this way, git hooks would search `.husky` directory instead of `.git/hooks/`.
Read more on git configuration in [Git book](https://git-scm.com/docs/githooks)
You can check it by running this command inside of your repo:
`git config core.hooksPath`
If it outputs `.husky` then this is your case
**How to fix?**
you need to point `core.gitHooks` value to `your-awesome-project/.git/hooks`. You can use this command:
`git config core.hooksPath .git/hooks/`
validate the value is set:
`git config core.hooksPath`
should output: `.git/hooks/`
Then remove the `.husky` folder that are generated previously by `husky`.
Full docs here: https://github.com/toplenboren/simple-git-hooks

@@ -59,3 +59,9 @@ const fs = require('fs')

if (match) {
return path.normalize(match[1])
let gitDir = match[1]
let commonDir = path.join(gitDir, 'commondir');
if (fs.existsSync(commonDir)) {
commonDir = fs.readFileSync(commonDir, 'utf8').trim();
return path.resolve(gitDir, commonDir)
}
return path.normalize(gitDir)
}

@@ -81,2 +87,7 @@ }

const indexOfStoreDir = projDir.indexOf('.store')
if (indexOfStoreDir > -1) {
return projDir.slice(0, indexOfStoreDir - 1).join('/');
}
// A yarn2 STAB

@@ -83,0 +94,0 @@ if (projDir.includes('.yarn') && projDir.includes('unplugged')) {

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