Skip to content

Commit d3e04b5

Browse files
Jasper De Moorfathyb
authored andcommitted
Fix worker environment variable (#1443)
1 parent 304eb5f commit d3e04b5

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/Logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function stringWidth(string) {
195195
// If we are in a worker, make a proxy class which will
196196
// send the logger calls to the main process via IPC.
197197
// These are handled in WorkerFarm and directed to handleMessage above.
198-
if (process.send && process.env.WORKER_TYPE === 'parcel-worker') {
198+
if (process.send && process.env.PARCEL_WORKER_TYPE === 'remote-worker') {
199199
const worker = require('./worker');
200200
class LoggerProxy {}
201201
for (let method of Object.getOwnPropertyNames(Logger.prototype)) {

src/worker.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
require('v8-compile-cache');
22
const Pipeline = require('./Pipeline');
3-
const child = require('./workerfarm/child');
43
const WorkerFarm = require('./workerfarm/WorkerFarm');
54

65
let 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

1821
async 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
2831
async 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) {
3639
exports.init = init;
3740
exports.run = run;
3841
exports.addCall = addCall;
42+
exports.setChildReference = setChildReference;

src/workerfarm/WorkerFarm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class WorkerFarm extends EventEmitter {
205205
}
206206

207207
init(options) {
208-
this.localWorker.init(options, true);
208+
this.localWorker.init(options);
209209
this.initRemoteWorkers(options);
210210
}
211211

src/workerfarm/child.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class Child {
99
this.responseQueue = new Map();
1010
this.responseId = 0;
1111
this.maxConcurrentCalls = 10;
12+
13+
process.env.PARCEL_WORKER_TYPE = 'remote-worker';
1214
}
1315

1416
messageListener(data) {

0 commit comments

Comments
 (0)