@@ -2,7 +2,7 @@ import { ConnectionSyncStatus, OrgRole, Prisma, RepoIndexingStatus } from '@sour
22import { env } from './env.mjs' ;
33import { prisma } from "@/prisma" ;
44import { SINGLE_TENANT_ORG_ID , SINGLE_TENANT_ORG_DOMAIN , SOURCEBOT_GUEST_USER_ID , SINGLE_TENANT_ORG_NAME } from './lib/constants' ;
5- import { watch } from 'fs ' ;
5+ import chokidar from 'chokidar ' ;
66import { ConnectionConfig } from '@sourcebot/schemas/v3/connection.type' ;
77import { hasEntitlement , loadConfig , isRemotePath , syncSearchContexts } from '@sourcebot/shared' ;
88import { isServiceError , getOrgMetadata } from './lib/utils' ;
@@ -227,9 +227,22 @@ const initSingleTenancy = async () => {
227227
228228 // watch for changes assuming it is a local file
229229 if ( ! isRemotePath ( configPath ) ) {
230- watch ( configPath , ( ) => {
230+ const watcher = chokidar . watch ( configPath , {
231+ ignoreInitial : true , // Don't fire events for existing files
232+ awaitWriteFinish : {
233+ stabilityThreshold : 100 , // File size stable for 100ms
234+ pollInterval : 100 // Check every 100ms
235+ } ,
236+ atomic : true // Handle atomic writes (temp file + rename)
237+ } ) ;
238+
239+ watcher . on ( 'change' , async ( ) => {
231240 logger . info ( `Config file ${ configPath } changed. Re-syncing...` ) ;
232- syncDeclarativeConfig ( configPath ) ;
241+ try {
242+ await syncDeclarativeConfig ( configPath ) ;
243+ } catch ( error ) {
244+ logger . error ( `Failed to sync config: ${ error } ` ) ;
245+ }
233246 } ) ;
234247 }
235248 }
0 commit comments