From fd4ccb6c8feae11665ef69152b0a2ab860e122a5 Mon Sep 17 00:00:00 2001 From: Joe Uhren Date: Sun, 20 Aug 2023 21:01:06 -0600 Subject: [PATCH] Fix pm2 + forever detection for npm 9.7.2+ -npm 9.7.2 added better color support detection which effectively broke the explorer's detection of whether pm2 or forever modules are installed due to extra color codes in the `npm list` output. This has been corrected so that pm2 and forever are now detected properly on newer and older npm versions --- scripts/prestart.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/prestart.js b/scripts/prestart.js index d1d1cc8..1a80db2 100644 --- a/scripts/prestart.js +++ b/scripts/prestart.js @@ -50,10 +50,10 @@ function check_arguments_passed(cb) { // run a cmd to check if pm2 is installed exec(`npm list${(isWinOS ? ' -g' : '')} pm2`, (err, stdout, stderr) => { // split stdout string by new line - var splitResponse = (stdout == null ? '' : stdout).split('\n').filter(element => element); + var splitResponse = (stdout == null ? '' : stdout.trim()).split('\n').filter(element => element); // check if the cmd result contains an @ symbol - if (splitResponse[splitResponse.length - 1].indexOf('@') == -1) { + if (splitResponse[1].indexOf('@') == -1) { console.log('Installing pm2 module.. Please wait..'); // install pm2 @@ -69,10 +69,10 @@ function check_arguments_passed(cb) { // run a cmd to check if forever is installed exec('npm list forever', (err, stdout, stderr) => { // split stdout string by new line - var splitResponse = (stdout == null ? '' : stdout).split('\n').filter(element => element); + var splitResponse = (stdout == null ? '' : stdout.trim()).split('\n').filter(element => element); // check if the cmd result contains an @ symbol - if (splitResponse[splitResponse.length - 1].indexOf('@') == -1) { + if (splitResponse[1].indexOf('@') == -1) { console.log('Installing forever module.. Please wait..'); // install forever