@parcel/workers 2.0.0-nightly.130 → 2.0.0-nightly.1303
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +23 -0
- package/lib/Handle.js +14 -45
- package/lib/Worker.js +100 -27
- package/lib/WorkerFarm.js +260 -104
- package/lib/bus.js +10 -2
- package/lib/child.js +129 -62
- package/lib/childState.js +1 -1
- package/lib/cpuCount.js +28 -7
- package/lib/index.js +41 -10
- package/lib/process/ProcessChild.js +22 -11
- package/lib/process/ProcessWorker.js +30 -19
- package/lib/threads/ThreadsChild.js +32 -14
- package/lib/threads/ThreadsWorker.js +28 -16
- package/package.json +19 -8
- package/src/Handle.js +10 -39
- package/src/Worker.js +82 -15
- package/src/WorkerFarm.js +219 -54
- package/src/bus.js +1 -1
- package/src/child.js +83 -24
- package/src/cpuCount.js +9 -4
- package/src/index.js +8 -2
- package/src/process/ProcessChild.js +2 -1
- package/src/process/ProcessWorker.js +1 -1
- package/src/threads/ThreadsWorker.js +2 -2
- package/test/cpuCount.test.js +1 -1
- package/test/integration/workerfarm/console.js +1 -1
- package/test/integration/workerfarm/logging.js +1 -1
- package/test/integration/workerfarm/reverse-handle.js +2 -2
- package/test/workerfarm.js +5 -5
- package/lib/Profiler.js +0 -70
- package/lib/Trace.js +0 -126
- package/src/Profiler.js +0 -93
- package/src/Trace.js +0 -121
package/lib/child.js
CHANGED
@@ -5,75 +5,114 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.Child = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
function _assert() {
|
9
|
+
const data = _interopRequireDefault(require("assert"));
|
9
10
|
|
10
|
-
|
11
|
+
_assert = function () {
|
12
|
+
return data;
|
13
|
+
};
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
var _diagnostic = _interopRequireWildcard(require("@parcel/diagnostic"));
|
15
|
-
|
16
|
-
var _bus = _interopRequireDefault(require("./bus"));
|
15
|
+
return data;
|
16
|
+
}
|
17
17
|
|
18
|
-
|
18
|
+
function _nullthrows() {
|
19
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
19
20
|
|
20
|
-
|
21
|
+
_nullthrows = function () {
|
22
|
+
return data;
|
23
|
+
};
|
21
24
|
|
22
|
-
|
25
|
+
return data;
|
26
|
+
}
|
23
27
|
|
24
|
-
function
|
28
|
+
function _logger() {
|
29
|
+
const data = _interopRequireWildcard(require("@parcel/logger"));
|
25
30
|
|
26
|
-
function
|
31
|
+
_logger = function () {
|
32
|
+
return data;
|
33
|
+
};
|
27
34
|
|
28
|
-
|
35
|
+
return data;
|
36
|
+
}
|
29
37
|
|
30
|
-
function
|
38
|
+
function _diagnostic() {
|
39
|
+
const data = _interopRequireWildcard(require("@parcel/diagnostic"));
|
31
40
|
|
32
|
-
|
41
|
+
_diagnostic = function () {
|
42
|
+
return data;
|
43
|
+
};
|
33
44
|
|
34
|
-
|
35
|
-
|
36
|
-
_defineProperty(this, "callQueue", []);
|
45
|
+
return data;
|
46
|
+
}
|
37
47
|
|
38
|
-
|
48
|
+
function _core() {
|
49
|
+
const data = require("@parcel/core");
|
39
50
|
|
40
|
-
|
51
|
+
_core = function () {
|
52
|
+
return data;
|
53
|
+
};
|
41
54
|
|
42
|
-
|
55
|
+
return data;
|
56
|
+
}
|
43
57
|
|
44
|
-
|
58
|
+
var _bus = _interopRequireDefault(require("./bus"));
|
45
59
|
|
46
|
-
|
60
|
+
function _profiler() {
|
61
|
+
const data = require("@parcel/profiler");
|
47
62
|
|
48
|
-
|
63
|
+
_profiler = function () {
|
64
|
+
return data;
|
65
|
+
};
|
49
66
|
|
50
|
-
|
67
|
+
return data;
|
68
|
+
}
|
51
69
|
|
52
|
-
|
70
|
+
var _Handle2 = _interopRequireDefault(require("./Handle"));
|
53
71
|
|
54
|
-
|
72
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
55
73
|
|
56
|
-
|
74
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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
75
|
|
58
|
-
|
76
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
59
77
|
|
60
|
-
|
78
|
+
// The import of './Handle' should really be imported eagerly (with @babel/plugin-transform-modules-commonjs's lazy mode).
|
79
|
+
const Handle = _Handle2.default;
|
61
80
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
81
|
+
class Child {
|
82
|
+
callQueue = [];
|
83
|
+
maxConcurrentCalls = 10;
|
84
|
+
responseId = 0;
|
85
|
+
responseQueue = new Map();
|
86
|
+
handles = new Map();
|
87
|
+
sharedReferences = new Map();
|
88
|
+
sharedReferencesByValue = new Map();
|
68
89
|
|
69
|
-
|
90
|
+
constructor(ChildBackend) {
|
91
|
+
this.child = new ChildBackend(m => {
|
92
|
+
this.messageListener(m);
|
93
|
+
}, () => this.handleEnd()); // Monitior all logging events inside this child process and forward to
|
70
94
|
// the main process via the bus.
|
71
95
|
|
72
|
-
this.loggerDisposable = _logger.default.onLog(event => {
|
96
|
+
this.loggerDisposable = _logger().default.onLog(event => {
|
73
97
|
_bus.default.emit('logEvent', event);
|
98
|
+
}); // .. and do the same for trace events
|
99
|
+
|
100
|
+
this.tracerDisposable = _profiler().tracer.onTrace(event => {
|
101
|
+
_bus.default.emit('traceEvent', event);
|
74
102
|
});
|
75
103
|
}
|
76
104
|
|
105
|
+
workerApi = {
|
106
|
+
callMaster: (request, awaitResponse = true) => this.addCall(request, awaitResponse),
|
107
|
+
createReverseHandle: fn => this.createReverseHandle(fn),
|
108
|
+
runHandle: (handle, args) => this.workerApi.callMaster({
|
109
|
+
handle: handle.id,
|
110
|
+
args
|
111
|
+
}, true),
|
112
|
+
getSharedReference: ref => this.sharedReferences.get(ref),
|
113
|
+
resolveSharedReference: value => this.sharedReferencesByValue.get(value)
|
114
|
+
};
|
115
|
+
|
77
116
|
messageListener(message) {
|
78
117
|
if (message.type === 'response') {
|
79
118
|
return this.handleResponse(message);
|
@@ -86,10 +125,14 @@ class Child {
|
|
86
125
|
this.child.send(data);
|
87
126
|
}
|
88
127
|
|
89
|
-
childInit(module, childId) {
|
128
|
+
async childInit(module, childId) {
|
90
129
|
// $FlowFixMe this must be dynamic
|
91
130
|
this.module = require(module);
|
92
131
|
this.childId = childId;
|
132
|
+
|
133
|
+
if (this.module.childInit != null) {
|
134
|
+
await this.module.childInit();
|
135
|
+
}
|
93
136
|
}
|
94
137
|
|
95
138
|
async handleRequest(data) {
|
@@ -99,7 +142,7 @@ class Child {
|
|
99
142
|
args,
|
100
143
|
handle: handleId
|
101
144
|
} = data;
|
102
|
-
let child = (0, _nullthrows.default)(data.child);
|
145
|
+
let child = (0, _nullthrows().default)(data.child);
|
103
146
|
|
104
147
|
const responseFromContent = content => ({
|
105
148
|
idx,
|
@@ -114,14 +157,16 @@ class Child {
|
|
114
157
|
child,
|
115
158
|
type: 'response',
|
116
159
|
contentType: 'error',
|
117
|
-
content: (0, _diagnostic.anyToDiagnostic)(e)
|
160
|
+
content: (0, _diagnostic().anyToDiagnostic)(e)
|
118
161
|
});
|
119
162
|
|
120
163
|
let result;
|
121
164
|
|
122
165
|
if (handleId != null) {
|
123
166
|
try {
|
124
|
-
|
167
|
+
var _this$handles$get;
|
168
|
+
|
169
|
+
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
170
|
result = responseFromContent(fn(...args));
|
126
171
|
} catch (e) {
|
127
172
|
result = errorResponseFromError(e);
|
@@ -130,21 +175,25 @@ class Child {
|
|
130
175
|
try {
|
131
176
|
let [moduleName, childOptions] = args;
|
132
177
|
|
133
|
-
if (childOptions.
|
134
|
-
(0, _logger.patchConsole)();
|
178
|
+
if (childOptions.shouldPatchConsole) {
|
179
|
+
(0, _logger().patchConsole)();
|
135
180
|
} else {
|
136
|
-
(0, _logger.unpatchConsole)();
|
181
|
+
(0, _logger().unpatchConsole)();
|
182
|
+
}
|
183
|
+
|
184
|
+
if (childOptions.shouldTrace) {
|
185
|
+
_profiler().tracer.enable();
|
137
186
|
}
|
138
187
|
|
139
|
-
result = responseFromContent(this.childInit(moduleName, child));
|
188
|
+
result = responseFromContent(await this.childInit(moduleName, child));
|
140
189
|
} catch (e) {
|
141
190
|
result = errorResponseFromError(e);
|
142
191
|
}
|
143
192
|
} else if (method === 'startProfile') {
|
144
|
-
this.profiler = new
|
193
|
+
this.profiler = new (_profiler().SamplingProfiler)();
|
145
194
|
|
146
195
|
try {
|
147
|
-
result = responseFromContent(
|
196
|
+
result = responseFromContent(await this.profiler.startProfiling());
|
148
197
|
} catch (e) {
|
149
198
|
result = errorResponseFromError(e);
|
150
199
|
}
|
@@ -155,35 +204,53 @@ class Child {
|
|
155
204
|
} catch (e) {
|
156
205
|
result = errorResponseFromError(e);
|
157
206
|
}
|
207
|
+
} else if (method === 'takeHeapSnapshot') {
|
208
|
+
try {
|
209
|
+
let v8 = require('v8');
|
210
|
+
|
211
|
+
result = responseFromContent(v8.writeHeapSnapshot('heap-' + args[0] + '-' + (this.childId ? 'worker' + this.childId : 'main') + '.heapsnapshot'));
|
212
|
+
} catch (e) {
|
213
|
+
result = errorResponseFromError(e);
|
214
|
+
}
|
158
215
|
} else if (method === 'createSharedReference') {
|
159
|
-
let [ref,
|
216
|
+
let [ref, _value] = args;
|
217
|
+
let value = _value instanceof ArrayBuffer ? // In the case the value is pre-serialized as a buffer,
|
218
|
+
// deserialize it.
|
219
|
+
(0, _core().deserialize)(Buffer.from(_value)) : _value;
|
160
220
|
this.sharedReferences.set(ref, value);
|
161
221
|
this.sharedReferencesByValue.set(value, ref);
|
162
222
|
result = responseFromContent(null);
|
163
223
|
} else if (method === 'deleteSharedReference') {
|
164
|
-
|
224
|
+
let ref = args[0];
|
225
|
+
let value = this.sharedReferences.get(ref);
|
226
|
+
this.sharedReferencesByValue.delete(value);
|
227
|
+
this.sharedReferences.delete(ref);
|
165
228
|
result = responseFromContent(null);
|
166
229
|
} else {
|
167
230
|
try {
|
168
|
-
result = responseFromContent(
|
169
|
-
await this.module[method](this.workerApi, ...args))
|
231
|
+
result = responseFromContent( // $FlowFixMe
|
232
|
+
await this.module[method](this.workerApi, ...args));
|
170
233
|
} catch (e) {
|
171
234
|
result = errorResponseFromError(e);
|
172
235
|
}
|
173
236
|
}
|
174
237
|
|
175
|
-
|
238
|
+
try {
|
239
|
+
this.send(result);
|
240
|
+
} catch (e) {
|
241
|
+
result = this.send(errorResponseFromError(e));
|
242
|
+
}
|
176
243
|
}
|
177
244
|
|
178
245
|
handleResponse(data) {
|
179
|
-
let idx = (0, _nullthrows.default)(data.idx);
|
246
|
+
let idx = (0, _nullthrows().default)(data.idx);
|
180
247
|
let contentType = data.contentType;
|
181
248
|
let content = data.content;
|
182
|
-
let call = (0, _nullthrows.default)(this.responseQueue.get(idx));
|
249
|
+
let call = (0, _nullthrows().default)(this.responseQueue.get(idx));
|
183
250
|
|
184
251
|
if (contentType === 'error') {
|
185
|
-
(0, _assert.default)(typeof content !== 'string');
|
186
|
-
call.reject(new _diagnostic.default({
|
252
|
+
(0, _assert().default)(typeof content !== 'string');
|
253
|
+
call.reject(new (_diagnostic().default)({
|
187
254
|
diagnostic: content
|
188
255
|
}));
|
189
256
|
} else {
|
@@ -200,14 +267,14 @@ class Child {
|
|
200
267
|
var _promise;
|
201
268
|
|
202
269
|
// $FlowFixMe
|
203
|
-
let call =
|
270
|
+
let call = { ...request,
|
204
271
|
type: 'request',
|
205
272
|
child: this.childId,
|
273
|
+
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
206
274
|
awaitResponse,
|
207
275
|
resolve: () => {},
|
208
276
|
reject: () => {}
|
209
|
-
}
|
210
|
-
|
277
|
+
};
|
211
278
|
let promise;
|
212
279
|
|
213
280
|
if (awaitResponse) {
|
@@ -254,12 +321,12 @@ class Child {
|
|
254
321
|
|
255
322
|
handleEnd() {
|
256
323
|
this.loggerDisposable.dispose();
|
324
|
+
this.tracerDisposable.dispose();
|
257
325
|
}
|
258
326
|
|
259
327
|
createReverseHandle(fn) {
|
260
|
-
let handle = new
|
328
|
+
let handle = new Handle({
|
261
329
|
fn,
|
262
|
-
workerApi: this.workerApi,
|
263
330
|
childId: this.childId
|
264
331
|
});
|
265
332
|
this.handles.set(handle.id, handle);
|
package/lib/childState.js
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.setChild = setChild;
|
7
6
|
exports.child = void 0;
|
7
|
+
exports.setChild = setChild;
|
8
8
|
// This file is imported by both the WorkerFarm and child implementation.
|
9
9
|
// When a worker is inited, it sets the state in this file.
|
10
10
|
// This way, WorkerFarm can access the state without directly importing the child code.
|
package/lib/cpuCount.js
CHANGED
@@ -3,18 +3,34 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.detectRealCores = detectRealCores;
|
7
6
|
exports.default = getCores;
|
7
|
+
exports.detectRealCores = detectRealCores;
|
8
|
+
|
9
|
+
function _os() {
|
10
|
+
const data = _interopRequireDefault(require("os"));
|
8
11
|
|
9
|
-
|
12
|
+
_os = function () {
|
13
|
+
return data;
|
14
|
+
};
|
15
|
+
|
16
|
+
return data;
|
17
|
+
}
|
10
18
|
|
11
|
-
|
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,17 +17,43 @@ Object.defineProperty(exports, "bus", {
|
|
17
17
|
});
|
18
18
|
exports.default = void 0;
|
19
19
|
|
20
|
-
|
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
|
-
|
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
|
|
28
|
-
function
|
44
|
+
function _profiler() {
|
45
|
+
const data = require("@parcel/profiler");
|
29
46
|
|
30
|
-
|
47
|
+
_profiler = function () {
|
48
|
+
return data;
|
49
|
+
};
|
50
|
+
|
51
|
+
return data;
|
52
|
+
}
|
53
|
+
|
54
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
55
|
+
|
56
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
|
31
57
|
|
32
58
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
59
|
|
@@ -36,35 +62,40 @@ if (!_WorkerFarm.default.isWorker()) {
|
|
36
62
|
_bus.default.on('logEvent', e => {
|
37
63
|
switch (e.level) {
|
38
64
|
case 'info':
|
39
|
-
_logger.default.info(e.diagnostics);
|
65
|
+
_logger().default.info(e.diagnostics);
|
40
66
|
|
41
67
|
break;
|
42
68
|
|
43
69
|
case 'progress':
|
44
|
-
(0, _assert.default)(typeof e.message === 'string');
|
70
|
+
(0, _assert().default)(typeof e.message === 'string');
|
45
71
|
|
46
|
-
_logger.default.progress(e.message);
|
72
|
+
_logger().default.progress(e.message);
|
47
73
|
|
48
74
|
break;
|
49
75
|
|
50
76
|
case 'verbose':
|
51
|
-
_logger.default.verbose(e.diagnostics);
|
77
|
+
_logger().default.verbose(e.diagnostics);
|
52
78
|
|
53
79
|
break;
|
54
80
|
|
55
81
|
case 'warn':
|
56
|
-
_logger.default.warn(e.diagnostics);
|
82
|
+
_logger().default.warn(e.diagnostics);
|
57
83
|
|
58
84
|
break;
|
59
85
|
|
60
86
|
case 'error':
|
61
|
-
_logger.default.error(e.diagnostics);
|
87
|
+
_logger().default.error(e.diagnostics);
|
62
88
|
|
63
89
|
break;
|
64
90
|
|
65
91
|
default:
|
66
92
|
throw new Error('Unknown log level');
|
67
93
|
}
|
94
|
+
}); // Forward all trace events originating from workers into the main process
|
95
|
+
|
96
|
+
|
97
|
+
_bus.default.on('traceEvent', e => {
|
98
|
+
_profiler().tracer.trace(e);
|
68
99
|
});
|
69
100
|
}
|
70
101
|
|
@@ -5,24 +5,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
|
8
|
-
|
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
|
-
|
22
|
+
function _core() {
|
23
|
+
const data = require("@parcel/core");
|
15
24
|
|
16
|
-
function
|
25
|
+
_core = function () {
|
26
|
+
return data;
|
27
|
+
};
|
17
28
|
|
18
|
-
|
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,13 +47,14 @@ 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) {
|
57
|
+
// $FlowFixMe[prop-missing]
|
47
58
|
if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
|
48
59
|
// IPC connection closed
|
49
60
|
// no need to keep the worker running if it can't send or receive data
|
@@ -5,34 +5,45 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
function _child_process() {
|
9
|
+
const data = _interopRequireDefault(require("child_process"));
|
9
10
|
|
10
|
-
|
11
|
+
_child_process = function () {
|
12
|
+
return data;
|
13
|
+
};
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
return data;
|
16
|
+
}
|
15
17
|
|
16
|
-
function
|
18
|
+
function _path() {
|
19
|
+
const data = _interopRequireDefault(require("path"));
|
17
20
|
|
18
|
-
|
21
|
+
_path = function () {
|
22
|
+
return data;
|
23
|
+
};
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
_defineProperty(this, "execArgv", void 0);
|
25
|
+
return data;
|
26
|
+
}
|
23
27
|
|
24
|
-
|
28
|
+
function _core() {
|
29
|
+
const data = require("@parcel/core");
|
25
30
|
|
26
|
-
|
31
|
+
_core = function () {
|
32
|
+
return data;
|
33
|
+
};
|
27
34
|
|
28
|
-
|
35
|
+
return data;
|
36
|
+
}
|
29
37
|
|
30
|
-
|
38
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
31
39
|
|
32
|
-
|
40
|
+
const WORKER_PATH = _path().default.join(__dirname, 'ProcessChild.js');
|
33
41
|
|
34
|
-
|
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;
|