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 options = require('./definitions').getOptions();
|
||||
|
||||
const allowedStrings = [];
|
||||
options.forEach(option => {
|
||||
if (option.allowString) {
|
||||
allowedStrings.push(option.name);
|
||||
}
|
||||
});
|
||||
let allowedStrings;
|
||||
|
||||
module.exports = {
|
||||
massageConfig,
|
||||
|
@ -14,6 +9,14 @@ module.exports = {
|
|||
|
||||
// Returns a massaged config
|
||||
function massageConfig(config) {
|
||||
if (!allowedStrings) {
|
||||
allowedStrings = [];
|
||||
options.forEach(option => {
|
||||
if (option.allowString) {
|
||||
allowedStrings.push(option.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
const massagedConfig = deepcopy(config);
|
||||
for (const key of Object.keys(config)) {
|
||||
const val = config[key];
|
||||
|
|
|
@ -2,10 +2,7 @@ const later = require('later');
|
|||
const deepcopy = require('deepcopy');
|
||||
const options = require('./definitions').getOptions();
|
||||
|
||||
const optionTypes = {};
|
||||
options.forEach(option => {
|
||||
optionTypes[option.name] = option.type;
|
||||
});
|
||||
let optionTypes;
|
||||
|
||||
module.exports = {
|
||||
migrateConfig,
|
||||
|
@ -27,6 +24,12 @@ const removedOptions = [
|
|||
|
||||
// Returns a migrated config
|
||||
function migrateConfig(config) {
|
||||
if (!optionTypes) {
|
||||
optionTypes = {};
|
||||
options.forEach(option => {
|
||||
optionTypes[option.name] = option.type;
|
||||
});
|
||||
}
|
||||
let isMigrated = false;
|
||||
const migratedConfig = deepcopy(config);
|
||||
for (const key of Object.keys(config)) {
|
||||
|
|
|
@ -161,7 +161,8 @@ async function getPreset(preset, logger) {
|
|||
logger.warn(`Cannot find preset ${preset}`);
|
||||
return {};
|
||||
}
|
||||
logger.debug({ presetConfig }, `Found preset ${preset}`);
|
||||
logger.debug(`Found preset ${preset}`);
|
||||
logger.trace({ presetConfig });
|
||||
if (params) {
|
||||
const argMapping = {};
|
||||
for (const [index, value] of params.entries()) {
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
const options = require('./definitions').getOptions();
|
||||
const { hasValidSchedule } = require('../workers/branch/schedule');
|
||||
|
||||
const optionTypes = {};
|
||||
options.forEach(option => {
|
||||
optionTypes[option.name] = option.type;
|
||||
});
|
||||
let optionTypes;
|
||||
|
||||
module.exports = {
|
||||
validateConfig,
|
||||
};
|
||||
|
||||
function validateConfig(config) {
|
||||
if (!optionTypes) {
|
||||
optionTypes = {};
|
||||
options.forEach(option => {
|
||||
optionTypes[option.name] = option.type;
|
||||
});
|
||||
}
|
||||
let errors = [];
|
||||
let warnings = [];
|
||||
|
||||
|
|
Loading…
Reference in a new issue