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 04:50:36 UTC

[openwhisk-wskdebug] branch wsk-package-var created (now 1d79129)

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

alexkli pushed a change to branch wsk-package-var
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git.


      at 1d79129  Support reading package name from WSK_PACKAGE env var #10

This branch includes the following new commits:

     new 776633e  npm audit fix
     new 1d79129  Support reading package name from WSK_PACKAGE env var #10

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[openwhisk-wskdebug] 01/02: npm audit fix

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 776633eeb87b02ac15751801cdd4b82adfe6fbf5
Author: Alexander Klimetschek <ak...@adobe.com>
AuthorDate: Thu Apr 9 20:53:59 2020 -0700

    npm audit fix
---
 package-lock.json | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index 64dbc66..8267421 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2018,18 +2018,18 @@
             }
         },
         "minimist": {
-            "version": "0.0.8",
-            "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
-            "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
+            "version": "1.2.5",
+            "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
+            "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
             "dev": true
         },
         "mkdirp": {
-            "version": "0.5.1",
-            "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
-            "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
+            "version": "0.5.5",
+            "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
+            "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
             "dev": true,
             "requires": {
-                "minimist": "0.0.8"
+                "minimist": "^1.2.5"
             }
         },
         "mkpath": {
@@ -2125,6 +2125,21 @@
                         "path-is-absolute": "^1.0.0"
                     }
                 },
+                "minimist": {
+                    "version": "0.0.8",
+                    "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
+                    "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
+                    "dev": true
+                },
+                "mkdirp": {
+                    "version": "0.5.1",
+                    "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
+                    "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
+                    "dev": true,
+                    "requires": {
+                        "minimist": "0.0.8"
+                    }
+                },
                 "ms": {
                     "version": "2.1.1",
                     "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",


[openwhisk-wskdebug] 02/02: Support reading package name from WSK_PACKAGE env var #10

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 1d79129c881167f17caacebc6431a493b87600ad
Author: Alexander Klimetschek <ak...@adobe.com>
AuthorDate: Thu Apr 9 21:50:12 2020 -0700

    Support reading package name from WSK_PACKAGE env var #10
---
 README.md                           | 37 +++++++++++++++++++++++++++++++-
 examples/nodejs/.env                |  2 ++
 examples/nodejs/.vscode/launch.json | 14 ++++++++++++-
 index.js                            |  4 ++++
 test/wskdebug.test.js               | 42 ++++++++++++++++++++++++++++++++++++-
 5 files changed, 96 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index d3b8943..7b79ffa 100644
--- a/README.md
+++ b/README.md
@@ -124,7 +124,7 @@ The action to debug (e.g. `myaction`) must already be deployed.
 
 Add the configuration below to your [launch.json](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations). Replace `MYACTION` with the name of your action and `ACTION.js` with the source file containing the action. When you run this, it will start wskdebug and should automatically connect the debugger.
 
-```
+```json
     "configurations": [
         {
             "type": "node",
@@ -145,6 +145,41 @@ This snippets enables browser LiveReloading using `-l`. For other reloading opti
 
 For troubleshooting, you can run the debugger in verbose mode by adding `"-v"` to the `args` array.
 
+#### Control wskprops credentials
+
+To use custom credentials from a custom `.wskprops` and/or use a developer-specific openwhisk package name, but avoid committing that into your source control system, you can use an `.env` file.
+
+1. Put this `.env` file in your VS Code project root:
+
+    ```
+    WSK_CONFIG_FILE=/Users/user/.wskprops-custom
+    WSK_PACKAGE=my-package
+    ```
+    
+   Set either of the variables as needed.
+
+2. Make sure to not commit this file into source control, by e.g. adding `.env` to a `.gitignore` file.
+
+2. Add an `envFile` setting to the `.vscode/launch.json`, which you can share with co-workers and commit to source control:
+
+    ```json
+    "configurations": [
+        {
+            "type": "node",
+            "request": "launch",
+            "name": "wskdebug",
+            "runtimeExecutable": "wskdebug",
+            "args": [ "MYACTION", "ACTION.js", "-l" ],
+            "localRoot": "${workspaceFolder}",
+            "remoteRoot": "/code",
+            "outputCapture": "std",
+            "envFile": "${workspaceFolder}/.env"
+        }
+    ]
+    ```
+
+
+
 <a name="nodejs-multiple-actions"></a>
 ### Node.js: Multiple actions
 
diff --git a/examples/nodejs/.env b/examples/nodejs/.env
new file mode 100644
index 0000000..d2c1e30
--- /dev/null
+++ b/examples/nodejs/.env
@@ -0,0 +1,2 @@
+WSK_PACKAGE=wskdebug-examples
+#WSK_CONFIG_FILE=<absolute-path-to-custom-wskprops>
diff --git a/examples/nodejs/.vscode/launch.json b/examples/nodejs/.vscode/launch.json
index aeb9f4e..47501f7 100644
--- a/examples/nodejs/.vscode/launch.json
+++ b/examples/nodejs/.vscode/launch.json
@@ -49,7 +49,19 @@
             "localRoot": "${workspaceFolder}",
             "remoteRoot": "/code",
             "outputCapture": "std"
+        },
+        {
+            "type": "node",
+            "request": "launch",
+            "name": "wskdebug with WSK_PACKAGE",
+            "runtimeExecutable": "wskdebug",
+            "args": [
+                "webaction"
+            ],
+            "localRoot": "${workspaceFolder}",
+            "remoteRoot": "/code",
+            "outputCapture": "std",
+            "envFile": "${workspaceFolder}/.env"
         }
-
     ]
 }
\ No newline at end of file
diff --git a/index.js b/index.js
index 96a83cb..0406efe 100644
--- a/index.js
+++ b/index.js
@@ -258,6 +258,10 @@ function normalizeArgs(argv) {
     argv.invokeParams = argv.P;
     argv.invokeAction = argv.a;
     argv.onChange = argv.r;
+
+    if (process.env.WSK_PACKAGE && argv.action && !argv.action.includes("/")) {
+        argv.action = `${process.env.WSK_PACKAGE}/${argv.action}`;
+    }
 }
 
 function printErrorAndExit(err, argv) {
diff --git a/test/wskdebug.test.js b/test/wskdebug.test.js
index ca8e941..959168e 100644
--- a/test/wskdebug.test.js
+++ b/test/wskdebug.test.js
@@ -22,13 +22,32 @@
 
 // tests basic cli
 
-const wskdebug = require('../index');
+let wskdebug = require('../index');
 
 const test = require('./test');
 const assert = require('assert');
 const stripAnsi = require('strip-ansi');
 const {execSync} = require('child_process');
 
+const mockRequire = require('mock-require');
+
+function mockDebugger() {
+    const receivedArgv = {};
+
+    class MockDebugger {
+        constructor(argv) {
+            Object.assign(receivedArgv, argv);
+        }
+
+        start() {}
+        run() {}
+    }
+
+    mockRequire("../src/debugger", MockDebugger);
+    wskdebug = mockRequire.reRequire("../index");
+    return receivedArgv;
+}
+
 describe('wskdebug cli', function() {
 
     it("should print version (via wskdebug.js)", async function() {
@@ -66,4 +85,25 @@ describe('wskdebug cli', function() {
         assert.equal(stripAnsi(stdio.stdout.trim()), require(`${process.cwd()}/package.json`).version);
     });
 
+    it("should take action argument", async function() {
+        const argv = mockDebugger();
+
+        await wskdebug(`action`);
+        assert.strictEqual(argv.action, "action");
+
+        await wskdebug(`package/action`);
+        assert.strictEqual(argv.action, "package/action");
+    });
+
+    it("should use WSK_PACKAGE env var as package name", async function() {
+        const argv = mockDebugger();
+
+        process.env.WSK_PACKAGE = "envPackage";
+        await wskdebug(`action`);
+        assert.strictEqual(argv.action, "envPackage/action");
+
+        // cli package takes precedence
+        await wskdebug(`package/action`);
+        assert.strictEqual(argv.action, "package/action");
+    });
 });