Fully remove when.js dependency

This commit is contained in:
Nick O'Leary
2020-11-30 14:38:48 +00:00
parent beccdac717
commit 5992ed1fab
49 changed files with 299 additions and 357 deletions

View File

@@ -92,11 +92,32 @@ module.exports = {
* @memberof node-red
*/
start: function() {
return runtime.start().then(function() {
// The top level red.js has always used 'otherwise' on the promise returned
// here. This is a non-standard promise function coming from our early use
// of the when.js library.
// We want to remove all dependency on when.js as native Promises now exist.
// But we have the issue that some embedders of Node-RED may have copied our
// top-level red.js a bit too much.
//
let startPromise = runtime.start().then(function() {
if (apiEnabled) {
return api.start();
}
});
startPromise._then = startPromise.then;
startPromise.then = function(resolve,reject) {
var inner = startPromise._then(resolve,reject);
inner.otherwise = function(cb) {
redUtil.log.error("**********************************************");
redUtil.log.error("* Deprecated call to RED.start().otherwise() *");
redUtil.log.error("* This will be removed in Node-RED 2.x *");
redUtil.log.error("* Use RED.start().catch() instead *")
redUtil.log.error("**********************************************");
return inner.catch(cb);
}
return inner;
}
return startPromise;
},
/**
* Stop the Node-RED application.

View File

@@ -429,7 +429,7 @@ httpsPromise.then(function(startupHttps) {
} else {
RED.log.info(RED.log._("server.headless-mode"));
}
}).otherwise(function(err) {
}).catch(function(err) {
RED.log.error(RED.log._("server.failed-to-start"));
if (err.stack) {
RED.log.error(err.stack);
@@ -468,4 +468,5 @@ httpsPromise.then(function(startupHttps) {
}).catch(function(err) {
console.log("Failed to get https settings: " + err);
console.log(err.stack)
});