MCPcopy Index your code
hub / github.com/Sandpack/nodebox-runtime / watch

Method watch

packages/nodebox/src/modules/fs.ts:174–195  ·  view source on GitHub ↗

* Subscribe to changes at the given file or directory.

(
    includes: string[],
    excludes: string[],
    listener?: (evt?: FileWatchEvent) => void
  )

Source from the content-addressed store, hash-verified

172 * Subscribe to changes at the given file or directory.
173 */
174 public async watch(
175 includes: string[],
176 excludes: string[],
177 listener?: (evt?: FileWatchEvent) => void
178 ): Promise<{ dispose: () => Promise<void> }> {
179 const watcherId = cuid();
180
181 await this.channel.send('fs/watch', { watcherId, includes, excludes });
182
183 this.channel.on('fs/watch-event', ({ data }) => {
184 if (data.watcherId === watcherId && listener) {
185 const evt = { ...data } as FSWatchEvent;
186 // @ts-ignore
187 delete evt.watcherId;
188 listener(evt);
189 }
190 });
191
192 return {
193 dispose: () => this.channel.send('fs/unwatch', { watcherId }),
194 };
195 }
196}

Callers 1

Calls 2

sendMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected