Update watcher to rebuild on api dir change

This commit is contained in:
Benjamin Toby 2026-04-05 06:09:22 +01:00
parent 5166ba037f
commit 333c84281d
3 changed files with 28 additions and 11 deletions

View File

@ -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 ...`,
});

View File

@ -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": {

View File

@ -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 ...`,