"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = require("@pnpm/logger");
const list_1 = require("../list");
exports.default = async (pkgs, args, cmd, opts) => {
    if (opts.lockfileDirectory) {
        console.log(await list_1.render(pkgs.map((pkg) => pkg.path), args, Object.assign(Object.assign({}, opts), { alwaysPrintRootPackage: opts.depth === -1, lockfileDirectory: opts.lockfileDirectory }), cmd));
        return;
    }
    const outputs = [];
    for (const { path } of pkgs) {
        try {
            const output = await list_1.render([path], args, Object.assign(Object.assign({}, opts), { alwaysPrintRootPackage: opts.depth === -1, lockfileDirectory: opts.lockfileDirectory || path }), cmd);
            if (!output)
                continue;
            outputs.push(output);
        }
        catch (err) {
            logger_1.default.info(err);
            err['prefix'] = path; // tslint:disable-line:no-string-literal
            throw err;
        }
    }
    if (outputs.length === 0)
        return;
    const joiner = typeof opts.depth === 'number' && opts.depth > -1 ? '\n\n' : '\n';
    const allOutput = outputs.join(joiner);
    console.log(allOutput);
};
