Skip to content

Commit 173ca0b

Browse files
authored
Merge pull request #47 from Djaler/fix-pnpm
fix project root detection in pnpm
2 parents 349ee17 + 8d4bb00 commit 173ca0b

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

simple-git-hooks.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,13 @@ function getProjectRootDirectoryFromNodeModules(projectPath) {
8484
const projDir = projectPath.split(/[\\/]/) // <- would split both on '/' and '\'
8585

8686
if (projDir.includes('.pnpm')
87-
&& projDir.length > 5
88-
&& _arraysAreEqual(projDir.slice(projDir.length - 5), [
87+
&& projDir.length > 3
88+
&& _arraysAreEqual(projDir.slice(projDir.length - 3), [
8989
'node_modules',
9090
'.pnpm',
9191
`simple-git-hooks@${packageVersion}`,
92-
'node_modules',
93-
'simple-git-hooks'
9492
])) {
95-
return projDir.slice(0, projDir.length - 5).join('/');
93+
return projDir.slice(0, projDir.length - 3).join('/');
9694
}
9795

9896
// A yarn2 STAB

simple-git-hooks.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test('getProjectRootDirectory falls back to undefined when we are not in node_mo
2121
})
2222

2323
test('getProjectRootDirectory return correct dir when installed using pnpm:', () => {
24-
expect(spc.getProjectRootDirectoryFromNodeModules(`var/my-project/node_modules/.pnpm/simple-git-hooks@${packageVersion}/node_modules/simple-git-hooks`)).toBe('var/my-project')
24+
expect(spc.getProjectRootDirectoryFromNodeModules(`var/my-project/node_modules/.pnpm/simple-git-hooks@${packageVersion}`)).toBe('var/my-project')
2525
})
2626

2727

0 commit comments

Comments
 (0)