From 9f60feaba2bbd2618265f985dcf5cef9071b9c9e Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Mon, 7 Mar 2022 14:02:42 +0000 Subject: [PATCH 1/4] Use a specific NR version --- index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 2dd6802..ba63469 100755 --- a/index.js +++ b/index.js @@ -25,11 +25,16 @@ options.logBufferMax = options.logBufferMax || 1000 const ext = process.platform === 'win32' ? '.cmd' : '' options.execPath = undefined -for (let i = 0; i < require.main.paths.length; i++) { - const execPath = path.join(require.main.paths[i], '.bin', `node-red${ext}`) - if (fs.existsSync(execPath)) { - options.execPath = execPath - break +if (process.env.FORGE_NR_PATH) { + options.execPath = path.join(process.env.FORGE_NR_PATH, 'node_modules', '.bin', `node-red${ext}`) +} else { + // Find the bundled version + for (let i = 0; i < require.main.paths.length; i++) { + const execPath = path.join(require.main.paths[i], '.bin', `node-red${ext}`) + if (fs.existsSync(execPath)) { + options.execPath = execPath + break + } } } From ac5a100ca608bb4d798efea6d9d56c5aa6acfc67 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Mon, 7 Mar 2022 14:37:52 +0000 Subject: [PATCH 2/4] Add fallback if NR version not found --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ba63469..9fcf246 100755 --- a/index.js +++ b/index.js @@ -27,7 +27,11 @@ const ext = process.platform === 'win32' ? '.cmd' : '' options.execPath = undefined if (process.env.FORGE_NR_PATH) { options.execPath = path.join(process.env.FORGE_NR_PATH, 'node_modules', '.bin', `node-red${ext}`) -} else { + if (!fs.existsSync(options.execPath)) { + options.execPath = undefined + } +} +if (!options.execPath) { // Find the bundled version for (let i = 0; i < require.main.paths.length; i++) { const execPath = path.join(require.main.paths[i], '.bin', `node-red${ext}`) From 1b4da6c08c9ab23b8c10b957c13a0ed24984b818 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Mon, 7 Mar 2022 14:42:38 +0000 Subject: [PATCH 3/4] Make NR Path a cmd line argument --- README.md | 3 ++- index.js | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e6b552c..42fdb87 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,6 @@ Custom laucher to start Node-RED is a loadale set of settings and to capture log - --port port to listen on for management interface - --project FlowForge project id UUID - --token Bearer Token to access Forge platfrom +- --nodeRedPath path to dir with a `node_modules` directory container a version of Node-RED -FORGE_URL, FORGE_PROJECT_ID & FORGE_PROJECT_TOKEN and be used as env vars instead of the cmd line args if not set (cmd line args take preceident) \ No newline at end of file +FORGE_URL, FORGE_PROJECT_ID, FORGE_PROJECT_TOKEN & FORGE_NR_PATH and be used as env vars instead of the cmd line args if not set (cmd line args take preceident) \ No newline at end of file diff --git a/index.js b/index.js index 9fcf246..eee175e 100755 --- a/index.js +++ b/index.js @@ -12,7 +12,8 @@ const cmdLineOptions = [ { name: 'forgeURL', type: String }, { name: 'project', type: String }, { name: 'token', type: String }, - { name: 'buffer', alias: 'b', type: Number } + { name: 'buffer', alias: 'b', type: Number }, + { name: 'nodeRedPath', alias: 'n', type: String } ] const options = commandLineArgs(cmdLineOptions) @@ -21,12 +22,13 @@ options.forgeURL = options.forgeURL || process.env.FORGE_URL options.project = options.project || process.env.FORGE_PROJECT_ID options.token = options.token || process.env.FORGE_PROJECT_TOKEN options.logBufferMax = options.logBufferMax || 1000 +options.nodeRedPath = options.nodeRedPath || process.env.FORGE_NR_PATH const ext = process.platform === 'win32' ? '.cmd' : '' options.execPath = undefined -if (process.env.FORGE_NR_PATH) { - options.execPath = path.join(process.env.FORGE_NR_PATH, 'node_modules', '.bin', `node-red${ext}`) +if (options.nodeRedPath) { + options.execPath = path.join(options.nodeRedPath, 'node_modules', '.bin', `node-red${ext}`) if (!fs.existsSync(options.execPath)) { options.execPath = undefined } From 13598e44238d765ff60d7332417ded35377437ff Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Fri, 11 Mar 2022 11:05:04 +0000 Subject: [PATCH 4/4] Add --max-oldspace to launched Node-RED This is set to 75% of the max memory for the project to get GC to kick in before the limit is reached --- lib/launcher.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/launcher.js b/lib/launcher.js index a503b4d..ee5f017 100644 --- a/lib/launcher.js +++ b/lib/launcher.js @@ -129,7 +129,8 @@ class Launcher { ] if (this.settings.stack?.['memory'] && /^[1-9]\d*$/.test(this.settings.stack['memory'])) { - processArguments.push(`--max-old-space-size=${this.settings.stack['memory']}`) + const memLimit = Math.round(this.settings.stack['memory'] * 0.75) + processArguments.push(`--max-old-space-size=${memLimit}`) } this.proc = childProcess.spawn(