toplenboren / simple-git-hooks

A simple git hooks manager for small projects
MIT License
1.32k stars 43 forks source link

Add support for `.cjs` configs #60

Closed JounQin closed 3 years ago

JounQin commented 3 years ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch simple-git-hooks@2.5.1 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.

toplenboren commented 3 years ago

Hi, thank you!

So, to add the support to .cjs I just need to add two lines in sources? Cool!