3 var path = require('path');
4 var which = require('which');
5 var LRU = require('lru-cache');
7 var commandCache = new LRU({ max: 50, maxAge: 30 * 1000 }); // Cache just for 30sec
9 function resolveCommand(command, noExtension) {
12 noExtension = !!noExtension;
13 resolved = commandCache.get(command + '!' + noExtension);
15 // Check if its resolved in the cache
16 if (commandCache.has(command)) {
17 return commandCache.get(command);
21 resolved = !noExtension ?
23 which.sync(command, { pathExt: path.delimiter + (process.env.PATHEXT || '') });
24 } catch (e) { /* empty */ }
26 commandCache.set(command + '!' + noExtension, resolved);
31 module.exports = resolveCommand;