"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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 constants_1 = require("@pnpm/constants");
const common_tags_1 = require("common-tags");
const isCI = require("is-ci");
const R = require("ramda");
const renderHelp = require("render-help");
const installDeps_1 = require("./installDeps");
exports.rcOptionsTypes = cliOptionsTypes;
function cliOptionsTypes() {
    return R.pick([
        'child-concurrency',
        'dev',
        'engine-strict',
        'frozen-lockfile',
        'force',
        'global-dir',
        'global-pnpmfile',
        'global',
        'hoist',
        'hoist-pattern',
        'ignore-pnpmfile',
        'ignore-scripts',
        'independent-leaves',
        'link-workspace-packages',
        'lock',
        'lockfile-dir',
        'lockfile-directory',
        'lockfile-only',
        'lockfile',
        'package-import-method',
        'pnpmfile',
        'prefer-frozen-lockfile',
        'prefer-offline',
        'production',
        'recursive',
        'registry',
        'reporter',
        'resolution-strategy',
        'shamefully-flatten',
        'shamefully-hoist',
        'shared-workspace-lockfile',
        'side-effects-cache-readonly',
        'side-effects-cache',
        'store',
        'store-dir',
        'strict-peer-dependencies',
        'offline',
        'only',
        'optional',
        'unsafe-perm',
        'use-running-store-server',
        'use-store-server',
        'verify-store-integrity',
        'virtual-store-dir',
    ], config_1.types);
}
exports.cliOptionsTypes = cliOptionsTypes;
exports.shorthands = {
    'D': '--dev',
    'P': '--production',
};
exports.commandNames = ['install', 'i'];
function help() {
    return renderHelp({
        aliases: ['i'],
        description: common_tags_1.oneLine `Installs all dependencies of the project in the current working directory.
      When executed inside a workspace, installs all dependencies of all projects.`,
        descriptionLists: [
            {
                title: 'Options',
                list: [
                    {
                        description: common_tags_1.oneLine `
              Run installation recursively in every package found in subdirectories.
              For options that may be used with \`-r\`, see "pnpm help recursive"`,
                        name: '--recursive',
                        shortAlias: '-r',
                    },
                    common_cli_options_help_1.OPTIONS.ignoreScripts,
                    common_cli_options_help_1.OPTIONS.offline,
                    common_cli_options_help_1.OPTIONS.preferOffline,
                    common_cli_options_help_1.OPTIONS.globalDir,
                    {
                        description: "Packages in \`devDependencies\` won't be installed",
                        name: '--prod',
                        shortAlias: '-P',
                    },
                    {
                        description: 'Only \`devDependencies\` are installed regardless of the \`NODE_ENV\`',
                        name: '--dev',
                        shortAlias: '-D',
                    },
                    {
                        description: '`optionalDependencies` are not installed',
                        name: '--no-optional',
                    },
                    {
                        description: `Don't read or generate a \`${constants_1.WANTED_LOCKFILE}\` file`,
                        name: '--no-lockfile',
                    },
                    {
                        description: `Dependencies are not downloaded. Only \`${constants_1.WANTED_LOCKFILE}\` is updated`,
                        name: '--lockfile-only',
                    },
                    {
                        description: "Don't generate a lockfile and fail if an update is needed",
                        name: '--frozen-lockfile',
                    },
                    {
                        description: `If the available \`${constants_1.WANTED_LOCKFILE}\` satisfies the \`package.json\` then perform a headless installation`,
                        name: '--prefer-frozen-lockfile',
                    },
                    {
                        description: `The directory in which the ${constants_1.WANTED_LOCKFILE} of the package will be created. Several projects may share a single lockfile`,
                        name: '--lockfile-dir <dir>',
                    },
                    {
                        description: 'Dependencies inside node_modules have access only to their listed dependencies',
                        name: '--no-hoist',
                    },
                    {
                        description: 'The subdeps will be hoisted into the root node_modules. Your code will have access to them',
                        name: '--shamefully-hoist',
                    },
                    {
                        description: common_tags_1.oneLine `
              Hoist all dependencies matching the pattern to \`node_modules/.pnpm/node_modules\`.
              The default pattern is * and matches everything. Hoisted packages can be required
              by any dependencies, so it is an emulation of a flat node_modules`,
                        name: '--hoist-pattern <pattern>',
                    },
                    common_cli_options_help_1.OPTIONS.storeDir,
                    common_cli_options_help_1.OPTIONS.virtualStoreDir,
                    {
                        description: 'Maximum number of concurrent network requests',
                        name: '--network-concurrency <number>',
                    },
                    {
                        description: 'Controls the number of child processes run parallelly to build node modules',
                        name: '--child-concurrency <number>',
                    },
                    {
                        description: 'Disable pnpm hooks defined in pnpmfile.js',
                        name: '--ignore-pnpmfile',
                    },
                    {
                        description: 'Symlinks leaf dependencies directly from the global store',
                        name: '--independent-leaves',
                    },
                    {
                        description: "If false, doesn't check whether packages in the store were mutated",
                        name: '--[no-]verify-store-integrity',
                    },
                    {
                        name: '--[no-]lock',
                    },
                    {
                        description: 'Fail on missing or invalid peer dependencies',
                        name: '--strict-peer-dependencies',
                    },
                    {
                        description: 'Starts a store server in the background. The store server will keep running after installation is done. To stop the store server, run \`pnpm server stop\`',
                        name: '--use-store-server',
                    },
                    {
                        description: 'Only allows installation with a store server. If no store server is running, installation will fail',
                        name: '--use-running-store-server',
                    },
                    {
                        description: 'Clones/hardlinks or copies packages. The selected method depends from the file system',
                        name: '--package-import-method auto',
                    },
                    {
                        description: 'Hardlink packages from the store',
                        name: '--package-import-method hardlink',
                    },
                    {
                        description: 'Copy packages from the store',
                        name: '--package-import-method copy',
                    },
                    {
                        description: 'Clone (aka copy-on-write) packages from the store',
                        name: '--package-import-method clone',
                    },
                    {
                        description: 'The default resolution strategy. Speed is preferred over deduplication',
                        name: '--resolution-strategy fast',
                    },
                    {
                        description: 'Already installed dependencies are preferred even if newer versions satisfy a range',
                        name: '--resolution-strategy fewer-dependencies',
                    },
                    ...common_cli_options_help_1.UNIVERSAL_OPTIONS,
                ],
            },
            {
                title: 'Output',
                list: [
                    {
                        description: 'No output is logged to the console, except fatal errors',
                        name: '--silent, --reporter silent',
                        shortAlias: '-s',
                    },
                    {
                        description: 'The default reporter when the stdout is TTY',
                        name: '--reporter default',
                    },
                    {
                        description: 'The output is always appended to the end. No cursor manipulations are performed',
                        name: '--reporter append-only',
                    },
                    {
                        description: 'The most verbose reporter. Prints all logs in ndjson format',
                        name: '--reporter ndjson',
                    },
                ],
            },
            common_cli_options_help_1.FILTERING,
            {
                title: 'Experimental options',
                list: [
                    {
                        description: 'Use or cache the results of (pre/post)install hooks',
                        name: '--side-effects-cache',
                    },
                    {
                        description: 'Only use the side effects cache if present, do not create it for new packages',
                        name: '--side-effects-cache-readonly',
                    },
                ],
            },
        ],
        url: cli_utils_1.docsUrl('install'),
        usages: ['pnpm install [options]'],
    });
}
exports.help = help;
function handler(input, opts) {
    const include = {
        dependencies: opts.production !== false,
        devDependencies: opts.dev !== false,
        optionalDependencies: opts.optional !== false,
    };
    return installDeps_1.default(input, {
        ...opts,
        frozenLockfileIfExists: isCI &&
            typeof opts.rawLocalConfig['frozen-lockfile'] === 'undefined',
        include,
        includeDirect: include,
    });
}
exports.handler = handler;
