@atlaspack/workers 2.14.21-typescript-1fd1095e8.0 → 2.14.21-typescript-b27501580.0

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.
@@ -1,69 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.WORKER_PATH = void 0;
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 _buildCache() {
22
- const data = require("@atlaspack/build-cache");
23
- _buildCache = function () {
24
- return data;
25
- };
26
- return data;
27
- }
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
- let WORKER_PATH = exports.WORKER_PATH = _path().default.join(__dirname, 'ThreadsChild.js');
30
- if (process.env.ATLASPACK_REGISTER_USE_SRC === 'true') {
31
- exports.WORKER_PATH = WORKER_PATH = _path().default.join(__dirname, 'ThreadsChild.ts');
32
- }
33
-
34
- // @ts-expect-error TS2420
35
- class ThreadsWorker {
36
- // @ts-expect-error TS2564
37
-
38
- constructor(execArgv, onMessage, onError, onExit) {
39
- this.execArgv = execArgv;
40
- this.onMessage = onMessage;
41
- this.onError = onError;
42
- this.onExit = onExit;
43
- }
44
- start() {
45
- this.worker = new (_worker_threads().Worker)(WORKER_PATH, {
46
- execArgv: this.execArgv,
47
- env: process.env
48
- });
49
- this.worker.on('message', data => this.handleMessage(data));
50
- this.worker.on('error', this.onError);
51
- this.worker.on('exit', this.onExit);
52
- return new Promise(resolve => {
53
- this.worker.on('online', resolve);
54
- });
55
- }
56
- stop() {
57
- // In node 12, this returns a promise, but previously it accepted a callback
58
- // TODO: Pass a callback in earlier versions of Node
59
- // @ts-expect-error TS2322
60
- return Promise.resolve(this.worker.terminate());
61
- }
62
- handleMessage(data) {
63
- this.onMessage((0, _buildCache().restoreDeserializedObject)(data));
64
- }
65
- send(data) {
66
- this.worker.postMessage((0, _buildCache().prepareForSerialization)(data));
67
- }
68
- }
69
- exports.default = ThreadsWorker;
package/lib/types.js DELETED
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,49 +0,0 @@
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
-
18
- // Type declarations for Web Worker environment
19
-
20
- // @ts-expect-error TS2420
21
- class WebChild {
22
- constructor(onMessage, onExit) {
23
- if (!(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)) {
24
- throw new Error('Only create WebChild instances in a worker!');
25
- }
26
- this.onMessage = onMessage;
27
- this.onExit = onExit;
28
- self.addEventListener('message', ({
29
- data
30
- }) => {
31
- if (data === 'stop') {
32
- this.onExit(0);
33
- self.postMessage('stopped');
34
- }
35
- this.handleMessage(data);
36
- });
37
- self.postMessage('online');
38
- }
39
- handleMessage(data) {
40
- this.onMessage((0, _buildCache().restoreDeserializedObject)(data));
41
- }
42
- send(data) {
43
- self.postMessage((0, _buildCache().prepareForSerialization)(data));
44
- }
45
- }
46
-
47
- // @ts-expect-error TS2345
48
- exports.default = WebChild;
49
- (0, _childState.setChild)(new _child.Child(WebChild));
@@ -1,101 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.WORKER_PATH = 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
-
23
- // @ts-expect-error This is actually a module
24
- let WORKER_PATH = exports.WORKER_PATH = new URL('./WebChild.js', import.meta.url);
25
- if (process.env.ATLASPACK_REGISTER_USE_SRC === 'true') {
26
- // @ts-expect-error This is actually a module
27
- exports.WORKER_PATH = WORKER_PATH = new URL('./WebChild.ts', import.meta.url);
28
- }
29
-
30
- // @ts-expect-error TS2420
31
- class WebWorker {
32
- // @ts-expect-error TS2564
33
-
34
- constructor(execArgv, onMessage, onError, onExit) {
35
- this.execArgv = execArgv;
36
- this.onMessage = onMessage;
37
- this.onError = onError;
38
- this.onExit = onExit;
39
- }
40
- start() {
41
- // @ts-expect-error TS1470
42
- this.worker = new Worker(new URL('./WebChild.js', import.meta.url), {
43
- name: `Parcel Worker ${id++}`,
44
- type: 'module'
45
- });
46
- let {
47
- deferred,
48
- promise
49
- } = (0, _utils().makeDeferredWithPromise)();
50
-
51
- // @ts-expect-error TS7031
52
- this.worker.onmessage = ({
53
- data
54
- }) => {
55
- if (data === 'online') {
56
- // @ts-expect-error TS2554
57
- deferred.resolve();
58
- return;
59
- }
60
- this.handleMessage(data);
61
- };
62
- this.worker.onerror = this.onError;
63
- // Web workers can't crash or intentionally stop on their own, apart from stop() below
64
- // this.worker.on('exit', this.onExit);
65
-
66
- // @ts-expect-error TS2322
67
- return promise;
68
- }
69
- stop() {
70
- if (!this.stopping) {
71
- // @ts-expect-error TS2322
72
- this.stopping = (async () => {
73
- this.worker.postMessage('stop');
74
- let {
75
- deferred,
76
- promise
77
- } = (0, _utils().makeDeferredWithPromise)();
78
- this.worker.addEventListener('message', ({
79
- data
80
- }) => {
81
- if (data === 'stopped') {
82
- // @ts-expect-error TS2554
83
- deferred.resolve();
84
- }
85
- });
86
- await promise;
87
- this.worker.terminate();
88
- this.onExit(0);
89
- })();
90
- }
91
- // @ts-expect-error TS2322
92
- return this.stopping;
93
- }
94
- handleMessage(data) {
95
- this.onMessage((0, _buildCache().restoreDeserializedObject)(data));
96
- }
97
- send(data) {
98
- this.worker.postMessage((0, _buildCache().prepareForSerialization)(data));
99
- }
100
- }
101
- exports.default = WebWorker;