2018-07-06 04:43:02 +00:00
|
|
|
const is = require('@sindresorhus/is');
|
2018-05-09 06:03:59 +00:00
|
|
|
const {
|
|
|
|
getManagerConfig,
|
|
|
|
mergeChildConfig,
|
|
|
|
filterConfig,
|
|
|
|
} = require('../../../config');
|
|
|
|
const { applyPackageRules } = require('../../../util/package-rules');
|
|
|
|
const { get } = require('../../../manager');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
flattenUpdates,
|
|
|
|
};
|
|
|
|
|
2018-07-06 04:43:02 +00:00
|
|
|
// Return only rules that contain an updateType
|
|
|
|
function getUpdateTypeRules(packageRules) {
|
|
|
|
return packageRules.filter(rule => !is.empty(rule.updateTypes));
|
|
|
|
}
|
|
|
|
|
2018-05-09 06:03:59 +00:00
|
|
|
function flattenUpdates(config, packageFiles) {
|
|
|
|
const updates = [];
|
|
|
|
for (const [manager, files] of Object.entries(packageFiles)) {
|
|
|
|
const managerConfig = getManagerConfig(config, manager);
|
|
|
|
for (const packageFile of files) {
|
|
|
|
const packageFileConfig = mergeChildConfig(managerConfig, packageFile);
|
|
|
|
for (const dep of packageFile.deps) {
|
2018-05-31 18:53:29 +00:00
|
|
|
if (dep.updates.length) {
|
2018-06-16 07:28:11 +00:00
|
|
|
const depConfig = mergeChildConfig(packageFileConfig, dep);
|
2018-05-31 18:53:29 +00:00
|
|
|
delete depConfig.deps;
|
|
|
|
for (const update of dep.updates) {
|
|
|
|
let updateConfig = mergeChildConfig(depConfig, update);
|
|
|
|
delete updateConfig.updates;
|
2018-06-16 07:28:11 +00:00
|
|
|
updateConfig = applyPackageRules(updateConfig);
|
2018-07-06 04:43:02 +00:00
|
|
|
// Keep only rules that haven't been applied yet (with updateTypes)
|
|
|
|
updateConfig.packageRules = getUpdateTypeRules(
|
|
|
|
updateConfig.packageRules
|
|
|
|
);
|
2018-05-31 18:53:29 +00:00
|
|
|
// apply major/minor/patch/pin/digest
|
|
|
|
updateConfig = mergeChildConfig(
|
|
|
|
updateConfig,
|
2018-07-04 08:11:53 +00:00
|
|
|
updateConfig[updateConfig.updateType]
|
2018-05-31 18:53:29 +00:00
|
|
|
);
|
2018-07-05 20:23:48 +00:00
|
|
|
// Apply again in case any were added by the updateType config
|
2018-06-27 05:14:41 +00:00
|
|
|
updateConfig = applyPackageRules(updateConfig);
|
2018-05-31 18:53:29 +00:00
|
|
|
updateConfig.depNameSanitized = updateConfig.depName
|
|
|
|
? updateConfig.depName
|
|
|
|
.replace('@types/', '')
|
|
|
|
.replace('@', '')
|
|
|
|
.replace('/', '-')
|
|
|
|
.replace(/\s+/g, '-')
|
|
|
|
.toLowerCase()
|
|
|
|
: undefined;
|
2018-06-29 04:55:42 +00:00
|
|
|
if (
|
|
|
|
updateConfig.language === 'docker' &&
|
|
|
|
updateConfig.depName.match(/(^|\/)node$/)
|
|
|
|
) {
|
|
|
|
updateConfig.managerBranchPrefix = '';
|
|
|
|
updateConfig.depNameSanitized = 'node';
|
|
|
|
}
|
2018-05-31 18:53:29 +00:00
|
|
|
delete updateConfig.repoIsOnboarded;
|
|
|
|
delete updateConfig.renovateJsonPresent;
|
|
|
|
updates.push(updateConfig);
|
|
|
|
}
|
2018-05-09 06:03:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
get(manager, 'supportsLockFileMaintenance') &&
|
|
|
|
managerConfig.lockFileMaintenance.enabled
|
|
|
|
) {
|
|
|
|
const lockFileConfig = mergeChildConfig(
|
|
|
|
managerConfig,
|
|
|
|
managerConfig.lockFileMaintenance
|
|
|
|
);
|
2018-07-04 08:11:53 +00:00
|
|
|
lockFileConfig.updateType = 'lockFileMaintenance';
|
2018-05-09 06:03:59 +00:00
|
|
|
updates.push(lockFileConfig);
|
|
|
|
}
|
|
|
|
}
|
2018-05-09 09:37:35 +00:00
|
|
|
return updates
|
|
|
|
.filter(update => update.enabled)
|
|
|
|
.map(update => filterConfig(update, 'branch'));
|
2018-05-09 06:03:59 +00:00
|
|
|
}
|