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 });
|
8 |
|
9 | function resolveCommand(command, noExtension) {
|
10 | var resolved;
|
11 |
|
12 | noExtension = !!noExtension;
|
13 | resolved = commandCache.get(command + '!' + noExtension);
|
14 |
|
15 |
|
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) { }
|
25 |
|
26 | commandCache.set(command + '!' + noExtension, resolved);
|
27 |
|
28 | return resolved;
|
29 | }
|
30 |
|
31 | module.exports = resolveCommand;
|