diff --git a/lib/index.js b/lib/index.js index 8e000a378..4ce0eac3d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -13,8 +13,26 @@ var defaults = require('./defaults') var Connection = require('./connection') var Pool = require('pg-pool') +let hasNewTarget + +try { + // eslint-disable-next-line eval + eval('(function () { new.target })') + hasNewTarget = true +} catch (error) { + hasNewTarget = false +} + const poolFactory = (Client) => { var BoundPool = function (options) { + // new.target is a syntax error in Node 4 + // eslint-disable-next-line eval + if (hasNewTarget && eval('new.target') === undefined) { + // process.emitWarning is supported when new.target is supported + // eslint-disable-next-line node/no-unsupported-features/node-builtins + process.emitWarning('Constructing a pg.Pool without new is deprecated and will stop working in pg 8.', 'DeprecationWarning', 'PG-POOL-NEW') + } + var config = Object.assign({ Client: Client }, options) return new Pool(config) }