From 333c84281d3137ec8558fba9adae85f13999b8db Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Sun, 5 Apr 2026 06:09:22 +0100 Subject: [PATCH] Update watcher to rebuild on api dir change --- dist/functions/server/watcher-esbuild-ctx.js | 17 +++++++++++++---- package.json | 2 +- src/functions/server/watcher-esbuild-ctx.ts | 20 ++++++++++++++------ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/dist/functions/server/watcher-esbuild-ctx.js b/dist/functions/server/watcher-esbuild-ctx.js index 0344491..027ea72 100644 --- a/dist/functions/server/watcher-esbuild-ctx.js +++ b/dist/functions/server/watcher-esbuild-ctx.js @@ -1,4 +1,4 @@ -import { watch, existsSync } from "fs"; +import { watch, existsSync, statSync } from "fs"; import path from "path"; import grabDirNames from "../../utils/grab-dir-names"; import { log } from "../../utils/log"; @@ -16,6 +16,10 @@ export default async function watcherEsbuildCTX() { return; } const full_file_path = path.join(ROOT_DIR, filename); + const does_file_exist = existsSync(full_file_path); + const file_stat = does_file_exist + ? statSync(full_file_path) + : undefined; if (full_file_path.match(/\/styles$/)) { global.RECOMPILING = true; await Bun.sleep(1000); @@ -49,7 +53,8 @@ export default async function watcherEsbuildCTX() { } return; } - const is_file_of_interest = Boolean(filename.match(target_files_match)); + const is_file_of_interest = Boolean(filename.match(target_files_match)) || + file_stat?.isDirectory(); if (!is_file_of_interest) { return; } @@ -61,8 +66,12 @@ export default async function watcherEsbuildCTX() { return; if (global.RECOMPILING) return; - const action = existsSync(full_file_path) ? "created" : "deleted"; - const type = filename.match(/\.css$/) ? "Sylesheet" : "Page"; + const action = does_file_exist ? "created" : "deleted"; + const type = filename.match(/\.css$/) + ? "Sylesheet" + : file_stat?.isDirectory() + ? "Directory" + : "Page"; await fullRebuild({ msg: `${type} ${action}: ${filename}. Rebuilding ...`, }); diff --git a/package.json b/package.json index 292c0bb..80b5a79 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@moduletrace/bunext", "module": "index.ts", "type": "module", - "version": "1.0.48", + "version": "1.0.49", "main": "dist/index.js", "types": "dist/index.d.ts", "exports": { diff --git a/src/functions/server/watcher-esbuild-ctx.ts b/src/functions/server/watcher-esbuild-ctx.ts index 9ba03af..9d993ec 100644 --- a/src/functions/server/watcher-esbuild-ctx.ts +++ b/src/functions/server/watcher-esbuild-ctx.ts @@ -1,4 +1,4 @@ -import { watch, existsSync } from "fs"; +import { watch, existsSync, statSync } from "fs"; import path from "path"; import grabDirNames from "../../utils/grab-dir-names"; import { log } from "../../utils/log"; @@ -22,6 +22,10 @@ export default async function watcherEsbuildCTX() { } const full_file_path = path.join(ROOT_DIR, filename); + const does_file_exist = existsSync(full_file_path); + const file_stat = does_file_exist + ? statSync(full_file_path) + : undefined; if (full_file_path.match(/\/styles$/)) { global.RECOMPILING = true; @@ -69,9 +73,9 @@ export default async function watcherEsbuildCTX() { return; } - const is_file_of_interest = Boolean( - filename.match(target_files_match), - ); + const is_file_of_interest = + Boolean(filename.match(target_files_match)) || + file_stat?.isDirectory(); if (!is_file_of_interest) { return; @@ -83,8 +87,12 @@ export default async function watcherEsbuildCTX() { if (global.RECOMPILING) return; - const action = existsSync(full_file_path) ? "created" : "deleted"; - const type = filename.match(/\.css$/) ? "Sylesheet" : "Page"; + const action = does_file_exist ? "created" : "deleted"; + const type = filename.match(/\.css$/) + ? "Sylesheet" + : file_stat?.isDirectory() + ? "Directory" + : "Page"; await fullRebuild({ msg: `${type} ${action}: ${filename}. Rebuilding ...`,