secure-husky-setup 1.0.1 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/git.js +16 -2
  2. package/package.json +4 -1
package/lib/git.js CHANGED
@@ -2,6 +2,20 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
4
  exports.isGitRepo = async () => {
5
- const gitPath = path.join(process.cwd(), '.git');
6
- return fs.existsSync(gitPath);
5
+ // Walk up directory tree to find .git folder
6
+ // This handles postinstall where cwd() is inside node_modules/package-name
7
+ let dir = process.cwd();
8
+
9
+ while (true) {
10
+ if (fs.existsSync(path.join(dir, '.git'))) {
11
+ // Change working directory to the project root
12
+ process.chdir(dir);
13
+ return true;
14
+ }
15
+ const parent = path.dirname(dir);
16
+ if (parent === dir) break; // reached filesystem root
17
+ dir = parent;
18
+ }
19
+
20
+ return false;
7
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "secure-husky-setup",
3
- "version": "1.0.1",
3
+ "version": "1.0.5",
4
4
  "description": "Automatic Husky + Gitleaks setup for any JS project",
5
5
  "main": "bin/index.js",
6
6
  "bin": {
@@ -24,5 +24,8 @@
24
24
  "execa": "^5.1.1",
25
25
  "fs-extra": "^11.3.3",
26
26
  "sonarqube-scanner": "^4.0.0"
27
+ },
28
+ "scripts": {
29
+ "postinstall": "node bin/index.js init"
27
30
  }
28
31
  }