Skip to content

Commit ad550d3

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 acb1bd7 commit ad550d3

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
@@ -201,6 +201,17 @@ class HeapProfileHandle {
201201
}
202202
}
203203

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

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

0 commit comments

Comments
 (0)