11require ( 'v8-compile-cache' ) ;
22const Pipeline = require ( './Pipeline' ) ;
3- const child = require ( './workerfarm/child' ) ;
43const WorkerFarm = require ( './workerfarm/WorkerFarm' ) ;
54
65let pipeline ;
6+ let child ;
77
8- function init ( options , isLocal = false ) {
8+ function setChildReference ( childReference ) {
9+ child = childReference ;
10+ }
11+
12+ function init ( options ) {
913 pipeline = new Pipeline ( options || { } ) ;
10- Object . assign ( process . env , options . env || { } ) ;
14+ Object . assign ( process . env , options . env || { } , {
15+ PARCEL_WORKER_TYPE : child ? 'remote-worker' : 'local-worker'
16+ } ) ;
1117 process . env . HMR_PORT = options . hmrPort ;
1218 process . env . HMR_HOSTNAME = options . hmrHostname ;
13- if ( isLocal ) {
14- process . env . WORKER_TYPE = 'parcel-worker' ;
15- }
1619}
1720
1821async function run ( path , isWarmUp ) {
@@ -26,7 +29,7 @@ async function run(path, isWarmUp) {
2629
2730// request.location is a module path relative to src or lib
2831async function addCall ( request , awaitResponse = true ) {
29- if ( process . send && process . env . WORKER_TYPE === 'parcel -worker' ) {
32+ if ( process . send && process . env . PARCEL_WORKER_TYPE === 'remote -worker' ) {
3033 return child . addCall ( request , awaitResponse ) ;
3134 } else {
3235 return WorkerFarm . getShared ( ) . processRequest ( request ) ;
@@ -36,3 +39,4 @@ async function addCall(request, awaitResponse = true) {
3639exports . init = init ;
3740exports . run = run ;
3841exports . addCall = addCall ;
42+ exports . setChildReference = setChildReference ;
0 commit comments