From 5109493b1513ce6a28f73d13e86855d70144c81d Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 29 Oct 2015 12:43:56 -0700 Subject: [PATCH] [refactor] Use more explicit pathing that does not rely on reading the file system in `lib/transports.js`. Fixes #731. --- lib/winston/transports.js | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/winston/transports.js b/lib/winston/transports.js index cc7a96b86..65c9f0c9e 100644 --- a/lib/winston/transports.js +++ b/lib/winston/transports.js @@ -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]; - }); -}); \ No newline at end of file + return acc; + }, {}) +);