Skip to content

Commit

Permalink
Handle new folders and folder renames smoothly with hot-reload. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
tipiirai committed Jan 15, 2024
1 parent c0df54a commit b7adbbd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
19 changes: 16 additions & 3 deletions packages/nuekit/src/nuefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { join, parse, sep } from 'node:path'
/*
Super minimalistic file system watcher.
Auto-follows new directories and symbolic links
Auto-follows new directories and symbolic (file) links
Simple alternative to Chokidar and Nodemon when you "just want to watch"
Expand All @@ -28,11 +28,24 @@ export async function fswatch(dir, onfile, onremove) {

// regular flie -> callback
const stat = await fs.lstat(join(dir, path))
if (!stat.isDirectory()) {

if (stat.isDirectory()) {
const paths = await fswalk(dir, path)

// deploy everything on the directory
for (const path of paths) {
const file = parse(path)
if (!ignore(file.name) && !ignore(file.dir)) {
await onfile({ ...file, path })
}
}

} else {
await onfile({ ...file, path, size: stat.size })
last = { path, ts: Date.now() }
}

last = { path, ts: Date.now() }

} catch (e) {
if (e.errno == -2) await onremove(path)
else console.error(e)
Expand Down
13 changes: 10 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b7adbbd

Please sign in to comment.