"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const modules_yaml_1 = require("@pnpm/modules-yaml");
const utils_1 = require("@pnpm/utils");
const path = require("path");
const pnpm_shrinkwrap_1 = require("pnpm-shrinkwrap");
exports.default = (importers, shrinkwrapDirectory, opts) => __awaiter(this, void 0, void 0, function* () {
    const virtualStoreDir = yield utils_1.realNodeModulesDir(shrinkwrapDirectory);
    const modules = yield modules_yaml_1.read(virtualStoreDir);
    return {
        importers: yield Promise.all(importers.map((importer) => __awaiter(this, void 0, void 0, function* () {
            let pkg = (yield utils_1.safeReadPackageFromDir(importer.prefix)) || {};
            const modulesDir = yield utils_1.realNodeModulesDir(importer.prefix);
            const importerId = pnpm_shrinkwrap_1.getImporterId(shrinkwrapDirectory, importer.prefix);
            return {
                bin: importer.bin || path.join(importer.prefix, 'node_modules', '.bin'),
                currentShamefullyFlatten: modules && modules.importers[importerId] && modules.importers[importerId].shamefullyFlatten,
                hoistedAliases: modules && modules.importers[importerId] && modules.importers[importerId].hoistedAliases || {},
                id: importerId,
                modulesDir,
                pkg,
                prefix: importer.prefix,
                shamefullyFlatten: Boolean(typeof importer.shamefullyFlatten === 'boolean' ? importer.shamefullyFlatten : opts.shamefullyFlatten),
            };
        }))),
        include: modules && modules.included || { dependencies: true, devDependencies: true, optionalDependencies: true },
        modules,
        pendingBuilds: modules && modules.pendingBuilds || [],
        registries: modules && modules.registries && utils_1.normalizeRegistries(modules.registries),
        skipped: new Set(modules && modules.skipped || []),
        virtualStoreDir,
    };
});
//# sourceMappingURL=index.js.map