mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Fully remove when.js dependency
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
var apiUtils = require("../util");
|
||||
var fs = require('fs');
|
||||
var fspath = require('path');
|
||||
var when = require('when');
|
||||
|
||||
var runtimeAPI;
|
||||
|
||||
|
@@ -28,7 +28,6 @@ var express = require("express");
|
||||
var bodyParser = require("body-parser");
|
||||
var util = require('util');
|
||||
var passport = require('passport');
|
||||
var when = require('when');
|
||||
var cors = require('cors');
|
||||
|
||||
var auth = require("./auth");
|
||||
@@ -111,11 +110,9 @@ function init(settings,_server,storage,runtimeAPI) {
|
||||
* @return {Promise} resolves when the application is ready to handle requests
|
||||
* @memberof @node-red/editor-api
|
||||
*/
|
||||
function start() {
|
||||
async function start() {
|
||||
if (editor) {
|
||||
return editor.start();
|
||||
} else {
|
||||
return when.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,11 +121,10 @@ function start() {
|
||||
* @return {Promise} resolves when the application is stopped
|
||||
* @memberof @node-red/editor-api
|
||||
*/
|
||||
function stop() {
|
||||
async function stop() {
|
||||
if (editor) {
|
||||
editor.stop();
|
||||
}
|
||||
return when.resolve();
|
||||
}
|
||||
module.exports = {
|
||||
init: init,
|
||||
|
@@ -32,7 +32,6 @@
|
||||
"passport-http-bearer": "1.0.1",
|
||||
"passport-oauth2-client-password": "0.1.2",
|
||||
"passport": "0.4.1",
|
||||
"when": "3.7.8",
|
||||
"ws": "6.2.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
|
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var when = require("when");
|
||||
var fs = require("fs-extra");
|
||||
var path = require("path");
|
||||
var semver = require("semver");
|
||||
@@ -92,7 +91,7 @@ function loadNodeFiles(nodeFiles) {
|
||||
nodeFiles[m].nodes[n] = nodeSet;
|
||||
nodes.push(nodeSet);
|
||||
}
|
||||
})()));
|
||||
})()).catch(err => {}));
|
||||
} catch(err) {
|
||||
//
|
||||
}
|
||||
@@ -101,7 +100,7 @@ function loadNodeFiles(nodeFiles) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return when.settle(promises).then(function(results) {
|
||||
return Promise.all(promises).then(function(results) {
|
||||
for (var module in nodeFiles) {
|
||||
if (nodeFiles.hasOwnProperty(module)) {
|
||||
if (!nodeFiles[module].err) {
|
||||
@@ -293,13 +292,13 @@ function loadNodeSetList(nodes) {
|
||||
var promises = [];
|
||||
nodes.forEach(function(node) {
|
||||
if (!node.err) {
|
||||
promises.push(loadNodeSet(node));
|
||||
promises.push(loadNodeSet(node).catch(err => {}));
|
||||
} else {
|
||||
promises.push(node);
|
||||
}
|
||||
});
|
||||
|
||||
return when.settle(promises).then(function() {
|
||||
return Promise.all(promises).then(function() {
|
||||
if (settings.available()) {
|
||||
return registry.saveNodeList();
|
||||
} else {
|
||||
|
@@ -17,7 +17,6 @@
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
|
||||
var events;
|
||||
var log;
|
||||
|
||||
var log = require("@node-red/util").log;
|
||||
@@ -29,7 +28,6 @@ var iconFileExtensions = [".png", ".gif", ".svg"];
|
||||
|
||||
function init(runtime) {
|
||||
settings = runtime.settings;
|
||||
events = runtime.events;
|
||||
}
|
||||
|
||||
function isIncluded(name) {
|
||||
@@ -75,7 +73,6 @@ function getLocalFile(file) {
|
||||
|
||||
/**
|
||||
* Synchronously walks the directory looking for node files.
|
||||
* Emits 'node-icon-dir' events for an icon dirs found
|
||||
* @param dir the directory to search
|
||||
* @return an array of fully-qualified paths to .js files
|
||||
*/
|
||||
@@ -229,7 +226,6 @@ function getModuleNodeFiles(module) {
|
||||
try {
|
||||
fs.statSync(examplesDir)
|
||||
result.examples = {path:examplesDir};
|
||||
// events.emit("node-examples-dir",{name:pkg.name,path:examplesDir});
|
||||
} catch(err) {
|
||||
}
|
||||
return result;
|
||||
|
@@ -19,7 +19,6 @@
|
||||
"@node-red/util": "1.3.0-beta.1",
|
||||
"semver": "6.3.0",
|
||||
"tar": "6.0.5",
|
||||
"uglify-js": "3.11.6",
|
||||
"when": "3.7.8"
|
||||
"uglify-js": "3.11.6"
|
||||
}
|
||||
}
|
||||
|
@@ -14,8 +14,6 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var when = require('when');
|
||||
|
||||
var externalAPI = require("./api");
|
||||
|
||||
var redNodes = require("./nodes");
|
||||
@@ -197,25 +195,24 @@ function start() {
|
||||
});
|
||||
}
|
||||
|
||||
var reinstallAttempts;
|
||||
var reinstallAttempts = 0;
|
||||
var reinstallTimeout;
|
||||
function reinstallModules(moduleList) {
|
||||
var promises = [];
|
||||
var failedModules = [];
|
||||
var reinstallList = [];
|
||||
|
||||
for (var i=0;i<moduleList.length;i++) {
|
||||
if (settings.autoInstallModules && i != "node-red") {
|
||||
promises.push(redNodes.installModule(moduleList[i].id,moduleList[i].version));
|
||||
if (settings.autoInstallModules && moduleList[i].id != "node-red") {
|
||||
(function(mod) {
|
||||
promises.push(redNodes.installModule(mod.id,mod.version).then(m => {
|
||||
events.emit("runtime-event",{id:"node/added",retain:false,payload:m.nodes});
|
||||
}).catch(err => {
|
||||
reinstallList.push(mod);
|
||||
}));
|
||||
})(moduleList[i])
|
||||
}
|
||||
}
|
||||
when.settle(promises).then(function(results) {
|
||||
var reinstallList = [];
|
||||
for (var i=0;i<results.length;i++) {
|
||||
if (results[i].state === 'rejected') {
|
||||
reinstallList.push(moduleList[i]);
|
||||
} else {
|
||||
events.emit("runtime-event",{id:"node/added",retain:false,payload:results[i].value.nodes});
|
||||
}
|
||||
}
|
||||
Promise.all(promises).then(function(results) {
|
||||
if (reinstallList.length > 0) {
|
||||
reinstallAttempts++;
|
||||
// First 5 at 1x timeout, next 5 at 2x, next 5 at 4x, then 8x
|
||||
|
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var when = require("when");
|
||||
var crypto = require('crypto');
|
||||
var runtime;
|
||||
var settings;
|
||||
@@ -60,7 +59,7 @@ var api = module.exports = {
|
||||
/**
|
||||
* Sets the credentials from storage.
|
||||
*/
|
||||
load: function (credentials) {
|
||||
load: async function (credentials) {
|
||||
dirty = false;
|
||||
var credentialsEncrypted = credentials.hasOwnProperty("$") && Object.keys(credentials).length === 1;
|
||||
|
||||
@@ -77,7 +76,7 @@ var api = module.exports = {
|
||||
// Case 4: credentialSecret set
|
||||
// - use it
|
||||
|
||||
var setupEncryptionPromise = when.resolve();
|
||||
var setupEncryptionPromise = Promise.resolve();
|
||||
|
||||
var projectKey = false;
|
||||
var activeProject;
|
||||
@@ -134,7 +133,7 @@ var api = module.exports = {
|
||||
log.warn(log._("nodes.credentials.error",{message:err.toString()}))
|
||||
var error = new Error("Failed to decrypt credentials");
|
||||
error.code = "credentials_load_failed";
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
dirty = true;
|
||||
@@ -163,7 +162,7 @@ var api = module.exports = {
|
||||
log.warn(log._("nodes.credentials.error",{message:err.toString()}))
|
||||
var error = new Error("Failed to decrypt credentials");
|
||||
error.code = "credentials_load_failed";
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
dirty = true;
|
||||
@@ -217,9 +216,9 @@ var api = module.exports = {
|
||||
// This is a project with a bad key. Mark it as invalid
|
||||
// TODO: this delves too deep into Project structure
|
||||
activeProject.credentialSecretInvalid = true;
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
// These are encrypted credentials
|
||||
try {
|
||||
@@ -235,9 +234,9 @@ var api = module.exports = {
|
||||
// This is a project with a bad key. Mark it as invalid
|
||||
// TODO: this delves too deep into Project structure
|
||||
activeProject.credentialSecretInvalid = true;
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
} else {
|
||||
credentialCache = credentials;
|
||||
@@ -257,12 +256,11 @@ var api = module.exports = {
|
||||
* @param creds an object of credential key/value pairs
|
||||
* @return a promise for backwards compatibility TODO: can this be removed?
|
||||
*/
|
||||
add: function (id, creds) {
|
||||
add: async function (id, creds) {
|
||||
if (!credentialCache.hasOwnProperty(id) || JSON.stringify(creds) !== JSON.stringify(credentialCache[id])) {
|
||||
credentialCache[id] = creds;
|
||||
dirty = true;
|
||||
}
|
||||
return when.resolve();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -293,7 +291,7 @@ var api = module.exports = {
|
||||
* @param config a flow config
|
||||
* @return a promise for the saving of credentials to storage
|
||||
*/
|
||||
clean: function (config) {
|
||||
clean: async function (config) {
|
||||
var existingIds = {};
|
||||
config.forEach(function(n) {
|
||||
existingIds[n.id] = true;
|
||||
@@ -313,7 +311,6 @@ var api = module.exports = {
|
||||
if (deletedCredentials) {
|
||||
dirty = true;
|
||||
}
|
||||
return when.resolve();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -432,7 +429,7 @@ var api = module.exports = {
|
||||
getKeyType: function() {
|
||||
return encryptionKeyType;
|
||||
},
|
||||
export: function() {
|
||||
export: async function() {
|
||||
var result = credentialCache;
|
||||
|
||||
if (encryptionEnabled) {
|
||||
@@ -455,7 +452,7 @@ var api = module.exports = {
|
||||
return result;
|
||||
})
|
||||
} else {
|
||||
return when.resolve(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var when = require("when");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var clone = require("clone");
|
||||
|
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var when = require("when");
|
||||
var clone = require("clone");
|
||||
var assert = require("assert");
|
||||
var log = require("@node-red/util").log; // TODO: separate module
|
||||
@@ -90,10 +89,10 @@ var persistentSettings = {
|
||||
globalSettings[prop] = clone(value);
|
||||
try {
|
||||
assert.deepEqual(current,value);
|
||||
return when.resolve();
|
||||
} catch(err) {
|
||||
return storage.saveSettings(clone(globalSettings));
|
||||
}
|
||||
return Promise.resolve();
|
||||
},
|
||||
delete: function(prop) {
|
||||
if (localSettings.hasOwnProperty(prop)) {
|
||||
@@ -106,7 +105,7 @@ var persistentSettings = {
|
||||
delete globalSettings[prop];
|
||||
return storage.saveSettings(clone(globalSettings));
|
||||
}
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
available: function() {
|
||||
@@ -180,7 +179,6 @@ var persistentSettings = {
|
||||
userSettings[username] = settings;
|
||||
try {
|
||||
assert.deepEqual(current,settings);
|
||||
return when.resolve();
|
||||
} catch(err) {
|
||||
globalSettings.users = userSettings;
|
||||
return storage.saveSettings(clone(globalSettings));
|
||||
|
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var when = require('when');
|
||||
var Path = require('path');
|
||||
var crypto = require('crypto');
|
||||
|
||||
@@ -50,15 +49,13 @@ function is_malicious(path) {
|
||||
}
|
||||
|
||||
var storageModuleInterface = {
|
||||
init: function(_runtime) {
|
||||
init: async function(_runtime) {
|
||||
runtime = _runtime;
|
||||
try {
|
||||
storageModule = moduleSelector(runtime.settings);
|
||||
settingsAvailable = storageModule.hasOwnProperty("getSettings") && storageModule.hasOwnProperty("saveSettings");
|
||||
sessionsAvailable = storageModule.hasOwnProperty("getSessions") && storageModule.hasOwnProperty("saveSessions");
|
||||
} catch (e) {
|
||||
return when.reject(e);
|
||||
}
|
||||
// Any errors thrown by the module will get passed up to the called
|
||||
// as a rejected promise
|
||||
storageModule = moduleSelector(runtime.settings);
|
||||
settingsAvailable = storageModule.hasOwnProperty("getSettings") && storageModule.hasOwnProperty("saveSettings");
|
||||
sessionsAvailable = storageModule.hasOwnProperty("getSessions") && storageModule.hasOwnProperty("saveSessions");
|
||||
if (!!storageModule.projects) {
|
||||
var projectsEnabled = false;
|
||||
if (runtime.settings.hasOwnProperty("editorTheme") && runtime.settings.editorTheme.hasOwnProperty("projects")) {
|
||||
@@ -73,7 +70,7 @@ var storageModuleInterface = {
|
||||
}
|
||||
return storageModule.init(runtime.settings,runtime);
|
||||
},
|
||||
getFlows: function() {
|
||||
getFlows: async function() {
|
||||
return storageModule.getFlows().then(function(flows) {
|
||||
return storageModule.getCredentials().then(function(creds) {
|
||||
var result = {
|
||||
@@ -85,14 +82,14 @@ var storageModuleInterface = {
|
||||
})
|
||||
});
|
||||
},
|
||||
saveFlows: function(config, user) {
|
||||
saveFlows: async function(config, user) {
|
||||
var flows = config.flows;
|
||||
var credentials = config.credentials;
|
||||
var credentialSavePromise;
|
||||
if (config.credentialsDirty) {
|
||||
credentialSavePromise = storageModule.saveCredentials(credentials);
|
||||
} else {
|
||||
credentialSavePromise = when.resolve();
|
||||
credentialSavePromise = Promise.resolve();
|
||||
}
|
||||
delete config.credentialsDirty;
|
||||
|
||||
@@ -105,64 +102,60 @@ var storageModuleInterface = {
|
||||
// getCredentials: function() {
|
||||
// return storageModule.getCredentials();
|
||||
// },
|
||||
saveCredentials: function(credentials) {
|
||||
saveCredentials: async function(credentials) {
|
||||
return storageModule.saveCredentials(credentials);
|
||||
},
|
||||
getSettings: function() {
|
||||
getSettings: async function() {
|
||||
if (settingsAvailable) {
|
||||
return storageModule.getSettings();
|
||||
} else {
|
||||
return when.resolve(null);
|
||||
return null
|
||||
}
|
||||
},
|
||||
saveSettings: function(settings) {
|
||||
saveSettings: async function(settings) {
|
||||
if (settingsAvailable) {
|
||||
return settingsSaveMutex.runExclusive(() => storageModule.saveSettings(settings))
|
||||
} else {
|
||||
return when.resolve();
|
||||
}
|
||||
},
|
||||
getSessions: function() {
|
||||
getSessions: async function() {
|
||||
if (sessionsAvailable) {
|
||||
return storageModule.getSessions();
|
||||
} else {
|
||||
return when.resolve(null);
|
||||
return null
|
||||
}
|
||||
},
|
||||
saveSessions: function(sessions) {
|
||||
saveSessions: async function(sessions) {
|
||||
if (sessionsAvailable) {
|
||||
return storageModule.saveSessions(sessions);
|
||||
} else {
|
||||
return when.resolve();
|
||||
}
|
||||
},
|
||||
|
||||
/* Library Functions */
|
||||
|
||||
getLibraryEntry: function(type, path) {
|
||||
getLibraryEntry: async function(type, path) {
|
||||
if (is_malicious(path)) {
|
||||
var err = new Error();
|
||||
err.code = "forbidden";
|
||||
return when.reject(err);
|
||||
throw err;
|
||||
}
|
||||
return storageModule.getLibraryEntry(type, path);
|
||||
},
|
||||
saveLibraryEntry: function(type, path, meta, body) {
|
||||
saveLibraryEntry: async function(type, path, meta, body) {
|
||||
if (is_malicious(path)) {
|
||||
var err = new Error();
|
||||
err.code = "forbidden";
|
||||
return when.reject(err);
|
||||
throw err;
|
||||
}
|
||||
return storageModule.saveLibraryEntry(type, path, meta, body);
|
||||
},
|
||||
|
||||
/* Deprecated functions */
|
||||
getAllFlows: function() {
|
||||
getAllFlows: async function() {
|
||||
if (storageModule.hasOwnProperty("getAllFlows")) {
|
||||
return storageModule.getAllFlows();
|
||||
} else {
|
||||
if (libraryFlowsCachedResult) {
|
||||
return Promise.resolve(libraryFlowsCachedResult);
|
||||
return libraryFlowsCachedResult;
|
||||
} else {
|
||||
return listFlows("/").then(function(result) {
|
||||
libraryFlowsCachedResult = result;
|
||||
@@ -175,7 +168,7 @@ var storageModuleInterface = {
|
||||
if (is_malicious(fn)) {
|
||||
var err = new Error();
|
||||
err.code = "forbidden";
|
||||
return when.reject(err);
|
||||
throw err;
|
||||
}
|
||||
if (storageModule.hasOwnProperty("getFlow")) {
|
||||
return storageModule.getFlow(fn);
|
||||
@@ -188,7 +181,7 @@ var storageModuleInterface = {
|
||||
if (is_malicious(fn)) {
|
||||
var err = new Error();
|
||||
err.code = "forbidden";
|
||||
return when.reject(err);
|
||||
throw err;
|
||||
}
|
||||
libraryFlowsCachedResult = null;
|
||||
if (storageModule.hasOwnProperty("saveFlow")) {
|
||||
@@ -204,40 +197,36 @@ var storageModuleInterface = {
|
||||
|
||||
function listFlows(path) {
|
||||
return storageModule.getLibraryEntry("flows",path).then(function(res) {
|
||||
return when.promise(function(resolve) {
|
||||
var promises = [];
|
||||
res.forEach(function(r) {
|
||||
if (typeof r === "string") {
|
||||
promises.push(listFlows(Path.join(path,r)));
|
||||
} else {
|
||||
promises.push(when.resolve(r));
|
||||
}
|
||||
});
|
||||
var i=0;
|
||||
when.settle(promises).then(function(res2) {
|
||||
var result = {};
|
||||
res2.forEach(function(r) {
|
||||
// TODO: name||fn
|
||||
if (r.value.fn) {
|
||||
var name = r.value.name;
|
||||
if (!name) {
|
||||
name = r.value.fn.replace(/\.json$/, "");
|
||||
}
|
||||
result.f = result.f || [];
|
||||
result.f.push(name);
|
||||
} else {
|
||||
result.d = result.d || {};
|
||||
result.d[res[i]] = r.value;
|
||||
//console.log(">",r.value);
|
||||
const promises = [];
|
||||
res.forEach(function(r) {
|
||||
if (typeof r === "string") {
|
||||
promises.push(listFlows(Path.join(path,r)));
|
||||
} else {
|
||||
promises.push(Promise.resolve(r));
|
||||
}
|
||||
});
|
||||
return Promise.all(promises).then(res2 => {
|
||||
let i = 0;
|
||||
const result = {};
|
||||
res2.forEach(function(r) {
|
||||
// TODO: name||fn
|
||||
if (r.fn) {
|
||||
var name = r.name;
|
||||
if (!name) {
|
||||
name = r.fn.replace(/\.json$/, "");
|
||||
}
|
||||
i++;
|
||||
});
|
||||
resolve(result);
|
||||
result.f = result.f || [];
|
||||
result.f.push(name);
|
||||
} else {
|
||||
result.d = result.d || {};
|
||||
result.d[res[i]] = r;
|
||||
//console.log(">",r.value);
|
||||
}
|
||||
i++;
|
||||
});
|
||||
return result;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = storageModuleInterface;
|
||||
|
@@ -15,9 +15,7 @@
|
||||
**/
|
||||
|
||||
var fs = require('fs-extra');
|
||||
var when = require('when');
|
||||
var fspath = require("path");
|
||||
var nodeFn = require('when/node/function');
|
||||
|
||||
var util = require("./util");
|
||||
|
||||
@@ -90,14 +88,14 @@ function getLibraryEntry(type,path) {
|
||||
var rootPath = fspath.join(libDir,type,path);
|
||||
|
||||
// don't create the folder if it does not exist - we are only reading....
|
||||
return nodeFn.call(fs.lstat, rootPath).then(function(stats) {
|
||||
return fs.lstat(rootPath).then(function(stats) {
|
||||
if (stats.isFile()) {
|
||||
return getFileBody(root,path);
|
||||
}
|
||||
if (path.substr(-1) == '/') {
|
||||
path = path.substr(0,path.length-1);
|
||||
}
|
||||
return nodeFn.call(fs.readdir, rootPath).then(function(fns) {
|
||||
return fs.readdir(rootPath).then(function(fns) {
|
||||
var dirs = [];
|
||||
var files = [];
|
||||
fns.sort().filter(function(fn) {
|
||||
@@ -143,21 +141,19 @@ function getLibraryEntry(type,path) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: function(_settings) {
|
||||
init: async function(_settings) {
|
||||
settings = _settings;
|
||||
libDir = fspath.join(settings.userDir,"lib");
|
||||
libFlowsDir = fspath.join(libDir,"flows");
|
||||
if (!settings.readOnly) {
|
||||
return fs.ensureDir(libFlowsDir);
|
||||
} else {
|
||||
return when.resolve();
|
||||
}
|
||||
},
|
||||
getLibraryEntry: getLibraryEntry,
|
||||
|
||||
saveLibraryEntry: function(type,path,meta,body) {
|
||||
saveLibraryEntry: async function(type,path,meta,body) {
|
||||
if (settings.readOnly) {
|
||||
return when.resolve();
|
||||
return;
|
||||
}
|
||||
if (type === "flows" && !path.endsWith(".json")) {
|
||||
path += ".json";
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
|
||||
var fs = require('fs-extra');
|
||||
var when = require('when');
|
||||
var fspath = require("path");
|
||||
var os = require('os');
|
||||
|
||||
@@ -108,12 +107,12 @@ Project.prototype.load = function () {
|
||||
// package.json isn't valid JSON... is a merge underway?
|
||||
project.package = {};
|
||||
}
|
||||
}));
|
||||
}).catch(err => {})); //
|
||||
if (missingFiles.indexOf('README.md') === -1) {
|
||||
project.paths['README.md'] = fspath.join(project.paths.root,"README.md");
|
||||
promises.push(fs.readFile(fspath.join(project.path,project.paths['README.md']),"utf8").then(function(content) {
|
||||
project.description = content;
|
||||
}));
|
||||
}).catch(err => {}));
|
||||
} else {
|
||||
project.description = "";
|
||||
}
|
||||
@@ -133,9 +132,9 @@ Project.prototype.load = function () {
|
||||
// project.paths.credentialsFile = fspath.join(project.path,"flow_cred.json");
|
||||
// }
|
||||
|
||||
promises.push(project.loadRemotes());
|
||||
promises.push(project.loadRemotes().catch(err => {}));
|
||||
|
||||
return when.settle(promises).then(function(results) {
|
||||
return Promise.all(promises).then(function(results) {
|
||||
return project;
|
||||
})
|
||||
});
|
||||
@@ -239,7 +238,7 @@ Project.prototype.isMerging = function() {
|
||||
return this.merging;
|
||||
}
|
||||
|
||||
Project.prototype.update = function (user, data) {
|
||||
Project.prototype.update = async function (user, data) {
|
||||
var username;
|
||||
if (!user) {
|
||||
username = "_";
|
||||
@@ -279,7 +278,7 @@ Project.prototype.update = function (user, data) {
|
||||
this.credentialSecret !== existingSecret) { // key doesn't match provided existing key
|
||||
var e = new Error("Cannot change credentialSecret without current key");
|
||||
e.code = "missing_current_credential_key";
|
||||
return when.reject(e);
|
||||
throw e;
|
||||
}
|
||||
this.credentialSecret = secret;
|
||||
|
||||
@@ -292,7 +291,7 @@ Project.prototype.update = function (user, data) {
|
||||
if (this.missingFiles.indexOf('package.json') !== -1) {
|
||||
if (!data.files || !data.files.package) {
|
||||
// Cannot update a project that doesn't have a known package.json
|
||||
return Promise.reject("Cannot update project with missing package.json");
|
||||
throw new Error("Cannot update project with missing package.json");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +301,7 @@ Project.prototype.update = function (user, data) {
|
||||
// We have a package file. It could be one that doesn't exist yet,
|
||||
// or it does exist and we need to load it.
|
||||
if (!/package\.json$/.test(data.files.package)) {
|
||||
return Promise.reject("Invalid package file: "+data.files.package)
|
||||
return new Error("Invalid package file: "+data.files.package)
|
||||
}
|
||||
var root = data.files.package.substring(0,data.files.package.length-12);
|
||||
this.paths.root = root;
|
||||
@@ -391,20 +390,20 @@ Project.prototype.update = function (user, data) {
|
||||
modifyRemotesPromise = modifyRemotesPromise.then(function() {
|
||||
return project.loadRemotes();
|
||||
});
|
||||
promises.push(modifyRemotesPromise);
|
||||
promises.push(modifyRemotesPromise.catch(err => {}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (saveSettings) {
|
||||
promises.push(settings.set("projects",globalProjectSettings));
|
||||
promises.push(settings.set("projects",globalProjectSettings).catch(err => {}));
|
||||
}
|
||||
|
||||
var modifiedFiles = [];
|
||||
|
||||
if (saveREADME) {
|
||||
promises.push(util.writeFile(fspath.join(this.path,this.paths['README.md']), this.description));
|
||||
promises.push(util.writeFile(fspath.join(this.path,this.paths['README.md']), this.description).catch(err => {}));
|
||||
modifiedFiles.push('README.md');
|
||||
}
|
||||
if (savePackage) {
|
||||
@@ -416,10 +415,10 @@ Project.prototype.update = function (user, data) {
|
||||
}
|
||||
this.package = Object.assign(currentPackage,this.package);
|
||||
return util.writeFile(fspath.join(project.path,this.paths['package.json']), JSON.stringify(this.package,"",4));
|
||||
}));
|
||||
}).catch(err => {}));
|
||||
modifiedFiles.push('package.json');
|
||||
}
|
||||
return when.settle(promises).then(function(res) {
|
||||
return Promise.all(promises).then(function(res) {
|
||||
var gitSettings = getUserGitSettings(user) || {};
|
||||
var workflowMode = (gitSettings.workflow||{}).mode || "manual";
|
||||
if (workflowMode === 'auto') {
|
||||
@@ -944,32 +943,17 @@ function createDefaultProject(user, project) {
|
||||
}
|
||||
function checkProjectFiles(project) {
|
||||
var promises = [];
|
||||
var paths = [];
|
||||
var missing = [];
|
||||
for (var file in defaultFileSet) {
|
||||
if (defaultFileSet.hasOwnProperty(file)) {
|
||||
paths.push(file);
|
||||
promises.push(fs.stat(fspath.join(project.path,project.paths.root,file)));
|
||||
(function(f) {
|
||||
promises.push(fs.stat(fspath.join(project.path,project.paths.root,f)).catch(err => {
|
||||
missing.push(f);
|
||||
}));
|
||||
})(file);
|
||||
}
|
||||
}
|
||||
return when.settle(promises).then(function(results) {
|
||||
var missing = [];
|
||||
results.forEach(function(result,i) {
|
||||
if (result.state === 'rejected') {
|
||||
missing.push(paths[i]);
|
||||
}
|
||||
});
|
||||
return missing;
|
||||
}).then(function(missing) {
|
||||
// if (createMissing) {
|
||||
// var promises = [];
|
||||
// missing.forEach(function(file) {
|
||||
// promises.push(util.writeFile(fspath.join(projectPath,file),defaultFileSet[file](project)));
|
||||
// });
|
||||
// return promises;
|
||||
// } else {
|
||||
return missing;
|
||||
// }
|
||||
});
|
||||
return Promise.all(promises).then(() => missing);
|
||||
}
|
||||
function createProject(user, metadata) {
|
||||
var username;
|
||||
|
@@ -15,9 +15,7 @@
|
||||
**/
|
||||
|
||||
var fs = require('fs-extra');
|
||||
var when = require('when');
|
||||
var fspath = require("path");
|
||||
var nodeFn = require('when/node/function');
|
||||
var crypto = require('crypto');
|
||||
|
||||
var storageSettings = require("../settings");
|
||||
@@ -223,7 +221,6 @@ function loadProject(name) {
|
||||
|
||||
function getProject(user, name) {
|
||||
checkActiveProject(name);
|
||||
//return when.resolve(activeProject.info);
|
||||
return Promise.resolve(activeProject.export());
|
||||
}
|
||||
|
||||
@@ -495,7 +492,7 @@ var flowsFileBackup;
|
||||
var credentialsFile;
|
||||
var credentialsFileBackup;
|
||||
|
||||
function getFlows() {
|
||||
async function getFlows() {
|
||||
if (!initialFlowLoadComplete) {
|
||||
initialFlowLoadComplete = true;
|
||||
log.info(log._("storage.localfilesystem.user-dir",{path:settings.userDir}));
|
||||
@@ -522,25 +519,25 @@ function getFlows() {
|
||||
log.warn("Project repository is empty");
|
||||
error = new Error("Project repository is empty");
|
||||
error.code = "project_empty";
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
if (activeProject.missingFiles && activeProject.missingFiles.indexOf('package.json') !== -1) {
|
||||
log.warn("Project missing package.json");
|
||||
error = new Error("Project missing package.json");
|
||||
error.code = "missing_package_file";
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
if (!activeProject.getFlowFile()) {
|
||||
log.warn("Project has no flow file");
|
||||
error = new Error("Project has no flow file");
|
||||
error.code = "missing_flow_file";
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
if (activeProject.isMerging()) {
|
||||
log.warn("Project has unmerged changes");
|
||||
error = new Error("Project has unmerged changes. Cannot load flows");
|
||||
error.code = "git_merge_conflict";
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -554,14 +551,14 @@ function getFlows() {
|
||||
});
|
||||
}
|
||||
|
||||
function saveFlows(flows, user) {
|
||||
async function saveFlows(flows, user) {
|
||||
if (settings.readOnly) {
|
||||
return when.resolve();
|
||||
return
|
||||
}
|
||||
if (activeProject && activeProject.isMerging()) {
|
||||
var error = new Error("Project has unmerged changes. Cannot deploy new flows");
|
||||
error.code = "git_merge_conflict";
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
flowsFileExists = true;
|
||||
@@ -589,9 +586,9 @@ function getCredentials() {
|
||||
return util.readFile(credentialsFile,credentialsFileBackup,{},'credentials');
|
||||
}
|
||||
|
||||
function saveCredentials(credentials) {
|
||||
async function saveCredentials(credentials) {
|
||||
if (settings.readOnly) {
|
||||
return when.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
var credentialData;
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var fs = require('fs-extra');
|
||||
var when = require('when');
|
||||
var fspath = require("path");
|
||||
var keygen = require("./keygen");
|
||||
|
||||
|
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var when = require('when');
|
||||
var fs = require('fs-extra');
|
||||
var fspath = require("path");
|
||||
|
||||
@@ -30,8 +29,8 @@ module.exports = {
|
||||
settings = _settings;
|
||||
sessionsFile = fspath.join(settings.userDir,".sessions.json");
|
||||
},
|
||||
getSessions: function() {
|
||||
return when.promise(function(resolve,reject) {
|
||||
getSessions: async function() {
|
||||
return new Promise(function(resolve,reject) {
|
||||
fs.readFile(sessionsFile,'utf8',function(err,data){
|
||||
if (!err) {
|
||||
try {
|
||||
@@ -44,9 +43,9 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
},
|
||||
saveSessions: function(sessions) {
|
||||
saveSessions: async function(sessions) {
|
||||
if (settings.readOnly) {
|
||||
return when.resolve();
|
||||
return;
|
||||
}
|
||||
return util.writeFile(sessionsFile,JSON.stringify(sessions));
|
||||
}
|
||||
|
@@ -22,7 +22,6 @@
|
||||
"clone": "2.1.2",
|
||||
"express": "4.17.1",
|
||||
"fs-extra": "8.1.0",
|
||||
"json-stringify-safe": "5.0.1",
|
||||
"when": "3.7.8"
|
||||
"json-stringify-safe": "5.0.1"
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,6 @@
|
||||
|
||||
var i18n = require("i18next");
|
||||
|
||||
var when = require("when");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
@@ -38,16 +37,16 @@ var initPromise;
|
||||
*/
|
||||
function registerMessageCatalogs(catalogs) {
|
||||
var promises = catalogs.map(function(catalog) {
|
||||
return registerMessageCatalog(catalog.namespace,catalog.dir,catalog.file);
|
||||
return registerMessageCatalog(catalog.namespace,catalog.dir,catalog.file).catch(err => {});
|
||||
});
|
||||
return when.settle(promises);
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a message catalog with i18n.
|
||||
* @memberof @node-red/util_i18n
|
||||
*/
|
||||
function registerMessageCatalog(namespace,dir,file) {
|
||||
async function registerMessageCatalog(namespace,dir,file) {
|
||||
return initPromise.then(function() {
|
||||
return new Promise((resolve,reject) => {
|
||||
resourceMap[namespace] = { basedir:dir, file:file, lngs: []};
|
||||
@@ -147,7 +146,7 @@ function init() {
|
||||
if (!initPromise) {
|
||||
// Keep this as a 'when' promise as top-level red.js uses 'otherwise'
|
||||
// and embedded users of NR may have copied that.
|
||||
initPromise = when.promise((resolve,reject) => {
|
||||
initPromise = new Promise((resolve,reject) => {
|
||||
i18n.use(MessageFileLoader);
|
||||
var opt = {
|
||||
// debug: true,
|
||||
|
@@ -20,7 +20,6 @@
|
||||
"json-stringify-safe": "5.0.1",
|
||||
"jsonata": "1.8.4",
|
||||
"lodash.clonedeep": "^4.5.0",
|
||||
"moment-timezone": "0.5.32",
|
||||
"when": "3.7.8"
|
||||
"moment-timezone": "0.5.32"
|
||||
}
|
||||
}
|
||||
|
23
packages/node_modules/node-red/lib/red.js
vendored
23
packages/node_modules/node-red/lib/red.js
vendored
@@ -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.
|
||||
|
3
packages/node_modules/node-red/red.js
vendored
3
packages/node_modules/node-red/red.js
vendored
@@ -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)
|
||||
});
|
||||
|
Reference in New Issue
Block a user