{"size": 836, "ext": "js", "max_stars_repo_path": "node_modules/node-sass/node_modules/cross-spawn/lib/resolveCommand.js", "max_stars_repo_name": "firojkabir/lsg", "max_stars_repo_stars_event_min_datetime": "2016-08-11T16:27:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-10T06:20:09.000Z", "max_issues_repo_path": "node_modules/node-sass/node_modules/cross-spawn/lib/resolveCommand.js", "max_issues_repo_name": "firojkabir/lsg", "max_issues_repo_issues_event_min_datetime": "2020-09-05T02:44:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T04:32:48.000Z", "max_forks_repo_path": "node_modules/node-sass/node_modules/cross-spawn/lib/resolveCommand.js", "max_forks_repo_name": "firojkabir/lsg", "max_forks_repo_forks_event_min_datetime": "2015-07-08T20:31:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T01:33:27.000Z"}
{"max_stars_count": 8, "max_issues_count": 15, "max_forks_count": 6, "avg_line_length": 26.125, "max_line_length": 92, "alphanum_fraction": 0.5992822967}
'use strict';

var path = require('path');
var which = require('which');
var LRU = require('lru-cache');

var commandCache = new LRU({ max: 50, maxAge: 30 * 1000 });  // Cache just for 30sec

function resolveCommand(command, noExtension) {
    var resolved;

    noExtension = !!noExtension;
    resolved = commandCache.get(command + '!' + noExtension);

    // Check if its resolved in the cache
    if (commandCache.has(command)) {
        return commandCache.get(command);
    }

    try {
        resolved = !noExtension ?
            which.sync(command) :
            which.sync(command, { pathExt: path.delimiter + (process.env.PATHEXT || '') });
    } catch (e) { /* empty */ }

    commandCache.set(command + '!' + noExtension, resolved);

    return resolved;
}

module.exports = resolveCommand;
