"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = exports.help = exports.commandNames = exports.cliOptionsTypes = exports.rcOptionsTypes = void 0;
const cli_utils_1 = require("@pnpm/cli-utils");
const common_cli_options_help_1 = require("@pnpm/common-cli-options-help");
const config_1 = require("@pnpm/config");
const error_1 = require("@pnpm/error");
const R = require("ramda");
const renderHelp = require("render-help");
const list_1 = require("./list");
function rcOptionsTypes() {
    return R.pick([
        'dev',
        'global-dir',
        'global',
        'json',
        'long',
        'only',
        'optional',
        'parseable',
        'production',
    ], config_1.types);
}
exports.rcOptionsTypes = rcOptionsTypes;
exports.cliOptionsTypes = () => ({
    ...rcOptionsTypes(),
    recursive: Boolean,
});
exports.commandNames = ['why'];
function help() {
    return renderHelp({
        description: `Shows the packages that depend on <pkg>
For example: pnpm why babel-* eslint-*`,
        descriptionLists: [
            {
                title: 'Options',
                list: [
                    {
                        description: `Perform command on every package in subdirectories \
or on every workspace package, when executed inside a workspace. \
For options that may be used with \`-r\`, see "pnpm help recursive"`,
                        name: '--recursive',
                        shortAlias: '-r',
                    },
                    {
                        description: 'Show extended information',
                        name: '--long',
                    },
                    {
                        description: 'Show parseable output instead of tree view',
                        name: '--parseable',
                    },
                    {
                        description: 'Show information in JSON format',
                        name: '--json',
                    },
                    {
                        description: 'List packages in the global install prefix instead of in the current project',
                        name: '--global',
                        shortAlias: '-g',
                    },
                    {
                        description: 'Display only the dependency graph for packages in \`dependencies\` and \`optionalDependencies\`',
                        name: '--prod',
                    },
                    {
                        description: 'Display only the dependency graph for packages in \`devDependencies\`',
                        name: '--dev',
                    },
                    {
                        description: "Don't display packages from `optionalDependencies`",
                        name: '--no-optional',
                    },
                    common_cli_options_help_1.OPTIONS.globalDir,
                    ...common_cli_options_help_1.UNIVERSAL_OPTIONS,
                ],
            },
            common_cli_options_help_1.FILTERING,
        ],
        url: cli_utils_1.docsUrl('why'),
        usages: [
            'pnpm why <pkg> ...',
        ],
    });
}
exports.help = help;
function handler(opts, params) {
    var _a;
    if (!params.length) {
        throw new error_1.default('MISSING_PACKAGE_NAME', '`pnpm why` requires the package name');
    }
    return list_1.handler({
        ...opts,
        cliOptions: {
            ...((_a = opts.cliOptions) !== null && _a !== void 0 ? _a : {}),
            depth: Infinity,
        },
    }, params);
}
exports.handler = handler;
//# sourceMappingURL=why.js.map