From 4ee8a28566a000e6f63a5a1ccfa49b4730c0c2f8 Mon Sep 17 00:00:00 2001 From: Xavier Fournet <461943+xfournet@users.noreply.github.com> Date: Mon, 23 Oct 2023 04:07:42 +0200 Subject: [PATCH] fix: avoid dynamic require (#386) (#387) (#402) (cherry picked from commit ce212b2f1dbf96cee001b5f621979c564638f0e7) --- lib/nconf.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/nconf.js b/lib/nconf.js index 26f6286d..0d59c91f 100644 --- a/lib/nconf.js +++ b/lib/nconf.js @@ -21,12 +21,24 @@ nconf.version = require('../package.json').version; // // Setup all stores as lazy-loaded getters. // -['argv', 'env', 'file', 'literal', 'memory'].forEach(function (store) { - var name = common.capitalize(store); +nconf.__defineGetter__('Argv', function () { + return require('./nconf/stores/argv').Argv; +}); + +nconf.__defineGetter__('Env', function () { + return require('./nconf/stores/env').Env; +}); + +nconf.__defineGetter__('File', function () { + return require('./nconf/stores/file').File; +}); + +nconf.__defineGetter__('Literal', function () { + return require('./nconf/stores/literal').Literal; +}); - nconf.__defineGetter__(name, function () { - return require('./nconf/stores/' + store)[name]; - }); +nconf.__defineGetter__('Memory', function () { + return require('./nconf/stores/memory').Memory; }); //