From c90cad6852c2a1fb21988c41f4c566482be94d9c Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 4 Jul 2018 02:13:11 -0600 Subject: [PATCH] lighten the load --- index.js | 23 ++++++++++++++++++----- lib/core.js | 10 +++++++++- package.json | 6 +++--- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 900b420..0d85575 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,17 @@ try { } catch(e) { PromiseA = global.Promise; } +var util = require('util'); +function promisifyAllSelf(obj) { + if (obj.__promisified) { return obj; } + Object.keys(obj).forEach(function (key) { + if ('function' === typeof obj[key]) { + obj[key + 'Async'] = util.promisify(obj[key]); + } + }); + obj.__promisified = true; + return obj; +} var Greenlock = module.exports; Greenlock.Greenlock = Greenlock; @@ -240,7 +251,7 @@ Greenlock.create = function (gl) { if (gl.acme.create) { gl.acme = gl.acme.create(gl); } - gl.acme = PromiseA.promisifyAll(gl.acme); + gl.acme = promisifyAllSelf(gl.acme); gl._acmeOpts = gl.acme.getOptions(); Object.keys(gl._acmeOpts).forEach(function (key) { if (!(key in gl)) { @@ -251,9 +262,9 @@ Greenlock.create = function (gl) { if (gl.store.create) { gl.store = gl.store.create(gl); } - gl.store = PromiseA.promisifyAll(gl.store); - gl.store.accounts = PromiseA.promisifyAll(gl.store.accounts); - gl.store.certificates = PromiseA.promisifyAll(gl.store.certificates); + gl.store = promisifyAllSelf(gl.store); + gl.store.accounts = promisifyAllSelf(gl.store.accounts); + gl.store.certificates = promisifyAllSelf(gl.store.certificates); gl._storeOpts = gl.store.getOptions(); Object.keys(gl._storeOpts).forEach(function (key) { if (!(key in gl)) { @@ -280,7 +291,9 @@ Greenlock.create = function (gl) { if (challenger.create) { challenger = gl.challenges[challengeType] = challenger.create(gl); } - challenger = gl.challenges[challengeType] = PromiseA.promisifyAll(challenger); + if (!challenger.getOptionsAsync) { + challenger = gl.challenges[challengeType] = promisifyAllSelf(challenger); + } gl['_challengeOpts_' + challengeType] = challenger.getOptions(); Object.keys(gl['_challengeOpts_' + challengeType]).forEach(function (key) { if (!(key in gl)) { diff --git a/lib/core.js b/lib/core.js index 586e1eb..dcd2065 100644 --- a/lib/core.js +++ b/lib/core.js @@ -6,6 +6,14 @@ try { } catch(e) { PromiseA = global.Promise; } +var util = require('util'); +function promisifyAll(obj) { + var aobj = {}; + Object.keys(obj).forEach(function (key) { + aobj[key + 'Async'] = util.promisify(obj[key]); + }); + return aobj; +} function _log(debug) { if (debug) { @@ -18,7 +26,7 @@ function _log(debug) { module.exports.create = function (gl) { var utils = require('./utils'); - var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA); + var RSA = promisifyAll(require('rsa-compat').RSA); var log = gl.log || _log; // allow custom log var pendingRegistrations = {}; diff --git a/package.json b/package.json index d4ee6da..893ff4f 100644 --- a/package.json +++ b/package.json @@ -61,18 +61,18 @@ "request": "^2.75.0" }, "trulyOptionalDependencies": { + "bluebird": "^3.5.1", "le-acme-core": "^2.1.3", "ursa": "^0.9.4" }, "dependencies": { "acme": "^1.0.6", - "acme-v2": "^1.0.6", + "acme-v2": "^1.1.1", "asn1js": "^1.2.12", - "bluebird": "^3.5.1", "certpem": "^1.0.0", "le-challenge-fs": "^2.0.2", "le-sni-auto": "^2.1.3", - "le-store-certbot": "^2.1.0", + "le-store-certbot": "^2.1.7", "node.extend": "^1.1.5", "pkijs": "^1.3.27", "rsa-compat": "^1.4.0"