Initial commit
[yaffs-website] / node_modules / cross-spawn / lib / resolveCommand.js
1 'use strict';
2
3 var path = require('path');
4 var which = require('which');
5 var LRU = require('lru-cache');
6
7 var commandCache = new LRU({ max: 50, maxAge: 30 * 1000 });  // Cache just for 30sec
8
9 function resolveCommand(command, noExtension) {
10     var resolved;
11
12     noExtension = !!noExtension;
13     resolved = commandCache.get(command + '!' + noExtension);
14
15     // Check if its resolved in the cache
16     if (commandCache.has(command)) {
17         return commandCache.get(command);
18     }
19
20     try {
21         resolved = !noExtension ?
22             which.sync(command) :
23             which.sync(command, { pathExt: path.delimiter + (process.env.PATHEXT || '') });
24     } catch (e) { /* empty */ }
25
26     commandCache.set(command + '!' + noExtension, resolved);
27
28     return resolved;
29 }
30
31 module.exports = resolveCommand;