Skip to content

Commit

Permalink
Merge pull request #47 from Djaler/fix-pnpm
Browse files Browse the repository at this point in the history
fix project root detection in pnpm
  • Loading branch information
toplenboren committed Apr 2, 2021
2 parents 349ee17 + 8d4bb00 commit 173ca0b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions simple-git-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,13 @@ function getProjectRootDirectoryFromNodeModules(projectPath) {
const projDir = projectPath.split(/[\\/]/) // <- would split both on '/' and '\'

if (projDir.includes('.pnpm')
&& projDir.length > 5
&& _arraysAreEqual(projDir.slice(projDir.length - 5), [
&& projDir.length > 3
&& _arraysAreEqual(projDir.slice(projDir.length - 3), [
'node_modules',
'.pnpm',
`simple-git-hooks@${packageVersion}`,
'node_modules',
'simple-git-hooks'
])) {
return projDir.slice(0, projDir.length - 5).join('/');
return projDir.slice(0, projDir.length - 3).join('/');
}

// A yarn2 STAB
Expand Down
2 changes: 1 addition & 1 deletion simple-git-hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('getProjectRootDirectory falls back to undefined when we are not in node_mo
})

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


Expand Down

0 comments on commit 173ca0b

Please sign in to comment.