Skip to content

Commit b06a7ca

Browse files
watch: track worker 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 watch mode, ensuring restarts when worker files change. Fixes: #62275 Signed-off-by: SudhansuBandha <[email protected]>
1 parent 4e3a873 commit b06a7ca

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
@@ -181,6 +181,9 @@ class FilesWatcher extends EventEmitter {
181181
if (ArrayIsArray(message['watch:import'])) {
182182
ArrayPrototypeForEach(message['watch:import'], (file) => this.filterFile(fileURLToPath(file), key));
183183
}
184+
if (ArrayIsArray(message['watch:worker'])) {
185+
ArrayPrototypeForEach(message['watch:worker'], (file) => this.filterFile(file, key));
186+
}
184187
} catch {
185188
// Failed watching file. ignore
186189
}

lib/internal/worker.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ class HeapProfileHandle {
202202
}
203203
}
204204

205+
/**
206+
* Tell the watch mode that a worker file was instantiated.
207+
* @param {string} filename Absolute path of the worker file
208+
* @returns {void}
209+
*/
210+
function reportWorkerToWatchMode(filename) {
211+
if (process.env.WATCH_REPORT_DEPENDENCIES && process.send) {
212+
process.send({ 'watch:worker': [filename] });
213+
}
214+
}
215+
205216
class Worker extends EventEmitter {
206217
constructor(filename, options = kEmptyObject) {
207218
throwIfBuildingSnapshot('Creating workers');
@@ -282,6 +293,11 @@ class Worker extends EventEmitter {
282293
name = StringPrototypeTrim(options.name);
283294
}
284295

296+
// Report to watch mode if this is a regular file (not eval, internal, or data URL)
297+
if (!isInternal && doEval === false) {
298+
reportWorkerToWatchMode(filename);
299+
}
300+
285301
debug('instantiating Worker.', `url: ${url}`, `doEval: ${doEval}`);
286302
// Set up the C++ handle for the worker, as well as some internal wiring.
287303
this[kHandle] = new WorkerImpl(url,

0 commit comments

Comments
 (0)