11cb0ef41Sopenharmony_civar fs = require('fs') 21cb0ef41Sopenharmony_civar core 31cb0ef41Sopenharmony_ciif (process.platform === 'win32' || global.TESTING_WINDOWS) { 41cb0ef41Sopenharmony_ci core = require('./windows.js') 51cb0ef41Sopenharmony_ci} else { 61cb0ef41Sopenharmony_ci core = require('./mode.js') 71cb0ef41Sopenharmony_ci} 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_cimodule.exports = isexe 101cb0ef41Sopenharmony_ciisexe.sync = sync 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cifunction isexe (path, options, cb) { 131cb0ef41Sopenharmony_ci if (typeof options === 'function') { 141cb0ef41Sopenharmony_ci cb = options 151cb0ef41Sopenharmony_ci options = {} 161cb0ef41Sopenharmony_ci } 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci if (!cb) { 191cb0ef41Sopenharmony_ci if (typeof Promise !== 'function') { 201cb0ef41Sopenharmony_ci throw new TypeError('callback not provided') 211cb0ef41Sopenharmony_ci } 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci return new Promise(function (resolve, reject) { 241cb0ef41Sopenharmony_ci isexe(path, options || {}, function (er, is) { 251cb0ef41Sopenharmony_ci if (er) { 261cb0ef41Sopenharmony_ci reject(er) 271cb0ef41Sopenharmony_ci } else { 281cb0ef41Sopenharmony_ci resolve(is) 291cb0ef41Sopenharmony_ci } 301cb0ef41Sopenharmony_ci }) 311cb0ef41Sopenharmony_ci }) 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci core(path, options || {}, function (er, is) { 351cb0ef41Sopenharmony_ci // ignore EACCES because that just means we aren't allowed to run it 361cb0ef41Sopenharmony_ci if (er) { 371cb0ef41Sopenharmony_ci if (er.code === 'EACCES' || options && options.ignoreErrors) { 381cb0ef41Sopenharmony_ci er = null 391cb0ef41Sopenharmony_ci is = false 401cb0ef41Sopenharmony_ci } 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci cb(er, is) 431cb0ef41Sopenharmony_ci }) 441cb0ef41Sopenharmony_ci} 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_cifunction sync (path, options) { 471cb0ef41Sopenharmony_ci // my kingdom for a filtered catch 481cb0ef41Sopenharmony_ci try { 491cb0ef41Sopenharmony_ci return core.sync(path, options || {}) 501cb0ef41Sopenharmony_ci } catch (er) { 511cb0ef41Sopenharmony_ci if (options && options.ignoreErrors || er.code === 'EACCES') { 521cb0ef41Sopenharmony_ci return false 531cb0ef41Sopenharmony_ci } else { 541cb0ef41Sopenharmony_ci throw er 551cb0ef41Sopenharmony_ci } 561cb0ef41Sopenharmony_ci } 571cb0ef41Sopenharmony_ci} 58