Skip to content

Commit

Permalink
[refactor] Use more explicit pathing that does not rely on reading th…
Browse files Browse the repository at this point in the history
…e file system in `lib/transports.js`. Fixes #731.
  • Loading branch information
indexzero committed Oct 29, 2015
1 parent 1581aa5 commit 5109493
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions lib/winston/transports.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,24 @@
*
*/

var fs = require('fs'),
path = require('path'),
common = require('./common');

var transports = exports;
var path = require('path');

//
// Setup all transports as lazy-loaded getters.
//
fs.readdirSync(path.join(__dirname, 'transports')).forEach(function (file) {
var transport = file.replace('.js', ''),
name = common.capitalize(transport);

if (transport === 'transport') {
return;
}
else if (~transport.indexOf('-')) {
name = transport.split('-').map(function (part) {
return common.capitalize(part);
}).join('');
}
Object.defineProperties(
exports,
['Console', 'File', 'Http', 'Memory']
.reduce(function (acc, name) {
acc[name] = {
configurable: true,
enumerable: true,
get: function () {
var fullpath = path.join(__dirname, 'transports', name);
return exports[name] = require(fullpath)[name];
}
};

transports.__defineGetter__(name, function () {
return require('./transports/' + transport)[name];
});
});
return acc;
}, {})
);

0 comments on commit 5109493

Please sign in to comment.