@parcel/workers 2.0.0-nightly.148 → 2.0.0-nightly.1481
Sign up to get free protection for your applications and to get access to all the features.
- package/index.d.ts +23 -0
- package/lib/Handle.js +16 -58
- package/lib/Worker.js +103 -62
- package/lib/WorkerFarm.js +272 -192
- package/lib/backend.js +4 -6
- package/lib/bus.js +11 -13
- package/lib/child.js +140 -116
- package/lib/childState.js +2 -4
- package/lib/core-worker.browser.js +4 -0
- package/lib/core-worker.js +4 -0
- package/lib/cpuCount.js +36 -25
- package/lib/index.js +35 -32
- package/lib/process/ProcessChild.js +18 -24
- package/lib/process/ProcessWorker.js +27 -38
- package/lib/threads/ThreadsChild.js +26 -28
- package/lib/threads/ThreadsWorker.js +25 -31
- package/lib/web/WebChild.js +44 -0
- package/lib/web/WebWorker.js +85 -0
- package/package.json +19 -8
- package/src/Handle.js +10 -39
- package/src/Worker.js +95 -22
- package/src/WorkerFarm.js +267 -62
- package/src/backend.js +5 -0
- package/src/bus.js +3 -2
- package/src/child.js +95 -26
- package/src/core-worker.browser.js +3 -0
- package/src/core-worker.js +2 -0
- package/src/cpuCount.js +23 -10
- package/src/index.js +8 -2
- package/src/process/ProcessChild.js +2 -1
- package/src/process/ProcessWorker.js +1 -1
- package/src/threads/ThreadsWorker.js +2 -2
- package/src/types.js +1 -1
- package/src/web/WebChild.js +50 -0
- package/src/web/WebWorker.js +85 -0
- package/test/cpuCount.test.js +1 -1
- package/test/integration/workerfarm/console.js +1 -1
- package/test/integration/workerfarm/logging.js +1 -1
- package/test/integration/workerfarm/reverse-handle.js +2 -2
- package/test/workerfarm.js +5 -5
- package/lib/Profiler.js +0 -70
- package/lib/Trace.js +0 -126
- package/src/Profiler.js +0 -93
- package/src/Trace.js +0 -121
package/lib/index.js
CHANGED
@@ -16,57 +16,60 @@ Object.defineProperty(exports, "bus", {
|
|
16
16
|
}
|
17
17
|
});
|
18
18
|
exports.default = void 0;
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
function _assert() {
|
20
|
+
const data = _interopRequireDefault(require("assert"));
|
21
|
+
_assert = function () {
|
22
|
+
return data;
|
23
|
+
};
|
24
|
+
return data;
|
25
|
+
}
|
22
26
|
var _WorkerFarm = _interopRequireWildcard(require("./WorkerFarm"));
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
function _logger() {
|
28
|
+
const data = _interopRequireDefault(require("@parcel/logger"));
|
29
|
+
_logger = function () {
|
30
|
+
return data;
|
31
|
+
};
|
32
|
+
return data;
|
33
|
+
}
|
26
34
|
var _bus = _interopRequireDefault(require("./bus"));
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
function _profiler() {
|
36
|
+
const data = require("@parcel/profiler");
|
37
|
+
_profiler = function () {
|
38
|
+
return data;
|
39
|
+
};
|
40
|
+
return data;
|
41
|
+
}
|
42
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
43
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
32
44
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
|
-
|
34
45
|
if (!_WorkerFarm.default.isWorker()) {
|
35
46
|
// Forward all logger events originating from workers into the main process
|
36
47
|
_bus.default.on('logEvent', e => {
|
37
48
|
switch (e.level) {
|
38
49
|
case 'info':
|
39
|
-
_logger.default.info(e.diagnostics);
|
40
|
-
|
50
|
+
_logger().default.info(e.diagnostics);
|
41
51
|
break;
|
42
|
-
|
43
52
|
case 'progress':
|
44
|
-
(0, _assert.default)(typeof e.message === 'string');
|
45
|
-
|
46
|
-
_logger.default.progress(e.message);
|
47
|
-
|
53
|
+
(0, _assert().default)(typeof e.message === 'string');
|
54
|
+
_logger().default.progress(e.message);
|
48
55
|
break;
|
49
|
-
|
50
56
|
case 'verbose':
|
51
|
-
_logger.default.verbose(e.diagnostics);
|
52
|
-
|
57
|
+
_logger().default.verbose(e.diagnostics);
|
53
58
|
break;
|
54
|
-
|
55
59
|
case 'warn':
|
56
|
-
_logger.default.warn(e.diagnostics);
|
57
|
-
|
60
|
+
_logger().default.warn(e.diagnostics);
|
58
61
|
break;
|
59
|
-
|
60
62
|
case 'error':
|
61
|
-
_logger.default.error(e.diagnostics);
|
62
|
-
|
63
|
+
_logger().default.error(e.diagnostics);
|
63
64
|
break;
|
64
|
-
|
65
65
|
default:
|
66
66
|
throw new Error('Unknown log level');
|
67
67
|
}
|
68
68
|
});
|
69
|
-
}
|
70
69
|
|
71
|
-
|
72
|
-
|
70
|
+
// Forward all trace events originating from workers into the main process
|
71
|
+
_bus.default.on('traceEvent', e => {
|
72
|
+
_profiler().tracer.trace(e);
|
73
|
+
});
|
74
|
+
}
|
75
|
+
var _default = exports.default = _WorkerFarm.default;
|
@@ -4,46 +4,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
function _nullthrows() {
|
8
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
9
|
+
_nullthrows = function () {
|
10
|
+
return data;
|
11
|
+
};
|
12
|
+
return data;
|
13
|
+
}
|
10
14
|
var _childState = require("../childState");
|
11
|
-
|
12
15
|
var _child = require("../child");
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
function _core() {
|
17
|
+
const data = require("@parcel/core");
|
18
|
+
_core = function () {
|
19
|
+
return data;
|
20
|
+
};
|
21
|
+
return data;
|
22
|
+
}
|
16
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
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
24
|
class ProcessChild {
|
21
25
|
constructor(onMessage, onExit) {
|
22
|
-
_defineProperty(this, "onMessage", void 0);
|
23
|
-
|
24
|
-
_defineProperty(this, "onExit", void 0);
|
25
|
-
|
26
26
|
if (!process.send) {
|
27
27
|
throw new Error('Only create ProcessChild instances in a worker!');
|
28
28
|
}
|
29
|
-
|
30
29
|
this.onMessage = onMessage;
|
31
30
|
this.onExit = onExit;
|
32
31
|
process.on('message', data => this.handleMessage(data));
|
33
32
|
}
|
34
|
-
|
35
33
|
handleMessage(data) {
|
36
34
|
if (data === 'die') {
|
37
35
|
return this.stop();
|
38
36
|
}
|
39
|
-
|
40
|
-
this.onMessage((0, _core.deserialize)(Buffer.from(data, 'base64')));
|
37
|
+
this.onMessage((0, _core().deserialize)(Buffer.from(data, 'base64')));
|
41
38
|
}
|
42
|
-
|
43
39
|
send(data) {
|
44
|
-
let processSend = (0, _nullthrows.default)(process.send).bind(process);
|
45
|
-
processSend((0, _core.serialize)(data).toString('base64'), err => {
|
40
|
+
let processSend = (0, _nullthrows().default)(process.send).bind(process);
|
41
|
+
processSend((0, _core().serialize)(data).toString('base64'), err => {
|
46
42
|
if (err && err instanceof Error) {
|
43
|
+
// $FlowFixMe[prop-missing]
|
47
44
|
if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
|
48
45
|
// IPC connection closed
|
49
46
|
// no need to keep the worker running if it can't send or receive data
|
@@ -52,13 +49,10 @@ class ProcessChild {
|
|
52
49
|
}
|
53
50
|
});
|
54
51
|
}
|
55
|
-
|
56
52
|
stop() {
|
57
53
|
this.onExit(0);
|
58
54
|
process.exit();
|
59
55
|
}
|
60
|
-
|
61
56
|
}
|
62
|
-
|
63
57
|
exports.default = ProcessChild;
|
64
58
|
(0, _childState.setChild)(new _child.Child(ProcessChild));
|
@@ -4,55 +4,51 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
function _child_process() {
|
8
|
+
const data = _interopRequireDefault(require("child_process"));
|
9
|
+
_child_process = function () {
|
10
|
+
return data;
|
11
|
+
};
|
12
|
+
return data;
|
13
|
+
}
|
14
|
+
function _path() {
|
15
|
+
const data = _interopRequireDefault(require("path"));
|
16
|
+
_path = function () {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
function _core() {
|
22
|
+
const data = require("@parcel/core");
|
23
|
+
_core = function () {
|
24
|
+
return data;
|
25
|
+
};
|
26
|
+
return data;
|
27
|
+
}
|
14
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
-
|
16
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
17
|
-
|
18
|
-
const WORKER_PATH = _path.default.join(__dirname, 'ProcessChild.js');
|
19
|
-
|
29
|
+
const WORKER_PATH = _path().default.join(__dirname, 'ProcessChild.js');
|
20
30
|
class ProcessWorker {
|
31
|
+
processQueue = true;
|
32
|
+
sendQueue = [];
|
21
33
|
constructor(execArgv, onMessage, onError, onExit) {
|
22
|
-
_defineProperty(this, "execArgv", void 0);
|
23
|
-
|
24
|
-
_defineProperty(this, "onMessage", void 0);
|
25
|
-
|
26
|
-
_defineProperty(this, "onError", void 0);
|
27
|
-
|
28
|
-
_defineProperty(this, "onExit", void 0);
|
29
|
-
|
30
|
-
_defineProperty(this, "child", void 0);
|
31
|
-
|
32
|
-
_defineProperty(this, "processQueue", true);
|
33
|
-
|
34
|
-
_defineProperty(this, "sendQueue", []);
|
35
|
-
|
36
34
|
this.execArgv = execArgv;
|
37
35
|
this.onMessage = onMessage;
|
38
36
|
this.onError = onError;
|
39
37
|
this.onExit = onExit;
|
40
38
|
}
|
41
|
-
|
42
39
|
start() {
|
43
|
-
this.child = _child_process.default.fork(WORKER_PATH, process.argv, {
|
40
|
+
this.child = _child_process().default.fork(WORKER_PATH, process.argv, {
|
44
41
|
execArgv: this.execArgv,
|
45
42
|
env: process.env,
|
46
43
|
cwd: process.cwd()
|
47
44
|
});
|
48
45
|
this.child.on('message', data => {
|
49
|
-
this.onMessage((0, _core.deserialize)(Buffer.from(data, 'base64')));
|
46
|
+
this.onMessage((0, _core().deserialize)(Buffer.from(data, 'base64')));
|
50
47
|
});
|
51
48
|
this.child.once('exit', this.onExit);
|
52
49
|
this.child.on('error', this.onError);
|
53
50
|
return Promise.resolve();
|
54
51
|
}
|
55
|
-
|
56
52
|
async stop() {
|
57
53
|
this.child.send('die');
|
58
54
|
let forceKill = setTimeout(() => this.child.kill('SIGINT'), 500);
|
@@ -61,34 +57,27 @@ class ProcessWorker {
|
|
61
57
|
});
|
62
58
|
clearTimeout(forceKill);
|
63
59
|
}
|
64
|
-
|
65
60
|
send(data) {
|
66
61
|
if (!this.processQueue) {
|
67
62
|
this.sendQueue.push(data);
|
68
63
|
return;
|
69
64
|
}
|
70
|
-
|
71
|
-
let result = this.child.send((0, _core.serialize)(data).toString('base64'), error => {
|
65
|
+
let result = this.child.send((0, _core().serialize)(data).toString('base64'), error => {
|
72
66
|
if (error && error instanceof Error) {
|
73
67
|
// Ignore this, the workerfarm handles child errors
|
74
68
|
return;
|
75
69
|
}
|
76
|
-
|
77
70
|
this.processQueue = true;
|
78
|
-
|
79
71
|
if (this.sendQueue.length > 0) {
|
80
72
|
let queueCopy = this.sendQueue.slice(0);
|
81
73
|
this.sendQueue = [];
|
82
74
|
queueCopy.forEach(entry => this.send(entry));
|
83
75
|
}
|
84
76
|
});
|
85
|
-
|
86
77
|
if (!result || /^win/.test(process.platform)) {
|
87
78
|
// Queue is handling too much messages throttle it
|
88
79
|
this.processQueue = false;
|
89
80
|
}
|
90
81
|
}
|
91
|
-
|
92
82
|
}
|
93
|
-
|
94
83
|
exports.default = ProcessWorker;
|
@@ -4,48 +4,46 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
function _worker_threads() {
|
8
|
+
const data = require("worker_threads");
|
9
|
+
_worker_threads = function () {
|
10
|
+
return data;
|
11
|
+
};
|
12
|
+
return data;
|
13
|
+
}
|
14
|
+
function _nullthrows() {
|
15
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
16
|
+
_nullthrows = function () {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
return data;
|
20
|
+
}
|
12
21
|
var _childState = require("../childState");
|
13
|
-
|
14
22
|
var _child = require("../child");
|
15
|
-
|
16
|
-
|
17
|
-
|
23
|
+
function _core() {
|
24
|
+
const data = require("@parcel/core");
|
25
|
+
_core = function () {
|
26
|
+
return data;
|
27
|
+
};
|
28
|
+
return data;
|
29
|
+
}
|
18
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
-
|
20
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
21
|
-
|
22
31
|
class ThreadsChild {
|
23
32
|
constructor(onMessage, onExit) {
|
24
|
-
|
25
|
-
|
26
|
-
_defineProperty(this, "onExit", void 0);
|
27
|
-
|
28
|
-
if (_worker_threads.isMainThread || !_worker_threads.parentPort) {
|
33
|
+
if (_worker_threads().isMainThread || !_worker_threads().parentPort) {
|
29
34
|
throw new Error('Only create ThreadsChild instances in a worker!');
|
30
35
|
}
|
31
|
-
|
32
36
|
this.onMessage = onMessage;
|
33
37
|
this.onExit = onExit;
|
34
|
-
|
35
|
-
_worker_threads.parentPort.on('
|
36
|
-
|
37
|
-
_worker_threads.parentPort.on('close', this.onExit);
|
38
|
+
_worker_threads().parentPort.on('message', data => this.handleMessage(data));
|
39
|
+
_worker_threads().parentPort.on('close', this.onExit);
|
38
40
|
}
|
39
|
-
|
40
41
|
handleMessage(data) {
|
41
|
-
this.onMessage((0, _core.restoreDeserializedObject)(data));
|
42
|
+
this.onMessage((0, _core().restoreDeserializedObject)(data));
|
42
43
|
}
|
43
|
-
|
44
44
|
send(data) {
|
45
|
-
(0, _nullthrows.default)(_worker_threads.parentPort).postMessage((0, _core.prepareForSerialization)(data));
|
45
|
+
(0, _nullthrows().default)(_worker_threads().parentPort).postMessage((0, _core().prepareForSerialization)(data));
|
46
46
|
}
|
47
|
-
|
48
47
|
}
|
49
|
-
|
50
48
|
exports.default = ThreadsChild;
|
51
49
|
(0, _childState.setChild)(new _child.Child(ThreadsChild));
|
@@ -4,39 +4,38 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
function _worker_threads() {
|
8
|
+
const data = require("worker_threads");
|
9
|
+
_worker_threads = function () {
|
10
|
+
return data;
|
11
|
+
};
|
12
|
+
return data;
|
13
|
+
}
|
14
|
+
function _path() {
|
15
|
+
const data = _interopRequireDefault(require("path"));
|
16
|
+
_path = function () {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
function _core() {
|
22
|
+
const data = require("@parcel/core");
|
23
|
+
_core = function () {
|
24
|
+
return data;
|
25
|
+
};
|
26
|
+
return data;
|
27
|
+
}
|
14
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
-
|
16
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
17
|
-
|
18
|
-
const WORKER_PATH = _path.default.join(__dirname, 'ThreadsChild.js');
|
19
|
-
|
29
|
+
const WORKER_PATH = _path().default.join(__dirname, 'ThreadsChild.js');
|
20
30
|
class ThreadsWorker {
|
21
31
|
constructor(execArgv, onMessage, onError, onExit) {
|
22
|
-
_defineProperty(this, "execArgv", void 0);
|
23
|
-
|
24
|
-
_defineProperty(this, "onMessage", void 0);
|
25
|
-
|
26
|
-
_defineProperty(this, "onError", void 0);
|
27
|
-
|
28
|
-
_defineProperty(this, "onExit", void 0);
|
29
|
-
|
30
|
-
_defineProperty(this, "worker", void 0);
|
31
|
-
|
32
32
|
this.execArgv = execArgv;
|
33
33
|
this.onMessage = onMessage;
|
34
34
|
this.onError = onError;
|
35
35
|
this.onExit = onExit;
|
36
36
|
}
|
37
|
-
|
38
37
|
start() {
|
39
|
-
this.worker = new _worker_threads.Worker(WORKER_PATH, {
|
38
|
+
this.worker = new (_worker_threads().Worker)(WORKER_PATH, {
|
40
39
|
execArgv: this.execArgv,
|
41
40
|
env: process.env
|
42
41
|
});
|
@@ -47,21 +46,16 @@ class ThreadsWorker {
|
|
47
46
|
this.worker.on('online', resolve);
|
48
47
|
});
|
49
48
|
}
|
50
|
-
|
51
49
|
stop() {
|
52
50
|
// In node 12, this returns a promise, but previously it accepted a callback
|
53
51
|
// TODO: Pass a callback in earlier versions of Node
|
54
52
|
return Promise.resolve(this.worker.terminate());
|
55
53
|
}
|
56
|
-
|
57
54
|
handleMessage(data) {
|
58
|
-
this.onMessage((0, _core.restoreDeserializedObject)(data));
|
55
|
+
this.onMessage((0, _core().restoreDeserializedObject)(data));
|
59
56
|
}
|
60
|
-
|
61
57
|
send(data) {
|
62
|
-
this.worker.postMessage((0, _core.prepareForSerialization)(data));
|
58
|
+
this.worker.postMessage((0, _core().prepareForSerialization)(data));
|
63
59
|
}
|
64
|
-
|
65
60
|
}
|
66
|
-
|
67
61
|
exports.default = ThreadsWorker;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _childState = require("../childState");
|
8
|
+
var _child = require("../child");
|
9
|
+
function _core() {
|
10
|
+
const data = require("@parcel/core");
|
11
|
+
_core = function () {
|
12
|
+
return data;
|
13
|
+
};
|
14
|
+
return data;
|
15
|
+
}
|
16
|
+
/* eslint-env worker*/
|
17
|
+
class WebChild {
|
18
|
+
constructor(onMessage, onExit) {
|
19
|
+
if (!(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)) {
|
20
|
+
throw new Error('Only create WebChild instances in a worker!');
|
21
|
+
}
|
22
|
+
this.onMessage = onMessage;
|
23
|
+
this.onExit = onExit;
|
24
|
+
self.addEventListener('message', ({
|
25
|
+
data
|
26
|
+
}) => {
|
27
|
+
if (data === 'stop') {
|
28
|
+
this.onExit(0);
|
29
|
+
self.postMessage('stopped');
|
30
|
+
}
|
31
|
+
// $FlowFixMe assume WorkerMessage as data
|
32
|
+
this.handleMessage(data);
|
33
|
+
});
|
34
|
+
self.postMessage('online');
|
35
|
+
}
|
36
|
+
handleMessage(data) {
|
37
|
+
this.onMessage((0, _core().restoreDeserializedObject)(data));
|
38
|
+
}
|
39
|
+
send(data) {
|
40
|
+
self.postMessage((0, _core().prepareForSerialization)(data));
|
41
|
+
}
|
42
|
+
}
|
43
|
+
exports.default = WebChild;
|
44
|
+
(0, _childState.setChild)(new _child.Child(WebChild));
|
@@ -0,0 +1,85 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
function _core() {
|
8
|
+
const data = require("@parcel/core");
|
9
|
+
_core = function () {
|
10
|
+
return data;
|
11
|
+
};
|
12
|
+
return data;
|
13
|
+
}
|
14
|
+
function _utils() {
|
15
|
+
const data = require("@parcel/utils");
|
16
|
+
_utils = function () {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
let id = 0;
|
22
|
+
class WebWorker {
|
23
|
+
constructor(execArgv, onMessage, onError, onExit) {
|
24
|
+
this.execArgv = execArgv;
|
25
|
+
this.onMessage = onMessage;
|
26
|
+
this.onError = onError;
|
27
|
+
this.onExit = onExit;
|
28
|
+
}
|
29
|
+
start() {
|
30
|
+
// $FlowFixMe[incompatible-call]
|
31
|
+
this.worker = new Worker(new URL('./WebChild.js', import.meta.url), {
|
32
|
+
name: `Parcel Worker ${id++}`,
|
33
|
+
type: 'module'
|
34
|
+
});
|
35
|
+
let {
|
36
|
+
deferred,
|
37
|
+
promise
|
38
|
+
} = (0, _utils().makeDeferredWithPromise)();
|
39
|
+
this.worker.onmessage = ({
|
40
|
+
data
|
41
|
+
}) => {
|
42
|
+
if (data === 'online') {
|
43
|
+
deferred.resolve();
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
|
47
|
+
// $FlowFixMe assume WorkerMessage as data
|
48
|
+
this.handleMessage(data);
|
49
|
+
};
|
50
|
+
this.worker.onerror = this.onError;
|
51
|
+
// Web workers can't crash or intentionally stop on their own, apart from stop() below
|
52
|
+
// this.worker.on('exit', this.onExit);
|
53
|
+
|
54
|
+
return promise;
|
55
|
+
}
|
56
|
+
stop() {
|
57
|
+
if (!this.stopping) {
|
58
|
+
this.stopping = (async () => {
|
59
|
+
this.worker.postMessage('stop');
|
60
|
+
let {
|
61
|
+
deferred,
|
62
|
+
promise
|
63
|
+
} = (0, _utils().makeDeferredWithPromise)();
|
64
|
+
this.worker.addEventListener('message', ({
|
65
|
+
data
|
66
|
+
}) => {
|
67
|
+
if (data === 'stopped') {
|
68
|
+
deferred.resolve();
|
69
|
+
}
|
70
|
+
});
|
71
|
+
await promise;
|
72
|
+
this.worker.terminate();
|
73
|
+
this.onExit(0);
|
74
|
+
})();
|
75
|
+
}
|
76
|
+
return this.stopping;
|
77
|
+
}
|
78
|
+
handleMessage(data) {
|
79
|
+
this.onMessage((0, _core().restoreDeserializedObject)(data));
|
80
|
+
}
|
81
|
+
send(data) {
|
82
|
+
this.worker.postMessage((0, _core().prepareForSerialization)(data));
|
83
|
+
}
|
84
|
+
}
|
85
|
+
exports.default = WebWorker;
|
package/package.json
CHANGED
@@ -1,29 +1,40 @@
|
|
1
1
|
{
|
2
2
|
"name": "@parcel/workers",
|
3
|
-
"version": "2.0.0-nightly.
|
3
|
+
"version": "2.0.0-nightly.1481+e92fe6448",
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
5
5
|
"license": "MIT",
|
6
6
|
"publishConfig": {
|
7
7
|
"access": "public"
|
8
8
|
},
|
9
|
+
"funding": {
|
10
|
+
"type": "opencollective",
|
11
|
+
"url": "https://opencollective.com/parcel"
|
12
|
+
},
|
9
13
|
"repository": {
|
10
14
|
"type": "git",
|
11
15
|
"url": "https://github.com/parcel-bundler/parcel.git"
|
12
16
|
},
|
13
17
|
"main": "lib/index.js",
|
14
18
|
"source": "src/index.js",
|
19
|
+
"types": "index.d.ts",
|
15
20
|
"engines": {
|
16
|
-
"node": ">=
|
21
|
+
"node": ">= 12.0.0"
|
17
22
|
},
|
18
23
|
"dependencies": {
|
19
|
-
"@parcel/diagnostic": "2.0.0-nightly.
|
20
|
-
"@parcel/logger": "2.0.0-nightly.
|
21
|
-
"@parcel/
|
22
|
-
"
|
24
|
+
"@parcel/diagnostic": "2.0.0-nightly.1481+e92fe6448",
|
25
|
+
"@parcel/logger": "2.0.0-nightly.1481+e92fe6448",
|
26
|
+
"@parcel/profiler": "2.11.1-nightly.3104+e92fe6448",
|
27
|
+
"@parcel/types": "2.0.0-nightly.1481+e92fe6448",
|
28
|
+
"@parcel/utils": "2.0.0-nightly.1481+e92fe6448",
|
23
29
|
"nullthrows": "^1.1.1"
|
24
30
|
},
|
25
31
|
"peerDependencies": {
|
26
|
-
"@parcel/core": "
|
32
|
+
"@parcel/core": "2.0.0-nightly.1479+e92fe6448"
|
33
|
+
},
|
34
|
+
"browser": {
|
35
|
+
"./src/process/ProcessWorker.js": false,
|
36
|
+
"./src/threads/ThreadsWorker.js": false,
|
37
|
+
"./src/core-worker.js": "./src/core-worker.browser.js"
|
27
38
|
},
|
28
|
-
"gitHead": "
|
39
|
+
"gitHead": "e92fe6448955f43a02c1bdca8f7e61bb86b1ac78"
|
29
40
|
}
|