Skip to content

Commit aaf3372

Browse files
committed
Warn when pg.Pool() isn’t called as a constructor
in preparation for #1541. `eval` is a bit awkward, but it’s more accurate than an `instanceof` check and will work on platforms new enough to support pg 8 (i.e. only not Node 4).
1 parent 8f56b8c commit aaf3372

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,19 @@ var defaults = require('./defaults')
1313
var Connection = require('./connection')
1414
var Pool = require('pg-pool')
1515

16+
let hasNewTarget = false
17+
18+
try {
19+
eval('(function () { new.target })')
20+
hasNewTarget = true
21+
} catch (error) {}
22+
1623
const poolFactory = (Client) => {
1724
var BoundPool = function (options) {
25+
if (hasNewTarget && eval('new.target') === undefined) {
26+
process.emitWarning('Constructing a pg.Pool without new is deprecated and will stop working in pg 8.', 'DeprecationWarning', 'PG-POOL-NEW')
27+
}
28+
1829
var config = Object.assign({ Client: Client }, options)
1930
return new Pool(config)
2031
}

0 commit comments

Comments
 (0)