Skip to content

Commit 07322af

Browse files
committed
[refactor] Use more explicit pathing that does not rely on reading the file system in lib/transports.js. Fixes #731.
1 parent a8045a3 commit 07322af

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

lib/winston/transports.js

+16-21
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,24 @@
66
*
77
*/
88

9-
var fs = require('fs'),
10-
path = require('path'),
11-
common = require('./common');
12-
13-
var transports = exports;
9+
var path = require('path');
1410

1511
//
1612
// Setup all transports as lazy-loaded getters.
1713
//
18-
fs.readdirSync(path.join(__dirname, 'transports')).forEach(function (file) {
19-
var transport = file.replace('.js', ''),
20-
name = common.capitalize(transport);
21-
22-
if (transport === 'transport') {
23-
return;
24-
}
25-
else if (~transport.indexOf('-')) {
26-
name = transport.split('-').map(function (part) {
27-
return common.capitalize(part);
28-
}).join('');
29-
}
14+
Object.defineProperties(
15+
exports,
16+
['Console', 'File', 'Http', 'Memory']
17+
.reduce(function (acc, name) {
18+
acc[name] = {
19+
configurable: true,
20+
enumerable: true,
21+
get: function () {
22+
var fullpath = path.join(__dirname, 'transports', name);
23+
return exports[name] = require(fullpath)[name];
24+
}
25+
};
3026

31-
transports.__defineGetter__(name, function () {
32-
return require('./transports/' + transport)[name];
33-
});
34-
});
27+
return acc;
28+
}, {})
29+
);

0 commit comments

Comments
 (0)