toplenboren / simple-git-hooks Goto Github PK
View Code? Open in Web Editor NEWA simple git hooks manager for small projects
License: MIT License
A simple git hooks manager for small projects
License: MIT License
node:internal/fs/utils:351
throw err;
^
Error: ENOENT: no such file or directory, stat '/project/node_modules/.store/simple-git-hooks-npm-2.8.1-284fd0e93b/package.json'
at Object.statSync (node:fs:1695:3)
at _getPackageJson (/project/node_modules/.store/simple-git-hooks-npm-2.8.1-284fd0e93b/node_modules/simple-git-hooks/simple-git-hooks.js:179:13)
at checkSimpleGitHooksInDependencies (/project/node_modules/.store/simple-git-hooks-npm-2.8.1-284fd0e93b/node_modules/simple-git-hooks/simple-git-hooks.js:102:34)
at postinstall (/project/node_modules/.store/simple-git-hooks-npm-2.8.1-284fd0e93b/node_modules/simple-git-hooks/postinstall.js:18:9)
at Object.<anonymous> (/project/node_modules/.store/simple-git-hooks-npm-2.8.1-284fd0e93b/node_modules/simple-git-hooks/postinstall.js:27:1)
at Module._compile (node:internal/modules/cjs/loader:1255:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
at Module.load (node:internal/modules/cjs/loader:1113:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) {
errno: -2,
syscall: 'stat',
code: 'ENOENT',
path: '/project/node_modules/.store/simple-git-hooks-npm-2.8.1-284fd0e93b/package.json'
}
Node.js v20.2.0
Yarn 3
nodeLinker: pnpm
node: 'v14.15.4', npm: '7.19.0'
Hi
When I run npm ci
the "prepare"
script (which is running npx simple-git-hooks
) runs without issues
But when I run npm ci --production
I'm prompted with this
Which fails when I type y
Running npx simple-git-hooks
doesn't throw any errors
My package.json looks something like this
"dependencies": {...},
"scripts": {
...
"prepare": "npx simple-git-hooks"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged && npm run test",
"pre-push": "npx tsc --project ./tsconfig.json --noEmit"
},
I'm curious if this is an issue with my setup, or with simple-git-hooks
Thanks.
package.license
is not enough. You need to add a separate file.
It is required by law. Also, GitHub will see the license.
Is this a good idea to do something like this?
"simple-git-hooks": {
"pre-commit": "npx simple-git-hooks && npx lint-staged"
}
so that people don't need to run npx simple-git-hooks
command when the config change
I found that .simple-pre-commit.json
(with dot) doesn’t work in the latest version.
➜ cat .simple-pre-commit.json
{
"simple-pre-commit": "npx lint-staged"
}
➜ npx simple-pre-commit
Couldn't parse command! Please add command to package.json or .simple-pre-commit.json. See README.md for details
os.exit is not a function
➜ mv .simple-pre-commit.json simple-pre-commit.json
➜ npx simple-pre-commit
Set pre commit hook: npx lint-staged
I personally prefer configs with .
, but it is not a big deal. We can just change docs to promote only simple-pre-commit.json
.
Hello! Thanks for the lib. I tried migrate from husky4 to this solution and found a problem.
When I try to install this lib:
yarn add -D simple-git-hooks
I see in console the following message:
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed in 0s 336ms
➤ YN0000: ┌ Link step
➤ YN0007: │ simple-git-hooks@npm:2.0.2 must be built because it never did before or the last one failed
➤ YN0009: │ simple-git-hooks@npm:2.0.2 couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/15/zr9tfbrs1z9_5w9yzszys8vh0000gn/T/xfs-e4784d06/build.log)
➤ YN0009: │ simple-git-hooks@npm:2.0.2 couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/15/zr9tfbrs1z9_5w9yzszys8vh0000gn/T/xfs-e4784d06/build.log)
➤ YN0000: └ Completed in 0s 391ms
➤ YN0000: Failed with errors in 0s 890ms
This is complete log:
# This file contains the result of Yarn building a package (simple-git-hooks@npm:2.0.2)
# Script name: postinstall
internal/fs/utils.js:307
throw err;
^
Error: ENOENT: no such file or directory, stat '/Users/igorkamyshev/Code/Solid-Soda/scripts/.yarn/unplugged/simple-git-hooks-npm-2.0.2-48676c6cda/package.json'
at Object.statSync (fs.js:1086:3)
at NodeFS.statSync (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:7751:24)
at makeCallSync.subPath.subPath (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:10325:26)
at ZipOpenFS.makeCallSync (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:10861:26)
at ZipOpenFS.statSync (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:10324:17)
at VirtualFS.statSync (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:8120:24)
at PosixFS.statSync (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:8120:24)
at _getPackageJson (/Users/igorkamyshev/Code/Solid-Soda/scripts/.yarn/unplugged/simple-git-hooks-npm-2.0.2-48676c6cda/node_modules/simple-git-hooks/simple-git-hooks.js:134:13)
at checkSimpleGitHooksInDependencies (/Users/igorkamyshev/Code/Solid-Soda/scripts/.yarn/unplugged/simple-git-hooks-npm-2.0.2-48676c6cda/node_modules/simple-git-hooks/simple-git-hooks.js:75:34)
at postinstall (/Users/igorkamyshev/Code/Solid-Soda/scripts/.yarn/unplugged/simple-git-hooks-npm-2.0.2-48676c6cda/node_modules/simple-git-hooks/postinstall.js:15:9) {
errno: -2,
syscall: 'stat',
code: 'ENOENT',
path: '/Users/igorkamyshev/Code/Solid-Soda/scripts/.yarn/unplugged/simple-git-hooks-npm-2.0.2-48676c6cda/package.json'
}
I use yarn version 2.4.1.
Could you help me to find a solution, please?
I see commit-msg
hook is supported, but I tried like following and failed:
module.exports = {
'pre-commit': 'npx lint-staged',
'commit-msg': 'npx commitlint -e', // it will work
}
As title
It would be nice to have the ability to define multiple hook commands.
Probabily would need a modifaction in the _setHook function.
To append multiple shell commands with a ;
or &&
.
This would allow for something like:
.simple-git-hooks.js
module.exports = {
...require('shared-package-with-base-hooks'),
'pre-commit': ['echo "1"', 'echo "2"', 'echo "3"']
}
shared-package-with-base-hooks -> entry.js
module.export = {
'pre-commit': 'echo "base package"',
}
Expected functionality:
On pre-commit
print:
base package
1
2
3
Hope this makes sense.
Ps, the ...require(....)
would basically evaluate to:
module.exports = {
'pre-commit': 'echo "base package"',
'pre-commit': ['echo "1"', 'echo "2"', 'echo "3"']
}
So not sure if that's possible or not. As the second pre-commit
probably overwrites the initial one? But there could be alternatives probably? One example alternative would be this StackOverflow
Now that the package is being renamed (#21), should we consider a shorter name? I found that the following are unused in npm:
For example, set-hooks would work well as a command: npx set-hooks
. On the other hand, it would’t be so good property name in package.json
.
It's a bit confusing.
And there is no CHANGELOG.
I came across a package that was updating its git hooks with a post install script:
"postinstall": "npx simple-git-hooks",
When that package was installed as a dependency of another package, it installed the hooks in the parent package.
How can I skip a pre-commit check by cli command?
node_modules/.pnpm/[email protected]/node_modules/simple-git-hooks: Running postinstall script, failed in 126ms
.../node_modules/simple-git-hooks postinstall$ node ./postinstall.js
│ internal/fs/utils.js:307
│ throw err;
│ ^
│ Error: ENOENT: no such file or directory, stat 'D:\Projects\vue-promise-dialogs\node_modules\.pnpm\[email protected]\package.json'
│ at Object.statSync (fs.js:1086:3)
│ at _getPackageJson (D:\Projects\vue-promise-dialogs\node_modules\.pnpm\[email protected]\node_modules\simple-git-hooks\simple-git-hooks.js:140:13)
│ at checkSimpleGitHooksInDependencies (D:\Projects\vue-promise-dialogs\node_modules\.pnpm\[email protected]\node_modules\simple-git-hooks\simple-git-hooks
│ at postinstall (D:\Projects\vue-promise-dialogs\node_modules\.pnpm\[email protected]\node_modules\simple-git-hooks\postinstall.js:15:9)
│ at Object.<anonymous> (D:\Projects\vue-promise-dialogs\node_modules\.pnpm\[email protected]\node_modules\simple-git-hooks\postinstall.js:24:1)
│ at Module._compile (internal/modules/cjs/loader.js:1063:30)
│ at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
│ at Module.load (internal/modules/cjs/loader.js:928:32)
│ at Function.Module._load (internal/modules/cjs/loader.js:769:14)
│ at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
│ errno: -4058,
│ syscall: 'stat',
│ code: 'ENOENT',
│ path: 'D:\\Projects\\vue-promise-dialogs\\node_modules\\.pnpm\\[email protected]\\package.json'
│ }
└─ Failed in 127ms
ERROR Command failed with exit code 1.
```
pnpm version: 5.18.7
It is not a bug but rather a documentation suggestion. We recently migrated from husky to simple-git-hooks which is nice and easy to setup so thank you for that. However we noticed that the hooks aren't running anymore.
After a deep investigation I noticed that the source of the issue was git configurations.
core.hooksPath
was set to .husky
and it needed to be $GIT_DIR/hooks
This would be solved by changing the core.hooksPath
or deleting project and recloning it.
Since the library relies on default git configuration I think it would make sense to be mentioned in the documentation.
I would also like to know if you know a better way to solve this issue.
Thanks again
I get the following errror
ENOENT: no such file or directory, open '/Users/niklaas/git/abc/def/.git/worktrees/<name of worktree>/hooks/pre-commit'
when running npx simple-pre-commit
inside a git worktree.
安装了,初始化了,一切配置按照官网来了。但是我之间commit 就像没有它一样,之间就commit,没有执行我需要的命令
Trying to replace Husky with simple-git-hooks in a create-react-app project as follows in package.json
:
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --write"
]
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
I am able to commit a properly formatted file i.e. no changes made by Prettier when the hook runs, however when I leave out a semi-colon to test Prettier formatting, I get a popup in VSCode saying "Git: [STARTED] Preparing..." with Show Command Output, Cancel, and Open Git Log buttons, then when I click Show Command Output I see the following:
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
[STARTED] Preparing...
[SUCCESS] Preparing...
[STARTED] Running tasks...
[STARTED] Running tasks for src/**/*.{js,jsx,ts,tsx,json,css,scss,md}
[STARTED] prettier --write
[SUCCESS] prettier --write
[SUCCESS] Running tasks for src/**/*.{js,jsx,ts,tsx,json,css,scss,md}
[SUCCESS] Running tasks...
[STARTED] Applying modifications...
[FAILED] Prevented an empty git commit!
[STARTED] Reverting to original state because of errors...
[SUCCESS] Reverting to original state because of errors...
[STARTED] Cleaning up...
[SUCCESS] Cleaning up...
⚠ lint-staged prevented an empty git commit.
Use the --allow-empty option to continue, or check your task configuration
npm ERR! code 1
npm ERR! path /Users/chris/Documents/Jobs/AFSCME/repos-legacy/afscme-cards
npm ERR! command failed
npm ERR! command sh -c lint-staged
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/chris/.npm/_logs/2021-04-29T06_37_56_082Z-debug.log
Any idea how to fix this so Prettier runs and the changes get added to the commit?
Stumbled upon this tiny package and am interested in using this due to its simplicity. However migrating from husky v6
is not as easy as it stated in the README, there is a missing step where you need to remove the entire .git/hooks
folder because everything inside the folder are generated to always run husky
.
# remove then run the setup command
$ rm -rf .git/hooks
$ npx simple-git-hooks
Here are small README.md
changes according to my experience:
Why?
subtitle and put features directly after the descriptionLightweight
→ the size in node_modules
(compare with husky?). Easy to install
or Dead simple to use
is hard to prove.pre-commit
hook. Add what is a reason to use it (ensure that everyone run linters/Prettier for the changed files) and lint to lint-staged
since it is the best pair.According to husky 4→5 post husky 4 uses 1 MB of the size.
But in your table, it is only 50 KB. Seems like you are not using dependencies in size calculation. It will increase the size of husky 4 and pre-commit a lot. And it will be pretty fair since dependencies size is the main reason to avoid dependencies for small projects.
npx simple-pre-commit
now returns an error on Linux systems:
/usr/bin/env: ‘node\r’: No such file or directory
Seems like the script has Windows \r\n
symbols. Maybe we need to change some git settings.
It doesn't seem that lint-staged
recommends using this package after lint-staged/lint-staged#960, so this might be a bit misleading, should it be removed?
The package is recommended by lint-staged
The small npm package size is one of the key features of this package. There is a reason to use every micro-optimization for art reasons.
For instance, adding and calling clean-publish instead of npm publish
will remove devDependencies
, lint-staged
, etc from package.json
.
Husky 5 can be removed, since it is not open source and replaced by Husky 6.
We have postinstall
to set .git/hooks/pre-commit
, but we forgot about the uninstall
script to remove the script on the simple-pre-commit
unsinatlling
In this way, we can update git hooks command in pre-commit
hooks, like #34 says, but won't be botherd by logging.
Hi, I am trying to migrate from Husky. I've added the following to my package.json:
"simple-git-hooks": { "pre-commit": "lint-staged", "commit-msg": "yarn commitlint -E --from=HEAD~1" },
I try to run:
$ git add .
$ git commit -m "testy: testy"
// works
BUT
yarn commitlint -E --from=HEAD~1"
`
⧗ input: testy: testy
✖ type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test] [type-enum]
✖ found 1 problems, 0 warnings
`
To test, I have tried to echo a string in the commit message spot but I still don't see it. Is this user error or a package problem? Thank you.
When setting the configuration from js
file (simple-git-hooks.js
or .simple-git-hooks.js
)
the npx simple-git-hooks
command executed on Windows 10 returns an error:
Line: 1
Char: 1
Error: 'module' is not defined
Source: Microsoft JScript runtime error
The problem happens because for some reason Windows might use internal JS interpreter instead of node. This internal interpreter does not know what module
is, thus throwing an error.
--
Possible workaround for now is to use configuration from package.json
or simple-git-hooks.json
files.
Also changing the default interpreter might help
Not sure why, but I started getting this error.
Tried re-installing and following the readme but still seeing it. I can confirm the binary is present. Let me know how I can help.
Hi 👋,
This is a feature request more than an issue.
My suggestion is to preserve the existing hooks path if it is defined in git config core.hooksPath
, so this way it's not necessary to take into account this step when you're migrating from Husky, for instance. This is also an issue when you're switching branches with different git hooks setup and requires executing a script in preinstall
or prepare
like explained here to make it transparent for users.
What do you think?
Thanks
Since this project does not use Projects and Wiki, you can simplify the page by disabling them in the project settings
I was looking through the repository and noticed something I wanted to clarify. In the package.json, the packageManager is set to npm. However, there's a yarn.lock file present in the project.
Is the yarn.lock file committed by mistake? If the project is solely relying on npm, would it be appropriate to remove the yarn.lock file to avoid any potential package management conflicts or confusion for contributors?
I appreciate your guidance on this matter, and thank you for all the work you've put into this package!
Since people can’t move to husky 5 for a while, it is a great time to compare simple-pre-commit
with husky 4 and put it to the docs.
Maybe you are also faster than husky 5?
"simple-git-hooks": "^2.0.1",
➜ npx simple-git-hooks
/usr/bin/env: ‘node\r’: No such file or directory
Hi. I use some custom commit-msg and prepare-commit-msg git hooks that grab data from a Jira system. And I use "simple-git-hooks" to run "lint-staged" on "pre-commit". The latest release of "simple-git-hooks" started removing "not-used git hooks" which breaks manually created git hooks. Could you please revert this change, or make it configurable maybe?
I'm using simple-git-hooks with VSCode. And all my environment variables are set in .bash_profile
and .bashrc
, including npm
and npx
. So when I use this, the default head of pre-commit file is #!/bin/sh
, which cause a npx not found
error when I commit in vscode. I really do wish there is an option about this. Thanks.
11:12:42.567 | $ simple-git-hooks && yarn-deduplicate --strategy fewer \|\| exit 0
11:12:42.655 | [ERROR], Was not able to set git hooks. Error: Error: ENOENT: no such file or directory, mkdir 'undefined/hooks/'
Running simple-git-hooks
with npx
or npm exec
causes the installation to fail.
$ npx -y simple-git-hooks@latest
> [email protected] postinstall
> node ./postinstall.js
node:internal/fs/utils:344fy:simple-git-hooks: sill audit bulk request { 'simple-git-hooks': [ '2.7.0' ] }
throw err;
^
Error: ENOENT: no such file or directory, stat '/Users/user/.npm/_npx/318daabbad435bbd/package.json'
at Object.statSync (node:fs:1536:3)
at _getPackageJson (/Users/user/.npm/_npx/318daabbad435bbd/node_modules/simple-git-hooks/simple-git-hooks.js:174:13)
at checkSimpleGitHooksInDependencies (/Users/user/.npm/_npx/318daabbad435bbd/node_modules/simple-git-hooks/simple-git-hooks.js:102:34)
at postinstall (/Users/user/.npm/_npx/318daabbad435bbd/node_modules/simple-git-hooks/postinstall.js:15:9)
at Object.<anonymous> (/Users/user/.npm/_npx/318daabbad435bbd/node_modules/simple-git-hooks/postinstall.js:24:1)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
errno: -2,
syscall: 'stat',
code: 'ENOENT',
path: '/Users/user/.npm/_npx/318daabbad435bbd/package.json'
}
Node.js v17.2.0
simple-git-hooks
should run correctly using npx
or npm exec
locally.
Running npx -y simple-git-hooks
or npm exec -y -- simple-git-hooks@latest
throws error.
$ npx -y envinfo
System:
OS: macOS 12.2
CPU: (10) arm64 Apple M1 Max
Memory: 13.90 GB / 64.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 17.2.0
npm: 8.1.4
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch [email protected]
for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/simple-git-hooks/simple-git-hooks.js b/node_modules/simple-git-hooks/simple-git-hooks.js
index 772b9a0..44cccbc 100644
--- a/node_modules/simple-git-hooks/simple-git-hooks.js
+++ b/node_modules/simple-git-hooks/simple-git-hooks.js
@@ -131,7 +131,9 @@ function _getConfig(projectRootPath) {
throw TypeError("Check project root path! Expected a string, but got " + typeof projectRootPath)
}
const sources = [
+ () => _getConfigFromFile(projectRootPath, '.simple-git-hooks.cjs'),
() => _getConfigFromFile(projectRootPath, '.simple-git-hooks.js'),
+ () => _getConfigFromFile(projectRootPath, 'simple-git-hooks.cjs'),
() => _getConfigFromFile(projectRootPath, 'simple-git-hooks.js'),
() => _getConfigFromFile(projectRootPath, '.simple-git-hooks.json'),
() => _getConfigFromFile(projectRootPath, 'simple-git-hooks.json'),
This issue body was partially generated by patch-package.
Hey!
How about someone (who isn't horrible at drawing things, like myself) create a customized icon for the config files: .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
?
Then it would be used with the amazing vscode-icons extension.
It's not a big deal, and it doesn't add any kind of new functionality, but it looks really nice! This is what I mean - below is a project of mine, and my vscode has vscode-icons installed:
.simple-git-hooks.json is the only file without a custom icon, it's showing the default JSON icon.
I thought about just opening a PR there and adding the files to use the default git icon but I think it should be different. Like the same icon with a little hook added to the lower right corner, maybe?
Like I said, I have zero talent for this kind of thing, but if anyone out there is willing to give it a shot... Here are the guidelines for creating an icon for the extension.
Thanks!
It's useful to skip git hooks installation when environment variable is set, e.g. SIMPLE_GIT_HOOKS=0
Similar functionality in husky: https://typicode.github.io/husky/guide.html#bypass-hooks
"simple-git-hooks": {
"pre-commit": "pnpm exec lint-staged --concurrent false"
},
"lint-staged": {
"*": [
"eslint --cache --fix",
"prettier --write --cache --ignore-unknown"
]
}
if :
git commit -m "...."
will brek error:
ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL Cannot read properties of undefined (reading '/home/shuang/Desktop/project/gui')
I'm using shared simple-git-hooks config, and using some dependencies which had migrated to ESM only, so it would be nice to support native ESM here.
Since it is a cli, so I suppose ESM only for this package would be fine.
I'm still using husky@4 because we share husky config in all of my projects:
// .huskyrc.js
modue.exports = require('@1stg/husky-confog')
Maybe I made a mistake by suggesting only pre-commit
hook support. We can add other hook support, but it will require the project to change the name (simple-hooks
?).
We can have the same one-line config for pre-commit
:
"simple-hooks": "npx lint-staged"
And object for custom hooks:
"simple-hooks": {
"pre-push": "npx x"
}
Big names are a good way to convince users in our hype-driven community. Here are a few names, which we can add to docs:
A few examples of the section in my projects:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.