Open
Milestone
started on Nov 18, 2025
Node watch better performance in windows or extenal drive
Node watching, in windows, can be slow.
We probably can act a solution like:
// system/watch.js
import { spawn } from 'node:child_process'
import { watch } from 'node:fs'
import { resolve } from 'node:path'
const ENGINE = resolve('./system-core/engine.js')
const WATCH_PATHS = [
'./server-public',
'./system-pkgs/htmlexpress/resources',
]
// Very small ignore list, keep it strict
const IGNORE_RE = /(^|[\\/])(\.git|node_modules|system-core)([\\/]|$)|(\.hmac$)|(\.keys$)/i
let child = null
let restarting = false
let timer = null
function start(args) {
child = spawn(process.execPath, [ENGINE, ...args], { stdio: 'inherit' })
child.on('exit', () => { child = null })
}
function stop() {
if (!child) return
// Try graceful first
child.kill('SIGTERM')
// Force kill after 800ms
setTimeout(() => {
if (child) child.kill('SIGKILL')
}, 800)
}
function restart(args, reasonPath) {
if (restarting) return
restarting = true
// optional: log
// console.log('[watch] restart →', reasonPath)
stop()
// Give OS a breath (Windows)
setTimeout(() => {
start(args)
restarting = false
}, 150)
}
function main() {
const args = process.argv.slice(2) // pass-through: "start", etc.
start(args)
for (const p of WATCH_PATHS) {
const abs = resolve(p)
// recursive works only on Windows/macOS. On Linux it throws.
const recursive = process.platform !== 'linux'
watch(abs, { recursive }, (eventType, filename) => {
const full = filename ? `${abs}/${filename}` : abs
if (IGNORE_RE.test(full)) return
clearTimeout(timer)
timer = setTimeout(() => restart(args, full), 120) // your debounce
})
}
}
main()Loading
Loading
Loading
Loading