"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const R = require("ramda");
const sortPackages = R.sortBy(R.prop('name'));
async function default_1(project, tree, opts) {
    const pkgs = sortPackages(flatten([
        ...(tree.optionalDependencies || []),
        ...(tree.dependencies || []),
        ...(tree.devDependencies || []),
        ...(tree.unsavedDependencies || []),
    ]));
    if (!opts.alwaysPrintRootPackage && !pkgs.length)
        return '';
    if (opts.long) {
        let firstLine = project.path;
        if (project.name) {
            firstLine += `:${project.name}`;
            if (project.version) {
                firstLine += `@${project.version}`;
            }
        }
        return [
            firstLine,
            ...pkgs.map((pkg) => `${pkg.path}:${pkg.name}@${pkg.version}`),
        ].join('\n');
    }
    return [
        project.path,
        ...pkgs.map((pkg) => pkg.path),
    ].join('\n');
}
exports.default = default_1;
function flatten(nodes) {
    let packages = [];
    for (const node of nodes) {
        packages.push(node);
        if (node.dependencies && node.dependencies.length) {
            packages = packages.concat(flatten(node.dependencies));
        }
    }
    return packages;
}
