This repository was archived by the owner on Oct 18, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -36,16 +36,32 @@ type resolve = (
3636
3737const isolatedLoader = compareNodeVersion ( [ 20 , 0 , 0 ] ) >= 0 ;
3838
39+ type SendToParent = ( data : {
40+ type : 'dependency' ;
41+ path : string ;
42+ } ) => void ;
43+
44+ let sendToParent : SendToParent | undefined = process . send ? process . send . bind ( process ) : undefined ;
45+
3946/**
4047 * Technically globalPreload is deprecated so it should be in loaders-deprecated
4148 * but it shares a closure with the new load hook
4249 */
4350let mainThreadPort : MessagePort | undefined ;
4451const _globalPreload : GlobalPreloadHook = ( { port } ) => {
4552 mainThreadPort = port ;
53+ sendToParent = port . postMessage . bind ( port ) ;
54+
4655 return `
4756 const require = getBuiltin('module').createRequire("${ import . meta. url } ");
4857 require('@esbuild-kit/core-utils').installSourceMapSupport(port);
58+ if (process.send) {
59+ port.addListener('message', (message) => {
60+ if (message.type === 'dependency') {
61+ process.send(message);
62+ }
63+ });
64+ }
4965 port.unref(); // Allows process to exit without waiting for port to close
5066 ` ;
5167} ;
@@ -220,8 +236,8 @@ export const load: LoadHook = async function (
220236 context ,
221237 defaultLoad ,
222238) {
223- if ( process . send ) {
224- process . send ( {
239+ if ( sendToParent ) {
240+ sendToParent ( {
225241 type : 'dependency' ,
226242 path : url ,
227243 } ) ;
You can’t perform that action at this time.
0 commit comments