* Transforms the /node_modules/simple-git-hooks to * @param projectPath - path to the simple-git-hooks in node modules * @return {string | undefined} - an absolute path to the project or undefined if projectPath is not in node_modules
(projectPath)
| 100 | * @return {string | undefined} - an absolute path to the project or undefined if projectPath is not in node_modules |
| 101 | */ |
| 102 | function getProjectRootDirectoryFromNodeModules(projectPath) { |
| 103 | function _arraysAreEqual(a1, a2) { |
| 104 | return JSON.stringify(a1) === JSON.stringify(a2) |
| 105 | } |
| 106 | |
| 107 | const projDir = projectPath.split(/[\\/]/) // <- would split both on '/' and '\' |
| 108 | |
| 109 | const indexOfPnpmDir = projDir.indexOf('.pnpm') |
| 110 | if (indexOfPnpmDir > -1) { |
| 111 | return projDir.slice(0, indexOfPnpmDir - 1).join('/'); |
| 112 | } |
| 113 | const indexOfDenoDir = projDir.indexOf('.deno') |
| 114 | if (indexOfDenoDir > -1) { |
| 115 | return projDir.slice(0, indexOfDenoDir - 1).join('/'); |
| 116 | } |
| 117 | |
| 118 | const indexOfStoreDir = projDir.indexOf('.store') |
| 119 | if (indexOfStoreDir > -1) { |
| 120 | return projDir.slice(0, indexOfStoreDir - 1).join('/'); |
| 121 | } |
| 122 | |
| 123 | // A yarn2 STAB |
| 124 | if (projDir.includes('.yarn') && projDir.includes('unplugged')) { |
| 125 | return undefined |
| 126 | } |
| 127 | |
| 128 | if (projDir.length > 2 && |
| 129 | _arraysAreEqual(projDir.slice(projDir.length - 2, projDir.length), [ |
| 130 | 'node_modules', |
| 131 | 'simple-git-hooks' |
| 132 | ])) { |
| 133 | |
| 134 | return projDir.slice(0, projDir.length - 2).join('/') |
| 135 | } |
| 136 | |
| 137 | return undefined |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Checks the 'simple-git-hooks' in dependencies of the project |
no test coverage detected
searching dependent graphs…