MCPcopy Create free account
hub / github.com/coderoad/coderoad-vscode / loadWatchers

Function loadWatchers

src/services/hooks/utils/watchers.ts:17–56  ·  view source on GitHub ↗
(watchers: string[] = [])

Source from the content-addressed store, hash-verified

15}
16
17export const loadWatchers = (watchers: string[] = []): void => {
18 if (!watchers.length) {
19 // remove all watchers
20 for (const watcher of Object.keys(watcherObject)) {
21 disposeWatcher(watcher)
22 }
23 }
24 for (const watcher of watchers) {
25 if (!watcherObject[watcher]) {
26 // see how glob patterns are used in VSCode (not like a regex)
27 // https://code.visualstudio.com/api/references/vscode-api#GlobPattern
28 const fsWatcher: chokidar.FSWatcher = chokidar.watch(watcher, {
29 cwd: WORKSPACE_ROOT,
30 interval: 1000,
31 })
32
33 // prevent firing tests within 1 second of last test check
34 const lastFire: Date | null = null
35
36 // run tests on watcher change
37 fsWatcher.on('change', (path, event) => {
38 const now = +new Date()
39 if (!lastFire || lastFire - now > 1000) {
40 vscode.commands.executeCommand(COMMANDS.RUN_TEST, {
41 callbacks: {
42 onSuccess: () => {
43 // cleanup watcher on success
44 disposeWatcher(watcher)
45 },
46 },
47 })
48 }
49 })
50
51 // key fs watcher on name
52 // to easily add/remove multiple watchers
53 watcherObject[watcher] = fsWatcher
54 }
55 }
56}
57
58export const resetWatchers = (): void => {
59 for (const watcher of Object.keys(watcherObject)) {

Callers 1

onSetupEnterFunction · 0.90

Calls 1

disposeWatcherFunction · 0.85

Tested by

no test coverage detected