MCPcopy Create free account
hub / github.com/toplenboren/simple-git-hooks / getProjectRootDirectory

Function getProjectRootDirectory

simple-git-hooks.js:162–169  ·  view source on GitHub ↗

* Resolves the project root during the postinstall step. * * Prefers INIT_CWD — the directory the package manager was invoked from, which * npm, pnpm, yarn, and bun all set to the project root when running lifecycle * scripts. Unlike getProjectRootDirectoryFromNodeModules, it does not depend on

(initCwd = process.env.INIT_CWD, cwd = process.cwd())

Source from the content-addressed store, hash-verified

160 * @return {string} - an absolute path to the project root
161 */
162function getProjectRootDirectory(initCwd = process.env.INIT_CWD, cwd = process.cwd()) {
163 if (initCwd && fs.existsSync(path.join(initCwd, 'package.json'))) {
164 return initCwd
165 }
166
167 const parsedProjectDirectory = getProjectRootDirectoryFromNodeModules(cwd)
168 return parsedProjectDirectory !== undefined ? parsedProjectDirectory : cwd
169}
170
171/**
172 * Checks the 'simple-git-hooks' in dependencies of the project

Callers 1

postinstallFunction · 0.85

Tested by

no test coverage detected