dsh-unlag 1.9.57 → 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 +10 -11
  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. */
@@ -261,17 +260,17 @@ function ensureLogDir(target) {
261
260
  function log(line) {
262
261
  try {
263
262
  const target = logTarget()
264
- // A file that only grows eventually costs the app its own memory budget: every 200 lines the
265
- // size is checked once, and a log past the cap starts over instead of growing without end.
266
- logWrites += 1
267
- if (logWrites % 200 === 1) {
268
- try {
269
- if (statSync(target).size > LOG_MAX_BYTES) writeFileSync(target, '')
270
- } catch {
271
- /* a missing or unreadable log is created by the append below */
272
- }
273
- }
274
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
+ }
275
274
  try {
276
275
  appendFileSync(target, text)
277
276
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unlag",
3
- "version": "1.9.57",
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",