smart-home-engine 0.24.2 → 0.24.4

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-7iwVdvJ3.js";/*!-----------------------------------------------------------------------------
1
+ import{m as O}from"./monaco-langs-BW2J83t5.js";import{t as I}from"./index-il0dS2iT.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-7iwVdvJ3.js"></script>
158
+ <script type="module" crossorigin src="/assets/index-il0dS2iT.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-OfBaeGiK.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-home-engine",
3
- "version": "0.24.2",
3
+ "version": "0.24.4",
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
@@ -362,7 +362,7 @@ if (config.url) {
362
362
  } else {
363
363
  if (!state) {
364
364
  log.error('invalid state', topic, payload);
365
- process.exit();
365
+ return;
366
366
  }
367
367
  if (!state.ts) {
368
368
  state.ts = new Date().getTime();
@@ -1329,12 +1329,21 @@ function loadDir(dir) {
1329
1329
  return;
1330
1330
  }
1331
1331
 
1332
- // .shelib marker changes - warn only, manual restart required
1332
+ // .shelib marker changes - unload or reload scripts in the affected directory
1333
1333
  if (basename === '.shelib') {
1334
+ const affectedDir = path.dirname(filePath);
1334
1335
  if (event === 'add') {
1335
- log.warn(makeLabel(filePath), 'library marker added - .js files in this directory will no longer load as scripts after daemon restart');
1336
+ log.info(makeLabel(filePath), 'library marker added - unloading scripts in this directory');
1337
+ Object.keys(scripts).forEach((scriptFile) => {
1338
+ const absScript = path.resolve(scriptFile);
1339
+ const absDir = path.resolve(affectedDir);
1340
+ if (absScript.startsWith(absDir + path.sep) || path.dirname(absScript) === absDir) {
1341
+ unloadScript(scriptFile);
1342
+ }
1343
+ });
1336
1344
  } else if (event === 'unlink') {
1337
- log.warn(makeLabel(filePath), 'library marker removed - .js files in this directory will load as scripts after daemon restart');
1345
+ log.info(makeLabel(filePath), 'library marker removed - loading scripts in this directory');
1346
+ loadDirRecursive(affectedDir, path.resolve(dir));
1338
1347
  }
1339
1348
  return;
1340
1349
  }
@@ -140,10 +140,18 @@ module.exports = function (she) {
140
140
  * @returns {Promise<string|object>}
141
141
  */
142
142
  she.fetch = function Sandbox_fetch(url, options) {
143
- return fetch(url, options).then((r) => {
143
+ const TIMEOUT_MS = 30_000;
144
+ let signal = options?.signal;
145
+ let timer;
146
+ if (!signal) {
147
+ const ac = new AbortController();
148
+ signal = ac.signal;
149
+ timer = setTimeout(() => ac.abort(new Error(`she.fetch timed out after ${TIMEOUT_MS / 1000}s`)), TIMEOUT_MS);
150
+ }
151
+ return fetch(url, { ...options, signal }).then((r) => {
144
152
  if (!r.ok) throw new Error(`HTTP ${r.status} ${r.statusText}`);
145
153
  const ct = r.headers.get('content-type') || '';
146
154
  return ct.includes('json') ? r.json() : r.text();
147
- });
155
+ }).finally(() => clearTimeout(timer));
148
156
  };
149
157
  };
@@ -63,7 +63,7 @@ function walk(dir, base, parentIsLib) {
63
63
  * Nested tree of all files and subdirectories.
64
64
  * Each node: { type:'file'|'dir', name, path, lib, size?, mtime?, children? }
65
65
  */
66
- function buildTree(dir, base, parentIsLib) {
66
+ function buildTree(dir, base, parentIsLib, parentIsDisabled = false) {
67
67
  let entries;
68
68
  try {
69
69
  entries = fs.readdirSync(dir, { withFileTypes: true });
@@ -81,13 +81,15 @@ function buildTree(dir, base, parentIsLib) {
81
81
  const abs = path.join(dir, entry.name);
82
82
  if (entry.isDirectory()) {
83
83
  const childIsLib = lib || hasShelibMarker(abs);
84
- const disabled = hasShedisableMarker(abs);
85
- const children = buildTree(abs, rel, childIsLib);
86
- result.push({ type: 'dir', name: entry.name, path: rel, lib: childIsLib, disabled, children });
84
+ const selfDisabled = hasShedisableMarker(abs);
85
+ const effectiveDisabled = parentIsDisabled || selfDisabled;
86
+ const children = buildTree(abs, rel, childIsLib, effectiveDisabled);
87
+ result.push({ type: 'dir', name: entry.name, path: rel, lib: childIsLib, disabled: selfDisabled, children });
87
88
  } else {
88
89
  const stat = fs.statSync(abs);
89
90
  const isJs = entry.name.endsWith('.js');
90
- const disabled = isJs ? hasShedisableMarker(abs) : false;
91
+ const selfDisabled = isJs ? hasShedisableMarker(abs) : false;
92
+ const disabled = parentIsDisabled || selfDisabled;
91
93
  result.push({ type: 'file', name: entry.name, path: rel, lib, size: stat.size, mtime: stat.mtimeMs, ...(isJs ? { disabled } : {}) });
92
94
  }
93
95
  }