import * as fetch from "node-fetch" ; declare var __fbBatchedBridge ; declare var __platformBundles ; process . on ( "message" , ( message ) => { let shouldQueueMessages = false ; const messageQueue = [ ] ; const processEnqueuedMessages = ( ) => { while ( messageQueue . length ) { const messageProcess = messageQueue . shift ( ) ; if ( messageProcess ) { messageProcess ( ) ; } } shouldQueueMessages = false ; } ; const messageHandlers = { executeApplicationScript ( message ) { for ( const key in message . inject ) { ( global as any ) [ key ] = JSON . parse ( message . inject [ key ] ) ; } shouldQueueMessages = true ; function evalJS ( js ) { try { eval ( js . replace ( /this\["webpackHotUpdate"\]/g , 'self["webpackHotUpdate"]' ) . replace ( "GLOBAL" , "global" ) ) ; } catch ( error ) { console . log ( `Error Message: ${ error . message }` ) ; console . log ( `Error stack: ${ error . stack }` ) ; } finally { if ( process . send ) { process . send ( { replyID : message . id } ) ; processEnqueuedMessages ( ) ; } } } if ( ( global as any ) . __platformBundles != undefined ) { const platformBundles = ( global as any ) . __platformBundles . concat ( ) ; delete ( global as any ) . __platformBundles ; for ( const [ index , pb ] of platformBundles . entries ( ) ) { eval ( pb ) ; } } fetch . default ( message . url ) . then ( ( resp ) => resp . text ( ) ) . then ( evalJS ) ; } , } ; const processMessage = ( ) => { const sendReply = function ( result , error ? ) { if ( process . send ) { process . send ( { replyID : message . id , result , error } ) ; } } ; const handler = messageHandlers [ message . method ] ; if ( handler ) { handler ( message ) ; return ; } let returnValue = [ [ ] , [ ] , [ ] , 0 ] ; try { if ( typeof __fbBatchedBridge === "object" ) { returnValue = __fbBatchedBridge [ message . method ] . apply ( null , message . arguments ) ; } } finally { sendReply ( JSON . stringify ( returnValue ) ) ; } } ; if ( shouldQueueMessages ) { messageQueue . push ( processMessage ) ; } else { processMessage ( ) ; } } ) ;