Merge pull request #5207 from node-red/node24-support

Updates for Node 24
This commit is contained in:
Nick O'Leary
2025-07-21 15:14:24 +01:00
committed by GitHub
5 changed files with 23 additions and 8 deletions

View File

@@ -91,7 +91,13 @@ module.exports = function(RED) {
const opts = isWindows ? { ...node.spawnOpt, shell: true } : node.spawnOpt
/* istanbul ignore else */
node.debug(cmd+" ["+arg+"]");
child = spawn(cmd,arg,opts);
if (opts.shell) {
// When called with shell: true, passing in separate args is deprecated in Node 24
// so we need to join the command and args into a single string.
child = spawn([cmd].concat(arg).join(" "), opts);
} else {
child = spawn(cmd,arg,opts);
}
node.status({fill:"blue",shape:"dot",text:"pid:"+child.pid});
var unknownCommand = (child.pid === undefined);
if (node.timer !== 0) {

View File

@@ -367,9 +367,10 @@ async function getModuleVersionFromNPM(module, version) {
if (version) {
installName += "@" + version;
}
return new Promise((resolve, reject) => {
child_process.execFile(npmCommand,['info','--json',installName],{ shell: true },function(err,stdout,stderr) {
child_process.execFile(`${npmCommand} info --json ${installName}`, { shell: true },function(err,stdout,stderr) {
try {
if (!stdout) {
log.warn(log._("server.install.install-failed-not-found",{name:module}));
@@ -595,7 +596,7 @@ async function checkPrereq() {
installerEnabled = false;
} else {
return new Promise(resolve => {
child_process.execFile(npmCommand,['-v'],{ shell: true },function(err,stdout) {
child_process.execFile(`${npmCommand} -v`,{ shell: true },function(err,stdout) {
if (err) {
log.info(log._("server.palette-editor.npm-not-found"));
installerEnabled = false;

View File

@@ -57,7 +57,15 @@ module.exports = {
return new Promise((resolve, reject) => {
let stdout = "";
let stderr = "";
const child = child_process.spawn(command,args,options);
let child
if (args && options.shell) {
// If we are using a shell, we need to join the args into a single string
// as passing a separate array of args is deprecated in Node 24
command = [command].concat(args).join(" ");
child = child_process.spawn(command, options)
} else {
child = child_process.spawn(command, args, options);
}
child.stdout.on('data', (data) => {
const str = ""+data;
stdout += str;

View File

@@ -529,18 +529,18 @@ httpsPromise.then(function(startupHttps) {
});
process.on('uncaughtException',function(err) {
util.log('[red] Uncaught Exception:');
console.log('[red] Uncaught Exception:');
if (err.stack) {
try {
RED.log.error(err.stack);
} catch(err2) {
util.log(err.stack);
console.log(err.stack);
}
} else {
try {
RED.log.error(err);
} catch(err2) {
util.log(err);
console.log(err);
}
}
process.exit(1);