// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { BaseInstallAction } from './BaseInstallAction';
import { SelectionParameterSet } from '../parsing/SelectionParameterSet';
import { getVariantAsync } from '../../api/Variants';
export class InstallAction extends BaseInstallAction {
    constructor(parser) {
        var _a;
        super({
            actionName: 'install',
            summary: 'Install package dependencies for all projects in the repo according to the shrinkwrap file',
            documentation: 'The "rush install" command installs package dependencies for all your projects,' +
                ' based on the shrinkwrap file that is created/updated using "rush update".' +
                ' (This "shrinkwrap" file stores a central inventory of all dependencies and versions' +
                ' for projects in your repo. It is found in the "common/config/rush" folder.)' +
                ' If the shrinkwrap file is missing or outdated (e.g. because project package.json files have' +
                ' changed), "rush install" will fail and tell you to run "rush update" instead.' +
                ' This read-only nature is the main feature:  Continuous integration builds should use' +
                ' "rush install" instead of "rush update" to catch developers who forgot to commit their' +
                ' shrinkwrap changes.  Cautious people can also use "rush install" if they want to avoid' +
                ' accidentally updating their shrinkwrap file.',
            parser
        });
        this._selectionParameters = new SelectionParameterSet(this.rushConfiguration, this, {
            gitOptions: {
                // Include lockfile processing since this expands the selection, and we need to select
                // at least the same projects selected with the same query to "rush build"
                includeExternalDependencies: true,
                // Disable filtering because rush-project.json is riggable and therefore may not be available
                enableFiltering: false
            },
            includeSubspaceSelector: true,
            cwd: this.parser.cwd
        });
        this._checkOnlyParameter = this.defineFlagParameter({
            parameterLongName: '--check-only',
            description: `Only check the validity of the shrinkwrap file without performing an install.`
        });
        if ((_a = this.rushConfiguration) === null || _a === void 0 ? void 0 : _a.isPnpm) {
            this._resolutionOnlyParameter = this.defineFlagParameter({
                parameterLongName: '--resolution-only',
                description: `Only perform dependency resolution, useful for ensuring peer dependendencies are up to date. Note that this flag is only supported when using the pnpm package manager.`
            });
        }
    }
    async buildInstallOptionsAsync() {
        var _a, _b, _c, _d, _e;
        const selectedProjects = (_b = (await ((_a = this._selectionParameters) === null || _a === void 0 ? void 0 : _a.getSelectedProjectsAsync(this.terminal)))) !== null && _b !== void 0 ? _b : new Set(this.rushConfiguration.projects);
        const variant = await getVariantAsync(this._variantParameter, this.rushConfiguration, false);
        return {
            debug: this.parser.isDebug,
            allowShrinkwrapUpdates: false,
            bypassPolicyAllowed: true,
            bypassPolicy: this._bypassPolicyParameter.value,
            noLink: this._noLinkParameter.value,
            fullUpgrade: false,
            recheckShrinkwrap: false,
            offline: this._offlineParameter.value,
            networkConcurrency: this._networkConcurrencyParameter.value,
            collectLogFile: this._debugPackageManagerParameter.value,
            variant,
            // Because the 'defaultValue' option on the _maxInstallAttempts parameter is set,
            // it is safe to assume that the value is not null
            maxInstallAttempts: this._maxInstallAttempts.value,
            // These are derived independently of the selection for command line brevity
            selectedProjects,
            pnpmFilterArgumentValues: (_d = (await ((_c = this._selectionParameters) === null || _c === void 0 ? void 0 : _c.getPnpmFilterArgumentValuesAsync(this.terminal)))) !== null && _d !== void 0 ? _d : [],
            checkOnly: this._checkOnlyParameter.value,
            resolutionOnly: (_e = this._resolutionOnlyParameter) === null || _e === void 0 ? void 0 : _e.value,
            beforeInstallAsync: (subspace) => this.rushSession.hooks.beforeInstall.promise(this, subspace, variant),
            afterInstallAsync: (subspace) => this.rushSession.hooks.afterInstall.promise(this, subspace, variant),
            terminal: this.terminal
        };
    }
}
//# sourceMappingURL=InstallAction.js.map