@parcel/workers 2.0.0-nightly.121 → 2.0.0-nightly.1211
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 +22 -0
- package/lib/Handle.js +14 -45
- package/lib/Profiler.js +20 -10
- package/lib/Trace.js +16 -11
- package/lib/Worker.js +97 -26
- package/lib/WorkerFarm.js +237 -101
- package/lib/bus.js +10 -2
- package/lib/child.js +113 -63
- package/lib/childState.js +1 -1
- package/lib/cpuCount.js +28 -7
- package/lib/index.js +26 -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 +18 -7
- package/src/Handle.js +10 -39
- package/src/Profiler.js +1 -1
- package/src/Trace.js +8 -4
- package/src/Worker.js +75 -11
- package/src/WorkerFarm.js +195 -50
- package/src/bus.js +1 -1
- package/src/child.js +70 -21
- package/src/cpuCount.js +9 -4
- package/src/index.js +1 -1
- 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/child.js
CHANGED
|
@@ -5,75 +5,102 @@ 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"));
|
|
17
|
-
|
|
18
|
-
var _Profiler = _interopRequireDefault(require("./Profiler"));
|
|
19
|
-
|
|
20
|
-
var _Handle = _interopRequireDefault(require("./Handle"));
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
21
17
|
|
|
22
|
-
function
|
|
18
|
+
function _nullthrows() {
|
|
19
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
_nullthrows = function () {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
function
|
|
28
|
+
function _logger() {
|
|
29
|
+
const data = _interopRequireWildcard(require("@parcel/logger"));
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
_logger = function () {
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
_defineProperty(this, "callQueue", []);
|
|
38
|
+
function _diagnostic() {
|
|
39
|
+
const data = _interopRequireWildcard(require("@parcel/diagnostic"));
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
_diagnostic = function () {
|
|
42
|
+
return data;
|
|
43
|
+
};
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
function _core() {
|
|
49
|
+
const data = require("@parcel/core");
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
_core = function () {
|
|
52
|
+
return data;
|
|
53
|
+
};
|
|
45
54
|
|
|
46
|
-
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
47
57
|
|
|
48
|
-
|
|
58
|
+
var _bus = _interopRequireDefault(require("./bus"));
|
|
49
59
|
|
|
50
|
-
|
|
60
|
+
var _Profiler = _interopRequireDefault(require("./Profiler"));
|
|
51
61
|
|
|
52
|
-
|
|
62
|
+
var _Handle2 = _interopRequireDefault(require("./Handle"));
|
|
53
63
|
|
|
54
|
-
|
|
64
|
+
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
65
|
|
|
56
|
-
|
|
66
|
+
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
67
|
|
|
58
|
-
|
|
68
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
59
69
|
|
|
60
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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(
|
|
180
|
+
result = responseFromContent(await this.profiler.startProfiling());
|
|
148
181
|
} catch (e) {
|
|
149
182
|
result = errorResponseFromError(e);
|
|
150
183
|
}
|
|
@@ -155,35 +188,53 @@ 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(v8.writeHeapSnapshot('heap-' + args[0] + '-' + (this.childId ? 'worker' + this.childId : 'main') + '.heapsnapshot'));
|
|
196
|
+
} catch (e) {
|
|
197
|
+
result = errorResponseFromError(e);
|
|
198
|
+
}
|
|
158
199
|
} else if (method === 'createSharedReference') {
|
|
159
|
-
let [ref,
|
|
200
|
+
let [ref, _value] = args;
|
|
201
|
+
let value = _value instanceof ArrayBuffer ? // In the case the value is pre-serialized as a buffer,
|
|
202
|
+
// deserialize it.
|
|
203
|
+
(0, _core().deserialize)(Buffer.from(_value)) : _value;
|
|
160
204
|
this.sharedReferences.set(ref, value);
|
|
161
205
|
this.sharedReferencesByValue.set(value, ref);
|
|
162
206
|
result = responseFromContent(null);
|
|
163
207
|
} else if (method === 'deleteSharedReference') {
|
|
164
|
-
|
|
208
|
+
let ref = args[0];
|
|
209
|
+
let value = this.sharedReferences.get(ref);
|
|
210
|
+
this.sharedReferencesByValue.delete(value);
|
|
211
|
+
this.sharedReferences.delete(ref);
|
|
165
212
|
result = responseFromContent(null);
|
|
166
213
|
} else {
|
|
167
214
|
try {
|
|
168
|
-
result = responseFromContent(
|
|
169
|
-
await this.module[method](this.workerApi, ...args))
|
|
215
|
+
result = responseFromContent( // $FlowFixMe
|
|
216
|
+
await this.module[method](this.workerApi, ...args));
|
|
170
217
|
} catch (e) {
|
|
171
218
|
result = errorResponseFromError(e);
|
|
172
219
|
}
|
|
173
220
|
}
|
|
174
221
|
|
|
175
|
-
|
|
222
|
+
try {
|
|
223
|
+
this.send(result);
|
|
224
|
+
} catch (e) {
|
|
225
|
+
result = this.send(errorResponseFromError(e));
|
|
226
|
+
}
|
|
176
227
|
}
|
|
177
228
|
|
|
178
229
|
handleResponse(data) {
|
|
179
|
-
let idx = (0, _nullthrows.default)(data.idx);
|
|
230
|
+
let idx = (0, _nullthrows().default)(data.idx);
|
|
180
231
|
let contentType = data.contentType;
|
|
181
232
|
let content = data.content;
|
|
182
|
-
let call = (0, _nullthrows.default)(this.responseQueue.get(idx));
|
|
233
|
+
let call = (0, _nullthrows().default)(this.responseQueue.get(idx));
|
|
183
234
|
|
|
184
235
|
if (contentType === 'error') {
|
|
185
|
-
(0, _assert.default)(typeof content !== 'string');
|
|
186
|
-
call.reject(new _diagnostic.default({
|
|
236
|
+
(0, _assert().default)(typeof content !== 'string');
|
|
237
|
+
call.reject(new (_diagnostic().default)({
|
|
187
238
|
diagnostic: content
|
|
188
239
|
}));
|
|
189
240
|
} else {
|
|
@@ -200,14 +251,14 @@ class Child {
|
|
|
200
251
|
var _promise;
|
|
201
252
|
|
|
202
253
|
// $FlowFixMe
|
|
203
|
-
let call =
|
|
254
|
+
let call = { ...request,
|
|
204
255
|
type: 'request',
|
|
205
256
|
child: this.childId,
|
|
257
|
+
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
|
206
258
|
awaitResponse,
|
|
207
259
|
resolve: () => {},
|
|
208
260
|
reject: () => {}
|
|
209
|
-
}
|
|
210
|
-
|
|
261
|
+
};
|
|
211
262
|
let promise;
|
|
212
263
|
|
|
213
264
|
if (awaitResponse) {
|
|
@@ -257,9 +308,8 @@ class Child {
|
|
|
257
308
|
}
|
|
258
309
|
|
|
259
310
|
createReverseHandle(fn) {
|
|
260
|
-
let handle = new
|
|
311
|
+
let handle = new Handle({
|
|
261
312
|
fn,
|
|
262
|
-
workerApi: this.workerApi,
|
|
263
313
|
childId: this.childId
|
|
264
314
|
});
|
|
265
315
|
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,33 @@ 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 _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
44
|
+
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); }
|
|
29
45
|
|
|
30
|
-
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; }
|
|
46
|
+
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
47
|
|
|
32
48
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
49
|
|
|
@@ -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
|
-
|
|
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;
|