dsh-unlag 1.9.106 → 1.9.108

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 +12 -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, mkdirSync, readFileSync, readdirSync, statSync, watch, writeFileSync } from 'node:fs'
3
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, 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'
@@ -271,9 +271,19 @@ function log(line) {
271
271
  * A file that only grows eventually costs the app its own memory budget, and a burst of lines
272
272
  * can land between two periodic checks: the size is read before every write and the whole
273
273
  * line has to fit, so the file never passes the cap even for one event.
274
+ *
275
+ * A full file is moved aside rather than emptied: its lines are the evidence for what led up to
276
+ * the write that filled it, which is the event a reader wants. One previous generation is
277
+ * kept, so a page that floods the log can cost at most one past million bytes.
274
278
  */
275
279
  try {
276
- if (statSync(target).size + Buffer.byteLength(text) > LOG_MAX_BYTES) writeFileSync(target, '')
280
+ if (statSync(target).size + Buffer.byteLength(text) > LOG_MAX_BYTES) {
281
+ try {
282
+ renameSync(target, `${target}.1`)
283
+ } catch {
284
+ writeFileSync(target, '')
285
+ }
286
+ }
277
287
  } catch {
278
288
  /* a missing or unreadable log is created by the append below */
279
289
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unlag",
3
- "version": "1.9.106",
3
+ "version": "1.9.108",
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",