@node-red/util 2.0.4 → 2.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/i18n.js +3 -2
  2. package/lib/util.js +17 -10
  3. package/package.json +3 -3
package/lib/i18n.js CHANGED
@@ -23,7 +23,7 @@
23
23
  var i18n = require("i18next");
24
24
 
25
25
  var path = require("path");
26
- var fs = require("fs-extra");
26
+ var fs = require("fs");
27
27
 
28
28
  var defaultLang = "en-US";
29
29
 
@@ -89,7 +89,7 @@ async function readFile(lng, ns) {
89
89
  return resourceCache[ns][lng];
90
90
  } else if (resourceMap[ns]) {
91
91
  const file = path.join(resourceMap[ns].basedir, lng, resourceMap[ns].file);
92
- const content = await fs.readFile(file, "utf8");
92
+ const content = await fs.promises.readFile(file, "utf8");
93
93
  resourceCache[ns] = resourceCache[ns] || {};
94
94
  resourceCache[ns][lng] = JSON.parse(content.replace(/^\uFEFF/, ''));
95
95
  var baseLng = lng.split('-')[0];
@@ -141,6 +141,7 @@ function init(settings) {
141
141
  initPromise = new Promise((resolve,reject) => {
142
142
  i18n.use(MessageFileLoader);
143
143
  var opt = {
144
+ compatibilityJSON: 'v3',
144
145
  // debug: true,
145
146
  defaultNS: "runtime",
146
147
  ns: [],
package/lib/util.js CHANGED
@@ -521,12 +521,17 @@ function setObjectProperty(msg,prop,value,createMissing) {
521
521
  * @param {String} name - name of variable
522
522
  * @return {String} value of env var
523
523
  */
524
- function getSetting(node, name) {
525
- if (node && node._flow) {
526
- var flow = node._flow;
527
- if (flow) {
528
- return flow.getSetting(name);
524
+ function getSetting(node, name, flow_) {
525
+ var flow = (flow_ ? flow_ : (node ? node._flow : null));
526
+ if (flow) {
527
+ if (node && node.g) {
528
+ const group = flow.getGroupNode(node.g);
529
+ const result = flow.getGroupEnvSetting(node, group, name);
530
+ if (result) {
531
+ return result.val;
532
+ }
529
533
  }
534
+ return flow.getSetting(name);
530
535
  }
531
536
  return process.env[name];
532
537
  }
@@ -544,18 +549,19 @@ function getSetting(node, name) {
544
549
  * @memberof @node-red/util_util
545
550
  */
546
551
  function evaluateEnvProperty(value, node) {
552
+ var flow = (node && node.hasOwnProperty("_flow")) ? node._flow : null;
547
553
  var result;
548
554
  if (/^\${[^}]+}$/.test(value)) {
549
555
  // ${ENV_VAR}
550
556
  var name = value.substring(2,value.length-1);
551
- result = getSetting(node, name);
557
+ result = getSetting(node, name, flow);
552
558
  } else if (!/\${\S+}/.test(value)) {
553
559
  // ENV_VAR
554
- result = getSetting(node, value);
560
+ result = getSetting(node, value, flow);
555
561
  } else {
556
562
  // FOO${ENV_VAR}BAR
557
563
  return value.replace(/\${([^}]+)}/g, function(match, name) {
558
- var val = getSetting(node, name);
564
+ var val = getSetting(node, name, flow);
559
565
  return (val === undefined)?"":val;
560
566
  });
561
567
  }
@@ -668,7 +674,7 @@ function prepareJSONataExpression(value,node) {
668
674
  return node.context().global.get(val, store);
669
675
  });
670
676
  expr.assign('env', function(name) {
671
- var val = getSetting(node, name);
677
+ var val = getSetting(node, name, node._flow);
672
678
  if (typeof val !== 'undefined') {
673
679
  return val;
674
680
  } else {
@@ -976,5 +982,6 @@ module.exports = {
976
982
  normaliseNodeTypeName: normaliseNodeTypeName,
977
983
  prepareJSONataExpression: prepareJSONataExpression,
978
984
  evaluateJSONataExpression: evaluateJSONataExpression,
979
- parseContextStore: parseContextStore
985
+ parseContextStore: parseContextStore,
986
+ getSetting: getSetting
980
987
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-red/util",
3
- "version": "2.0.4",
3
+ "version": "2.1.0-beta.2",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,9 +16,9 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "fs-extra": "10.0.0",
19
- "i18next": "20.3.2",
19
+ "i18next": "21.3.1",
20
20
  "json-stringify-safe": "5.0.1",
21
- "jsonata": "1.8.4",
21
+ "jsonata": "1.8.5",
22
22
  "lodash.clonedeep": "^4.5.0",
23
23
  "moment-timezone": "0.5.33"
24
24
  }