dsh-unlag 1.9.46 → 1.9.47

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 +27 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks'
2
2
  import { createHash } from 'node:crypto'
3
- import { appendFileSync, existsSync, readFileSync, readdirSync, statSync, watch, writeFileSync } from 'node:fs'
3
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, watch, writeFileSync } from 'node:fs'
4
4
  import { homedir } from 'node:os'
5
5
  import { join, resolve } from 'node:path'
6
6
  import { Script } from 'node:vm'
@@ -222,6 +222,23 @@ export function oneLine(value, limit = 2000) {
222
222
  return text.length > limit ? `${text.slice(0, limit)}\u2026` : text
223
223
  }
224
224
 
225
+ /** Whether the directory holding the log has already been made, so one attempt per process. */
226
+ let logDirTried = false
227
+ /**
228
+ * The log is the only evidence a failed update leaves behind, and a home directory that never ran
229
+ * this app yet has no directory for it: one attempt per process to make that directory, then the
230
+ * write is retried. Every failure stays silent, because logging must never take a press down.
231
+ */
232
+ function ensureLogDir(target) {
233
+ if (logDirTried) return
234
+ logDirTried = true
235
+ const cut = target.lastIndexOf('/')
236
+ if (cut <= 0) return
237
+ try {
238
+ mkdirSync(target.slice(0, cut), { recursive: true })
239
+ } catch {}
240
+ }
241
+
225
242
  function log(line) {
226
243
  try {
227
244
  const target = logTarget()
@@ -235,7 +252,15 @@ function log(line) {
235
252
  /* a missing or unreadable log is created by the append below */
236
253
  }
237
254
  }
238
- appendFileSync(target, `${new Date().toISOString()} ${oneLine(line)}\n`)
255
+ const text = `${new Date().toISOString()} ${oneLine(line)}\n`
256
+ try {
257
+ appendFileSync(target, text)
258
+ } catch {
259
+ ensureLogDir(target)
260
+ try {
261
+ appendFileSync(target, text)
262
+ } catch {}
263
+ }
239
264
  } catch {}
240
265
  }
241
266
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unlag",
3
- "version": "1.9.46",
3
+ "version": "1.9.47",
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",