You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by al...@apache.org on 2020/04/10 06:52:18 UTC

[openwhisk-wskdebug] 04/04: make ngrok an optional dependency

This is an automated email from the ASF dual-hosted git repository.

alexkli pushed a commit to branch optional-ngrok
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git

commit cdea63a476256448f68d7f5ce2ce454599c68e70
Author: Alexander Klimetschek <ak...@adobe.com>
AuthorDate: Thu Apr 9 23:50:47 2020 -0700

    make ngrok an optional dependency
    
    had to use peerDependencies in package.json as optionalDependencies
    are still installed by default and ngrok fails without --unsafe-perm=true
    even if in an optionalDependencies
---
 package.json    |  4 +++-
 src/agentmgr.js | 14 ++++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/package.json b/package.json
index 801767f..5f83e6b 100644
--- a/package.json
+++ b/package.json
@@ -46,10 +46,12 @@
         "isomorphic-fetch": "^2.2.1",
         "livereload": "^0.9.1",
         "manakin": "^0.5.2",
-        "ngrok": "^3.2.7",
         "openwhisk": "^3.21.1",
         "yargs": "^15.3.1"
     },
+    "peerDependencies": {
+        "ngrok": "^3.2.7"
+    },
     "devDependencies": {
         "chmodr": "^1.2.0",
         "clone": "^2.1.2",
diff --git a/src/agentmgr.js b/src/agentmgr.js
index 15ea202..c83f31c 100644
--- a/src/agentmgr.js
+++ b/src/agentmgr.js
@@ -17,7 +17,14 @@
 
 'use strict';
 
-const NgrokAgent = require('./agents/ngrok');
+let NgrokAgent;
+try {
+    // optional dependency, only needed if --ngrok is set
+    NgrokAgent = require('./agents/ngrok');
+} catch (err) {
+    NgrokAgent = null
+}
+
 const fs = require('fs-extra');
 const sleep = require('util').promisify(setTimeout);
 
@@ -79,6 +86,10 @@ class AgentMgr {
         this.wsk = wsk;
         this.actionName = actionName;
         this.polling = true;
+
+        if (this.argv.ngrok && !NgrokAgent) {
+            throw new Error("ngrok dependency required for --ngrok is not installed. Please install it using:\n\n    npm install -g ngrok --unsafe-perm=true\n");
+        }
     }
 
     async readAction() {
@@ -140,7 +151,6 @@ class AgentMgr {
         let agentCode;
         if (this.argv.ngrok) {
             // user manually requested ngrok
-
             this.ngrokAgent = new NgrokAgent(this.argv, invoker);
 
             // agent using ngrok for forwarding