Skip to content

Commit

Permalink
Merge pull request #107 from jzaefferer/cwd-fix
Browse files Browse the repository at this point in the history
Harden getProjectPath() to deal with different PATHs
  • Loading branch information
Alexander Lisianoi authored Feb 2, 2018
2 parents 61df38a + 8f0809f commit 80bc841
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,32 @@ function sliceEnvPath (suffix) {
// commitplease. Previously, process.cwd() made the job easy but its
// output changed with node v8.1.2 (at least compared to 7.10.0)
function getProjectPath () {
// Rely on npm to inject some path into PATH; However, the injected
// path can both be relative or absolute, so add extra path.resolve()

// During npm install, npm will inject a path that ends with
// commitplease/node_modules/.bin into process.env.PATH
var p = sliceEnvPath(
path.join('node_modules', 'commitplease', 'node_modules', '.bin')
)

if (p !== undefined) {
return p
return path.resolve(p)
}

// During npm run, npm will inject a path that ends with
// node_modules/.bin into process.env.PATH
p = sliceEnvPath(path.join('node_modules', '.bin'))

if (p !== undefined) {
return p
return path.resolve(p)
}

// During git commit there will be no process.env.PATH modifications
// So, assume we are being run by git which will set process.cwd()
// to the root of the project as described in the manual:
// https://git-scm.com/docs/githooks/2.9.0
return process.cwd()
return path.resolve(process.cwd())
}

function getOptions () {
Expand Down

0 comments on commit 80bc841

Please sign in to comment.