Skip to content

Commit

Permalink
fix: avoid dynamic require (#386) (#387) (#402)
Browse files Browse the repository at this point in the history
(cherry picked from commit ce212b2)
  • Loading branch information
xfournet authored Oct 23, 2023
1 parent 583e713 commit 4ee8a28
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/nconf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

//
Expand Down

0 comments on commit 4ee8a28

Please sign in to comment.