From aaf337255a501a3de2ca09dbf513a2f5b136157b Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Thu, 5 Dec 2019 17:35:14 -0800 Subject: [PATCH] =?UTF-8?q?Warn=20when=20pg.Pool()=20isn=E2=80=99t=20calle?= =?UTF-8?q?d=20as=20a=20constructor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- lib/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/index.js b/lib/index.js index 8e000a378..bc84aab05 100644 --- a/lib/index.js +++ b/lib/index.js @@ -13,8 +13,19 @@ var defaults = require('./defaults') var Connection = require('./connection') var Pool = require('pg-pool') +let hasNewTarget = false + +try { + eval('(function () { new.target })') + hasNewTarget = true +} catch (error) {} + const poolFactory = (Client) => { var BoundPool = function (options) { + if (hasNewTarget && eval('new.target') === undefined) { + 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) }