"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lockfile_file_1 = require("@pnpm/lockfile-file");
const modules_yaml_1 = require("@pnpm/modules-yaml");
const normalize_registries_1 = require("@pnpm/normalize-registries");
const path = require("path");
const realpathMissing = require("realpath-missing");
async function default_1(projects, opts) {
    var _a, _b;
    const relativeModulesDir = (_a = opts.modulesDir) !== null && _a !== void 0 ? _a : 'node_modules';
    const rootModulesDir = await realpathMissing(path.join(opts.lockfileDir, relativeModulesDir));
    const modules = await modules_yaml_1.read(rootModulesDir);
    return {
        currentHoistPattern: modules === null || modules === void 0 ? void 0 : modules.hoistPattern,
        currentPublicHoistPattern: modules === null || modules === void 0 ? void 0 : modules.publicHoistPattern,
        hoist: !modules ? undefined : Boolean(modules.hoistPattern),
        hoistedDependencies: (_b = modules === null || modules === void 0 ? void 0 : modules.hoistedDependencies) !== null && _b !== void 0 ? _b : {},
        include: (modules === null || modules === void 0 ? void 0 : modules.included) || { dependencies: true, devDependencies: true, optionalDependencies: true },
        modules,
        pendingBuilds: (modules === null || modules === void 0 ? void 0 : modules.pendingBuilds) || [],
        projects: await Promise.all(projects.map(async (project) => {
            var _a, _b;
            const modulesDir = await realpathMissing(path.join(project.rootDir, (_a = project.modulesDir) !== null && _a !== void 0 ? _a : relativeModulesDir));
            const importerId = lockfile_file_1.getLockfileImporterId(opts.lockfileDir, project.rootDir);
            return {
                ...project,
                binsDir: (_b = project.binsDir) !== null && _b !== void 0 ? _b : path.join(project.rootDir, relativeModulesDir, '.bin'),
                id: importerId,
                modulesDir,
            };
        })),
        registries: (modules === null || modules === void 0 ? void 0 : modules.registries) && normalize_registries_1.default(modules.registries),
        rootModulesDir,
        skipped: new Set((modules === null || modules === void 0 ? void 0 : modules.skipped) || []),
    };
}
exports.default = default_1;
//# sourceMappingURL=index.js.map