Skip to content

Commit

Permalink
fix: avoid dynamic require (#386) (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
xfournet authored Nov 1, 2021
1 parent 194b9fc commit ce212b2
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 ce212b2

Please sign in to comment.