Skip to content

Commit 930dc62

Browse files
watch: track worker thread dependencies in --watch mode for esm modules
1 parent c9f14a3 commit 930dc62

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/internal/modules/esm/loader.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,19 @@ class ModuleLoader {
531531
const type = requestType === kRequireInImportedCJS ? 'require' : 'import';
532532
process.send({ [`watch:${type}`]: [url] });
533533
}
534+
535+
// Relay Events from worker to main thread
536+
if (process.env.WATCH_REPORT_DEPENDENCIES && !process.send) {
537+
const { isMainThread } = internalBinding('worker');
538+
if (isMainThread) {
539+
return;
540+
}
541+
const { parentPort } = require('worker_threads');
542+
if (!parentPort) {
543+
return;
544+
}
545+
parentPort.postMessage({ 'watch:import': [url] });
546+
}
534547

535548
// TODO(joyeecheung): update the module requests to use importAttributes as property names.
536549
const importAttributes = resolveResult.importAttributes ?? request.attributes;

lib/internal/worker.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ class Worker extends EventEmitter {
341341
if (ArrayIsArray(message?.['watch:require'])) {
342342
process.send({ 'watch:require': message['watch:require'] });
343343
}
344+
if (ArrayIsArray(message?.['watch:import'])) {
345+
process.send({ 'watch:import': message['watch:import'] });
346+
}
344347
});
345348
}
346349
this[kPort].postMessage({

0 commit comments

Comments
 (0)