windows.js 890 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. module.exports = isexe
  2. isexe.sync = sync
  3. var fs = require('fs')
  4. function checkPathExt (path, options) {
  5. var pathext = options.pathExt !== undefined ?
  6. options.pathExt : process.env.PATHEXT
  7. if (!pathext) {
  8. return true
  9. }
  10. pathext = pathext.split(';')
  11. if (pathext.indexOf('') !== -1) {
  12. return true
  13. }
  14. for (var i = 0; i < pathext.length; i++) {
  15. var p = pathext[i].toLowerCase()
  16. if (p && path.substr(-p.length).toLowerCase() === p) {
  17. return true
  18. }
  19. }
  20. return false
  21. }
  22. function checkStat (stat, path, options) {
  23. if (!stat.isSymbolicLink() && !stat.isFile()) {
  24. return false
  25. }
  26. return checkPathExt(path, options)
  27. }
  28. function isexe (path, options, cb) {
  29. fs.stat(path, function (er, stat) {
  30. cb(er, er ? false : checkStat(stat, path, options))
  31. })
  32. }
  33. function sync (path, options) {
  34. return checkStat(fs.statSync(path), path, options)
  35. }