From 3bd3ee0429ddece4b79c5688ff189f45a7a1c8dd Mon Sep 17 00:00:00 2001 From: Rizky Date: Fri, 21 Jun 2024 04:59:04 +0700 Subject: [PATCH] fix --- app/srv/util/parse-type-def.ts | 1 + app/srv/ws/sync/code/parts/init/typings.ts | 42 ++++++++++++---------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/srv/util/parse-type-def.ts b/app/srv/util/parse-type-def.ts index 22fa3046..8cb796c3 100644 --- a/app/srv/util/parse-type-def.ts +++ b/app/srv/util/parse-type-def.ts @@ -7,6 +7,7 @@ type SingleExport = { val: string; }; export const parseTypeDef = async (path: string) => { + console.log("parsing", path); const ast = await parseFile(path, { syntax: "typescript" }); const exports = {} as Record; diff --git a/app/srv/ws/sync/code/parts/init/typings.ts b/app/srv/ws/sync/code/parts/init/typings.ts index 1432d4b8..febefedd 100644 --- a/app/srv/ws/sync/code/parts/init/typings.ts +++ b/app/srv/ws/sync/code/parts/init/typings.ts @@ -94,27 +94,31 @@ export const initTypings = async ( } } - const res = JSON.stringify(await parseTypeDef(path)); - await Bun.write( - dir.data(`/code/${id_site}/site/type_def.${file.lastModified}.json`), - res - ); + try { + const res = JSON.stringify(await parseTypeDef(path)); + await Bun.write( + dir.data( + `/code/${id_site}/site/type_def.${file.lastModified}.json` + ), + res + ); - const client_ids = new Set(); - user.active.findAll({ site_id: id_site }).forEach((e) => { - client_ids.add(e.client_id); - }); + const client_ids = new Set(); + user.active.findAll({ site_id: id_site }).forEach((e) => { + client_ids.add(e.client_id); + }); - const now = Date.now(); - client_ids.forEach((client_id) => { - const ws = conns.get(client_id)?.ws; - if (ws) - sendWS(ws, { - type: SyncType.Event, - event: "code_changes", - data: { ts: now, mode: "typings" }, - }); - }); + const now = Date.now(); + client_ids.forEach((client_id) => { + const ws = conns.get(client_id)?.ws; + if (ws) + sendWS(ws, { + type: SyncType.Event, + event: "code_changes", + data: { ts: now, mode: "typings" }, + }); + }); + } catch (e) {} }, 180); }); } catch (e) {