mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 14:36:25 +00:00
refactor: move config globals inside functions (#1088)
This was necessary when attempting to use jest mock all
This commit is contained in:
parent
9dd3fd968c
commit
1e5a5cab79
4 changed files with 25 additions and 15 deletions
|
@ -1,12 +1,7 @@
|
||||||
const deepcopy = require('deepcopy');
|
const deepcopy = require('deepcopy');
|
||||||
const options = require('./definitions').getOptions();
|
const options = require('./definitions').getOptions();
|
||||||
|
|
||||||
const allowedStrings = [];
|
let allowedStrings;
|
||||||
options.forEach(option => {
|
|
||||||
if (option.allowString) {
|
|
||||||
allowedStrings.push(option.name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
massageConfig,
|
massageConfig,
|
||||||
|
@ -14,6 +9,14 @@ module.exports = {
|
||||||
|
|
||||||
// Returns a massaged config
|
// Returns a massaged config
|
||||||
function massageConfig(config) {
|
function massageConfig(config) {
|
||||||
|
if (!allowedStrings) {
|
||||||
|
allowedStrings = [];
|
||||||
|
options.forEach(option => {
|
||||||
|
if (option.allowString) {
|
||||||
|
allowedStrings.push(option.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
const massagedConfig = deepcopy(config);
|
const massagedConfig = deepcopy(config);
|
||||||
for (const key of Object.keys(config)) {
|
for (const key of Object.keys(config)) {
|
||||||
const val = config[key];
|
const val = config[key];
|
||||||
|
|
|
@ -2,10 +2,7 @@ const later = require('later');
|
||||||
const deepcopy = require('deepcopy');
|
const deepcopy = require('deepcopy');
|
||||||
const options = require('./definitions').getOptions();
|
const options = require('./definitions').getOptions();
|
||||||
|
|
||||||
const optionTypes = {};
|
let optionTypes;
|
||||||
options.forEach(option => {
|
|
||||||
optionTypes[option.name] = option.type;
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
migrateConfig,
|
migrateConfig,
|
||||||
|
@ -27,6 +24,12 @@ const removedOptions = [
|
||||||
|
|
||||||
// Returns a migrated config
|
// Returns a migrated config
|
||||||
function migrateConfig(config) {
|
function migrateConfig(config) {
|
||||||
|
if (!optionTypes) {
|
||||||
|
optionTypes = {};
|
||||||
|
options.forEach(option => {
|
||||||
|
optionTypes[option.name] = option.type;
|
||||||
|
});
|
||||||
|
}
|
||||||
let isMigrated = false;
|
let isMigrated = false;
|
||||||
const migratedConfig = deepcopy(config);
|
const migratedConfig = deepcopy(config);
|
||||||
for (const key of Object.keys(config)) {
|
for (const key of Object.keys(config)) {
|
||||||
|
|
|
@ -161,7 +161,8 @@ async function getPreset(preset, logger) {
|
||||||
logger.warn(`Cannot find preset ${preset}`);
|
logger.warn(`Cannot find preset ${preset}`);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
logger.debug({ presetConfig }, `Found preset ${preset}`);
|
logger.debug(`Found preset ${preset}`);
|
||||||
|
logger.trace({ presetConfig });
|
||||||
if (params) {
|
if (params) {
|
||||||
const argMapping = {};
|
const argMapping = {};
|
||||||
for (const [index, value] of params.entries()) {
|
for (const [index, value] of params.entries()) {
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
const options = require('./definitions').getOptions();
|
const options = require('./definitions').getOptions();
|
||||||
const { hasValidSchedule } = require('../workers/branch/schedule');
|
const { hasValidSchedule } = require('../workers/branch/schedule');
|
||||||
|
|
||||||
const optionTypes = {};
|
let optionTypes;
|
||||||
options.forEach(option => {
|
|
||||||
optionTypes[option.name] = option.type;
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
validateConfig,
|
validateConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
function validateConfig(config) {
|
function validateConfig(config) {
|
||||||
|
if (!optionTypes) {
|
||||||
|
optionTypes = {};
|
||||||
|
options.forEach(option => {
|
||||||
|
optionTypes[option.name] = option.type;
|
||||||
|
});
|
||||||
|
}
|
||||||
let errors = [];
|
let errors = [];
|
||||||
let warnings = [];
|
let warnings = [];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue