[bug] Fix after merge

This commit is contained in:
Sergey Konovalov
2025-08-24 18:47:27 +03:00
parent 8f8fb27d40
commit 4ed38ded04
2 changed files with 28 additions and 27 deletions

View File

@ -135,7 +135,7 @@ Context.prototype.toJSON = function() {
};
Context.prototype.getCfg = function(property, defaultValue) {
if (this.config){
return getImpl(this.config, property) ?? defaultValue;
return utils.getImpl(this.config, property) ?? defaultValue;
}
return defaultValue;
};
@ -147,30 +147,5 @@ Context.prototype.getFullCfg = function() {
return utils.deepMergeObjects(config.util.toObject(), this.config);
};
/**
* Underlying get mechanism
*
* @private
* @method getImpl
* @param object {object} - Object to get the property for
* @param property {string | array[string]} - The property name to get (as an array or '.' delimited string)
* @return value {*} - Property value, including undefined if not defined.
*/
function getImpl(object, property) {
//from https://github.com/node-config/node-config/blob/a8b91ac86b499d11b90974a2c9915ce31266044a/lib/config.js#L137
var t = this,
elems = Array.isArray(property) ? property : property.split('.'),
name = elems[0],
value = object[name];
if (elems.length <= 1) {
return value;
}
// Note that typeof null === 'object'
if (value === null || typeof value !== 'object') {
return undefined;
}
return getImpl(value, elems.slice(1));
};
exports.Context = Context;
exports.global = new Context();

View File

@ -1444,4 +1444,30 @@ exports.watchWithFallback = async function watchWithFallback(ctx, dirPath, fileP
ctx.logger.info(`watchWithFallback error ${dirPath} fallback to watchFile ${filePath}: ${err.message}`);
return fs.watchFile(filePath, opts, listener);
}
}
}
/**
* Underlying get mechanism
*
* @private
* @method getImpl
* @param object {object} - Object to get the property for
* @param property {string | array[string]} - The property name to get (as an array or '.' delimited string)
* @return value {*} - Property value, including undefined if not defined.
*/
function getImpl(object, property) {
//from https://github.com/node-config/node-config/blob/a8b91ac86b499d11b90974a2c9915ce31266044a/lib/config.js#L137
var t = this,
elems = Array.isArray(property) ? property : property.split('.'),
name = elems[0],
value = object[name];
if (elems.length <= 1) {
return value;
}
// Note that typeof null === 'object'
if (value === null || typeof value !== 'object') {
return undefined;
}
return getImpl(value, elems.slice(1));
};
exports.getImpl = getImpl;