Skip to content

Commit 1d5d726

Browse files
committed
Make native non-enumerable
Making it non-enumerable means less spurious "Cannot find module" errors in your logs when iterating over `pg` objects. `Object.defineProperty` has been available since Node 0.12. See brianc#1894 (comment)
1 parent fde5ec5 commit 1d5d726

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

lib/index.js

+18-13
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,25 @@ if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') {
4040
module.exports = new PG(Client)
4141

4242
// lazy require native module...the native module may not have installed
43-
module.exports.__defineGetter__('native', function () {
44-
delete module.exports.native
45-
var native = null
46-
try {
47-
native = new PG(require('./native'))
48-
} catch (err) {
49-
if (err.code !== 'MODULE_NOT_FOUND') {
50-
throw err
43+
Object.defineProperty(module.exports, 'native', {
44+
enumerable: false,
45+
configurable: true,
46+
writable: true,
47+
get () {
48+
delete module.exports.native
49+
var native = null
50+
try {
51+
native = new PG(require('./native'))
52+
} catch (err) {
53+
if (err.code !== 'MODULE_NOT_FOUND') {
54+
throw err
55+
}
56+
/* eslint-disable no-console */
57+
console.error(err.message)
58+
/* eslint-enable no-console */
5159
}
52-
/* eslint-disable no-console */
53-
console.error(err.message)
54-
/* eslint-enable no-console */
60+
module.exports.native = native
61+
return native
5562
}
56-
module.exports.native = native
57-
return native
5863
})
5964
}

0 commit comments

Comments
 (0)