From b7adbbdd4aefc6159eb3835d0a67246255a352ec Mon Sep 17 00:00:00 2001 From: Tero Piirainen Date: Mon, 15 Jan 2024 14:43:12 +0200 Subject: [PATCH] Handle new folders and folder renames smoothly with hot-reload. Fixes #166 --- packages/nuekit/src/nuefs.js | 19 ++++++++++++++++--- pnpm-lock.yaml | 13 ++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/nuekit/src/nuefs.js b/packages/nuekit/src/nuefs.js index e0b4672c..4612c9df 100644 --- a/packages/nuekit/src/nuefs.js +++ b/packages/nuekit/src/nuefs.js @@ -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" @@ -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) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 820114a5..63c44393 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,15 +19,18 @@ importers: diff-dom: specifier: ^5.0.6 version: 5.1.2 + import-meta-resolve: + specifier: ^4.0.0 + version: 4.0.0 js-yaml: specifier: ^4.1.0 version: 4.1.0 - marked: - specifier: ^9.1.6 - version: 9.1.6 nuejs-core: specifier: ^0.3.0 version: link:../nuejs + nuemark: + specifier: ^0.1.0 + version: link:../nuemark packages/nuemark: dependencies: @@ -89,6 +92,10 @@ packages: entities: 4.5.0 dev: false + /import-meta-resolve@4.0.0: + resolution: {integrity: sha512-okYUR7ZQPH+efeuMJGlq4f8ubUgO50kByRPyt/Cy1Io4PSRsPjxME+YlVaCOx+NIToW7hCsZNFJyTPFFKepRSA==} + dev: false + /js-yaml@4.1.0: resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==} hasBin: true