dsh-unlag 1.9.56 → 1.9.58

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 (2) hide show
  1. package/index.js +32 -14
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -64,7 +64,6 @@ const CODE_STAMP = (() => {
64
64
  return 'unknown'
65
65
  }
66
66
  })()
67
- let logWrites = 0
68
67
  /** Tests point this at a scratch file, so a test run leaves the live log readable. */
69
68
  const logTarget = () => process.env.DSH_UNLAG_LOG ?? LOG_PATH
70
69
  /** Survives a module replacement, so a reload cannot leave a second watcher behind. */
@@ -200,15 +199,34 @@ export const Config = {
200
199
  },
201
200
  }
202
201
 
202
+ /** Switches already reported, so a settings form read repeatedly writes one line, not many. */
203
+ const STRANGE_SWITCHES = new Set()
204
+ /**
205
+ * One switch. Absent means the default; a boolean means itself; anything else — a hand-edited
206
+ * string, a number, a list — is not a yes and is read as off, with one line saying so. A row that
207
+ * says "off" must not swap plugin code because the value happened to be the word "no".
208
+ */
209
+ function booleanSwitch(config, key, fallback) {
210
+ const value = config?.[key]
211
+ if (value === undefined || value === null) return fallback
212
+ if (typeof value === 'boolean') return value
213
+ const seen = `${key}=${oneLine(value, 40)}`
214
+ if (!STRANGE_SWITCHES.has(seen) && STRANGE_SWITCHES.size < 32) {
215
+ STRANGE_SWITCHES.add(seen)
216
+ log(`a switch that is not a boolean was read as off: ${seen}`)
217
+ }
218
+ return false
219
+ }
220
+
203
221
  /**
204
222
  * The three switches from any config shape. The press switches default on; automatic reloading
205
223
  * defaults off, and the undocumented `plugins: 'off'` from older configs keeps meaning off.
206
224
  */
207
225
  function settingsOf(config) {
208
226
  return {
209
- reloadPlugins: config?.reloadPlugins !== false,
210
- reloadInterface: config?.reloadInterface !== false,
211
- autoReload: config?.plugins === 'off' ? false : config?.autoReload === true,
227
+ reloadPlugins: booleanSwitch(config, 'reloadPlugins', true),
228
+ reloadInterface: booleanSwitch(config, 'reloadInterface', true),
229
+ autoReload: config?.plugins === 'off' ? false : booleanSwitch(config, 'autoReload', false),
212
230
  }
213
231
  }
214
232
 
@@ -242,17 +260,17 @@ function ensureLogDir(target) {
242
260
  function log(line) {
243
261
  try {
244
262
  const target = logTarget()
245
- // A file that only grows eventually costs the app its own memory budget: every 200 lines the
246
- // size is checked once, and a log past the cap starts over instead of growing without end.
247
- logWrites += 1
248
- if (logWrites % 200 === 1) {
249
- try {
250
- if (statSync(target).size > LOG_MAX_BYTES) writeFileSync(target, '')
251
- } catch {
252
- /* a missing or unreadable log is created by the append below */
253
- }
254
- }
255
263
  const text = `${new Date().toISOString()} ${oneLine(line)}\n`
264
+ /**
265
+ * A file that only grows eventually costs the app its own memory budget, and a burst of lines
266
+ * can land between two periodic checks: the size is read before every write and the whole
267
+ * line has to fit, so the file never passes the cap even for one event.
268
+ */
269
+ try {
270
+ if (statSync(target).size + Buffer.byteLength(text) > LOG_MAX_BYTES) writeFileSync(target, '')
271
+ } catch {
272
+ /* a missing or unreadable log is created by the append below */
273
+ }
256
274
  try {
257
275
  appendFileSync(target, text)
258
276
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unlag",
3
- "version": "1.9.56",
3
+ "version": "1.9.58",
4
4
  "type": "module",
5
5
  "description": "A press applies plugin edits right away and brings a laggy interface back; automatic reloading stays off unless you turn it on, so the press is the only trigger, and nothing restarts.",
6
6
  "license": "MIT",