MCPcopy Index your code
hub / github.com/Waishnav/devspace / watchDirectory

Function watchDirectory

scripts/dev-server.mjs:63–99  ·  view source on GitHub ↗
(root)

Source from the content-addressed store, hash-verified

61}
62
63function watchDirectory(root) {
64 const watchers = [];
65 const seen = new Set();
66
67 function addDirectory(dir) {
68 if (seen.has(dir)) return;
69 seen.add(dir);
70
71 const watcher = watch(dir, (event, filename) => {
72 if (!filename) {
73 scheduleRestart();
74 return;
75 }
76
77 const path = join(dir, filename.toString());
78 if (event === "rename") maybeAddDirectory(path);
79 scheduleRestart();
80 });
81 watchers.push(watcher);
82
83 for (const entry of readdirSync(dir)) {
84 maybeAddDirectory(join(dir, entry));
85 }
86 }
87
88 function maybeAddDirectory(path) {
89 try {
90 const stats = statSync(path);
91 if (stats.isDirectory()) addDirectory(path);
92 } catch {
93 // The file may have been deleted between the watch event and stat call.
94 }
95 }
96
97 addDirectory(root);
98 return watchers;
99}
100
101function shutdown() {
102 shuttingDown = true;

Callers 1

dev-server.mjsFile · 0.85

Calls 1

addDirectoryFunction · 0.85

Tested by

no test coverage detected