MCPcopy Index your code
hub / github.com/nodejs/node / #watchFolder

Method #watchFolder

lib/internal/fs/recursive_watch.js:121–167  ·  view source on GitHub ↗
(folder)

Source from the content-addressed store, hash-verified

119 }
120
121 #watchFolder(folder) {
122 const { readdirSync } = lazyLoadFsSync();
123
124 try {
125 const files = readdirSync(folder, {
126 withFileTypes: true,
127 });
128
129 for (const file of files) {
130 if (this.#closed) {
131 break;
132 }
133
134 const f = pathJoin(folder, file.name);
135 const relativePath = pathRelative(this.#rootPath, f);
136
137 // Skip watching ignored paths entirely to avoid kernel resource pressure
138 if (this.#ignoreMatcher?.(relativePath)) {
139 continue;
140 }
141
142 if (!this.#files.has(f)) {
143 this.emit('change', 'rename', relativePath);
144
145 if (file.isSymbolicLink()) {
146 this.#symbolicFiles.add(f);
147 }
148
149 try {
150 this.#watchFile(f);
151 if (file.isDirectory() && !file.isSymbolicLink()) {
152 this.#watchFolder(f);
153 }
154 } catch (err) {
155 // Ignore ENOENT
156 if (err.code !== 'ENOENT') {
157 throw err;
158 }
159 }
160 }
161 }
162 } catch (error) {
163 if (error.code !== 'ENOENT') {
164 this.emit('error', error);
165 }
166 }
167 }
168
169 #watchFile(file) {
170 if (this.#closed) {

Callers 2

#watchFileMethod · 0.95
[kFSWatchStart]Method · 0.95

Calls 8

#watchFileMethod · 0.95
lazyLoadFsSyncFunction · 0.85
hasMethod · 0.65
addMethod · 0.65
readdirSyncFunction · 0.50
emitMethod · 0.45
isSymbolicLinkMethod · 0.45
isDirectoryMethod · 0.45

Tested by

no test coverage detected