• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('fs')
2var core
3if (process.platform === 'win32' || global.TESTING_WINDOWS) {
4  core = require('./windows.js')
5} else {
6  core = require('./mode.js')
7}
8
9module.exports = isexe
10isexe.sync = sync
11
12function isexe (path, options, cb) {
13  if (typeof options === 'function') {
14    cb = options
15    options = {}
16  }
17
18  if (!cb) {
19    if (typeof Promise !== 'function') {
20      throw new TypeError('callback not provided')
21    }
22
23    return new Promise(function (resolve, reject) {
24      isexe(path, options || {}, function (er, is) {
25        if (er) {
26          reject(er)
27        } else {
28          resolve(is)
29        }
30      })
31    })
32  }
33
34  core(path, options || {}, function (er, is) {
35    // ignore EACCES because that just means we aren't allowed to run it
36    if (er) {
37      if (er.code === 'EACCES' || options && options.ignoreErrors) {
38        er = null
39        is = false
40      }
41    }
42    cb(er, is)
43  })
44}
45
46function sync (path, options) {
47  // my kingdom for a filtered catch
48  try {
49    return core.sync(path, options || {})
50  } catch (er) {
51    if (options && options.ignoreErrors || er.code === 'EACCES') {
52      return false
53    } else {
54      throw er
55    }
56  }
57}
58