@parcel/workers 2.0.0-beta.1 → 2.0.0-nightly.1002
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 +63 -31
- package/lib/WorkerFarm.js +191 -82
- package/lib/bus.js +10 -2
- package/lib/child.js +111 -56
- package/lib/childState.js +1 -1
- package/lib/cpuCount.js +28 -6
- package/lib/index.js +26 -10
- package/lib/process/ProcessChild.js +21 -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 +39 -16
- package/src/WorkerFarm.js +145 -29
- package/src/bus.js +1 -1
- package/src/child.js +70 -20
- package/src/cpuCount.js +9 -3
- package/src/index.js +1 -1
- package/src/process/ProcessChild.js +1 -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,71 +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
|
+
return data;
|
|
16
|
+
}
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
function _nullthrows() {
|
|
19
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
_nullthrows = function () {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
_defineProperty(this, "callQueue", []);
|
|
38
|
+
function _diagnostic() {
|
|
39
|
+
const data = _interopRequireWildcard(require("@parcel/diagnostic"));
|
|
33
40
|
|
|
34
|
-
|
|
41
|
+
_diagnostic = function () {
|
|
42
|
+
return data;
|
|
43
|
+
};
|
|
35
44
|
|
|
36
|
-
|
|
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
|
+
var _Profiler = _interopRequireDefault(require("./Profiler"));
|
|
47
61
|
|
|
48
|
-
|
|
62
|
+
var _Handle2 = _interopRequireDefault(require("./Handle"));
|
|
49
63
|
|
|
50
|
-
|
|
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); }
|
|
51
65
|
|
|
52
|
-
|
|
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; }
|
|
53
67
|
|
|
54
|
-
|
|
68
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
55
69
|
|
|
56
|
-
|
|
70
|
+
// The import of './Handle' should really be imported eagerly (with @babel/plugin-transform-modules-commonjs's lazy mode).
|
|
71
|
+
const Handle = _Handle2.default;
|
|
57
72
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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();
|
|
64
81
|
|
|
65
|
-
|
|
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
|
|
66
86
|
// the main process via the bus.
|
|
67
87
|
|
|
68
|
-
this.loggerDisposable = _logger.default.onLog(event => {
|
|
88
|
+
this.loggerDisposable = _logger().default.onLog(event => {
|
|
69
89
|
_bus.default.emit('logEvent', event);
|
|
70
90
|
});
|
|
71
91
|
}
|
|
72
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
|
+
|
|
73
104
|
messageListener(message) {
|
|
74
105
|
if (message.type === 'response') {
|
|
75
106
|
return this.handleResponse(message);
|
|
@@ -82,10 +113,14 @@ class Child {
|
|
|
82
113
|
this.child.send(data);
|
|
83
114
|
}
|
|
84
115
|
|
|
85
|
-
childInit(module, childId) {
|
|
116
|
+
async childInit(module, childId) {
|
|
86
117
|
// $FlowFixMe this must be dynamic
|
|
87
118
|
this.module = require(module);
|
|
88
119
|
this.childId = childId;
|
|
120
|
+
|
|
121
|
+
if (this.module.childInit != null) {
|
|
122
|
+
await this.module.childInit();
|
|
123
|
+
}
|
|
89
124
|
}
|
|
90
125
|
|
|
91
126
|
async handleRequest(data) {
|
|
@@ -95,7 +130,7 @@ class Child {
|
|
|
95
130
|
args,
|
|
96
131
|
handle: handleId
|
|
97
132
|
} = data;
|
|
98
|
-
let child = (0, _nullthrows.default)(data.child);
|
|
133
|
+
let child = (0, _nullthrows().default)(data.child);
|
|
99
134
|
|
|
100
135
|
const responseFromContent = content => ({
|
|
101
136
|
idx,
|
|
@@ -110,14 +145,16 @@ class Child {
|
|
|
110
145
|
child,
|
|
111
146
|
type: 'response',
|
|
112
147
|
contentType: 'error',
|
|
113
|
-
content: (0, _diagnostic.anyToDiagnostic)(e)
|
|
148
|
+
content: (0, _diagnostic().anyToDiagnostic)(e)
|
|
114
149
|
});
|
|
115
150
|
|
|
116
151
|
let result;
|
|
117
152
|
|
|
118
153
|
if (handleId != null) {
|
|
119
154
|
try {
|
|
120
|
-
|
|
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);
|
|
121
158
|
result = responseFromContent(fn(...args));
|
|
122
159
|
} catch (e) {
|
|
123
160
|
result = errorResponseFromError(e);
|
|
@@ -126,13 +163,13 @@ class Child {
|
|
|
126
163
|
try {
|
|
127
164
|
let [moduleName, childOptions] = args;
|
|
128
165
|
|
|
129
|
-
if (childOptions.
|
|
130
|
-
(0, _logger.patchConsole)();
|
|
166
|
+
if (childOptions.shouldPatchConsole) {
|
|
167
|
+
(0, _logger().patchConsole)();
|
|
131
168
|
} else {
|
|
132
|
-
(0, _logger.unpatchConsole)();
|
|
169
|
+
(0, _logger().unpatchConsole)();
|
|
133
170
|
}
|
|
134
171
|
|
|
135
|
-
result = responseFromContent(this.childInit(moduleName, child));
|
|
172
|
+
result = responseFromContent(await this.childInit(moduleName, child));
|
|
136
173
|
} catch (e) {
|
|
137
174
|
result = errorResponseFromError(e);
|
|
138
175
|
}
|
|
@@ -140,7 +177,7 @@ class Child {
|
|
|
140
177
|
this.profiler = new _Profiler.default();
|
|
141
178
|
|
|
142
179
|
try {
|
|
143
|
-
result = responseFromContent(
|
|
180
|
+
result = responseFromContent(await this.profiler.startProfiling());
|
|
144
181
|
} catch (e) {
|
|
145
182
|
result = errorResponseFromError(e);
|
|
146
183
|
}
|
|
@@ -151,35 +188,54 @@ class Child {
|
|
|
151
188
|
} catch (e) {
|
|
152
189
|
result = errorResponseFromError(e);
|
|
153
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
|
+
}
|
|
154
200
|
} else if (method === 'createSharedReference') {
|
|
155
|
-
let [ref,
|
|
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;
|
|
156
205
|
this.sharedReferences.set(ref, value);
|
|
157
206
|
this.sharedReferencesByValue.set(value, ref);
|
|
158
207
|
result = responseFromContent(null);
|
|
159
208
|
} else if (method === 'deleteSharedReference') {
|
|
160
|
-
|
|
209
|
+
let ref = args[0];
|
|
210
|
+
let value = this.sharedReferences.get(ref);
|
|
211
|
+
this.sharedReferencesByValue.delete(value);
|
|
212
|
+
this.sharedReferences.delete(ref);
|
|
161
213
|
result = responseFromContent(null);
|
|
162
214
|
} else {
|
|
163
215
|
try {
|
|
164
|
-
result = responseFromContent(
|
|
165
|
-
await this.module[method](this.workerApi, ...args))
|
|
216
|
+
result = responseFromContent( // $FlowFixMe
|
|
217
|
+
await this.module[method](this.workerApi, ...args));
|
|
166
218
|
} catch (e) {
|
|
167
219
|
result = errorResponseFromError(e);
|
|
168
220
|
}
|
|
169
221
|
}
|
|
170
222
|
|
|
171
|
-
|
|
223
|
+
try {
|
|
224
|
+
this.send(result);
|
|
225
|
+
} catch (e) {
|
|
226
|
+
result = this.send(errorResponseFromError(e));
|
|
227
|
+
}
|
|
172
228
|
}
|
|
173
229
|
|
|
174
230
|
handleResponse(data) {
|
|
175
|
-
let idx = (0, _nullthrows.default)(data.idx);
|
|
231
|
+
let idx = (0, _nullthrows().default)(data.idx);
|
|
176
232
|
let contentType = data.contentType;
|
|
177
233
|
let content = data.content;
|
|
178
|
-
let call = (0, _nullthrows.default)(this.responseQueue.get(idx));
|
|
234
|
+
let call = (0, _nullthrows().default)(this.responseQueue.get(idx));
|
|
179
235
|
|
|
180
236
|
if (contentType === 'error') {
|
|
181
|
-
(0, _assert.default)(typeof content !== 'string');
|
|
182
|
-
call.reject(new _diagnostic.default({
|
|
237
|
+
(0, _assert().default)(typeof content !== 'string');
|
|
238
|
+
call.reject(new (_diagnostic().default)({
|
|
183
239
|
diagnostic: content
|
|
184
240
|
}));
|
|
185
241
|
} else {
|
|
@@ -253,9 +309,8 @@ class Child {
|
|
|
253
309
|
}
|
|
254
310
|
|
|
255
311
|
createReverseHandle(fn) {
|
|
256
|
-
let handle = new
|
|
312
|
+
let handle = new Handle({
|
|
257
313
|
fn,
|
|
258
|
-
workerApi: this.workerApi,
|
|
259
314
|
childId: this.childId
|
|
260
315
|
});
|
|
261
316
|
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) {
|
|
@@ -55,7 +77,7 @@ function getCores(bypassCache = false) {
|
|
|
55
77
|
cores = detectRealCores();
|
|
56
78
|
} catch (e) {
|
|
57
79
|
// Guess the amount of real cores
|
|
58
|
-
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;
|
|
59
81
|
} // Another fallback
|
|
60
82
|
|
|
61
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,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
|
-
|
|
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;
|
|
@@ -5,44 +5,62 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
function _worker_threads() {
|
|
9
|
+
const data = require("worker_threads");
|
|
9
10
|
|
|
10
|
-
|
|
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
|
-
|
|
32
|
+
function _core() {
|
|
33
|
+
const data = require("@parcel/core");
|
|
17
34
|
|
|
18
|
-
function
|
|
35
|
+
_core = function () {
|
|
36
|
+
return data;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
19
41
|
|
|
20
|
-
function
|
|
42
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
43
|
|
|
22
44
|
class ThreadsChild {
|
|
23
45
|
constructor(onMessage, onExit) {
|
|
24
|
-
|
|
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
|
}
|