runGlobal.js
2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = __importDefault(require("lodash"));
const chalk_1 = __importDefault(require("chalk"));
const logging_1 = require("../logging");
const getInstalledPackages_1 = __importDefault(require("./getInstalledPackages"));
const upgradePackageDefinitions_1 = __importDefault(require("./upgradePackageDefinitions"));
/** Checks global dependencies for upgrades. */
async function runGlobal(options) {
const chalk = options.color ? new chalk_1.default.Instance({ level: 1 }) : chalk_1.default;
(0, logging_1.print)(options, 'Getting installed packages', 'verbose');
const globalPackages = await (0, getInstalledPackages_1.default)(lodash_1.default.pick(options, [
'cwd',
'filter',
'filterVersion',
'global',
'packageManager',
'prefix',
'reject',
'rejectVersion',
]));
(0, logging_1.print)(options, 'globalPackages', 'silly');
(0, logging_1.print)(options, globalPackages, 'silly');
(0, logging_1.print)(options, '', 'silly');
(0, logging_1.print)(options, `Fetching ${options.target} versions`, 'verbose');
const [upgraded, latest] = await (0, upgradePackageDefinitions_1.default)(globalPackages, options);
(0, logging_1.print)(options, latest, 'silly');
const upgradedPackageNames = Object.keys(upgraded);
(0, logging_1.printUpgrades)(options, {
current: globalPackages,
upgraded,
// since an interactive upgrade of globals is not available, the numUpgraded is always all
numUpgraded: upgradedPackageNames.length,
total: upgradedPackageNames.length,
});
const instruction = upgraded ? upgradedPackageNames.map(pkg => pkg + '@' + upgraded[pkg]).join(' ') : '[package]';
if (options.json) {
// since global packages do not have a package.json, return the upgraded deps directly (no version range replacements)
(0, logging_1.printJson)(options, upgraded);
}
else if (instruction.length) {
const upgradeCmd = options.packageManager === 'yarn' ? 'yarn global upgrade' : 'npm -g install';
(0, logging_1.print)(options, '\n' +
chalk.cyan('ncu') +
' itself cannot upgrade global packages. Run the following to upgrade all global packages: \n\n' +
chalk.cyan(`${upgradeCmd} ` + instruction) +
'\n');
}
// if errorLevel is 2, exit with non-zero error code
if (options.cli && options.errorLevel === 2 && upgradedPackageNames.length > 0) {
process.exit(1);
}
return upgraded;
}
exports.default = runGlobal;
//# sourceMappingURL=runGlobal.js.map