Skip to content

Commit

Permalink
Fix worker environment variable (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper De Moor authored and fathyb committed May 26, 2018
1 parent 304eb5f commit d3e04b5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function stringWidth(string) {
// If we are in a worker, make a proxy class which will
// send the logger calls to the main process via IPC.
// These are handled in WorkerFarm and directed to handleMessage above.
if (process.send && process.env.WORKER_TYPE === 'parcel-worker') {
if (process.send && process.env.PARCEL_WORKER_TYPE === 'remote-worker') {
const worker = require('./worker');
class LoggerProxy {}
for (let method of Object.getOwnPropertyNames(Logger.prototype)) {
Expand Down
18 changes: 11 additions & 7 deletions src/worker.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
require('v8-compile-cache');
const Pipeline = require('./Pipeline');
const child = require('./workerfarm/child');
const WorkerFarm = require('./workerfarm/WorkerFarm');

let pipeline;
let child;

function init(options, isLocal = false) {
function setChildReference(childReference) {
child = childReference;
}

function init(options) {
pipeline = new Pipeline(options || {});
Object.assign(process.env, options.env || {});
Object.assign(process.env, options.env || {}, {
PARCEL_WORKER_TYPE: child ? 'remote-worker' : 'local-worker'
});
process.env.HMR_PORT = options.hmrPort;
process.env.HMR_HOSTNAME = options.hmrHostname;
if (isLocal) {
process.env.WORKER_TYPE = 'parcel-worker';
}
}

async function run(path, isWarmUp) {
Expand All @@ -26,7 +29,7 @@ async function run(path, isWarmUp) {

// request.location is a module path relative to src or lib
async function addCall(request, awaitResponse = true) {
if (process.send && process.env.WORKER_TYPE === 'parcel-worker') {
if (process.send && process.env.PARCEL_WORKER_TYPE === 'remote-worker') {
return child.addCall(request, awaitResponse);
} else {
return WorkerFarm.getShared().processRequest(request);
Expand All @@ -36,3 +39,4 @@ async function addCall(request, awaitResponse = true) {
exports.init = init;
exports.run = run;
exports.addCall = addCall;
exports.setChildReference = setChildReference;
2 changes: 1 addition & 1 deletion src/workerfarm/WorkerFarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class WorkerFarm extends EventEmitter {
}

init(options) {
this.localWorker.init(options, true);
this.localWorker.init(options);
this.initRemoteWorkers(options);
}

Expand Down
2 changes: 2 additions & 0 deletions src/workerfarm/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Child {
this.responseQueue = new Map();
this.responseId = 0;
this.maxConcurrentCalls = 10;

process.env.PARCEL_WORKER_TYPE = 'remote-worker';
}

messageListener(data) {
Expand Down

0 comments on commit d3e04b5

Please sign in to comment.