| 11 | return { |
| 12 | name: `watch-workspace-packages`, |
| 13 | configureServer(server: any) { |
| 14 | const watchPaths = [ |
| 15 | path.resolve(__dirname, `../../../packages/db/dist`), |
| 16 | path.resolve(__dirname, `../../../packages/offline-transactions/dist`), |
| 17 | path.resolve( |
| 18 | __dirname, |
| 19 | `../../../packages/browser-db-sqlite-persistence/dist`, |
| 20 | ), |
| 21 | path.resolve( |
| 22 | __dirname, |
| 23 | `../../../packages/db-sqlite-persistence-core/dist`, |
| 24 | ), |
| 25 | ] |
| 26 | |
| 27 | console.log(`[watch-workspace] Starting to watch paths:`) |
| 28 | watchPaths.forEach((p) => console.log(` - ${p}`)) |
| 29 | console.log(`[watch-workspace] Current directory: ${__dirname}`) |
| 30 | console.log(`[watch-workspace] Resolved paths:`) |
| 31 | watchPaths.forEach((p) => console.log(` - ${path.resolve(p)}`)) |
| 32 | |
| 33 | let ready = false |
| 34 | |
| 35 | const watcher = chokidar.watch(watchPaths, { |
| 36 | ignored: /node_modules/, |
| 37 | persistent: true, |
| 38 | }) |
| 39 | |
| 40 | watcher.on(`ready`, () => { |
| 41 | ready = true |
| 42 | console.log( |
| 43 | `[watch-workspace] Initial scan complete. Watching for changes...`, |
| 44 | ) |
| 45 | }) |
| 46 | |
| 47 | watcher.on(`add`, (filePath) => { |
| 48 | if (!ready) return |
| 49 | console.log(`[watch-workspace] File added: ${filePath}`) |
| 50 | server.ws.send({ |
| 51 | type: `full-reload`, |
| 52 | }) |
| 53 | }) |
| 54 | |
| 55 | watcher.on(`change`, (filePath) => { |
| 56 | if (!ready) return |
| 57 | console.log(`[watch-workspace] File changed: ${filePath}`) |
| 58 | server.ws.send({ |
| 59 | type: `full-reload`, |
| 60 | }) |
| 61 | }) |
| 62 | |
| 63 | watcher.on(`error`, (error) => { |
| 64 | console.error(`[watch-workspace] Watcher error:`, error) |
| 65 | }) |
| 66 | }, |
| 67 | } |
| 68 | } |
| 69 | |