"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@pnpm/utils");
const mem = require("mem");
const createResolver_1 = require("./createResolver");
function default_1(opts) {
    const resolve = createResolver_1.default(opts);
    return mem(getLatestVersion.bind(null, resolve, opts));
}
exports.default = default_1;
async function getLatestVersion(resolve, opts, packageName) {
    const resolution = await resolve({ alias: packageName, pref: 'latest' }, {
        lockfileDirectory: opts.lockfileDirectory,
        preferredVersions: {},
        prefix: opts.prefix,
        registry: utils_1.pickRegistryForPackage(opts.registries, packageName),
    });
    return resolution && resolution.latest || null;
}
exports.getLatestVersion = getLatestVersion;
