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

Commit

Permalink
fix(exec): make node script detection more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Jul 17, 2017
1 parent 255aeeb commit 0f821a4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
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 0f821a4

Please sign in to comment.