Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Commit

Permalink
fix(exec): detect a wider range of shebang lines for node scripts (#89)
Browse files Browse the repository at this point in the history
Fixes: #54
  • Loading branch information
zkat authored Jul 17, 2017
1 parent 255aeeb commit 1841b6f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,7 @@ function findNodeScript (existing, opts) {
throw new Error(Y()`command not found: ${existing}`)
}
} else if (process.platform !== 'win32') {
const line = '#!/usr/bin/env node\n'
const bytecount = line.length
const bytecount = 400
const buf = Buffer.alloc(bytecount)
return promisify(fs.open)(existing, 'r').then(fd => {
return promisify(fs.read)(fd, buf, 0, bytecount, 0).then(() => {
Expand All @@ -335,7 +334,8 @@ function findNodeScript (existing, opts) {
return promisify(fs.close)(fd).then(() => { throw err })
})
}).then(() => {
return buf.toString('utf8') === line && existing
const re = /#!\s*(?:\/usr\/bin\/env\s*node|\/usr\/local\/bin\/node|\/usr\/bin\/node)\s*\r?\n/i
return buf.toString('utf8').match(re) && existing
})
} else if (process.platform === 'win32') {
const buf = Buffer.alloc(1000)
Expand Down

0 comments on commit 1841b6f

Please sign in to comment.