Skip to content

Commit f04d1b1

Browse files
watch: track worker thread dependencies in --watch mode for esm modules
1 parent b350212 commit f04d1b1

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
@@ -534,6 +534,19 @@ class ModuleLoader {
534534
const type = requestType === kRequireInImportedCJS ? 'require' : 'import';
535535
process.send({ [`watch:${type}`]: [url] });
536536
}
537+
538+
// Relay Events from worker to main thread
539+
if (process.env.WATCH_REPORT_DEPENDENCIES && !process.send) {
540+
const { isMainThread } = internalBinding('worker');
541+
if (isMainThread) {
542+
return;
543+
}
544+
const { parentPort } = require('worker_threads');
545+
if (!parentPort) {
546+
return;
547+
}
548+
parentPort.postMessage({ 'watch:import': [url] });
549+
}
537550

538551
// TODO(joyeecheung): update the module requests to use importAttributes as property names.
539552
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)