@parcel/workers 2.0.0-beta.3.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 +3 -18
- package/lib/Profiler.js +0 -6
- package/lib/Trace.js +0 -8
- package/lib/Worker.js +12 -34
- package/lib/WorkerFarm.js +59 -125
- package/lib/bus.js +3 -11
- package/lib/child.js +36 -74
- package/lib/childState.js +1 -1
- package/lib/cpuCount.js +1 -1
- package/lib/index.js +9 -26
- package/lib/process/ProcessChild.js +3 -25
- package/lib/process/ProcessWorker.js +3 -16
- package/lib/threads/ThreadsChild.js +3 -25
- package/lib/threads/ThreadsWorker.js +0 -12
- package/package.json +13 -6
- package/src/Worker.js +1 -1
- package/src/WorkerFarm.js +9 -1
- package/src/child.js +10 -4
- package/src/cpuCount.js +3 -2
- package/test/cpuCount.test.js +1 -1
- package/test/workerfarm.js +1 -1
package/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {FilePath} from '@parcel/types';
|
|
2
|
+
|
|
3
|
+
type BackendType = 'process' | 'threads';
|
|
4
|
+
|
|
5
|
+
export type FarmOptions = {
|
|
6
|
+
maxConcurrentWorkers: number,
|
|
7
|
+
maxConcurrentCallsPerWorker: number,
|
|
8
|
+
forcedKillTime: number,
|
|
9
|
+
useLocalWorker: boolean,
|
|
10
|
+
warmWorkers: boolean,
|
|
11
|
+
workerPath?: FilePath,
|
|
12
|
+
backend: BackendType,
|
|
13
|
+
shouldPatchConsole?: boolean,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare class WorkerFarm {
|
|
17
|
+
constructor(options: FarmOptions);
|
|
18
|
+
|
|
19
|
+
end(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default WorkerFarm;
|
package/lib/Handle.js
CHANGED
|
@@ -15,20 +15,11 @@ function _core() {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
const data = _interopRequireDefault(require("../package.json"));
|
|
20
|
-
|
|
21
|
-
_package = function () {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
18
|
+
var _package = _interopRequireDefault(require("../package.json"));
|
|
27
19
|
|
|
28
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
21
|
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
// $FlowFixMe
|
|
32
23
|
let HANDLE_ID = 0; // $FlowFixMe
|
|
33
24
|
|
|
34
25
|
const handleById = new Map();
|
|
@@ -37,12 +28,6 @@ class Handle {
|
|
|
37
28
|
constructor(opts) {
|
|
38
29
|
var _opts$id;
|
|
39
30
|
|
|
40
|
-
_defineProperty(this, "id", void 0);
|
|
41
|
-
|
|
42
|
-
_defineProperty(this, "childId", void 0);
|
|
43
|
-
|
|
44
|
-
_defineProperty(this, "fn", void 0);
|
|
45
|
-
|
|
46
31
|
this.id = (_opts$id = opts.id) !== null && _opts$id !== void 0 ? _opts$id : ++HANDLE_ID;
|
|
47
32
|
this.fn = opts.fn;
|
|
48
33
|
this.childId = opts.childId;
|
|
@@ -69,4 +54,4 @@ class Handle {
|
|
|
69
54
|
|
|
70
55
|
|
|
71
56
|
exports.default = Handle;
|
|
72
|
-
(0, _core().registerSerializableClass)(`${_package
|
|
57
|
+
(0, _core().registerSerializableClass)(`${_package.default.version}:Handle`, Handle);
|
package/lib/Profiler.js
CHANGED
|
@@ -27,13 +27,7 @@ function _diagnostic() {
|
|
|
27
27
|
|
|
28
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
29
|
|
|
30
|
-
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; }
|
|
31
|
-
|
|
32
30
|
class Profiler {
|
|
33
|
-
constructor() {
|
|
34
|
-
_defineProperty(this, "session", void 0);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
31
|
startProfiling() {
|
|
38
32
|
let inspector;
|
|
39
33
|
|
package/lib/Trace.js
CHANGED
|
@@ -15,16 +15,8 @@ function _chromeTraceEvent() {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
17
|
|
|
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; }
|
|
19
|
-
|
|
20
18
|
class Trace {
|
|
21
19
|
constructor() {
|
|
22
|
-
_defineProperty(this, "tracer", void 0);
|
|
23
|
-
|
|
24
|
-
_defineProperty(this, "tid", void 0);
|
|
25
|
-
|
|
26
|
-
_defineProperty(this, "eventId", void 0);
|
|
27
|
-
|
|
28
20
|
this.tracer = new (_chromeTraceEvent().Tracer)();
|
|
29
21
|
this.tid = 0;
|
|
30
22
|
this.eventId = 0;
|
package/lib/Worker.js
CHANGED
|
@@ -35,46 +35,24 @@ function _diagnostic() {
|
|
|
35
35
|
return data;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
const data = require("./backend");
|
|
40
|
-
|
|
41
|
-
_backend = function () {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
38
|
+
var _backend = require("./backend");
|
|
47
39
|
|
|
48
40
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
41
|
|
|
50
|
-
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; }
|
|
51
|
-
|
|
52
42
|
let WORKER_ID = 0;
|
|
53
43
|
|
|
54
44
|
class Worker extends _events().default {
|
|
45
|
+
id = WORKER_ID++;
|
|
46
|
+
sharedReferences = new Map();
|
|
47
|
+
calls = new Map();
|
|
48
|
+
exitCode = null;
|
|
49
|
+
callId = 0;
|
|
50
|
+
ready = false;
|
|
51
|
+
stopped = false;
|
|
52
|
+
isStopping = false;
|
|
53
|
+
|
|
55
54
|
constructor(options) {
|
|
56
55
|
super();
|
|
57
|
-
|
|
58
|
-
_defineProperty(this, "options", void 0);
|
|
59
|
-
|
|
60
|
-
_defineProperty(this, "worker", void 0);
|
|
61
|
-
|
|
62
|
-
_defineProperty(this, "id", WORKER_ID++);
|
|
63
|
-
|
|
64
|
-
_defineProperty(this, "sharedReferences", new Map());
|
|
65
|
-
|
|
66
|
-
_defineProperty(this, "calls", new Map());
|
|
67
|
-
|
|
68
|
-
_defineProperty(this, "exitCode", null);
|
|
69
|
-
|
|
70
|
-
_defineProperty(this, "callId", 0);
|
|
71
|
-
|
|
72
|
-
_defineProperty(this, "ready", false);
|
|
73
|
-
|
|
74
|
-
_defineProperty(this, "stopped", false);
|
|
75
|
-
|
|
76
|
-
_defineProperty(this, "isStopping", false);
|
|
77
|
-
|
|
78
56
|
this.options = options;
|
|
79
57
|
}
|
|
80
58
|
|
|
@@ -96,7 +74,7 @@ class Worker extends _events().default {
|
|
|
96
74
|
let opts = [''];
|
|
97
75
|
let quote = false;
|
|
98
76
|
|
|
99
|
-
for (let c of (0, _nullthrows().default)(process.env.NODE_OPTIONS.match(
|
|
77
|
+
for (let c of (0, _nullthrows().default)(process.env.NODE_OPTIONS.match(/.|^$/g))) {
|
|
100
78
|
if (c === '"') {
|
|
101
79
|
quote = !quote;
|
|
102
80
|
} else if (!quote && c === ' ') {
|
|
@@ -116,7 +94,7 @@ class Worker extends _events().default {
|
|
|
116
94
|
}
|
|
117
95
|
}
|
|
118
96
|
|
|
119
|
-
let WorkerBackend = (0, _backend
|
|
97
|
+
let WorkerBackend = (0, _backend.getWorkerBackend)(this.options.backend);
|
|
120
98
|
this.worker = new WorkerBackend(filteredArgs, data => this.receive(data), err => {
|
|
121
99
|
this.emit('error', err);
|
|
122
100
|
}, code => {
|
package/lib/WorkerFarm.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "Handle", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return _Handle
|
|
9
|
+
return _Handle.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
exports.default = void 0;
|
|
@@ -61,75 +61,19 @@ function _diagnostic() {
|
|
|
61
61
|
return data;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
const data = _interopRequireDefault(require("./Worker"));
|
|
64
|
+
var _Worker = _interopRequireDefault(require("./Worker"));
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
return data;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
return data;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function _cpuCount() {
|
|
75
|
-
const data = _interopRequireDefault(require("./cpuCount"));
|
|
76
|
-
|
|
77
|
-
_cpuCount = function () {
|
|
78
|
-
return data;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
return data;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function _Handle() {
|
|
85
|
-
const data = _interopRequireDefault(require("./Handle"));
|
|
86
|
-
|
|
87
|
-
_Handle = function () {
|
|
88
|
-
return data;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
return data;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function _childState() {
|
|
95
|
-
const data = require("./childState");
|
|
96
|
-
|
|
97
|
-
_childState = function () {
|
|
98
|
-
return data;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
return data;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function _backend() {
|
|
105
|
-
const data = require("./backend");
|
|
66
|
+
var _cpuCount = _interopRequireDefault(require("./cpuCount"));
|
|
106
67
|
|
|
107
|
-
|
|
108
|
-
return data;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
return data;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function _Profiler() {
|
|
115
|
-
const data = _interopRequireDefault(require("./Profiler"));
|
|
116
|
-
|
|
117
|
-
_Profiler = function () {
|
|
118
|
-
return data;
|
|
119
|
-
};
|
|
68
|
+
var _Handle = _interopRequireDefault(require("./Handle"));
|
|
120
69
|
|
|
121
|
-
|
|
122
|
-
}
|
|
70
|
+
var _childState = require("./childState");
|
|
123
71
|
|
|
124
|
-
|
|
125
|
-
const data = _interopRequireDefault(require("./Trace"));
|
|
72
|
+
var _backend = require("./backend");
|
|
126
73
|
|
|
127
|
-
|
|
128
|
-
return data;
|
|
129
|
-
};
|
|
74
|
+
var _Profiler = _interopRequireDefault(require("./Profiler"));
|
|
130
75
|
|
|
131
|
-
|
|
132
|
-
}
|
|
76
|
+
var _Trace = _interopRequireDefault(require("./Trace"));
|
|
133
77
|
|
|
134
78
|
function _fs() {
|
|
135
79
|
const data = _interopRequireDefault(require("fs"));
|
|
@@ -151,69 +95,28 @@ function _logger() {
|
|
|
151
95
|
return data;
|
|
152
96
|
}
|
|
153
97
|
|
|
154
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
98
|
+
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); }
|
|
155
99
|
|
|
156
|
-
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; }
|
|
100
|
+
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; }
|
|
157
101
|
|
|
158
102
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
159
103
|
|
|
160
|
-
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; }
|
|
161
|
-
|
|
162
104
|
let referenceId = 1;
|
|
163
105
|
|
|
164
106
|
/**
|
|
165
107
|
* workerPath should always be defined inside farmOptions
|
|
166
108
|
*/
|
|
167
109
|
class WorkerFarm extends _events().default {
|
|
110
|
+
callQueue = [];
|
|
111
|
+
ending = false;
|
|
112
|
+
warmWorkers = 0;
|
|
113
|
+
workers = new Map();
|
|
114
|
+
handles = new Map();
|
|
115
|
+
sharedReferences = new Map();
|
|
116
|
+
sharedReferencesByValue = new Map();
|
|
117
|
+
|
|
168
118
|
constructor(farmOptions = {}) {
|
|
169
119
|
super();
|
|
170
|
-
|
|
171
|
-
_defineProperty(this, "callQueue", []);
|
|
172
|
-
|
|
173
|
-
_defineProperty(this, "ending", false);
|
|
174
|
-
|
|
175
|
-
_defineProperty(this, "localWorker", void 0);
|
|
176
|
-
|
|
177
|
-
_defineProperty(this, "options", void 0);
|
|
178
|
-
|
|
179
|
-
_defineProperty(this, "run", void 0);
|
|
180
|
-
|
|
181
|
-
_defineProperty(this, "warmWorkers", 0);
|
|
182
|
-
|
|
183
|
-
_defineProperty(this, "workers", new Map());
|
|
184
|
-
|
|
185
|
-
_defineProperty(this, "handles", new Map());
|
|
186
|
-
|
|
187
|
-
_defineProperty(this, "sharedReferences", new Map());
|
|
188
|
-
|
|
189
|
-
_defineProperty(this, "sharedReferencesByValue", new Map());
|
|
190
|
-
|
|
191
|
-
_defineProperty(this, "profiler", void 0);
|
|
192
|
-
|
|
193
|
-
_defineProperty(this, "workerApi", {
|
|
194
|
-
callMaster: async (request, awaitResponse = true) => {
|
|
195
|
-
// $FlowFixMe
|
|
196
|
-
let result = await this.processRequest({ ...request,
|
|
197
|
-
awaitResponse
|
|
198
|
-
});
|
|
199
|
-
return (0, _core().deserialize)((0, _core().serialize)(result));
|
|
200
|
-
},
|
|
201
|
-
createReverseHandle: fn => this.createReverseHandle(fn),
|
|
202
|
-
callChild: (childId, request) => new Promise((resolve, reject) => {
|
|
203
|
-
(0, _nullthrows().default)(this.workers.get(childId)).call({ ...request,
|
|
204
|
-
resolve,
|
|
205
|
-
reject,
|
|
206
|
-
retries: 0
|
|
207
|
-
});
|
|
208
|
-
}),
|
|
209
|
-
runHandle: (handle, args) => this.workerApi.callChild((0, _nullthrows().default)(handle.childId), {
|
|
210
|
-
handle: handle.id,
|
|
211
|
-
args
|
|
212
|
-
}),
|
|
213
|
-
getSharedReference: ref => this.sharedReferences.get(ref),
|
|
214
|
-
resolveSharedReference: value => this.sharedReferencesByValue.get(value)
|
|
215
|
-
});
|
|
216
|
-
|
|
217
120
|
this.options = {
|
|
218
121
|
maxConcurrentWorkers: WorkerFarm.getNumWorkers(),
|
|
219
122
|
maxConcurrentCallsPerWorker: WorkerFarm.getConcurrentCallsPerWorker(),
|
|
@@ -221,7 +124,7 @@ class WorkerFarm extends _events().default {
|
|
|
221
124
|
warmWorkers: false,
|
|
222
125
|
useLocalWorker: true,
|
|
223
126
|
// TODO: setting this to false makes some tests fail, figure out why
|
|
224
|
-
backend: (0, _backend
|
|
127
|
+
backend: (0, _backend.detectBackend)(),
|
|
225
128
|
...farmOptions
|
|
226
129
|
};
|
|
227
130
|
|
|
@@ -231,10 +134,35 @@ class WorkerFarm extends _events().default {
|
|
|
231
134
|
|
|
232
135
|
|
|
233
136
|
this.localWorker = require(this.options.workerPath);
|
|
137
|
+
this.localWorkerInit = this.localWorker.childInit != null ? this.localWorker.childInit() : null;
|
|
234
138
|
this.run = this.createHandle('run');
|
|
235
139
|
this.startMaxWorkers();
|
|
236
140
|
}
|
|
237
141
|
|
|
142
|
+
workerApi = {
|
|
143
|
+
callMaster: async (request, awaitResponse = true) => {
|
|
144
|
+
// $FlowFixMe
|
|
145
|
+
let result = await this.processRequest({ ...request,
|
|
146
|
+
awaitResponse
|
|
147
|
+
});
|
|
148
|
+
return (0, _core().deserialize)((0, _core().serialize)(result));
|
|
149
|
+
},
|
|
150
|
+
createReverseHandle: fn => this.createReverseHandle(fn),
|
|
151
|
+
callChild: (childId, request) => new Promise((resolve, reject) => {
|
|
152
|
+
(0, _nullthrows().default)(this.workers.get(childId)).call({ ...request,
|
|
153
|
+
resolve,
|
|
154
|
+
reject,
|
|
155
|
+
retries: 0
|
|
156
|
+
});
|
|
157
|
+
}),
|
|
158
|
+
runHandle: (handle, args) => this.workerApi.callChild((0, _nullthrows().default)(handle.childId), {
|
|
159
|
+
handle: handle.id,
|
|
160
|
+
args
|
|
161
|
+
}),
|
|
162
|
+
getSharedReference: ref => this.sharedReferences.get(ref),
|
|
163
|
+
resolveSharedReference: value => this.sharedReferencesByValue.get(value)
|
|
164
|
+
};
|
|
165
|
+
|
|
238
166
|
warmupWorker(method, args) {
|
|
239
167
|
// Workers are already stopping
|
|
240
168
|
if (this.ending) {
|
|
@@ -262,7 +190,7 @@ class WorkerFarm extends _events().default {
|
|
|
262
190
|
}
|
|
263
191
|
|
|
264
192
|
createHandle(method) {
|
|
265
|
-
return (...args) => {
|
|
193
|
+
return async (...args) => {
|
|
266
194
|
// Child process workers are slow to start (~600ms).
|
|
267
195
|
// While we're waiting, just run on the main thread.
|
|
268
196
|
// This significantly speeds up startup time.
|
|
@@ -274,6 +202,12 @@ class WorkerFarm extends _events().default {
|
|
|
274
202
|
}
|
|
275
203
|
|
|
276
204
|
let processedArgs = (0, _core().restoreDeserializedObject)((0, _core().prepareForSerialization)([...args, false]));
|
|
205
|
+
|
|
206
|
+
if (this.localWorkerInit != null) {
|
|
207
|
+
await this.localWorkerInit;
|
|
208
|
+
this.localWorkerInit = null;
|
|
209
|
+
}
|
|
210
|
+
|
|
277
211
|
return this.localWorker[method](this.workerApi, ...processedArgs);
|
|
278
212
|
}
|
|
279
213
|
};
|
|
@@ -289,7 +223,7 @@ class WorkerFarm extends _events().default {
|
|
|
289
223
|
}
|
|
290
224
|
|
|
291
225
|
startChild() {
|
|
292
|
-
let worker = new
|
|
226
|
+
let worker = new _Worker.default({
|
|
293
227
|
forcedKillTime: this.options.forcedKillTime,
|
|
294
228
|
backend: this.options.backend,
|
|
295
229
|
shouldPatchConsole: this.options.shouldPatchConsole,
|
|
@@ -467,7 +401,7 @@ class WorkerFarm extends _events().default {
|
|
|
467
401
|
}
|
|
468
402
|
|
|
469
403
|
createReverseHandle(fn) {
|
|
470
|
-
let handle = new
|
|
404
|
+
let handle = new _Handle.default({
|
|
471
405
|
fn
|
|
472
406
|
});
|
|
473
407
|
this.handles.set(handle.id, handle);
|
|
@@ -531,7 +465,7 @@ class WorkerFarm extends _events().default {
|
|
|
531
465
|
}));
|
|
532
466
|
}
|
|
533
467
|
|
|
534
|
-
this.profiler = new
|
|
468
|
+
this.profiler = new _Profiler.default();
|
|
535
469
|
promises.push(this.profiler.startProfiling());
|
|
536
470
|
await Promise.all(promises);
|
|
537
471
|
}
|
|
@@ -559,7 +493,7 @@ class WorkerFarm extends _events().default {
|
|
|
559
493
|
}
|
|
560
494
|
|
|
561
495
|
var profiles = await Promise.all(promises);
|
|
562
|
-
let trace = new
|
|
496
|
+
let trace = new _Trace.default();
|
|
563
497
|
let filename = `profile-${getTimeId()}.trace`;
|
|
564
498
|
let stream = trace.pipe(_fs().default.createWriteStream(filename));
|
|
565
499
|
|
|
@@ -625,16 +559,16 @@ class WorkerFarm extends _events().default {
|
|
|
625
559
|
}
|
|
626
560
|
|
|
627
561
|
static getNumWorkers() {
|
|
628
|
-
return process.env.PARCEL_WORKERS ? parseInt(process.env.PARCEL_WORKERS, 10) : Math.ceil((0, _cpuCount
|
|
562
|
+
return process.env.PARCEL_WORKERS ? parseInt(process.env.PARCEL_WORKERS, 10) : Math.ceil((0, _cpuCount.default)() / 2);
|
|
629
563
|
}
|
|
630
564
|
|
|
631
565
|
static isWorker() {
|
|
632
|
-
return !!_childState
|
|
566
|
+
return !!_childState.child;
|
|
633
567
|
}
|
|
634
568
|
|
|
635
569
|
static getWorkerApi() {
|
|
636
|
-
(0, _assert().default)(_childState
|
|
637
|
-
return _childState
|
|
570
|
+
(0, _assert().default)(_childState.child != null, 'WorkerFarm.getWorkerApi can only be called within workers');
|
|
571
|
+
return _childState.child.workerApi;
|
|
638
572
|
}
|
|
639
573
|
|
|
640
574
|
static getConcurrentCallsPerWorker() {
|
package/lib/bus.js
CHANGED
|
@@ -15,22 +15,14 @@ function _events() {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
const data = require("./childState");
|
|
20
|
-
|
|
21
|
-
_childState = function () {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
18
|
+
var _childState = require("./childState");
|
|
27
19
|
|
|
28
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
21
|
|
|
30
22
|
class Bus extends _events().default {
|
|
31
23
|
emit(event, ...args) {
|
|
32
|
-
if (_childState
|
|
33
|
-
_childState
|
|
24
|
+
if (_childState.child) {
|
|
25
|
+
_childState.child.workerApi.callMaster({
|
|
34
26
|
location: __filename,
|
|
35
27
|
method: 'emit',
|
|
36
28
|
args: [event, ...args]
|
package/lib/child.js
CHANGED
|
@@ -55,94 +55,52 @@ function _core() {
|
|
|
55
55
|
return data;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
const data = _interopRequireDefault(require("./bus"));
|
|
58
|
+
var _bus = _interopRequireDefault(require("./bus"));
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
return data;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
return data;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function _Profiler() {
|
|
69
|
-
const data = _interopRequireDefault(require("./Profiler"));
|
|
70
|
-
|
|
71
|
-
_Profiler = function () {
|
|
72
|
-
return data;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
return data;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function _Handle2() {
|
|
79
|
-
const data = _interopRequireDefault(require("./Handle"));
|
|
80
|
-
|
|
81
|
-
_Handle2 = function () {
|
|
82
|
-
return data;
|
|
83
|
-
};
|
|
60
|
+
var _Profiler = _interopRequireDefault(require("./Profiler"));
|
|
84
61
|
|
|
85
|
-
|
|
86
|
-
}
|
|
62
|
+
var _Handle2 = _interopRequireDefault(require("./Handle"));
|
|
87
63
|
|
|
88
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
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); }
|
|
89
65
|
|
|
90
|
-
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; }
|
|
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; }
|
|
91
67
|
|
|
92
68
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
93
69
|
|
|
94
|
-
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; }
|
|
95
|
-
|
|
96
70
|
// The import of './Handle' should really be imported eagerly (with @babel/plugin-transform-modules-commonjs's lazy mode).
|
|
97
|
-
const Handle = _Handle2
|
|
71
|
+
const Handle = _Handle2.default;
|
|
98
72
|
|
|
99
73
|
class Child {
|
|
100
|
-
|
|
101
|
-
|
|
74
|
+
callQueue = [];
|
|
75
|
+
maxConcurrentCalls = 10;
|
|
76
|
+
responseId = 0;
|
|
77
|
+
responseQueue = new Map();
|
|
78
|
+
handles = new Map();
|
|
79
|
+
sharedReferences = new Map();
|
|
80
|
+
sharedReferencesByValue = new Map();
|
|
102
81
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
_defineProperty(this, "module", void 0);
|
|
108
|
-
|
|
109
|
-
_defineProperty(this, "responseId", 0);
|
|
110
|
-
|
|
111
|
-
_defineProperty(this, "responseQueue", new Map());
|
|
112
|
-
|
|
113
|
-
_defineProperty(this, "loggerDisposable", void 0);
|
|
114
|
-
|
|
115
|
-
_defineProperty(this, "child", void 0);
|
|
116
|
-
|
|
117
|
-
_defineProperty(this, "profiler", void 0);
|
|
118
|
-
|
|
119
|
-
_defineProperty(this, "workerApi", void 0);
|
|
120
|
-
|
|
121
|
-
_defineProperty(this, "handles", new Map());
|
|
122
|
-
|
|
123
|
-
_defineProperty(this, "sharedReferences", new Map());
|
|
124
|
-
|
|
125
|
-
_defineProperty(this, "sharedReferencesByValue", new Map());
|
|
126
|
-
|
|
127
|
-
_defineProperty(this, "workerApi", {
|
|
128
|
-
callMaster: (request, awaitResponse = true) => this.addCall(request, awaitResponse),
|
|
129
|
-
createReverseHandle: fn => this.createReverseHandle(fn),
|
|
130
|
-
runHandle: (handle, args) => this.workerApi.callMaster({
|
|
131
|
-
handle: handle.id,
|
|
132
|
-
args
|
|
133
|
-
}, true),
|
|
134
|
-
getSharedReference: ref => this.sharedReferences.get(ref),
|
|
135
|
-
resolveSharedReference: value => this.sharedReferencesByValue.get(value)
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
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
|
|
139
86
|
// the main process via the bus.
|
|
140
87
|
|
|
141
88
|
this.loggerDisposable = _logger().default.onLog(event => {
|
|
142
|
-
_bus
|
|
89
|
+
_bus.default.emit('logEvent', event);
|
|
143
90
|
});
|
|
144
91
|
}
|
|
145
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
|
+
|
|
146
104
|
messageListener(message) {
|
|
147
105
|
if (message.type === 'response') {
|
|
148
106
|
return this.handleResponse(message);
|
|
@@ -155,10 +113,14 @@ class Child {
|
|
|
155
113
|
this.child.send(data);
|
|
156
114
|
}
|
|
157
115
|
|
|
158
|
-
childInit(module, childId) {
|
|
116
|
+
async childInit(module, childId) {
|
|
159
117
|
// $FlowFixMe this must be dynamic
|
|
160
118
|
this.module = require(module);
|
|
161
119
|
this.childId = childId;
|
|
120
|
+
|
|
121
|
+
if (this.module.childInit != null) {
|
|
122
|
+
await this.module.childInit();
|
|
123
|
+
}
|
|
162
124
|
}
|
|
163
125
|
|
|
164
126
|
async handleRequest(data) {
|
|
@@ -207,12 +169,12 @@ class Child {
|
|
|
207
169
|
(0, _logger().unpatchConsole)();
|
|
208
170
|
}
|
|
209
171
|
|
|
210
|
-
result = responseFromContent(this.childInit(moduleName, child));
|
|
172
|
+
result = responseFromContent(await this.childInit(moduleName, child));
|
|
211
173
|
} catch (e) {
|
|
212
174
|
result = errorResponseFromError(e);
|
|
213
175
|
}
|
|
214
176
|
} else if (method === 'startProfile') {
|
|
215
|
-
this.profiler = new
|
|
177
|
+
this.profiler = new _Profiler.default();
|
|
216
178
|
|
|
217
179
|
try {
|
|
218
180
|
result = responseFromContent(await this.profiler.startProfiling());
|
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
package/lib/index.js
CHANGED
|
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "Handle", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return _WorkerFarm
|
|
9
|
+
return _WorkerFarm.Handle;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "bus", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function () {
|
|
15
|
-
return _bus
|
|
15
|
+
return _bus.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
exports.default = void 0;
|
|
@@ -27,15 +27,7 @@ function _assert() {
|
|
|
27
27
|
return data;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
const data = _interopRequireWildcard(require("./WorkerFarm"));
|
|
32
|
-
|
|
33
|
-
_WorkerFarm = function () {
|
|
34
|
-
return data;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
30
|
+
var _WorkerFarm = _interopRequireWildcard(require("./WorkerFarm"));
|
|
39
31
|
|
|
40
32
|
function _logger() {
|
|
41
33
|
const data = _interopRequireDefault(require("@parcel/logger"));
|
|
@@ -47,25 +39,17 @@ function _logger() {
|
|
|
47
39
|
return data;
|
|
48
40
|
}
|
|
49
41
|
|
|
50
|
-
|
|
51
|
-
const data = _interopRequireDefault(require("./bus"));
|
|
42
|
+
var _bus = _interopRequireDefault(require("./bus"));
|
|
52
43
|
|
|
53
|
-
|
|
54
|
-
return data;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return data;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
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); }
|
|
61
45
|
|
|
62
|
-
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; }
|
|
63
47
|
|
|
64
48
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
65
49
|
|
|
66
|
-
if (!_WorkerFarm
|
|
50
|
+
if (!_WorkerFarm.default.isWorker()) {
|
|
67
51
|
// Forward all logger events originating from workers into the main process
|
|
68
|
-
_bus
|
|
52
|
+
_bus.default.on('logEvent', e => {
|
|
69
53
|
switch (e.level) {
|
|
70
54
|
case 'info':
|
|
71
55
|
_logger().default.info(e.diagnostics);
|
|
@@ -100,6 +84,5 @@ if (!_WorkerFarm().default.isWorker()) {
|
|
|
100
84
|
});
|
|
101
85
|
}
|
|
102
86
|
|
|
103
|
-
var _default = _WorkerFarm
|
|
104
|
-
|
|
87
|
+
var _default = _WorkerFarm.default;
|
|
105
88
|
exports.default = _default;
|
|
@@ -15,25 +15,9 @@ function _nullthrows() {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
const data = require("../childState");
|
|
18
|
+
var _childState = require("../childState");
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _child() {
|
|
29
|
-
const data = require("../child");
|
|
30
|
-
|
|
31
|
-
_child = function () {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
20
|
+
var _child = require("../child");
|
|
37
21
|
|
|
38
22
|
function _core() {
|
|
39
23
|
const data = require("@parcel/core");
|
|
@@ -47,14 +31,8 @@ function _core() {
|
|
|
47
31
|
|
|
48
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
33
|
|
|
50
|
-
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; }
|
|
51
|
-
|
|
52
34
|
class ProcessChild {
|
|
53
35
|
constructor(onMessage, onExit) {
|
|
54
|
-
_defineProperty(this, "onMessage", void 0);
|
|
55
|
-
|
|
56
|
-
_defineProperty(this, "onExit", void 0);
|
|
57
|
-
|
|
58
36
|
if (!process.send) {
|
|
59
37
|
throw new Error('Only create ProcessChild instances in a worker!');
|
|
60
38
|
}
|
|
@@ -93,4 +71,4 @@ class ProcessChild {
|
|
|
93
71
|
}
|
|
94
72
|
|
|
95
73
|
exports.default = ProcessChild;
|
|
96
|
-
(0, _childState
|
|
74
|
+
(0, _childState.setChild)(new _child.Child(ProcessChild));
|
|
@@ -37,26 +37,13 @@ function _core() {
|
|
|
37
37
|
|
|
38
38
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
39
|
|
|
40
|
-
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; }
|
|
41
|
-
|
|
42
40
|
const WORKER_PATH = _path().default.join(__dirname, 'ProcessChild.js');
|
|
43
41
|
|
|
44
42
|
class ProcessWorker {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
_defineProperty(this, "onMessage", void 0);
|
|
49
|
-
|
|
50
|
-
_defineProperty(this, "onError", void 0);
|
|
51
|
-
|
|
52
|
-
_defineProperty(this, "onExit", void 0);
|
|
53
|
-
|
|
54
|
-
_defineProperty(this, "child", void 0);
|
|
55
|
-
|
|
56
|
-
_defineProperty(this, "processQueue", true);
|
|
57
|
-
|
|
58
|
-
_defineProperty(this, "sendQueue", []);
|
|
43
|
+
processQueue = true;
|
|
44
|
+
sendQueue = [];
|
|
59
45
|
|
|
46
|
+
constructor(execArgv, onMessage, onError, onExit) {
|
|
60
47
|
this.execArgv = execArgv;
|
|
61
48
|
this.onMessage = onMessage;
|
|
62
49
|
this.onError = onError;
|
|
@@ -25,25 +25,9 @@ function _nullthrows() {
|
|
|
25
25
|
return data;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
const data = require("../childState");
|
|
28
|
+
var _childState = require("../childState");
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function _child() {
|
|
39
|
-
const data = require("../child");
|
|
40
|
-
|
|
41
|
-
_child = function () {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
30
|
+
var _child = require("../child");
|
|
47
31
|
|
|
48
32
|
function _core() {
|
|
49
33
|
const data = require("@parcel/core");
|
|
@@ -57,14 +41,8 @@ function _core() {
|
|
|
57
41
|
|
|
58
42
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
59
43
|
|
|
60
|
-
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; }
|
|
61
|
-
|
|
62
44
|
class ThreadsChild {
|
|
63
45
|
constructor(onMessage, onExit) {
|
|
64
|
-
_defineProperty(this, "onMessage", void 0);
|
|
65
|
-
|
|
66
|
-
_defineProperty(this, "onExit", void 0);
|
|
67
|
-
|
|
68
46
|
if (_worker_threads().isMainThread || !_worker_threads().parentPort) {
|
|
69
47
|
throw new Error('Only create ThreadsChild instances in a worker!');
|
|
70
48
|
}
|
|
@@ -88,4 +66,4 @@ class ThreadsChild {
|
|
|
88
66
|
}
|
|
89
67
|
|
|
90
68
|
exports.default = ThreadsChild;
|
|
91
|
-
(0, _childState
|
|
69
|
+
(0, _childState.setChild)(new _child.Child(ThreadsChild));
|
|
@@ -37,22 +37,10 @@ function _core() {
|
|
|
37
37
|
|
|
38
38
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
39
|
|
|
40
|
-
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; }
|
|
41
|
-
|
|
42
40
|
const WORKER_PATH = _path().default.join(__dirname, 'ThreadsChild.js');
|
|
43
41
|
|
|
44
42
|
class ThreadsWorker {
|
|
45
43
|
constructor(execArgv, onMessage, onError, onExit) {
|
|
46
|
-
_defineProperty(this, "execArgv", void 0);
|
|
47
|
-
|
|
48
|
-
_defineProperty(this, "onMessage", void 0);
|
|
49
|
-
|
|
50
|
-
_defineProperty(this, "onError", void 0);
|
|
51
|
-
|
|
52
|
-
_defineProperty(this, "onExit", void 0);
|
|
53
|
-
|
|
54
|
-
_defineProperty(this, "worker", void 0);
|
|
55
|
-
|
|
56
44
|
this.execArgv = execArgv;
|
|
57
45
|
this.onMessage = onMessage;
|
|
58
46
|
this.onError = onError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/workers",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-nightly.1002+5530a6ef",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -16,18 +16,25 @@
|
|
|
16
16
|
},
|
|
17
17
|
"main": "lib/index.js",
|
|
18
18
|
"source": "src/index.js",
|
|
19
|
+
"types": "index.d.ts",
|
|
19
20
|
"engines": {
|
|
20
21
|
"node": ">= 12.0.0"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.0.0-
|
|
24
|
-
"@parcel/logger": "2.0.0-
|
|
25
|
-
"@parcel/
|
|
24
|
+
"@parcel/diagnostic": "2.0.0-nightly.1002+5530a6ef",
|
|
25
|
+
"@parcel/logger": "2.0.0-nightly.1002+5530a6ef",
|
|
26
|
+
"@parcel/types": "2.0.0-nightly.1002+5530a6ef",
|
|
27
|
+
"@parcel/utils": "2.0.0-nightly.1002+5530a6ef",
|
|
26
28
|
"chrome-trace-event": "^1.0.2",
|
|
27
29
|
"nullthrows": "^1.1.1"
|
|
28
30
|
},
|
|
29
31
|
"peerDependencies": {
|
|
30
|
-
"@parcel/core": "
|
|
32
|
+
"@parcel/core": "2.0.0-nightly.1000+5530a6ef"
|
|
31
33
|
},
|
|
32
|
-
"
|
|
34
|
+
"browser": {
|
|
35
|
+
"./src/cpuCount.js": false,
|
|
36
|
+
"./src/process/ProcessWorker.js": false,
|
|
37
|
+
"./src/threads/ThreadsWorker.js": false
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "5530a6eff8b619873353baeb0457ae4ec591e9fa"
|
|
33
40
|
}
|
package/src/Worker.js
CHANGED
|
@@ -67,7 +67,7 @@ export default class Worker extends EventEmitter {
|
|
|
67
67
|
// arg parsing logic adapted from https://stackoverflow.com/a/46946420/2352201
|
|
68
68
|
let opts = [''];
|
|
69
69
|
let quote = false;
|
|
70
|
-
for (let c of nullthrows(process.env.NODE_OPTIONS.match(
|
|
70
|
+
for (let c of nullthrows(process.env.NODE_OPTIONS.match(/.|^$/g))) {
|
|
71
71
|
if (c === '"') {
|
|
72
72
|
quote = !quote;
|
|
73
73
|
} else if (!quote && c === ' ') {
|
package/src/WorkerFarm.js
CHANGED
|
@@ -68,6 +68,7 @@ export default class WorkerFarm extends EventEmitter {
|
|
|
68
68
|
callQueue: Array<WorkerCall> = [];
|
|
69
69
|
ending: boolean = false;
|
|
70
70
|
localWorker: WorkerModule;
|
|
71
|
+
localWorkerInit: ?Promise<void>;
|
|
71
72
|
options: FarmOptions;
|
|
72
73
|
run: HandleFunction;
|
|
73
74
|
warmWorkers: number = 0;
|
|
@@ -95,6 +96,8 @@ export default class WorkerFarm extends EventEmitter {
|
|
|
95
96
|
|
|
96
97
|
// $FlowFixMe this must be dynamic
|
|
97
98
|
this.localWorker = require(this.options.workerPath);
|
|
99
|
+
this.localWorkerInit =
|
|
100
|
+
this.localWorker.childInit != null ? this.localWorker.childInit() : null;
|
|
98
101
|
this.run = this.createHandle('run');
|
|
99
102
|
|
|
100
103
|
this.startMaxWorkers();
|
|
@@ -173,7 +176,7 @@ export default class WorkerFarm extends EventEmitter {
|
|
|
173
176
|
}
|
|
174
177
|
|
|
175
178
|
createHandle(method: string): HandleFunction {
|
|
176
|
-
return (...args) => {
|
|
179
|
+
return async (...args) => {
|
|
177
180
|
// Child process workers are slow to start (~600ms).
|
|
178
181
|
// While we're waiting, just run on the main thread.
|
|
179
182
|
// This significantly speeds up startup time.
|
|
@@ -187,6 +190,11 @@ export default class WorkerFarm extends EventEmitter {
|
|
|
187
190
|
let processedArgs = restoreDeserializedObject(
|
|
188
191
|
prepareForSerialization([...args, false]),
|
|
189
192
|
);
|
|
193
|
+
|
|
194
|
+
if (this.localWorkerInit != null) {
|
|
195
|
+
await this.localWorkerInit;
|
|
196
|
+
this.localWorkerInit = null;
|
|
197
|
+
}
|
|
190
198
|
return this.localWorker[method](this.workerApi, ...processedArgs);
|
|
191
199
|
}
|
|
192
200
|
};
|
package/src/child.js
CHANGED
|
@@ -46,8 +46,10 @@ export class Child {
|
|
|
46
46
|
|
|
47
47
|
constructor(ChildBackend: Class<ChildImpl>) {
|
|
48
48
|
this.child = new ChildBackend(
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
m => {
|
|
50
|
+
this.messageListener(m);
|
|
51
|
+
},
|
|
52
|
+
() => this.handleEnd(),
|
|
51
53
|
);
|
|
52
54
|
|
|
53
55
|
// Monitior all logging events inside this child process and forward to
|
|
@@ -93,10 +95,14 @@ export class Child {
|
|
|
93
95
|
this.child.send(data);
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
childInit(module: string, childId: number): void {
|
|
98
|
+
async childInit(module: string, childId: number): Promise<void> {
|
|
97
99
|
// $FlowFixMe this must be dynamic
|
|
98
100
|
this.module = require(module);
|
|
99
101
|
this.childId = childId;
|
|
102
|
+
|
|
103
|
+
if (this.module.childInit != null) {
|
|
104
|
+
await this.module.childInit();
|
|
105
|
+
}
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
async handleRequest(data: WorkerRequest): Promise<void> {
|
|
@@ -136,7 +142,7 @@ export class Child {
|
|
|
136
142
|
unpatchConsole();
|
|
137
143
|
}
|
|
138
144
|
|
|
139
|
-
result = responseFromContent(this.childInit(moduleName, child));
|
|
145
|
+
result = responseFromContent(await this.childInit(moduleName, child));
|
|
140
146
|
} catch (e) {
|
|
141
147
|
result = errorResponseFromError(e);
|
|
142
148
|
}
|
package/src/cpuCount.js
CHANGED
|
@@ -53,8 +53,9 @@ export default function getCores(bypassCache?: boolean = false): number {
|
|
|
53
53
|
// Guess the amount of real cores
|
|
54
54
|
cores = os
|
|
55
55
|
.cpus()
|
|
56
|
-
.filter(
|
|
57
|
-
|
|
56
|
+
.filter(
|
|
57
|
+
(cpu, index) => !cpu.model.includes('Intel') || index % 2 === 1,
|
|
58
|
+
).length;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
// Another fallback
|
package/test/cpuCount.test.js
CHANGED
|
@@ -3,7 +3,7 @@ import os from 'os';
|
|
|
3
3
|
|
|
4
4
|
import getCores, {detectRealCores} from '../src/cpuCount';
|
|
5
5
|
|
|
6
|
-
describe('cpuCount', function() {
|
|
6
|
+
describe('cpuCount', function () {
|
|
7
7
|
it('Should be able to detect real cpu count', () => {
|
|
8
8
|
// Windows not supported as getting the cpu count takes a couple seconds...
|
|
9
9
|
if (os.platform() === 'win32') return;
|
package/test/workerfarm.js
CHANGED