Skip to content

Commit 48e5a4a

Browse files
watch: track worker thread entry files in --watch mode
Currently, --watch mode only tracks dependencies from the main module graph (require/import). Worker thread entry points created via new Worker() are not included, so changes to worker files do not trigger restarts. This change hooks into Worker initialization and registers the worker entry file with the watch mode, ensuring restarts when worker files change. Fixes: #62275
1 parent 86282b5 commit 48e5a4a

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

lib/internal/watch_mode/files_watcher.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ class FilesWatcher extends EventEmitter {
179179
if (ArrayIsArray(message['watch:import'])) {
180180
ArrayPrototypeForEach(message['watch:import'], (file) => this.filterFile(fileURLToPath(file), key));
181181
}
182+
if (ArrayIsArray(message['watch:worker'])) {
183+
ArrayPrototypeForEach(message['watch:worker'], (file) => this.filterFile(file, key));
184+
}
182185
} catch {
183186
// Failed watching file. ignore
184187
}

lib/internal/worker.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,17 @@ class HeapProfileHandle {
195195
}
196196
}
197197

198+
/**
199+
* Tell the watch mode that a worker file was instantiated.
200+
* @param {string} filename Absolute path of the worker file
201+
* @returns {void}
202+
*/
203+
function reportWorkerToWatchMode(filename) {
204+
if (process.env.WATCH_REPORT_DEPENDENCIES && process.send) {
205+
process.send({ 'watch:worker': [filename] });
206+
}
207+
}
208+
198209
class Worker extends EventEmitter {
199210
constructor(filename, options = kEmptyObject) {
200211
throwIfBuildingSnapshot('Creating workers');
@@ -275,6 +286,11 @@ class Worker extends EventEmitter {
275286
name = StringPrototypeTrim(options.name);
276287
}
277288

289+
// Report to watch mode if this is a regular file (not eval, internal, or data URL)
290+
if (!isInternal && doEval === false) {
291+
reportWorkerToWatchMode(filename);
292+
}
293+
278294
debug('instantiating Worker.', `url: ${url}`, `doEval: ${doEval}`);
279295
// Set up the C++ handle for the worker, as well as some internal wiring.
280296
this[kHandle] = new WorkerImpl(url,

0 commit comments

Comments
 (0)