Skip to content

Commit 0b9b334

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 0b9b334

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

lib/index.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,23 @@ 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+
get () {
46+
delete module.exports.native
47+
var native = null
48+
try {
49+
native = new PG(require('./native'))
50+
} catch (err) {
51+
if (err.code !== 'MODULE_NOT_FOUND') {
52+
throw err
53+
}
54+
/* eslint-disable no-console */
55+
console.error(err.message)
56+
/* eslint-enable no-console */
5157
}
52-
/* eslint-disable no-console */
53-
console.error(err.message)
54-
/* eslint-enable no-console */
58+
module.exports.native = native
59+
return native
5560
}
56-
module.exports.native = native
57-
return native
5861
})
5962
}

0 commit comments

Comments
 (0)