windows.js 735 B

123456789101112131415161718192021222324252627282930313233343536
  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 isexe (path, options, cb) {
  23. fs.stat(path, function (er, st) {
  24. cb(er, er ? false : checkPathExt(path, options))
  25. })
  26. }
  27. function sync (path, options) {
  28. fs.statSync(path)
  29. return checkPathExt(path, options)
  30. }