"use strict";
exports.id = "InteractiveUpgrader";
exports.ids = ["InteractiveUpgrader"];
exports.modules = {

/***/ 787280
/*!***********************************************************!*\
  !*** ./lib-intermediate-esm/logic/InteractiveUpgrader.js ***!
  \***********************************************************/
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   InteractiveUpgrader: () => (/* binding */ InteractiveUpgrader)
/* harmony export */ });
/* harmony import */ var _rushstack_npm_check_fork__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @rushstack/npm-check-fork */ 366560);
/* harmony import */ var _rushstack_npm_check_fork__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_rushstack_npm_check_fork__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _rushstack_terminal__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @rushstack/terminal */ 367587);
/* harmony import */ var _rushstack_terminal__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _utilities_InteractiveUpgradeUI__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utilities/InteractiveUpgradeUI */ 580636);
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.



class InteractiveUpgrader {
    constructor(rushConfiguration) {
        this._rushConfiguration = rushConfiguration;
    }
    async upgradeAsync() {
        const rushProject = await this._getUserSelectedProjectForUpgradeAsync();
        const dependenciesState = await this._getPackageDependenciesStatusAsync(rushProject);
        const depsToUpgrade = await this._getUserSelectedDependenciesToUpgradeAsync(dependenciesState);
        return { projects: [rushProject], depsToUpgrade };
    }
    async _getUserSelectedDependenciesToUpgradeAsync(packages) {
        return (0,_utilities_InteractiveUpgradeUI__WEBPACK_IMPORTED_MODULE_2__.upgradeInteractive)(packages);
    }
    async _getUserSelectedProjectForUpgradeAsync() {
        const projects = this._rushConfiguration.projects;
        const { default: search } = await Promise.resolve(/*! import() */).then(__webpack_require__.t.bind(__webpack_require__, /*! @inquirer/search */ 381622, 23));
        return await search({
            message: 'Select a project you would like to upgrade',
            source: (term) => {
                const choices = projects.map((project) => ({
                    name: _rushstack_terminal__WEBPACK_IMPORTED_MODULE_1__.Colorize.green(project.packageName),
                    short: project.packageName,
                    value: project
                }));
                if (!term) {
                    return choices;
                }
                const filter = term.toUpperCase();
                return choices.filter((choice) => choice.short.toUpperCase().includes(filter));
            },
            pageSize: 12
        });
    }
    async _getPackageDependenciesStatusAsync(rushProject) {
        var _a;
        const { projectFolder } = rushProject;
        const currentState = await (0,_rushstack_npm_check_fork__WEBPACK_IMPORTED_MODULE_0__.NpmCheck)({
            cwd: projectFolder
        });
        return (_a = currentState.packages) !== null && _a !== void 0 ? _a : [];
    }
}
//# sourceMappingURL=InteractiveUpgrader.js.map

/***/ },

/***/ 580636
/*!****************************************************************!*\
  !*** ./lib-intermediate-esm/utilities/InteractiveUpgradeUI.js ***!
  \****************************************************************/
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   UI_GROUPS: () => (/* binding */ UI_GROUPS),
/* harmony export */   upgradeInteractive: () => (/* binding */ upgradeInteractive)
/* harmony export */ });
/* harmony import */ var _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @rushstack/terminal */ 367587);
/* harmony import */ var _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__);
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

function greenUnderlineBold(text) {
    return _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.underline(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.bold(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.green(text)));
}
function yellowUnderlineBold(text) {
    return _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.underline(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.bold(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.yellow(text)));
}
function redUnderlineBold(text) {
    return _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.underline(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.bold(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.red(text)));
}
function magentaUnderlineBold(text) {
    return _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.underline(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.bold(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.magenta(text)));
}
const UI_GROUPS = [
    {
        title: greenUnderlineBold('Update package.json to match version installed.'),
        filter: { mismatch: true, bump: undefined }
    },
    {
        title: `${greenUnderlineBold('Missing.')} ${_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.green('You probably want these.')}`,
        filter: { notInstalled: true, bump: undefined }
    },
    {
        title: `${greenUnderlineBold('Patch Update')} ${_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.green('Backwards-compatible bug fixes.')}`,
        filter: { bump: 'patch' }
    },
    {
        title: `${yellowUnderlineBold('Minor Update')} ${_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.yellow('New backwards-compatible features.')}`,
        bgColor: 'yellow',
        filter: { bump: 'minor' }
    },
    {
        title: `${redUnderlineBold('Major Update')} ${_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.red('Potentially breaking API changes. Use caution.')}`,
        filter: { bump: 'major' }
    },
    {
        title: `${magentaUnderlineBold('Non-Semver')} ${_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.magenta('Versions less than 1.0.0, caution.')}`,
        filter: { bump: 'nonSemver' }
    }
];
function label(dep) {
    const bumpInstalled = dep.bump ? dep.installed : '';
    const installed = dep.mismatch ? dep.packageJson : bumpInstalled;
    const name = _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.yellow(dep.moduleName);
    const type = dep.devDependency ? _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.green(' devDep') : '';
    const missing = dep.notInstalled ? _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.red(' missing') : '';
    const homepage = dep.homepage ? _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.blue(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.underline(dep.homepage)) : '';
    return [
        name + type + missing,
        installed,
        installed && '>',
        _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.Colorize.bold(dep.latest || ''),
        dep.latest ? homepage : getErrorDep(dep)
    ];
}
function getErrorDep(dep) {
    if (dep.regError !== undefined && dep.regError && dep.regError instanceof Error) {
        return dep.regError.message;
    }
    else if (dep.pkgError !== undefined && dep.pkgError && dep.pkgError instanceof Error) {
        return dep.pkgError.message;
    }
    return '';
}
function short(dep) {
    return `${dep.moduleName}@${dep.latest}`;
}
function getChoice(dep) {
    if (!dep.mismatch && !dep.bump && !dep.notInstalled) {
        return false;
    }
    return {
        value: dep,
        name: label(dep),
        short: short(dep)
    };
}
const upgradeInteractive = async (pkgs) => {
    const { default: checkbox, Separator } = await Promise.resolve(/*! import() */).then(__webpack_require__.t.bind(__webpack_require__, /*! @inquirer/checkbox */ 30979, 23));
    function unselectable(options) {
        return new Separator(_rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.AnsiEscape.removeCodes(options ? options.title : ''));
    }
    function createChoices(packages, options) {
        const { filter } = options;
        const filteredChoices = packages.filter((pkg) => {
            if ('mismatch' in filter && pkg.mismatch !== filter.mismatch) {
                return false;
            }
            else if ('bump' in filter && pkg.bump !== filter.bump) {
                return false;
            }
            else if ('notInstalled' in filter && pkg.notInstalled !== filter.notInstalled) {
                return false;
            }
            else {
                return true;
            }
        });
        const choices = filteredChoices
            .map(getChoice)
            .filter(Boolean);
        const cliTable = new _rushstack_terminal__WEBPACK_IMPORTED_MODULE_0__.TerminalTable({
            borderless: true,
            colWidths: [50, 10, 3, 10, 100]
        });
        for (const choice of choices) {
            if (typeof choice === 'object' && 'name' in choice) {
                // choice.name is string[] at this point (set by label()); it is only replaced
                // with a string after the table is rendered below.
                cliTable.push(choice.name);
            }
        }
        const choicesAsATable = cliTable.getLines();
        for (let i = 0; i < choices.length; i++) {
            const choice = choices[i];
            if (typeof choice === 'object' && 'name' in choice) {
                choice.name = choicesAsATable[i];
            }
        }
        if (choices.length > 0) {
            choices.unshift(unselectable(options));
            choices.unshift(unselectable());
            return choices;
        }
    }
    const choicesGrouped = UI_GROUPS.map((group) => createChoices(pkgs, group)).filter(Boolean);
    const choices = [];
    for (const choiceGroup of choicesGrouped) {
        if (choiceGroup) {
            choices.push(...choiceGroup);
        }
    }
    if (!choices.length) {
        // eslint-disable-next-line no-console
        console.log('All dependencies are up to date!');
        return { packages: [] };
    }
    choices.push(unselectable());
    choices.push(unselectable({ title: 'Space to select. Enter to start upgrading. Control-C to cancel.' }));
    const packages = await checkbox({
        message: 'Choose which packages to upgrade',
        // At this point choices only contains Separator and IUpgradeInteractiveDepChoice items
        // with their `name` fields already set to strings by createChoices.
        choices: choices.concat(unselectable()),
        pageSize: process.stdout.rows - 2
    });
    return { packages };
};
//# sourceMappingURL=InteractiveUpgradeUI.js.map

/***/ }

};
;
//# sourceMappingURL=InteractiveUpgrader.js.map