"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const default_resolver_1 = require("@pnpm/default-resolver");
const utils_1 = require("@pnpm/utils");
const LRU = require("lru-cache");
const mem = require("mem");
function default_1(opts) {
    const resolve = default_resolver_1.default(Object.assign(opts, {
        fullMetadata: true,
        metaCache: new LRU({
            max: 10000,
            maxAge: 120 * 1000,
        }),
    }));
    return mem(getLatestManifest.bind(null, resolve, opts));
}
exports.default = default_1;
async function getLatestManifest(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.package || null;
}
exports.getLatestManifest = getLatestManifest;
