Skip to content

Commit 28ac4c0

Browse files
authored
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.
1 parent 787d789 commit 28ac4c0

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

core/nodejsActionBase/runner.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,25 @@ function initializeActionHandler(message) {
5050
return Promise.reject('Zipped actions must contain either package.json or index.js at the root.');
5151
}
5252

53-
// install npm modules during init if source code zip doesn´t containt them
54-
// check if package.json exists and node_modules don`t
55-
if (fs.existsSync('package.json') && !fs.existsSync('./node_modules/')) {
56-
var package_json = JSON.parse(fs.readFileSync('package.json', 'utf8'));
57-
if (package_json.hasOwnProperty('dependencies')) {
58-
if (Object.keys(package_json.dependencies).length > 0) {
59-
exec("npm install")
53+
54+
// check environment variable OW_ENABLE_INIT_INSTALL if we should do a 'npm install' to load not yet installed modules.
55+
let enableInitInstall= !process.env.OW_ENABLE_INIT_INSTALL ? 'true' : process.env.OW_ENABLE_INIT_INSTALL;
56+
57+
if (enableInitInstall === 'true') {
58+
// install npm modules during init if source code zip doesn´t containt them
59+
// check if package.json exists and node_modules don`t
60+
if (fs.existsSync('package.json') && !fs.existsSync('./node_modules/')) {
61+
var package_json = JSON.parse(fs.readFileSync('package.json', 'utf8'));
62+
if (package_json.hasOwnProperty('dependencies')) {
63+
if (Object.keys(package_json.dependencies).length > 0) {
64+
exec("npm install")
65+
}
6066
}
6167
}
6268
}
6369

70+
71+
6472
// The module to require.
6573
let whatToRequire = index !== undefined ? path.join(moduleDir, index) : moduleDir;
6674
let handler = eval('require("' + whatToRequire + '").' + main);

0 commit comments

Comments
 (0)