upgradePackageDefinitions.js
2.7 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
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.upgradePackageDefinitions = void 0;
const lodash_1 = __importDefault(require("lodash"));
const semver_1 = require("semver");
const getPeerDependenciesFromRegistry_1 = __importDefault(require("./getPeerDependenciesFromRegistry"));
const queryVersions_1 = __importDefault(require("./queryVersions"));
const upgradeDependencies_1 = __importDefault(require("./upgradeDependencies"));
const keyValueBy_1 = __importDefault(require("./keyValueBy"));
/**
* Returns an 3-tuple of upgradedDependencies, their latest versions and the resulting peer dependencies.
*
* @param currentDependencies
* @param options
* @returns
*/
async function upgradePackageDefinitions(currentDependencies, options) {
const latestVersionResults = await (0, queryVersions_1.default)(currentDependencies, options);
const latestVersions = (0, keyValueBy_1.default)(latestVersionResults, (dep, result) => (result === null || result === void 0 ? void 0 : result.version)
? {
[dep]: result.version,
}
: null);
const upgradedDependencies = (0, upgradeDependencies_1.default)(currentDependencies, latestVersions, {
removeRange: options.removeRange,
});
const filteredUpgradedDependencies = lodash_1.default.pickBy(upgradedDependencies, (v, dep) => {
return !options.jsonUpgraded || !options.minimal || !(0, semver_1.satisfies)(latestVersions[dep], currentDependencies[dep]);
});
if (options.peer && !lodash_1.default.isEmpty(filteredUpgradedDependencies)) {
const upgradedPeerDependencies = await (0, getPeerDependenciesFromRegistry_1.default)(filteredUpgradedDependencies, options);
const peerDependencies = { ...options.peerDependencies, ...upgradedPeerDependencies };
if (!lodash_1.default.isEqual(options.peerDependencies, peerDependencies)) {
const [newUpgradedDependencies, newLatestVersions, newPeerDependencies] = await upgradePackageDefinitions({ ...currentDependencies, ...filteredUpgradedDependencies }, { ...options, peerDependencies, loglevel: 'silent' });
return [
{ ...filteredUpgradedDependencies, ...newUpgradedDependencies },
{ ...latestVersionResults, ...newLatestVersions },
newPeerDependencies,
];
}
}
return [filteredUpgradedDependencies, latestVersionResults, options.peerDependencies];
}
exports.upgradePackageDefinitions = upgradePackageDefinitions;
exports.default = upgradePackageDefinitions;
//# sourceMappingURL=upgradePackageDefinitions.js.map