smart-home-engine 0.23.2 → 0.23.5

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.
@@ -1,4 +1,4 @@
1
- import{m as O}from"./monaco-langs-BW2J83t5.js";import{t as I}from"./index-IaTuET9d.js";/*!-----------------------------------------------------------------------------
1
+ import{m as O}from"./monaco-langs-BW2J83t5.js";import{t as I}from"./index-BYKQI-fk.js";/*!-----------------------------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
4
4
  * Released under the MIT license
@@ -155,7 +155,7 @@
155
155
  }
156
156
  })();
157
157
  </script>
158
- <script type="module" crossorigin src="/assets/index-IaTuET9d.js"></script>
158
+ <script type="module" crossorigin src="/assets/index-BYKQI-fk.js"></script>
159
159
  <link rel="modulepreload" crossorigin href="/assets/monaco-langs-BW2J83t5.js">
160
160
  <link rel="stylesheet" crossorigin href="/assets/monaco-langs-DyX1CsEw.css">
161
161
  <link rel="stylesheet" crossorigin href="/assets/index-BPk8Jr3B.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-home-engine",
3
- "version": "0.23.2",
3
+ "version": "0.23.5",
4
4
  "description": "Node.js based script runner for use in MQTT based Smart Home environments",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -27,12 +27,12 @@ if (process.argv.includes('--install')) {
27
27
 
28
28
  // Resolve --data-dir early so that storage.js and config.js both see the correct
29
29
  // data root when they are first require()'d below.
30
- ;(function () {
30
+ (function () {
31
31
  const idx = process.argv.indexOf('--data-dir');
32
32
  if (idx !== -1 && process.argv[idx + 1] && !process.argv[idx + 1].startsWith('-')) {
33
33
  process.env.SHE_DATA_DIR = process.argv[idx + 1];
34
34
  }
35
- }());
35
+ })();
36
36
 
37
37
  // Ensure the data directory exists before anything else runs
38
38
  require('./lib/storage').ensureRoot();
@@ -73,6 +73,21 @@ const log = {
73
73
  const config = require('./config.js');
74
74
  const pkg = require('../package.json');
75
75
 
76
+ /**
77
+ * Build a short log label for a script file.
78
+ * Uses the path relative to the configured script dir(s) when possible,
79
+ * falling back to the bare filename for files outside the script dir.
80
+ */
81
+ function makeLabel(filePath) {
82
+ const normalized = filePath.replace(/\\/g, '/');
83
+ const dirs = config.dir ? (Array.isArray(config.dir) ? config.dir : [config.dir]) : [];
84
+ for (const d of dirs) {
85
+ const rel = path.relative(d, normalized).replace(/\\/g, '/');
86
+ if (!rel.startsWith('..')) return rel + ':';
87
+ }
88
+ return path.basename(normalized) + ':';
89
+ }
90
+
76
91
  log.setLevel(['debug', 'info', 'warn', 'error'].indexOf(config.verbosity) === -1 ? 'info' : config.verbosity);
77
92
  log.info('she ' + pkg.version + ' starting');
78
93
  log.debug('loaded config: ', config);
@@ -296,9 +311,9 @@ if (config.url) {
296
311
  const _mqttOpts = { will: { topic: config.name + '/connected', payload: '0', retain: true } };
297
312
  if (config.mqttUsername) _mqttOpts.username = config.mqttUsername;
298
313
  if (config.mqttPassword) _mqttOpts.password = config.mqttPassword;
299
- if (config.mqttCa) _mqttOpts.ca = config.mqttCa;
314
+ if (config.mqttCa) _mqttOpts.ca = config.mqttCa;
300
315
  if (config.mqttCert) _mqttOpts.cert = config.mqttCert;
301
- if (config.mqttKey) _mqttOpts.key = config.mqttKey;
316
+ if (config.mqttKey) _mqttOpts.key = config.mqttKey;
302
317
  mqtt = modules.mqtt.connect(config.url, _mqttOpts);
303
318
  mqtt.publish(config.name + '/connected', '2', { retain: true });
304
319
 
@@ -497,18 +512,19 @@ function setVariable(name, val) {
497
512
  }
498
513
 
499
514
  function createScript(source, name) {
500
- log.debug(name, 'compiling');
515
+ const compileLabel = makeLabel(name);
516
+ log.debug(compileLabel, 'compiling');
501
517
  try {
502
518
  return new vm.Script(source, { filename: name });
503
519
  } catch (err) {
504
- log.error(name, err.name + ':', err.message);
520
+ log.error(compileLabel, err.name + ':', err.message);
505
521
  return false;
506
522
  }
507
523
  }
508
524
 
509
525
  function runScript(script, name, origin) {
510
526
  const scriptDir = path.dirname(path.resolve(name));
511
- const logLabel = (origin || 'user') + '::' + path.basename(name) + ':';
527
+ const logLabel = makeLabel(name);
512
528
 
513
529
  // Initialise per-script resource tracking
514
530
  if (!scriptJobs.has(name)) scriptJobs.set(name, []);
@@ -980,7 +996,7 @@ function runScript(script, name, origin) {
980
996
  md(she, { scriptDomain, scriptName, scriptFile: name });
981
997
  });
982
998
 
983
- log.debug(name, 'contextifying sandbox');
999
+ log.debug(logLabel, 'contextifying sandbox');
984
1000
  const context = vm.createContext(Sandbox);
985
1001
 
986
1002
  scriptDomain.on('error', (e) => {
@@ -1009,7 +1025,7 @@ function runScript(script, name, origin) {
1009
1025
  function loadScript(file, origin) {
1010
1026
  origin = origin || 'user';
1011
1027
  file = file.replace(/\\/g, '/');
1012
- const loadLabel = (origin || 'user') + '::' + path.basename(file) + ':';
1028
+ const loadLabel = makeLabel(file);
1013
1029
  if (scripts[file]) {
1014
1030
  log.error(loadLabel, 'already loaded?!');
1015
1031
  return;
@@ -1037,7 +1053,7 @@ function loadScript(file, origin) {
1037
1053
  function unloadScript(file) {
1038
1054
  file = file.replace(/\\/g, '/');
1039
1055
  const origin = scriptOrigins.get(file) || 'user';
1040
- const unloadLabel = (origin || 'user') + '::' + path.basename(file) + ':';
1056
+ const unloadLabel = makeLabel(file);
1041
1057
  log.info(unloadLabel, 'unloading');
1042
1058
  scriptOrigins.delete(file);
1043
1059
 
@@ -1046,12 +1062,18 @@ function unloadScript(file) {
1046
1062
 
1047
1063
  // Remove MQTT subscriptions belonging to this script
1048
1064
  for (let i = subscriptions.length - 1; i >= 0; i--) {
1049
- if (subscriptions[i]._script === file) { subscriptions.splice(i, 1); removedCallbacks++; }
1065
+ if (subscriptions[i]._script === file) {
1066
+ subscriptions.splice(i, 1);
1067
+ removedCallbacks++;
1068
+ }
1050
1069
  }
1051
1070
 
1052
1071
  // Remove MQTT event callbacks (connect/disconnect) belonging to this script
1053
1072
  for (let i = mqttEventCallbacks.length - 1; i >= 0; i--) {
1054
- if (mqttEventCallbacks[i]._script === file) { mqttEventCallbacks.splice(i, 1); removedCallbacks++; }
1073
+ if (mqttEventCallbacks[i]._script === file) {
1074
+ mqttEventCallbacks.splice(i, 1);
1075
+ removedCallbacks++;
1076
+ }
1055
1077
  }
1056
1078
 
1057
1079
  // Remove HTTP routes registered by this script via she.api
@@ -1158,7 +1180,7 @@ function loadSandbox(callback) {
1158
1180
  sandboxWatcher.on('ready', () => log.debug('watch', dir, 'initialized'));
1159
1181
  sandboxWatcher.on('all', (event, filePath) => {
1160
1182
  sandboxWatcher.close();
1161
- log.info(filePath, 'sandbox change detected. exiting.');
1183
+ log.info(makeLabel(filePath), 'sandbox change detected. exiting.');
1162
1184
  process.exit(0);
1163
1185
  });
1164
1186
  }
@@ -1290,9 +1312,9 @@ function loadDir(dir) {
1290
1312
  // .shelib marker changes - warn only, manual restart required
1291
1313
  if (basename === '.shelib') {
1292
1314
  if (event === 'add') {
1293
- log.warn(filePath, 'library marker added - .js files in this directory will no longer load as scripts after daemon restart');
1315
+ log.warn(makeLabel(filePath), 'library marker added - .js files in this directory will no longer load as scripts after daemon restart');
1294
1316
  } else if (event === 'unlink') {
1295
- log.warn(filePath, 'library marker removed - .js files in this directory will load as scripts after daemon restart');
1317
+ log.warn(makeLabel(filePath), 'library marker removed - .js files in this directory will load as scripts after daemon restart');
1296
1318
  }
1297
1319
  return;
1298
1320
  }
@@ -1312,32 +1334,33 @@ function loadDir(dir) {
1312
1334
  return;
1313
1335
  }
1314
1336
 
1337
+ const fileLabel = makeLabel(filePath);
1315
1338
  if (event === 'change' && filePath.endsWith('.js')) {
1316
1339
  if (isLibFile(filePath, dir)) {
1317
- log.warn(filePath, 'is a library file - scripts that require() it will see the old version until they or the daemon are restarted');
1340
+ log.warn(fileLabel, 'is a library file - scripts that require() it will see the old version until they or the daemon are restarted');
1318
1341
  return;
1319
1342
  }
1320
1343
  if (isDisabledPath(filePath) || isInDisabledDir(filePath, dir)) {
1321
- log.debug(filePath, 'is disabled - ignoring change');
1344
+ log.debug(fileLabel, 'is disabled - ignoring change');
1322
1345
  return;
1323
1346
  }
1324
- log.info(filePath, 'change detected. hot-reloading.');
1347
+ log.info(fileLabel, 'change detected. hot-reloading.');
1325
1348
  unloadScript(filePath);
1326
1349
  loadScript(filePath);
1327
1350
  } else if (event === 'add' && filePath.endsWith('.js')) {
1328
1351
  if (isLibFile(filePath, dir)) {
1329
- log.debug(filePath, 'is a library file - not loading as script');
1352
+ log.debug(fileLabel, 'is a library file - not loading as script');
1330
1353
  return;
1331
1354
  }
1332
1355
  if (isDisabledPath(filePath) || isInDisabledDir(filePath, dir)) {
1333
- log.debug(filePath, 'is disabled - not loading as script');
1356
+ log.debug(fileLabel, 'is disabled - not loading as script');
1334
1357
  return;
1335
1358
  }
1336
- log.info(filePath, 'added. loading.');
1359
+ log.info(fileLabel, 'added. loading.');
1337
1360
  loadScript(filePath);
1338
1361
  } else if (event === 'unlink' && filePath.endsWith('.js')) {
1339
1362
  if (scripts[filePath]) {
1340
- log.info(filePath, 'removed. unloading.');
1363
+ log.info(fileLabel, 'removed. unloading.');
1341
1364
  unloadScript(filePath);
1342
1365
  }
1343
1366
  }
@@ -46,6 +46,7 @@ function walk(dir, base, parentIsLib) {
46
46
  for (const entry of entries) {
47
47
  if (entry.name === '.shelib') continue;
48
48
  if (entry.name.startsWith('.shedisable-')) continue;
49
+ if (entry.isDirectory() && entry.name.startsWith('.')) continue;
49
50
  const rel = base ? `${base}/${entry.name}` : entry.name;
50
51
  if (entry.isDirectory()) {
51
52
  results.push(...walk(path.join(dir, entry.name), rel, lib));
@@ -75,6 +76,7 @@ function buildTree(dir, base, parentIsLib) {
75
76
  for (const entry of entries) {
76
77
  if (entry.name === '.shelib') continue;
77
78
  if (entry.name.startsWith('.shedisable-')) continue;
79
+ if (entry.isDirectory() && entry.name.startsWith('.')) continue;
78
80
  const rel = base ? `${base}/${entry.name}` : entry.name;
79
81
  const abs = path.join(dir, entry.name);
80
82
  if (entry.isDirectory()) {