@parcel/workers 2.0.0-beta.3.1 → 2.0.0-dev.1514
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +23 -0
- package/lib/Handle.js +7 -33
- package/lib/Worker.js +35 -86
- package/lib/WorkerFarm.js +156 -244
- package/lib/backend.js +4 -6
- package/lib/bus.js +6 -24
- package/lib/child.js +67 -132
- 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 +15 -25
- package/lib/index.js +17 -47
- package/lib/process/ProcessChild.js +4 -42
- package/lib/process/ProcessWorker.js +2 -37
- package/lib/threads/ThreadsChild.js +3 -45
- package/lib/threads/ThreadsWorker.js +0 -30
- package/lib/web/WebChild.js +44 -0
- package/lib/web/WebWorker.js +85 -0
- package/package.json +14 -7
- package/src/Worker.js +24 -14
- package/src/WorkerFarm.js +139 -36
- package/src/backend.js +5 -0
- package/src/bus.js +2 -1
- package/src/child.js +36 -12
- package/src/core-worker.browser.js +3 -0
- package/src/core-worker.js +2 -0
- package/src/cpuCount.js +17 -8
- package/src/index.js +7 -1
- package/src/process/ProcessChild.js +1 -0
- 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/workerfarm.js +1 -1
- package/lib/Profiler.js +0 -86
- package/lib/Trace.js +0 -139
- package/src/Profiler.js +0 -93
- package/src/Trace.js +0 -125
package/lib/index.js
CHANGED
|
@@ -6,100 +6,70 @@ 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;
|
|
19
|
-
|
|
20
19
|
function _assert() {
|
|
21
20
|
const data = _interopRequireDefault(require("assert"));
|
|
22
|
-
|
|
23
21
|
_assert = function () {
|
|
24
22
|
return data;
|
|
25
23
|
};
|
|
26
|
-
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function _WorkerFarm() {
|
|
31
|
-
const data = _interopRequireWildcard(require("./WorkerFarm"));
|
|
32
|
-
|
|
33
|
-
_WorkerFarm = function () {
|
|
34
|
-
return data;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
24
|
return data;
|
|
38
25
|
}
|
|
39
|
-
|
|
26
|
+
var _WorkerFarm = _interopRequireWildcard(require("./WorkerFarm"));
|
|
40
27
|
function _logger() {
|
|
41
28
|
const data = _interopRequireDefault(require("@parcel/logger"));
|
|
42
|
-
|
|
43
29
|
_logger = function () {
|
|
44
30
|
return data;
|
|
45
31
|
};
|
|
46
|
-
|
|
47
32
|
return data;
|
|
48
33
|
}
|
|
49
|
-
|
|
50
|
-
function
|
|
51
|
-
const data =
|
|
52
|
-
|
|
53
|
-
_bus = function () {
|
|
34
|
+
var _bus = _interopRequireDefault(require("./bus"));
|
|
35
|
+
function _profiler() {
|
|
36
|
+
const data = require("@parcel/profiler");
|
|
37
|
+
_profiler = function () {
|
|
54
38
|
return data;
|
|
55
39
|
};
|
|
56
|
-
|
|
57
40
|
return data;
|
|
58
41
|
}
|
|
59
|
-
|
|
60
|
-
function
|
|
61
|
-
|
|
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; }
|
|
63
|
-
|
|
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; }
|
|
64
44
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
65
|
-
|
|
66
|
-
if (!_WorkerFarm().default.isWorker()) {
|
|
45
|
+
if (!_WorkerFarm.default.isWorker()) {
|
|
67
46
|
// Forward all logger events originating from workers into the main process
|
|
68
|
-
_bus
|
|
47
|
+
_bus.default.on('logEvent', e => {
|
|
69
48
|
switch (e.level) {
|
|
70
49
|
case 'info':
|
|
71
50
|
_logger().default.info(e.diagnostics);
|
|
72
|
-
|
|
73
51
|
break;
|
|
74
|
-
|
|
75
52
|
case 'progress':
|
|
76
53
|
(0, _assert().default)(typeof e.message === 'string');
|
|
77
|
-
|
|
78
54
|
_logger().default.progress(e.message);
|
|
79
|
-
|
|
80
55
|
break;
|
|
81
|
-
|
|
82
56
|
case 'verbose':
|
|
83
57
|
_logger().default.verbose(e.diagnostics);
|
|
84
|
-
|
|
85
58
|
break;
|
|
86
|
-
|
|
87
59
|
case 'warn':
|
|
88
60
|
_logger().default.warn(e.diagnostics);
|
|
89
|
-
|
|
90
61
|
break;
|
|
91
|
-
|
|
92
62
|
case 'error':
|
|
93
63
|
_logger().default.error(e.diagnostics);
|
|
94
|
-
|
|
95
64
|
break;
|
|
96
|
-
|
|
97
65
|
default:
|
|
98
66
|
throw new Error('Unknown log level');
|
|
99
67
|
}
|
|
100
68
|
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
var _default = _WorkerFarm().default;
|
|
104
69
|
|
|
105
|
-
|
|
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,78 +4,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _nullthrows() {
|
|
9
8
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
10
|
-
|
|
11
9
|
_nullthrows = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _childState() {
|
|
19
|
-
const data = require("../childState");
|
|
20
|
-
|
|
21
|
-
_childState = function () {
|
|
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
12
|
return data;
|
|
36
13
|
}
|
|
37
|
-
|
|
14
|
+
var _childState = require("../childState");
|
|
15
|
+
var _child = require("../child");
|
|
38
16
|
function _core() {
|
|
39
17
|
const data = require("@parcel/core");
|
|
40
|
-
|
|
41
18
|
_core = function () {
|
|
42
19
|
return data;
|
|
43
20
|
};
|
|
44
|
-
|
|
45
21
|
return data;
|
|
46
22
|
}
|
|
47
|
-
|
|
48
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
|
-
|
|
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
24
|
class ProcessChild {
|
|
53
25
|
constructor(onMessage, onExit) {
|
|
54
|
-
_defineProperty(this, "onMessage", void 0);
|
|
55
|
-
|
|
56
|
-
_defineProperty(this, "onExit", void 0);
|
|
57
|
-
|
|
58
26
|
if (!process.send) {
|
|
59
27
|
throw new Error('Only create ProcessChild instances in a worker!');
|
|
60
28
|
}
|
|
61
|
-
|
|
62
29
|
this.onMessage = onMessage;
|
|
63
30
|
this.onExit = onExit;
|
|
64
31
|
process.on('message', data => this.handleMessage(data));
|
|
65
32
|
}
|
|
66
|
-
|
|
67
33
|
handleMessage(data) {
|
|
68
34
|
if (data === 'die') {
|
|
69
35
|
return this.stop();
|
|
70
36
|
}
|
|
71
|
-
|
|
72
37
|
this.onMessage((0, _core().deserialize)(Buffer.from(data, 'base64')));
|
|
73
38
|
}
|
|
74
|
-
|
|
75
39
|
send(data) {
|
|
76
40
|
let processSend = (0, _nullthrows().default)(process.send).bind(process);
|
|
77
41
|
processSend((0, _core().serialize)(data).toString('base64'), err => {
|
|
78
42
|
if (err && err instanceof Error) {
|
|
43
|
+
// $FlowFixMe[prop-missing]
|
|
79
44
|
if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
|
|
80
45
|
// IPC connection closed
|
|
81
46
|
// no need to keep the worker running if it can't send or receive data
|
|
@@ -84,13 +49,10 @@ class ProcessChild {
|
|
|
84
49
|
}
|
|
85
50
|
});
|
|
86
51
|
}
|
|
87
|
-
|
|
88
52
|
stop() {
|
|
89
53
|
this.onExit(0);
|
|
90
54
|
process.exit();
|
|
91
55
|
}
|
|
92
|
-
|
|
93
56
|
}
|
|
94
|
-
|
|
95
57
|
exports.default = ProcessChild;
|
|
96
|
-
(0, _childState
|
|
58
|
+
(0, _childState.setChild)(new _child.Child(ProcessChild));
|
|
@@ -4,65 +4,38 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _child_process() {
|
|
9
8
|
const data = _interopRequireDefault(require("child_process"));
|
|
10
|
-
|
|
11
9
|
_child_process = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _path() {
|
|
19
15
|
const data = _interopRequireDefault(require("path"));
|
|
20
|
-
|
|
21
16
|
_path = function () {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _core() {
|
|
29
22
|
const data = require("@parcel/core");
|
|
30
|
-
|
|
31
23
|
_core = function () {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
29
|
const WORKER_PATH = _path().default.join(__dirname, 'ProcessChild.js');
|
|
43
|
-
|
|
44
30
|
class ProcessWorker {
|
|
31
|
+
processQueue = true;
|
|
32
|
+
sendQueue = [];
|
|
45
33
|
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, "child", void 0);
|
|
55
|
-
|
|
56
|
-
_defineProperty(this, "processQueue", true);
|
|
57
|
-
|
|
58
|
-
_defineProperty(this, "sendQueue", []);
|
|
59
|
-
|
|
60
34
|
this.execArgv = execArgv;
|
|
61
35
|
this.onMessage = onMessage;
|
|
62
36
|
this.onError = onError;
|
|
63
37
|
this.onExit = onExit;
|
|
64
38
|
}
|
|
65
|
-
|
|
66
39
|
start() {
|
|
67
40
|
this.child = _child_process().default.fork(WORKER_PATH, process.argv, {
|
|
68
41
|
execArgv: this.execArgv,
|
|
@@ -76,7 +49,6 @@ class ProcessWorker {
|
|
|
76
49
|
this.child.on('error', this.onError);
|
|
77
50
|
return Promise.resolve();
|
|
78
51
|
}
|
|
79
|
-
|
|
80
52
|
async stop() {
|
|
81
53
|
this.child.send('die');
|
|
82
54
|
let forceKill = setTimeout(() => this.child.kill('SIGINT'), 500);
|
|
@@ -85,34 +57,27 @@ class ProcessWorker {
|
|
|
85
57
|
});
|
|
86
58
|
clearTimeout(forceKill);
|
|
87
59
|
}
|
|
88
|
-
|
|
89
60
|
send(data) {
|
|
90
61
|
if (!this.processQueue) {
|
|
91
62
|
this.sendQueue.push(data);
|
|
92
63
|
return;
|
|
93
64
|
}
|
|
94
|
-
|
|
95
65
|
let result = this.child.send((0, _core().serialize)(data).toString('base64'), error => {
|
|
96
66
|
if (error && error instanceof Error) {
|
|
97
67
|
// Ignore this, the workerfarm handles child errors
|
|
98
68
|
return;
|
|
99
69
|
}
|
|
100
|
-
|
|
101
70
|
this.processQueue = true;
|
|
102
|
-
|
|
103
71
|
if (this.sendQueue.length > 0) {
|
|
104
72
|
let queueCopy = this.sendQueue.slice(0);
|
|
105
73
|
this.sendQueue = [];
|
|
106
74
|
queueCopy.forEach(entry => this.send(entry));
|
|
107
75
|
}
|
|
108
76
|
});
|
|
109
|
-
|
|
110
77
|
if (!result || /^win/.test(process.platform)) {
|
|
111
78
|
// Queue is handling too much messages throttle it
|
|
112
79
|
this.processQueue = false;
|
|
113
80
|
}
|
|
114
81
|
}
|
|
115
|
-
|
|
116
82
|
}
|
|
117
|
-
|
|
118
83
|
exports.default = ProcessWorker;
|
|
@@ -4,88 +4,46 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _worker_threads() {
|
|
9
8
|
const data = require("worker_threads");
|
|
10
|
-
|
|
11
9
|
_worker_threads = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _nullthrows() {
|
|
19
15
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
20
|
-
|
|
21
16
|
_nullthrows = function () {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _childState() {
|
|
29
|
-
const data = require("../childState");
|
|
30
|
-
|
|
31
|
-
_childState = function () {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
19
|
return data;
|
|
36
20
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const data = require("../child");
|
|
40
|
-
|
|
41
|
-
_child = function () {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
|
|
21
|
+
var _childState = require("../childState");
|
|
22
|
+
var _child = require("../child");
|
|
48
23
|
function _core() {
|
|
49
24
|
const data = require("@parcel/core");
|
|
50
|
-
|
|
51
25
|
_core = function () {
|
|
52
26
|
return data;
|
|
53
27
|
};
|
|
54
|
-
|
|
55
28
|
return data;
|
|
56
29
|
}
|
|
57
|
-
|
|
58
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
59
|
-
|
|
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
31
|
class ThreadsChild {
|
|
63
32
|
constructor(onMessage, onExit) {
|
|
64
|
-
_defineProperty(this, "onMessage", void 0);
|
|
65
|
-
|
|
66
|
-
_defineProperty(this, "onExit", void 0);
|
|
67
|
-
|
|
68
33
|
if (_worker_threads().isMainThread || !_worker_threads().parentPort) {
|
|
69
34
|
throw new Error('Only create ThreadsChild instances in a worker!');
|
|
70
35
|
}
|
|
71
|
-
|
|
72
36
|
this.onMessage = onMessage;
|
|
73
37
|
this.onExit = onExit;
|
|
74
|
-
|
|
75
38
|
_worker_threads().parentPort.on('message', data => this.handleMessage(data));
|
|
76
|
-
|
|
77
39
|
_worker_threads().parentPort.on('close', this.onExit);
|
|
78
40
|
}
|
|
79
|
-
|
|
80
41
|
handleMessage(data) {
|
|
81
42
|
this.onMessage((0, _core().restoreDeserializedObject)(data));
|
|
82
43
|
}
|
|
83
|
-
|
|
84
44
|
send(data) {
|
|
85
45
|
(0, _nullthrows().default)(_worker_threads().parentPort).postMessage((0, _core().prepareForSerialization)(data));
|
|
86
46
|
}
|
|
87
|
-
|
|
88
47
|
}
|
|
89
|
-
|
|
90
48
|
exports.default = ThreadsChild;
|
|
91
|
-
(0, _childState
|
|
49
|
+
(0, _childState.setChild)(new _child.Child(ThreadsChild));
|
|
@@ -4,61 +4,36 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _worker_threads() {
|
|
9
8
|
const data = require("worker_threads");
|
|
10
|
-
|
|
11
9
|
_worker_threads = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _path() {
|
|
19
15
|
const data = _interopRequireDefault(require("path"));
|
|
20
|
-
|
|
21
16
|
_path = function () {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _core() {
|
|
29
22
|
const data = require("@parcel/core");
|
|
30
|
-
|
|
31
23
|
_core = function () {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
29
|
const WORKER_PATH = _path().default.join(__dirname, 'ThreadsChild.js');
|
|
43
|
-
|
|
44
30
|
class ThreadsWorker {
|
|
45
31
|
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
32
|
this.execArgv = execArgv;
|
|
57
33
|
this.onMessage = onMessage;
|
|
58
34
|
this.onError = onError;
|
|
59
35
|
this.onExit = onExit;
|
|
60
36
|
}
|
|
61
|
-
|
|
62
37
|
start() {
|
|
63
38
|
this.worker = new (_worker_threads().Worker)(WORKER_PATH, {
|
|
64
39
|
execArgv: this.execArgv,
|
|
@@ -71,21 +46,16 @@ class ThreadsWorker {
|
|
|
71
46
|
this.worker.on('online', resolve);
|
|
72
47
|
});
|
|
73
48
|
}
|
|
74
|
-
|
|
75
49
|
stop() {
|
|
76
50
|
// In node 12, this returns a promise, but previously it accepted a callback
|
|
77
51
|
// TODO: Pass a callback in earlier versions of Node
|
|
78
52
|
return Promise.resolve(this.worker.terminate());
|
|
79
53
|
}
|
|
80
|
-
|
|
81
54
|
handleMessage(data) {
|
|
82
55
|
this.onMessage((0, _core().restoreDeserializedObject)(data));
|
|
83
56
|
}
|
|
84
|
-
|
|
85
57
|
send(data) {
|
|
86
58
|
this.worker.postMessage((0, _core().prepareForSerialization)(data));
|
|
87
59
|
}
|
|
88
|
-
|
|
89
60
|
}
|
|
90
|
-
|
|
91
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/workers",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-dev.1514+023281607",
|
|
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/
|
|
26
|
-
"
|
|
24
|
+
"@parcel/diagnostic": "2.0.0-dev.1514+023281607",
|
|
25
|
+
"@parcel/logger": "2.0.0-dev.1514+023281607",
|
|
26
|
+
"@parcel/profiler": "2.12.1-dev.3137+023281607",
|
|
27
|
+
"@parcel/types": "2.0.0-dev.1514+023281607",
|
|
28
|
+
"@parcel/utils": "2.0.0-dev.1514+023281607",
|
|
27
29
|
"nullthrows": "^1.1.1"
|
|
28
30
|
},
|
|
29
31
|
"peerDependencies": {
|
|
30
|
-
"@parcel/core": "^2.0.0-
|
|
32
|
+
"@parcel/core": "^2.0.0-dev.1512+023281607"
|
|
31
33
|
},
|
|
32
|
-
"
|
|
34
|
+
"browser": {
|
|
35
|
+
"./src/process/ProcessWorker.js": false,
|
|
36
|
+
"./src/threads/ThreadsWorker.js": false,
|
|
37
|
+
"./src/core-worker.js": "./src/core-worker.browser.js"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "023281607649691b36120ce9b885985a1f059803"
|
|
33
40
|
}
|