@parcel/workers 2.0.0-nightly.97 → 2.0.0-nightly.970

Sign up to get free protection for your applications and to get access to all the features.
package/lib/child.js CHANGED
@@ -5,75 +5,102 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Child = void 0;
7
7
 
8
- var _assert = _interopRequireDefault(require("assert"));
8
+ function _assert() {
9
+ const data = _interopRequireDefault(require("assert"));
9
10
 
10
- var _nullthrows = _interopRequireDefault(require("nullthrows"));
11
+ _assert = function () {
12
+ return data;
13
+ };
11
14
 
12
- var _logger = _interopRequireWildcard(require("@parcel/logger"));
13
-
14
- var _diagnostic = _interopRequireWildcard(require("@parcel/diagnostic"));
15
-
16
- var _bus = _interopRequireDefault(require("./bus"));
17
-
18
- var _Profiler = _interopRequireDefault(require("./Profiler"));
19
-
20
- var _Handle = _interopRequireDefault(require("./Handle"));
15
+ return data;
16
+ }
21
17
 
22
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
18
+ function _nullthrows() {
19
+ const data = _interopRequireDefault(require("nullthrows"));
23
20
 
24
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+ _nullthrows = function () {
22
+ return data;
23
+ };
25
24
 
26
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+ return data;
26
+ }
27
27
 
28
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
28
+ function _logger() {
29
+ const data = _interopRequireWildcard(require("@parcel/logger"));
29
30
 
30
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
31
+ _logger = function () {
32
+ return data;
33
+ };
31
34
 
32
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+ return data;
36
+ }
33
37
 
34
- class Child {
35
- constructor(ChildBackend) {
36
- _defineProperty(this, "callQueue", []);
38
+ function _diagnostic() {
39
+ const data = _interopRequireWildcard(require("@parcel/diagnostic"));
37
40
 
38
- _defineProperty(this, "childId", void 0);
41
+ _diagnostic = function () {
42
+ return data;
43
+ };
39
44
 
40
- _defineProperty(this, "maxConcurrentCalls", 10);
45
+ return data;
46
+ }
41
47
 
42
- _defineProperty(this, "module", void 0);
48
+ function _core() {
49
+ const data = require("@parcel/core");
43
50
 
44
- _defineProperty(this, "responseId", 0);
51
+ _core = function () {
52
+ return data;
53
+ };
45
54
 
46
- _defineProperty(this, "responseQueue", new Map());
55
+ return data;
56
+ }
47
57
 
48
- _defineProperty(this, "loggerDisposable", void 0);
58
+ var _bus = _interopRequireDefault(require("./bus"));
49
59
 
50
- _defineProperty(this, "child", void 0);
60
+ var _Profiler = _interopRequireDefault(require("./Profiler"));
51
61
 
52
- _defineProperty(this, "profiler", void 0);
62
+ var _Handle2 = _interopRequireDefault(require("./Handle"));
53
63
 
54
- _defineProperty(this, "workerApi", void 0);
64
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
55
65
 
56
- _defineProperty(this, "handles", new Map());
66
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
57
67
 
58
- _defineProperty(this, "sharedReferences", new Map());
68
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
59
69
 
60
- _defineProperty(this, "sharedReferencesByValue", new Map());
70
+ // The import of './Handle' should really be imported eagerly (with @babel/plugin-transform-modules-commonjs's lazy mode).
71
+ const Handle = _Handle2.default;
61
72
 
62
- _defineProperty(this, "workerApi", {
63
- callMaster: (request, awaitResponse = true) => this.addCall(request, awaitResponse),
64
- createReverseHandle: fn => this.createReverseHandle(fn),
65
- getSharedReference: ref => this.sharedReferences.get(ref),
66
- resolveSharedReference: value => this.sharedReferencesByValue.get(value)
67
- });
73
+ class Child {
74
+ callQueue = [];
75
+ maxConcurrentCalls = 10;
76
+ responseId = 0;
77
+ responseQueue = new Map();
78
+ handles = new Map();
79
+ sharedReferences = new Map();
80
+ sharedReferencesByValue = new Map();
68
81
 
69
- this.child = new ChildBackend(this.messageListener.bind(this), this.handleEnd.bind(this)); // Monitior all logging events inside this child process and forward to
82
+ constructor(ChildBackend) {
83
+ this.child = new ChildBackend(m => {
84
+ this.messageListener(m);
85
+ }, () => this.handleEnd()); // Monitior all logging events inside this child process and forward to
70
86
  // the main process via the bus.
71
87
 
72
- this.loggerDisposable = _logger.default.onLog(event => {
88
+ this.loggerDisposable = _logger().default.onLog(event => {
73
89
  _bus.default.emit('logEvent', event);
74
90
  });
75
91
  }
76
92
 
93
+ workerApi = {
94
+ callMaster: (request, awaitResponse = true) => this.addCall(request, awaitResponse),
95
+ createReverseHandle: fn => this.createReverseHandle(fn),
96
+ runHandle: (handle, args) => this.workerApi.callMaster({
97
+ handle: handle.id,
98
+ args
99
+ }, true),
100
+ getSharedReference: ref => this.sharedReferences.get(ref),
101
+ resolveSharedReference: value => this.sharedReferencesByValue.get(value)
102
+ };
103
+
77
104
  messageListener(message) {
78
105
  if (message.type === 'response') {
79
106
  return this.handleResponse(message);
@@ -86,10 +113,14 @@ class Child {
86
113
  this.child.send(data);
87
114
  }
88
115
 
89
- childInit(module, childId) {
116
+ async childInit(module, childId) {
90
117
  // $FlowFixMe this must be dynamic
91
118
  this.module = require(module);
92
119
  this.childId = childId;
120
+
121
+ if (this.module.childInit != null) {
122
+ await this.module.childInit();
123
+ }
93
124
  }
94
125
 
95
126
  async handleRequest(data) {
@@ -99,7 +130,7 @@ class Child {
99
130
  args,
100
131
  handle: handleId
101
132
  } = data;
102
- let child = (0, _nullthrows.default)(data.child);
133
+ let child = (0, _nullthrows().default)(data.child);
103
134
 
104
135
  const responseFromContent = content => ({
105
136
  idx,
@@ -114,14 +145,16 @@ class Child {
114
145
  child,
115
146
  type: 'response',
116
147
  contentType: 'error',
117
- content: (0, _diagnostic.anyToDiagnostic)(e)
148
+ content: (0, _diagnostic().anyToDiagnostic)(e)
118
149
  });
119
150
 
120
151
  let result;
121
152
 
122
153
  if (handleId != null) {
123
154
  try {
124
- let fn = (0, _nullthrows.default)(this.handles.get(handleId)).fn;
155
+ var _this$handles$get;
156
+
157
+ let fn = (0, _nullthrows().default)((_this$handles$get = this.handles.get(handleId)) === null || _this$handles$get === void 0 ? void 0 : _this$handles$get.fn);
125
158
  result = responseFromContent(fn(...args));
126
159
  } catch (e) {
127
160
  result = errorResponseFromError(e);
@@ -130,13 +163,13 @@ class Child {
130
163
  try {
131
164
  let [moduleName, childOptions] = args;
132
165
 
133
- if (childOptions.patchConsole) {
134
- (0, _logger.patchConsole)();
166
+ if (childOptions.shouldPatchConsole) {
167
+ (0, _logger().patchConsole)();
135
168
  } else {
136
- (0, _logger.unpatchConsole)();
169
+ (0, _logger().unpatchConsole)();
137
170
  }
138
171
 
139
- result = responseFromContent(this.childInit(moduleName, child));
172
+ result = responseFromContent(await this.childInit(moduleName, child));
140
173
  } catch (e) {
141
174
  result = errorResponseFromError(e);
142
175
  }
@@ -144,7 +177,7 @@ class Child {
144
177
  this.profiler = new _Profiler.default();
145
178
 
146
179
  try {
147
- result = responseFromContent((await this.profiler.startProfiling()));
180
+ result = responseFromContent(await this.profiler.startProfiling());
148
181
  } catch (e) {
149
182
  result = errorResponseFromError(e);
150
183
  }
@@ -155,35 +188,54 @@ class Child {
155
188
  } catch (e) {
156
189
  result = errorResponseFromError(e);
157
190
  }
191
+ } else if (method === 'takeHeapSnapshot') {
192
+ try {
193
+ let v8 = require('v8');
194
+
195
+ result = responseFromContent( // $FlowFixMe
196
+ v8.writeHeapSnapshot('heap-' + args[0] + '-' + (this.childId ? 'worker' + this.childId : 'main') + '.heapsnapshot'));
197
+ } catch (e) {
198
+ result = errorResponseFromError(e);
199
+ }
158
200
  } else if (method === 'createSharedReference') {
159
- let [ref, value] = args;
201
+ let [ref, _value] = args;
202
+ let value = _value instanceof ArrayBuffer ? // In the case the value is pre-serialized as a buffer,
203
+ // deserialize it.
204
+ (0, _core().deserialize)(Buffer.from(_value)) : _value;
160
205
  this.sharedReferences.set(ref, value);
161
206
  this.sharedReferencesByValue.set(value, ref);
162
207
  result = responseFromContent(null);
163
208
  } else if (method === 'deleteSharedReference') {
164
- this.sharedReferences.delete(args[0]);
209
+ let ref = args[0];
210
+ let value = this.sharedReferences.get(ref);
211
+ this.sharedReferencesByValue.delete(value);
212
+ this.sharedReferences.delete(ref);
165
213
  result = responseFromContent(null);
166
214
  } else {
167
215
  try {
168
- result = responseFromContent(( // $FlowFixMe
169
- await this.module[method](this.workerApi, ...args)));
216
+ result = responseFromContent( // $FlowFixMe
217
+ await this.module[method](this.workerApi, ...args));
170
218
  } catch (e) {
171
219
  result = errorResponseFromError(e);
172
220
  }
173
221
  }
174
222
 
175
- this.send(result);
223
+ try {
224
+ this.send(result);
225
+ } catch (e) {
226
+ result = this.send(errorResponseFromError(e));
227
+ }
176
228
  }
177
229
 
178
230
  handleResponse(data) {
179
- let idx = (0, _nullthrows.default)(data.idx);
231
+ let idx = (0, _nullthrows().default)(data.idx);
180
232
  let contentType = data.contentType;
181
233
  let content = data.content;
182
- let call = (0, _nullthrows.default)(this.responseQueue.get(idx));
234
+ let call = (0, _nullthrows().default)(this.responseQueue.get(idx));
183
235
 
184
236
  if (contentType === 'error') {
185
- (0, _assert.default)(typeof content !== 'string');
186
- call.reject(new _diagnostic.default({
237
+ (0, _assert().default)(typeof content !== 'string');
238
+ call.reject(new (_diagnostic().default)({
187
239
  diagnostic: content
188
240
  }));
189
241
  } else {
@@ -200,14 +252,14 @@ class Child {
200
252
  var _promise;
201
253
 
202
254
  // $FlowFixMe
203
- let call = _objectSpread({}, request, {
255
+ let call = { ...request,
204
256
  type: 'request',
205
257
  child: this.childId,
258
+ // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
206
259
  awaitResponse,
207
260
  resolve: () => {},
208
261
  reject: () => {}
209
- });
210
-
262
+ };
211
263
  let promise;
212
264
 
213
265
  if (awaitResponse) {
@@ -257,9 +309,8 @@ class Child {
257
309
  }
258
310
 
259
311
  createReverseHandle(fn) {
260
- let handle = new _Handle.default({
312
+ let handle = new Handle({
261
313
  fn,
262
- workerApi: this.workerApi,
263
314
  childId: this.childId
264
315
  });
265
316
  this.handles.set(handle.id, handle);
package/lib/cpuCount.js CHANGED
@@ -6,15 +6,31 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.detectRealCores = detectRealCores;
7
7
  exports.default = getCores;
8
8
 
9
- var _os = _interopRequireDefault(require("os"));
9
+ function _os() {
10
+ const data = _interopRequireDefault(require("os"));
10
11
 
11
- var _child_process = require("child_process");
12
+ _os = function () {
13
+ return data;
14
+ };
15
+
16
+ return data;
17
+ }
18
+
19
+ function _child_process() {
20
+ const data = require("child_process");
21
+
22
+ _child_process = function () {
23
+ return data;
24
+ };
25
+
26
+ return data;
27
+ }
12
28
 
13
29
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
30
 
15
31
  const exec = command => {
16
32
  try {
17
- let stdout = (0, _child_process.execSync)(command, {
33
+ let stdout = (0, _child_process().execSync)(command, {
18
34
  encoding: 'utf8',
19
35
  // This prevents the command from outputting to the console
20
36
  stdio: [null, null, null]
@@ -26,7 +42,7 @@ const exec = command => {
26
42
  };
27
43
 
28
44
  function detectRealCores() {
29
- let platform = _os.default.platform();
45
+ let platform = _os().default.platform();
30
46
 
31
47
  let amount = 0;
32
48
 
@@ -34,6 +50,12 @@ function detectRealCores() {
34
50
  amount = parseInt(exec('lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l'), 10);
35
51
  } else if (platform === 'darwin') {
36
52
  amount = parseInt(exec('sysctl -n hw.physicalcpu_max'), 10);
53
+ } else if (platform === 'win32') {
54
+ const str = exec('wmic cpu get NumberOfCores').match(/\d+/g);
55
+
56
+ if (str !== null) {
57
+ amount = parseInt(str.filter(n => n !== '')[0], 10);
58
+ }
37
59
  }
38
60
 
39
61
  if (!amount || amount <= 0) {
@@ -47,7 +69,6 @@ let cores;
47
69
 
48
70
  function getCores(bypassCache = false) {
49
71
  // Do not re-run commands if we already have the count...
50
- // $FlowFixMe
51
72
  if (cores && !bypassCache) {
52
73
  return cores;
53
74
  }
@@ -56,7 +77,7 @@ function getCores(bypassCache = false) {
56
77
  cores = detectRealCores();
57
78
  } catch (e) {
58
79
  // Guess the amount of real cores
59
- cores = _os.default.cpus().filter((cpu, index) => !cpu.model.includes('Intel') || index % 2 === 1).length;
80
+ cores = _os().default.cpus().filter((cpu, index) => !cpu.model.includes('Intel') || index % 2 === 1).length;
60
81
  } // Another fallback
61
82
 
62
83
 
package/lib/index.js CHANGED
@@ -17,11 +17,27 @@ Object.defineProperty(exports, "bus", {
17
17
  });
18
18
  exports.default = void 0;
19
19
 
20
- var _assert = _interopRequireDefault(require("assert"));
20
+ function _assert() {
21
+ const data = _interopRequireDefault(require("assert"));
22
+
23
+ _assert = function () {
24
+ return data;
25
+ };
26
+
27
+ return data;
28
+ }
21
29
 
22
30
  var _WorkerFarm = _interopRequireWildcard(require("./WorkerFarm"));
23
31
 
24
- var _logger = _interopRequireDefault(require("@parcel/logger"));
32
+ function _logger() {
33
+ const data = _interopRequireDefault(require("@parcel/logger"));
34
+
35
+ _logger = function () {
36
+ return data;
37
+ };
38
+
39
+ return data;
40
+ }
25
41
 
26
42
  var _bus = _interopRequireDefault(require("./bus"));
27
43
 
@@ -36,29 +52,29 @@ if (!_WorkerFarm.default.isWorker()) {
36
52
  _bus.default.on('logEvent', e => {
37
53
  switch (e.level) {
38
54
  case 'info':
39
- _logger.default.info(e.diagnostics);
55
+ _logger().default.info(e.diagnostics);
40
56
 
41
57
  break;
42
58
 
43
59
  case 'progress':
44
- (0, _assert.default)(typeof e.message === 'string');
60
+ (0, _assert().default)(typeof e.message === 'string');
45
61
 
46
- _logger.default.progress(e.message);
62
+ _logger().default.progress(e.message);
47
63
 
48
64
  break;
49
65
 
50
66
  case 'verbose':
51
- _logger.default.verbose(e.diagnostics);
67
+ _logger().default.verbose(e.diagnostics);
52
68
 
53
69
  break;
54
70
 
55
71
  case 'warn':
56
- _logger.default.warn(e.diagnostics);
72
+ _logger().default.warn(e.diagnostics);
57
73
 
58
74
  break;
59
75
 
60
76
  case 'error':
61
- _logger.default.error(e.diagnostics);
77
+ _logger().default.error(e.diagnostics);
62
78
 
63
79
  break;
64
80
 
@@ -5,24 +5,34 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _nullthrows = _interopRequireDefault(require("nullthrows"));
8
+ function _nullthrows() {
9
+ const data = _interopRequireDefault(require("nullthrows"));
10
+
11
+ _nullthrows = function () {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
9
17
 
10
18
  var _childState = require("../childState");
11
19
 
12
20
  var _child = require("../child");
13
21
 
14
- var _core = require("@parcel/core");
22
+ function _core() {
23
+ const data = require("@parcel/core");
15
24
 
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+ _core = function () {
26
+ return data;
27
+ };
17
28
 
18
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
+ return data;
30
+ }
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
33
 
20
34
  class ProcessChild {
21
35
  constructor(onMessage, onExit) {
22
- _defineProperty(this, "onMessage", void 0);
23
-
24
- _defineProperty(this, "onExit", void 0);
25
-
26
36
  if (!process.send) {
27
37
  throw new Error('Only create ProcessChild instances in a worker!');
28
38
  }
@@ -37,12 +47,12 @@ class ProcessChild {
37
47
  return this.stop();
38
48
  }
39
49
 
40
- this.onMessage((0, _core.deserialize)(Buffer.from(data, 'base64')));
50
+ this.onMessage((0, _core().deserialize)(Buffer.from(data, 'base64')));
41
51
  }
42
52
 
43
53
  send(data) {
44
- let processSend = (0, _nullthrows.default)(process.send).bind(process);
45
- processSend((0, _core.serialize)(data).toString('base64'), err => {
54
+ let processSend = (0, _nullthrows().default)(process.send).bind(process);
55
+ processSend((0, _core().serialize)(data).toString('base64'), err => {
46
56
  if (err && err instanceof Error) {
47
57
  if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
48
58
  // IPC connection closed
@@ -5,34 +5,45 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _child_process = _interopRequireDefault(require("child_process"));
8
+ function _child_process() {
9
+ const data = _interopRequireDefault(require("child_process"));
9
10
 
10
- var _path = _interopRequireDefault(require("path"));
11
+ _child_process = function () {
12
+ return data;
13
+ };
11
14
 
12
- var _core = require("@parcel/core");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ return data;
16
+ }
15
17
 
16
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
+ function _path() {
19
+ const data = _interopRequireDefault(require("path"));
17
20
 
18
- const WORKER_PATH = _path.default.join(__dirname, 'ProcessChild.js');
21
+ _path = function () {
22
+ return data;
23
+ };
19
24
 
20
- class ProcessWorker {
21
- constructor(execArgv, onMessage, onError, onExit) {
22
- _defineProperty(this, "execArgv", void 0);
25
+ return data;
26
+ }
23
27
 
24
- _defineProperty(this, "onMessage", void 0);
28
+ function _core() {
29
+ const data = require("@parcel/core");
25
30
 
26
- _defineProperty(this, "onError", void 0);
31
+ _core = function () {
32
+ return data;
33
+ };
27
34
 
28
- _defineProperty(this, "onExit", void 0);
35
+ return data;
36
+ }
29
37
 
30
- _defineProperty(this, "child", void 0);
38
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
39
 
32
- _defineProperty(this, "processQueue", true);
40
+ const WORKER_PATH = _path().default.join(__dirname, 'ProcessChild.js');
33
41
 
34
- _defineProperty(this, "sendQueue", []);
42
+ class ProcessWorker {
43
+ processQueue = true;
44
+ sendQueue = [];
35
45
 
46
+ constructor(execArgv, onMessage, onError, onExit) {
36
47
  this.execArgv = execArgv;
37
48
  this.onMessage = onMessage;
38
49
  this.onError = onError;
@@ -40,13 +51,13 @@ class ProcessWorker {
40
51
  }
41
52
 
42
53
  start() {
43
- this.child = _child_process.default.fork(WORKER_PATH, process.argv, {
54
+ this.child = _child_process().default.fork(WORKER_PATH, process.argv, {
44
55
  execArgv: this.execArgv,
45
56
  env: process.env,
46
57
  cwd: process.cwd()
47
58
  });
48
59
  this.child.on('message', data => {
49
- this.onMessage((0, _core.deserialize)(Buffer.from(data, 'base64')));
60
+ this.onMessage((0, _core().deserialize)(Buffer.from(data, 'base64')));
50
61
  });
51
62
  this.child.once('exit', this.onExit);
52
63
  this.child.on('error', this.onError);
@@ -68,7 +79,7 @@ class ProcessWorker {
68
79
  return;
69
80
  }
70
81
 
71
- let result = this.child.send((0, _core.serialize)(data).toString('base64'), error => {
82
+ let result = this.child.send((0, _core().serialize)(data).toString('base64'), error => {
72
83
  if (error && error instanceof Error) {
73
84
  // Ignore this, the workerfarm handles child errors
74
85
  return;
@@ -5,44 +5,62 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _worker_threads = require("worker_threads");
8
+ function _worker_threads() {
9
+ const data = require("worker_threads");
9
10
 
10
- var _nullthrows = _interopRequireDefault(require("nullthrows"));
11
+ _worker_threads = function () {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _nullthrows() {
19
+ const data = _interopRequireDefault(require("nullthrows"));
20
+
21
+ _nullthrows = function () {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
11
27
 
12
28
  var _childState = require("../childState");
13
29
 
14
30
  var _child = require("../child");
15
31
 
16
- var _core = require("@parcel/core");
32
+ function _core() {
33
+ const data = require("@parcel/core");
17
34
 
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+ _core = function () {
36
+ return data;
37
+ };
38
+
39
+ return data;
40
+ }
19
41
 
20
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
42
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
43
 
22
44
  class ThreadsChild {
23
45
  constructor(onMessage, onExit) {
24
- _defineProperty(this, "onMessage", void 0);
25
-
26
- _defineProperty(this, "onExit", void 0);
27
-
28
- if (_worker_threads.isMainThread || !_worker_threads.parentPort) {
46
+ if (_worker_threads().isMainThread || !_worker_threads().parentPort) {
29
47
  throw new Error('Only create ThreadsChild instances in a worker!');
30
48
  }
31
49
 
32
50
  this.onMessage = onMessage;
33
51
  this.onExit = onExit;
34
52
 
35
- _worker_threads.parentPort.on('message', data => this.handleMessage(data));
53
+ _worker_threads().parentPort.on('message', data => this.handleMessage(data));
36
54
 
37
- _worker_threads.parentPort.on('close', this.onExit);
55
+ _worker_threads().parentPort.on('close', this.onExit);
38
56
  }
39
57
 
40
58
  handleMessage(data) {
41
- this.onMessage((0, _core.restoreDeserializedObject)(data));
59
+ this.onMessage((0, _core().restoreDeserializedObject)(data));
42
60
  }
43
61
 
44
62
  send(data) {
45
- (0, _nullthrows.default)(_worker_threads.parentPort).postMessage((0, _core.prepareForSerialization)(data));
63
+ (0, _nullthrows().default)(_worker_threads().parentPort).postMessage((0, _core().prepareForSerialization)(data));
46
64
  }
47
65
 
48
66
  }