From 4e511eef9efbde1d5c178a209bfb4d8fb5f5cf8d Mon Sep 17 00:00:00 2001 From: Rizky Date: Mon, 19 Aug 2024 20:29:51 +0700 Subject: [PATCH] fix --- app/srv/ws/sync/code/parts/init/frontend.ts | 15 +++++++++++++-- app/srv/ws/sync/code/parts/init/watcher.ts | 1 + app/srv/ws/sync/code/parts/watcher.ts | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/srv/ws/sync/code/parts/init/frontend.ts b/app/srv/ws/sync/code/parts/init/frontend.ts index f9cad98e..245181ed 100644 --- a/app/srv/ws/sync/code/parts/init/frontend.ts +++ b/app/srv/ws/sync/code/parts/init/frontend.ts @@ -21,6 +21,8 @@ export const initFrontEnd = async ( ) => { let existing = code.internal.frontend[id_site]; + await isInstalling(id_site); + if (existing) { if (existing.npm) { if (pending[id_site]) return; @@ -48,8 +50,6 @@ export const initFrontEnd = async ( } try { - await isInstalling(id_site); - if (code.internal.frontend[id_site]?.watch) { await code.internal.frontend[id_site].watch.close(); } @@ -111,6 +111,17 @@ const isInstalling = async (id_site: string) => { } } + for (const k of Object.keys(pkg_json.dependencies)) { + if ( + !(await Bun.file( + code.path(id_site, "site", "src", `node_modules/${k}`) + ).exists()) + ) { + should_install = true; + break; + } + } + if (should_install) { await Bun.write(pkg, JSON.stringify(pkg_json, null, 2)); await $`npm i`.cwd(code.path(id_site, "site", "src")).quiet(); diff --git a/app/srv/ws/sync/code/parts/init/watcher.ts b/app/srv/ws/sync/code/parts/init/watcher.ts index 7952782a..12ac3dab 100644 --- a/app/srv/ws/sync/code/parts/init/watcher.ts +++ b/app/srv/ws/sync/code/parts/init/watcher.ts @@ -8,6 +8,7 @@ const watchers = {} as Record; const createWatcher = (p: string, recursive: boolean) => { return watch(p, { recursive }, (e, filename) => { + if (filename === "global.d.ts") return; if ( filename?.endsWith(".tsx") || filename?.endsWith(".ts") || diff --git a/app/srv/ws/sync/code/parts/watcher.ts b/app/srv/ws/sync/code/parts/watcher.ts index 3810e93f..7373e3d4 100644 --- a/app/srv/ws/sync/code/parts/watcher.ts +++ b/app/srv/ws/sync/code/parts/watcher.ts @@ -41,6 +41,7 @@ export class Watcher { stdout: "inherit", stderr: "inherit", ipc(message, childProc) { + console.log(id_site, message); const fe = code.internal.frontend[id_site]; if (typeof fe !== "undefined" && !fe.rebuilding) { fe.rebuilding = true;