@atlaspack/workers 2.14.0 → 2.14.1-canary.3710
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/LICENSE +201 -0
- package/lib/Handle.js +45 -0
- package/lib/Worker.js +188 -0
- package/lib/WorkerFarm.js +553 -0
- package/lib/backend.js +34 -0
- package/lib/bus.js +31 -0
- package/lib/child.js +284 -0
- package/lib/childState.js +14 -0
- package/lib/cpuCount.js +79 -0
- package/lib/index.js +75 -0
- package/lib/process/ProcessChild.js +58 -0
- package/lib/process/ProcessWorker.js +83 -0
- package/lib/threads/ThreadsChild.js +49 -0
- package/lib/threads/ThreadsWorker.js +61 -0
- package/lib/types.js +1 -0
- package/lib/web/WebChild.js +44 -0
- package/lib/web/WebWorker.js +85 -0
- package/package.json +9 -8
package/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function _buildCache() {
|
|
8
|
+
const data = require("@atlaspack/build-cache");
|
|
9
|
+
_buildCache = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
var _child = require("../child");
|
|
15
|
+
var _childState = require("../childState");
|
|
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, _buildCache().restoreDeserializedObject)(data));
|
|
38
|
+
}
|
|
39
|
+
send(data) {
|
|
40
|
+
self.postMessage((0, _buildCache().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 _buildCache() {
|
|
8
|
+
const data = require("@atlaspack/build-cache");
|
|
9
|
+
_buildCache = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _utils() {
|
|
15
|
+
const data = require("@atlaspack/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, _buildCache().restoreDeserializedObject)(data));
|
|
80
|
+
}
|
|
81
|
+
send(data) {
|
|
82
|
+
this.worker.postMessage((0, _buildCache().prepareForSerialization)(data));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.default = WebWorker;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/workers",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.1-canary.3710+d874396ab",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"publishConfig": {
|
|
@@ -24,17 +24,18 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@atlaspack/build-cache": "2.13.
|
|
28
|
-
"@atlaspack/diagnostic": "2.14.
|
|
29
|
-
"@atlaspack/logger": "2.14.
|
|
30
|
-
"@atlaspack/profiler": "2.14.
|
|
31
|
-
"@atlaspack/types-internal": "2.14.
|
|
32
|
-
"@atlaspack/utils": "2.14.
|
|
27
|
+
"@atlaspack/build-cache": "2.13.3-canary.3710+d874396ab",
|
|
28
|
+
"@atlaspack/diagnostic": "2.14.1-canary.3710+d874396ab",
|
|
29
|
+
"@atlaspack/logger": "2.14.1-canary.3710+d874396ab",
|
|
30
|
+
"@atlaspack/profiler": "2.14.1-canary.3710+d874396ab",
|
|
31
|
+
"@atlaspack/types-internal": "2.14.1-canary.3710+d874396ab",
|
|
32
|
+
"@atlaspack/utils": "2.14.1-canary.3710+d874396ab",
|
|
33
33
|
"nullthrows": "^1.1.1"
|
|
34
34
|
},
|
|
35
35
|
"browser": {
|
|
36
36
|
"./src/process/ProcessWorker.js": false,
|
|
37
37
|
"./src/threads/ThreadsWorker.js": false
|
|
38
38
|
},
|
|
39
|
-
"type": "commonjs"
|
|
39
|
+
"type": "commonjs",
|
|
40
|
+
"gitHead": "d874396ab648d0d5505d66c7eb73e1748f1eaf68"
|
|
40
41
|
}
|