You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by lu...@apache.org on 2023/06/19 15:18:13 UTC

[openwhisk-runtime-nodejs] branch master updated: Make 'npm install' during init configurable. (#240)

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

lukeroy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-nodejs.git


The following commit(s) were added to refs/heads/master by this push:
     new 28ac4c0  Make 'npm install' during init configurable. (#240)
28ac4c0 is described below

commit 28ac4c071bf1d6ede62de853a806bc58be75c389
Author: falkzoll <fa...@de.ibm.com>
AuthorDate: Mon Jun 19 17:18:07 2023 +0200

    Make 'npm install' during init configurable. (#240)
    
    - Use environment variable OW_ENABLE_INIT_INSTALL ('true', 'false') to decide if 'npm install' during init should be done or not.
      The default is 'true' (do an install). Reason to do this is that 'npm install' takes time and that production load may not want to install untested module versions.
---
 core/nodejsActionBase/runner.js | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/core/nodejsActionBase/runner.js b/core/nodejsActionBase/runner.js
index 84ae1c7..db9f34a 100644
--- a/core/nodejsActionBase/runner.js
+++ b/core/nodejsActionBase/runner.js
@@ -50,17 +50,25 @@ function initializeActionHandler(message) {
                     return Promise.reject('Zipped actions must contain either package.json or index.js at the root.');
                 }
 
-                // install npm modules during init if source code zip doesn´t containt them
-                // check if package.json exists and node_modules don`t
-                if (fs.existsSync('package.json') && !fs.existsSync('./node_modules/')) {
-                    var package_json = JSON.parse(fs.readFileSync('package.json', 'utf8'));
-                    if (package_json.hasOwnProperty('dependencies')) {
-                        if (Object.keys(package_json.dependencies).length > 0) {
-                            exec("npm install")
+
+                // check environment variable OW_ENABLE_INIT_INSTALL if we should do a 'npm install' to load not yet installed modules.
+                let enableInitInstall= !process.env.OW_ENABLE_INIT_INSTALL ? 'true' : process.env.OW_ENABLE_INIT_INSTALL;
+
+                if (enableInitInstall === 'true') {
+                    // install npm modules during init if source code zip doesn´t containt them
+                    // check if package.json exists and node_modules don`t
+                    if (fs.existsSync('package.json') && !fs.existsSync('./node_modules/')) {
+                        var package_json = JSON.parse(fs.readFileSync('package.json', 'utf8'));
+                        if (package_json.hasOwnProperty('dependencies')) {
+                            if (Object.keys(package_json.dependencies).length > 0) {
+                                exec("npm install")
+                            }
                         }
                     }
                 }
 
+
+
                 //  The module to require.
                 let whatToRequire = index !== undefined ? path.join(moduleDir, index) : moduleDir;
                 let handler = eval('require("' + whatToRequire + '").' + main);