@anonaddy/omni-worker 0.0.1 → 0.2.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.
- package/README.md +92 -28
- package/dist/cjs/{builder/helpers.js → helpers/builder.js} +2 -2
- package/dist/cjs/{builder/helpers.js.map → helpers/builder.js.map} +1 -1
- package/dist/cjs/helpers/pool.js +9 -0
- package/dist/cjs/helpers/pool.js.map +1 -0
- package/dist/cjs/node/builder/constants.js +19 -0
- package/dist/cjs/node/builder/constants.js.map +1 -0
- package/dist/cjs/node/builder/helpers.js +144 -0
- package/dist/cjs/node/builder/helpers.js.map +1 -0
- package/dist/cjs/node/builder/index.js +26 -0
- package/dist/cjs/node/builder/index.js.map +1 -0
- package/dist/cjs/node/index.js +125 -0
- package/dist/cjs/node/index.js.map +1 -0
- package/dist/cjs/node/pool.js +144 -0
- package/dist/cjs/node/pool.js.map +1 -0
- package/dist/cjs/node.js +6 -0
- package/dist/cjs/node.js.map +1 -0
- package/dist/cjs/types/helpers.js +11 -0
- package/dist/cjs/types/helpers.js.map +1 -0
- package/dist/cjs/types/node-omni-worker.js +3 -0
- package/dist/cjs/types/node-omni-worker.js.map +1 -0
- package/dist/cjs/types/web-omni-worker.js +3 -0
- package/dist/cjs/types/web-omni-worker.js.map +1 -0
- package/dist/cjs/web/builder/helpers.js +9 -0
- package/dist/cjs/web/builder/helpers.js.map +1 -0
- package/dist/cjs/web/builder/index.js +47 -0
- package/dist/cjs/web/builder/index.js.map +1 -0
- package/dist/cjs/{types/omni-worker.js → web/builder/model.js} +1 -1
- package/dist/cjs/web/builder/model.js.map +1 -0
- package/dist/cjs/web/index.js +156 -0
- package/dist/cjs/web/index.js.map +1 -0
- package/dist/cjs/web/pool.js +143 -0
- package/dist/cjs/web/pool.js.map +1 -0
- package/dist/cjs/web/provider/helpers.js +9 -0
- package/dist/cjs/web/provider/helpers.js.map +1 -0
- package/dist/cjs/web/provider/index.js +69 -0
- package/dist/cjs/web/provider/index.js.map +1 -0
- package/dist/cjs/web/provider/model.js +3 -0
- package/dist/cjs/web/provider/model.js.map +1 -0
- package/dist/cjs/web.js +8 -0
- package/dist/cjs/web.js.map +1 -0
- package/dist/mjs/{builder/helpers.js → helpers/builder.js} +2 -2
- package/dist/mjs/{builder/helpers.js.map → helpers/builder.js.map} +1 -1
- package/dist/mjs/helpers/pool.js +6 -0
- package/dist/mjs/helpers/pool.js.map +1 -0
- package/dist/mjs/node/builder/constants.js +13 -0
- package/dist/mjs/node/builder/constants.js.map +1 -0
- package/dist/mjs/node/builder/helpers.js +138 -0
- package/dist/mjs/node/builder/helpers.js.map +1 -0
- package/dist/mjs/node/builder/index.js +18 -0
- package/dist/mjs/node/builder/index.js.map +1 -0
- package/dist/mjs/node/index.js +119 -0
- package/dist/mjs/node/index.js.map +1 -0
- package/dist/mjs/node/pool.js +141 -0
- package/dist/mjs/node/pool.js.map +1 -0
- package/dist/mjs/node.js +2 -0
- package/dist/mjs/node.js.map +1 -0
- package/dist/mjs/types/helpers.js +8 -0
- package/dist/mjs/types/helpers.js.map +1 -0
- package/dist/mjs/types/node-omni-worker.js +2 -0
- package/dist/mjs/types/node-omni-worker.js.map +1 -0
- package/dist/mjs/types/web-omni-worker.js +2 -0
- package/dist/mjs/types/web-omni-worker.js.map +1 -0
- package/dist/mjs/web/builder/helpers.js +6 -0
- package/dist/mjs/web/builder/helpers.js.map +1 -0
- package/dist/mjs/web/builder/index.js +10 -0
- package/dist/mjs/web/builder/index.js.map +1 -0
- package/dist/mjs/web/builder/model.js +2 -0
- package/dist/mjs/web/builder/model.js.map +1 -0
- package/dist/mjs/web/index.js +120 -0
- package/dist/mjs/web/index.js.map +1 -0
- package/dist/mjs/web/pool.js +140 -0
- package/dist/mjs/web/pool.js.map +1 -0
- package/dist/mjs/web/provider/helpers.js +6 -0
- package/dist/mjs/web/provider/helpers.js.map +1 -0
- package/dist/mjs/web/provider/index.js +32 -0
- package/dist/mjs/web/provider/index.js.map +1 -0
- package/dist/mjs/web/provider/model.js +2 -0
- package/dist/mjs/web/provider/model.js.map +1 -0
- package/dist/mjs/web.js +3 -0
- package/dist/mjs/web.js.map +1 -0
- package/dist/types/{builder/helpers.d.ts → helpers/builder.d.ts} +1 -1
- package/dist/types/helpers/builder.d.ts.map +1 -0
- package/dist/types/helpers/pool.d.ts +2 -0
- package/dist/types/helpers/pool.d.ts.map +1 -0
- package/dist/types/node/builder/constants.d.ts +5 -0
- package/dist/types/node/builder/constants.d.ts.map +1 -0
- package/dist/types/node/builder/helpers.d.ts +2 -0
- package/dist/types/node/builder/helpers.d.ts.map +1 -0
- package/dist/types/node/builder/index.d.ts +8 -0
- package/dist/types/node/builder/index.d.ts.map +1 -0
- package/dist/types/node/index.d.ts +32 -0
- package/dist/types/node/index.d.ts.map +1 -0
- package/dist/types/node/pool.d.ts +31 -0
- package/dist/types/node/pool.d.ts.map +1 -0
- package/dist/types/node.d.ts +3 -0
- package/dist/types/node.d.ts.map +1 -0
- package/dist/types/types/helpers.d.ts +6 -0
- package/dist/types/types/helpers.d.ts.map +1 -0
- package/dist/types/types/node-omni-worker.d.ts +90 -0
- package/dist/types/types/node-omni-worker.d.ts.map +1 -0
- package/dist/types/types/web-omni-worker.d.ts +103 -0
- package/dist/types/types/web-omni-worker.d.ts.map +1 -0
- package/dist/types/web/builder/helpers.d.ts +3 -0
- package/dist/types/web/builder/helpers.d.ts.map +1 -0
- package/dist/types/web/builder/index.d.ts +8 -0
- package/dist/types/web/builder/index.d.ts.map +1 -0
- package/dist/types/web/builder/model.d.ts +11 -0
- package/dist/types/web/builder/model.d.ts.map +1 -0
- package/dist/types/web/index.d.ts +35 -0
- package/dist/types/web/index.d.ts.map +1 -0
- package/dist/types/web/pool.d.ts +31 -0
- package/dist/types/web/pool.d.ts.map +1 -0
- package/dist/types/web/provider/helpers.d.ts +2 -0
- package/dist/types/web/provider/helpers.d.ts.map +1 -0
- package/dist/types/web/provider/index.d.ts +16 -0
- package/dist/types/web/provider/index.d.ts.map +1 -0
- package/dist/types/web/provider/model.d.ts +7 -0
- package/dist/types/web/provider/model.d.ts.map +1 -0
- package/dist/types/web.d.ts +4 -0
- package/dist/types/web.d.ts.map +1 -0
- package/package.json +37 -16
- package/dist/cjs/builder/node.js +0 -80
- package/dist/cjs/builder/node.js.map +0 -1
- package/dist/cjs/builder/plugins/external-imports.js +0 -44
- package/dist/cjs/builder/plugins/external-imports.js.map +0 -1
- package/dist/cjs/builder/plugins/native-module.js +0 -18
- package/dist/cjs/builder/plugins/native-module.js.map +0 -1
- package/dist/cjs/index.js +0 -84
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/types/omni-worker.js.map +0 -1
- package/dist/mjs/builder/node.js +0 -40
- package/dist/mjs/builder/node.js.map +0 -1
- package/dist/mjs/builder/plugins/external-imports.js +0 -39
- package/dist/mjs/builder/plugins/external-imports.js.map +0 -1
- package/dist/mjs/builder/plugins/native-module.js +0 -15
- package/dist/mjs/builder/plugins/native-module.js.map +0 -1
- package/dist/mjs/index.js +0 -44
- package/dist/mjs/index.js.map +0 -1
- package/dist/mjs/types/omni-worker.js +0 -2
- package/dist/mjs/types/omni-worker.js.map +0 -1
- package/dist/types/builder/helpers.d.ts.map +0 -1
- package/dist/types/builder/node.d.ts +0 -3
- package/dist/types/builder/node.d.ts.map +0 -1
- package/dist/types/builder/plugins/external-imports.d.ts +0 -4
- package/dist/types/builder/plugins/external-imports.d.ts.map +0 -1
- package/dist/types/builder/plugins/native-module.d.ts +0 -3
- package/dist/types/builder/plugins/native-module.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -26
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/types/omni-worker.d.ts +0 -21
- package/dist/types/types/omni-worker.d.ts.map +0 -1
package/README.md
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
# 👷 Omni Worker - A Versatile Worker for Typescript
|
2
|
-
Webworkers (browser) and thread workers (NodeJS) are usually
|
2
|
+
Webworkers (browser) and thread workers (NodeJS) are usually hard to implement, since the code that runs on a worker needs to be serializable and have complex interfaces to transfer the data into the workers. 3rd party modules are usually hard to get working or don't work at all giving you a serious headache when implementing them...
|
3
3
|
|
4
|
-
Enter the stage, OmniWorkers! These workers allow you to simply declare
|
4
|
+
Enter the stage, OmniWorkers! These workers allow you to simply declare an interface with functions (currently with the exception of callbacks) that will actually run inside a worker. Whether it be on the web (webworker) or on NodeJS (thread worker), these workers will run your code inside a worker, period.
|
5
5
|
|
6
6
|
## How does it Work?
|
7
|
-
In the case of
|
7
|
+
In the case of using typescript for front-end projects, a UI will simply block at certain tasks if they're too heavy. You could use yielding functions, but that will slow your code down as a result. Similarly, in case of NodeJS, load times can significantly increase since the JavaScript V8 engine only runs one event loop thread. Even when using asynchronous code, the event loop is still just running on one thread.
|
8
8
|
|
9
9
|
### Workers
|
10
|
-
The [Webworker API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) for the web and [Worker Threads](https://nodejs.org/api/worker_threads.html) for NodeJS allow us to declare code inside a seperate file, which will run in its own context. The advantage
|
10
|
+
The [Webworker API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) for the web and [Worker Threads](https://nodejs.org/api/worker_threads.html) for NodeJS allow us to declare code inside a seperate file, which will run in its own context (event loop). The advantage of this is that we now have more than one event loop thread to work with.
|
11
|
+
|
12
|
+
The drawback here, is that all code executed inside these (contexed) workers needs to be serializable, since your code is basically shipped into the worker for execution. This is done through the Worker communication interface. Should your code depend on other 3rd party libraries, your code would have most-likely not executed, since the code inside the worker context is closed off from the main thread context.
|
11
13
|
|
12
14
|
### 👷 OmniWorkers
|
13
|
-
So
|
15
|
+
So what makes OmniWorkers to special? First off, their simplicity. Simply declare your code and expose it to the main event loop. Then build the OmniWorker by simply referencing you file. Now, the OmniWorker will expose the object with functions or a class you've injected into the worker container. You can use your own functions with primitive types, functions directly taken from 3rd party modules or a hybrid mix of both. Let's first look at an example for NodeJS:
|
14
16
|
|
15
17
|
#### `👷♀️ workers/worker.ts`
|
16
18
|
```javascript
|
17
19
|
import { NodeOmniWorker } from "@anonaddy/omni-worker";
|
20
|
+
|
21
|
+
// Interface declared by you
|
18
22
|
import { IMyOmniWorkerFunctions } from "./worker-model";
|
23
|
+
|
24
|
+
// 3rd party module dependency
|
19
25
|
import { capitalize } from "lodash";
|
20
26
|
|
21
27
|
// Declare your functions using an interface
|
@@ -27,9 +33,9 @@ const fnObj: IMyOmniWorkerFunctions = {
|
|
27
33
|
// In this case, diamond interface can even be omitted, since inferred
|
28
34
|
NodeOmniWorker.expose<IMyOmniWorkerFunctions>(fnObj);
|
29
35
|
```
|
30
|
-
The worker.ts file contains the logic you would like to run inside the container. In our example above we created our own function, but we
|
36
|
+
The worker.ts file contains the logic you would like to run inside the container. In our example above we created our own function inside a object containing functions, but notice how we included a 3rd party module (lodash). This demonstrates that an OmniWorker can just as well use any other 3rd party module as well as logic defined by you.
|
31
37
|
|
32
|
-
What's important, is to expose your logic using the expose function. This will make sure that the container exposes (or shares) your code logic with the main event loop
|
38
|
+
What's important, is to expose your logic using the expose function. This will make sure that the container exposes (or shares) your code logic with the main event loop, for you to access it in the rest of your code:
|
33
39
|
|
34
40
|
#### `🏭 index.ts`
|
35
41
|
```javascript
|
@@ -37,15 +43,16 @@ import { NodeOmniWorker } from "@anonaddy/omni-worker";
|
|
37
43
|
import { IMyOmniWorkerFunctions } from "./worker-model";
|
38
44
|
|
39
45
|
// Use the static path from your project's root
|
40
|
-
const WORKER_DIR = "src/workers";
|
41
|
-
|
42
|
-
// Build the worker from the file you specified and the
|
43
|
-
// functions that were exposed
|
44
|
-
const worker = await NodeOmniWorker
|
45
|
-
.build<IMyOmniWorkerFunctions>(`${WORKER_DIR}/worker`);
|
46
|
+
const WORKER_DIR = "./src/workers";
|
46
47
|
|
47
48
|
// Placing anonymous async function on the event loop
|
48
|
-
|
49
|
+
(async () => {
|
50
|
+
|
51
|
+
// Build the worker from the file you specified and the
|
52
|
+
// functions that were exposed
|
53
|
+
const worker = await NodeOmniWorker
|
54
|
+
.build<IMyOmniWorkerFunctions>(`${WORKER_DIR}/worker.ts`);
|
55
|
+
|
49
56
|
const sum = await worker.use().add(1, 2);
|
50
57
|
const str = await worker.use().capitalize("hello");
|
51
58
|
|
@@ -54,34 +61,91 @@ setTimeout(async () => {
|
|
54
61
|
The result of my sum is: ${sum}!
|
55
62
|
Aren't Omniworkers just awesome?!
|
56
63
|
`);
|
57
|
-
|
64
|
+
|
65
|
+
// Release resources once you're done!
|
66
|
+
await worker.destroy();
|
67
|
+
})();
|
58
68
|
```
|
59
|
-
Your code can now just asynchronously call the logic you have declared and exposed inside your worker. Simply call the `worker.use()` function and you'll have access to all the functions defined by you inside your `IMyOwnWorkerFunctions` interface.
|
69
|
+
Your code can now just **asynchronously** call the logic you have declared and exposed inside your worker.ts. Simply call the `worker.use()` function and you'll have access to all the functions defined by you inside your `IMyOwnWorkerFunctions` interface.
|
60
70
|
|
61
|
-
|
62
|
-
|
71
|
+
> `⚠️ Even if your functions are not returning a Promise in your declaration file, now they will!`
|
72
|
+
|
73
|
+
### Worker Pools
|
74
|
+
Sometimes, having one worker just isn't enough. Worker pools are capable of instantiating multiple workers and consuming their compute power in a round-robin fashion. Let's look at an example:
|
63
75
|
|
64
|
-
|
65
|
-
|
76
|
+
#### `🏊♂️ pool.ts`
|
77
|
+
```javascript
|
78
|
+
import { NodeOmniWorkerPool } from '@anonaddy/omni-worker';
|
79
|
+
import { IMyOmniWorkerFunctions } from "./worker-model";
|
80
|
+
|
81
|
+
(async () => {
|
82
|
+
|
83
|
+
const pool = await NodeOmniWorkerPool
|
84
|
+
.buildAndLaunch<IMyOmniWorkerFunctions>(
|
85
|
+
'./src/worker/workers/normal.worker.ts',
|
86
|
+
{ numOfWorkers: 4 }
|
87
|
+
);
|
88
|
+
|
89
|
+
const sentence = "i very much like your new tie brother joe";
|
90
|
+
const fns: (() => Promise<string>)[] = [];
|
91
|
+
|
92
|
+
// capitalize each word (promisified)
|
93
|
+
for (const word of sentence.split(' ')) {
|
94
|
+
const fn = async () => {
|
95
|
+
return await pool.use().capitalize(word);
|
96
|
+
}
|
97
|
+
fns.push(fn);
|
98
|
+
}
|
99
|
+
|
100
|
+
// await all promises and join up the words
|
101
|
+
const result = await Promise.all(fns.map(fn => fn()));
|
102
|
+
console.log(result.join(' '));
|
103
|
+
|
104
|
+
// Release resources once you're done!
|
105
|
+
await pool.destroy();
|
106
|
+
|
107
|
+
})();
|
108
|
+
|
109
|
+
```
|
110
|
+
The code example above will create a worker pool of 4 workers with the code you specified. All work will be distributed round-robin across the OmniWorkers. We recommend using as many workers inside the pool as you have threads on the processor running the code. This will make sure that performance is optimal. Too many workers can AND WILL degrade performance in JavaScript.
|
111
|
+
|
112
|
+
### 🕸️ WebOmniWorkers
|
113
|
+
When you're building a module for the web, you can't use Node's module resolution. Instead, you will use a bundler (e.g. Webpack, Rollup) to bundle your code, usually in a format like ESM. This use case is covered by WebOmniWorkers.
|
114
|
+
|
115
|
+
The only difference when instantiating a WebOmniWorker is that instead of a project file path, a URL object needs to be parsed into the build function. Also, when using any 3rd party modules, these need to be statically linked inside your `worker.ts` file and can't be linked using Node's module resolution.
|
116
|
+
|
117
|
+
Please see the [demos](https://github.com/avluent/omni-worker-demos) project to see how a WebOmniWorker(pool) can be instantiated on a JavaScript module project.
|
118
|
+
|
119
|
+
### Under the Hood
|
120
|
+
This modules leverages [Webpack](https://www.npmjs.com/package/webpack) to parse your container code and build it. From there, it's wired up to the main event loop using a great module called [Comlink](https://github.com/GoogleChromeLabs/comlink). This module abstracts away the communication between the main event loop and Workers.
|
66
121
|
|
67
122
|
# Potential Issues
|
68
|
-
There's cases where building the worker could lead to errors. Especially when working with
|
123
|
+
There's cases where building the worker(pool)s could lead to errors. Especially when working with modules that use bindings to other languages such as C or C++. These are usually compiled to native code such as `*.node` binary files using node-gyp. A common error is:
|
69
124
|
```
|
70
|
-
❌ Module did not self-register: /path/to/
|
125
|
+
❌ Module did not self-register: /path/to/native/binary.node
|
71
126
|
```
|
72
|
-
|
127
|
+
If you're trying to run multiple OmniWorkers (for example inside an OmniWorkerPool) and multiple OmniWorkers depend on the same library (with native .node binary), then this could lead to serious issues. The reason for this, is that multiple contexts are trying to access the same .node file at the same time, which leads to NodeJS not being able to access the file (DLOPEN fails).
|
128
|
+
|
129
|
+
If you're absolutely sure that you're only running one OmniWorker and that your OmniWorker depends on native code, but the build still fails, theses are some steps you could try, before trying to start the OmniWorker again:
|
73
130
|
``` bash
|
74
|
-
#
|
131
|
+
# rebuild the .node native code
|
75
132
|
npm rebuild <your lib>
|
76
133
|
|
77
|
-
# if that didn't work
|
134
|
+
# if that didn't work try deleting package info
|
78
135
|
rm -rf node_modules
|
79
136
|
mv package-lock.json package-lock.json.backup # make sure to make a backup!
|
80
137
|
npm i
|
81
138
|
```
|
82
|
-
Should you
|
139
|
+
Should you not be able to solve your issue, please drop me an email so we can have a look at your case. We're constantly attempt at improving compatitiblity for these types of use cases. Should you have an idea of you own, also feel free to provide a pull request.
|
83
140
|
|
84
141
|
# Project Status
|
85
|
-
|
142
|
+
We're happy to announce that `WebOmniWorker`s along with their pools are now available. In case you have any questions, make sure to drop me an [email](mailto:7ebr7fa0@anonaddy.com) and I will get back to you asap.
|
143
|
+
|
144
|
+
## Change Log
|
145
|
+
|Version|Description|
|
146
|
+
|:-:|-|
|
147
|
+
|**v0.2.0**|Introduced the WebOmniWorker and the WebOmniWorker pool. Split the project for Node and Web|
|
148
|
+
|**v0.1.0**|Switched from ESBuild to Webpack for NodeJS and introduced the NodeOmniWorkerPool|
|
149
|
+
|**v0.0.1**|Basic of single NodeOmniWorker with code having native dependencies still crashing|
|
86
150
|
|
87
|
-
🏗️
|
151
|
+
### 🏗️ Happy (Omni)Working!! 🏗️
|
@@ -15,8 +15,8 @@ function getCallerDir() {
|
|
15
15
|
return dirName;
|
16
16
|
}
|
17
17
|
catch (e) {
|
18
|
-
console.error('building caller path failed', e);
|
18
|
+
// console.error('building caller path failed', e);
|
19
19
|
return './';
|
20
20
|
}
|
21
21
|
}
|
22
|
-
//# sourceMappingURL=
|
22
|
+
//# sourceMappingURL=builder.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../../src/helpers/builder.ts"],"names":[],"mappings":";;;;;AAEA,oCAaC;AAfD,gDAAwB;AAExB,SAAgB,YAAY;IAC1B,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,KAAM,CAAC;QACjC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEnC,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mDAAmD;QACnD,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/helpers/pool.ts"],"names":[],"mappings":";;AAAA,0BAIC;AAJD,SAAgB,OAAO;IACrB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.tsNodeCompilerOptions = exports.tsCompilerOptions = void 0;
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
8
|
+
exports.tsCompilerOptions = {
|
9
|
+
module: typescript_1.default.ModuleKind.CommonJS,
|
10
|
+
target: typescript_1.default.ScriptTarget.ES2018,
|
11
|
+
};
|
12
|
+
exports.tsNodeCompilerOptions = {
|
13
|
+
transpileOnly: true,
|
14
|
+
compilerOptions: {
|
15
|
+
module: 'CommonJS',
|
16
|
+
target: 'ES5'
|
17
|
+
}
|
18
|
+
};
|
19
|
+
//# sourceMappingURL=constants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/node/builder/constants.ts"],"names":[],"mappings":";;;;;;AACA,4DAA6B;AAEhB,QAAA,iBAAiB,GAAuB;IACnD,MAAM,EAAE,oBAAE,CAAC,UAAU,CAAC,QAAQ;IAC9B,MAAM,EAAE,oBAAE,CAAC,YAAY,CAAC,MAAM;CAC/B,CAAA;AAEY,QAAA,qBAAqB,GAAoB;IACpD,aAAa,EAAE,IAAI;IACnB,eAAe,EAAE;QACf,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,KAAK;KACd;CACF,CAAA"}
|
@@ -0,0 +1,144 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.buildWorkerCode = buildWorkerCode;
|
7
|
+
const webpack_node_externals_1 = __importDefault(require("webpack-node-externals"));
|
8
|
+
const path_1 = __importDefault(require("path"));
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
10
|
+
const webpack_1 = require("webpack");
|
11
|
+
const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
|
12
|
+
const BUILD_PATH = path_1.default.join(__dirname, '.out');
|
13
|
+
const BUILD_FILENAME = 'bundle.js';
|
14
|
+
const BUILD_FILE_PATH = path_1.default.join(BUILD_PATH, BUILD_FILENAME);
|
15
|
+
function buildWorkerCode(entryFile) {
|
16
|
+
if (!fs_1.default.existsSync(BUILD_PATH)) {
|
17
|
+
fs_1.default.mkdirSync(BUILD_PATH, { recursive: true });
|
18
|
+
}
|
19
|
+
const config = getWebpackConfig(entryFile);
|
20
|
+
const compiler = (0, webpack_1.webpack)(config);
|
21
|
+
return new Promise((resolve, reject) => {
|
22
|
+
compiler.run((err, stats) => {
|
23
|
+
if (err) {
|
24
|
+
reject(err);
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
/*
|
28
|
+
console.log(stats?.toString({
|
29
|
+
chunks: false,
|
30
|
+
colors: true
|
31
|
+
}));
|
32
|
+
*/
|
33
|
+
const bundledCode = fs_1.default
|
34
|
+
.readFileSync(BUILD_FILE_PATH, 'utf8');
|
35
|
+
// clean up the build folder
|
36
|
+
fs_1.default.rm(BUILD_PATH, { recursive: true, force: false }, (err) => {
|
37
|
+
if (err) {
|
38
|
+
reject(err);
|
39
|
+
}
|
40
|
+
});
|
41
|
+
resolve(bundledCode);
|
42
|
+
});
|
43
|
+
});
|
44
|
+
}
|
45
|
+
const getWebpackConfig = (entry) => ({
|
46
|
+
entry,
|
47
|
+
output: {
|
48
|
+
filename: BUILD_FILENAME,
|
49
|
+
path: BUILD_PATH,
|
50
|
+
libraryTarget: 'commonjs2',
|
51
|
+
module: false,
|
52
|
+
iife: false,
|
53
|
+
umdNamedDefine: true,
|
54
|
+
},
|
55
|
+
resolve: {
|
56
|
+
extensions: ['.ts', '.js'],
|
57
|
+
fallback: {
|
58
|
+
assert: false,
|
59
|
+
buffer: false,
|
60
|
+
console: false,
|
61
|
+
constants: false,
|
62
|
+
crypto: false,
|
63
|
+
domain: false,
|
64
|
+
events: false,
|
65
|
+
fs: false,
|
66
|
+
http: false,
|
67
|
+
https: false,
|
68
|
+
module: false,
|
69
|
+
net: false,
|
70
|
+
os: false,
|
71
|
+
path: false,
|
72
|
+
process: false,
|
73
|
+
punycode: false,
|
74
|
+
querystring: false,
|
75
|
+
readline: false,
|
76
|
+
stream: false,
|
77
|
+
string_decoder: false,
|
78
|
+
sys: false,
|
79
|
+
timers: false,
|
80
|
+
tls: false,
|
81
|
+
tty: false,
|
82
|
+
url: false,
|
83
|
+
util: false,
|
84
|
+
vm: false,
|
85
|
+
worker_threads: false,
|
86
|
+
zlib: false,
|
87
|
+
},
|
88
|
+
},
|
89
|
+
resolveLoader: {
|
90
|
+
modules: [
|
91
|
+
path_1.default.resolve(process.cwd(), 'node_modules')
|
92
|
+
]
|
93
|
+
},
|
94
|
+
mode: 'production',
|
95
|
+
optimization: {
|
96
|
+
minimize: true,
|
97
|
+
minimizer: [
|
98
|
+
new terser_webpack_plugin_1.default({
|
99
|
+
terserOptions: {
|
100
|
+
compress: {
|
101
|
+
drop_console: true,
|
102
|
+
drop_debugger: true
|
103
|
+
},
|
104
|
+
}
|
105
|
+
})
|
106
|
+
]
|
107
|
+
},
|
108
|
+
target: 'node',
|
109
|
+
module: {
|
110
|
+
rules: [
|
111
|
+
{
|
112
|
+
test: /\.ts$/,
|
113
|
+
use: [
|
114
|
+
{
|
115
|
+
loader: resolveNodeModules('babel-loader'),
|
116
|
+
options: {
|
117
|
+
presets: [
|
118
|
+
resolveNodeModules('@babel/preset-env'),
|
119
|
+
resolveNodeModules('@babel/preset-typescript')
|
120
|
+
],
|
121
|
+
plugins: [
|
122
|
+
resolveNodeModules('@babel/plugin-transform-modules-commonjs'),
|
123
|
+
[resolveNodeModules('@babel/plugin-proposal-decorators'), { "legacy": true }],
|
124
|
+
]
|
125
|
+
},
|
126
|
+
}
|
127
|
+
],
|
128
|
+
exclude: /node_modules/
|
129
|
+
}
|
130
|
+
],
|
131
|
+
},
|
132
|
+
devtool: 'source-map',
|
133
|
+
stats: 'verbose',
|
134
|
+
externals: [(0, webpack_node_externals_1.default)({
|
135
|
+
importType: 'commonjs',
|
136
|
+
})],
|
137
|
+
cache: false
|
138
|
+
});
|
139
|
+
const resolveNodeModules = (packageName) => require.resolve(packageName, {
|
140
|
+
paths: [
|
141
|
+
path_1.default.resolve(__dirname, 'node_modules')
|
142
|
+
]
|
143
|
+
});
|
144
|
+
//# sourceMappingURL=helpers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../src/node/builder/helpers.ts"],"names":[],"mappings":";;;;;AAWA,0CAoCC;AA/CD,oFAAmD;AACnD,gDAAwB;AAExB,4CAAoB;AACpB,qCAAkC;AAClC,kFAAiD;AAEjD,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAChD,MAAM,cAAc,GAAG,WAAW,CAAC;AACnC,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;AAE9D,SAAgB,eAAe,CAAC,SAAiB;IAE/C,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,YAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;IACD,MAAM,MAAM,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAA,iBAAO,EAAC,MAAM,CAAC,CAAC;IAEjC,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAE7C,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YAC1B,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,CAAC,GAAG,CAAC,CAAC;gBACZ,OAAO;YACT,CAAC;YAED;;;;;cAKE;YAEF,MAAM,WAAW,GAAG,YAAE;iBACnB,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;YAEzC,4BAA4B;YAC5B,YA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EAAE,cAAc,CAAC;KACxC;CACF,CAAC,CAAC"}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.buildNodeApiAndWorkerFromCode = exports.genWorkerCodeFromFile = void 0;
|
7
|
+
const comlink_1 = __importDefault(require("comlink"));
|
8
|
+
const worker_threads_1 = require("worker_threads");
|
9
|
+
const node_adapter_js_1 = __importDefault(require("comlink/dist/umd/node-adapter.js"));
|
10
|
+
const helpers_1 = require("./helpers");
|
11
|
+
const path_1 = __importDefault(require("path"));
|
12
|
+
const builder_1 = require("../../helpers/builder");
|
13
|
+
const genWorkerCodeFromFile = async (workerPath) => {
|
14
|
+
const callerDir = (0, builder_1.getCallerDir)();
|
15
|
+
const resolvedPath = path_1.default.resolve(callerDir, workerPath);
|
16
|
+
const code = await (0, helpers_1.buildWorkerCode)(resolvedPath);
|
17
|
+
return code;
|
18
|
+
};
|
19
|
+
exports.genWorkerCodeFromFile = genWorkerCodeFromFile;
|
20
|
+
const buildNodeApiAndWorkerFromCode = (code) => {
|
21
|
+
const worker = new worker_threads_1.Worker(code, { eval: true });
|
22
|
+
const api = comlink_1.default.wrap((0, node_adapter_js_1.default)(worker));
|
23
|
+
return { worker, api };
|
24
|
+
};
|
25
|
+
exports.buildNodeApiAndWorkerFromCode = buildNodeApiAndWorkerFromCode;
|
26
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/node/builder/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAC9B,mDAAwD;AACxD,uFAA4D;AAC5D,uCAA4C;AAC5C,gDAAwB;AACxB,mDAAqD;AAE9C,MAAM,qBAAqB,GAAG,KAAK,EACxC,UAAkB,EACD,EAAE;IACnB,MAAM,SAAS,GAAG,IAAA,sBAAY,GAAE,CAAC;IACjC,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACzD,MAAM,IAAI,GAAG,MAAM,IAAA,yBAAe,EAAC,YAAY,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC;AACd,CAAC,CAAA;AAPY,QAAA,qBAAqB,yBAOjC;AAEM,MAAM,6BAA6B,GAAG,CAC3C,IAAY,EAC4C,EAAE;IAE1D,MAAM,MAAM,GAAG,IAAI,uBAAY,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,MAAM,GAAG,GAAG,iBAAO,CAAC,IAAI,CAAI,IAAA,yBAAY,EAAC,MAAM,CAAC,CAAC,CAAC;IAElD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AACzB,CAAC,CAAA;AARY,QAAA,6BAA6B,iCAQzC"}
|
@@ -0,0 +1,125 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
7
|
+
var _, done = false;
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
9
|
+
var context = {};
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
14
|
+
if (kind === "accessor") {
|
15
|
+
if (result === void 0) continue;
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
20
|
+
}
|
21
|
+
else if (_ = accept(result)) {
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
23
|
+
else descriptor[key] = _;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
27
|
+
done = true;
|
28
|
+
};
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
30
|
+
var useValue = arguments.length > 2;
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
33
|
+
}
|
34
|
+
return useValue ? value : void 0;
|
35
|
+
};
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
39
|
+
};
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
42
|
+
};
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
44
|
+
exports.NodeOmniWorker = void 0;
|
45
|
+
const worker_threads_1 = require("worker_threads");
|
46
|
+
const comlink_1 = __importDefault(require("comlink"));
|
47
|
+
const node_adapter_1 = __importDefault(require("comlink/dist/umd/node-adapter"));
|
48
|
+
const builder_1 = require("./builder");
|
49
|
+
const helpers_1 = require("../types/helpers");
|
50
|
+
/**
|
51
|
+
* OmniWorker for NodeJS
|
52
|
+
*/
|
53
|
+
let NodeOmniWorker = (() => {
|
54
|
+
let _classDecorators = [(0, helpers_1.staticImplements)(), (0, helpers_1.staticImplements)()];
|
55
|
+
let _classDescriptor;
|
56
|
+
let _classExtraInitializers = [];
|
57
|
+
let _classThis;
|
58
|
+
var NodeOmniWorker = _classThis = class {
|
59
|
+
constructor(code, worker, api) {
|
60
|
+
this.isInitialized = () => (this._api !== undefined);
|
61
|
+
this.use = () => {
|
62
|
+
const isInitialized = this.isInitialized();
|
63
|
+
if (isInitialized) {
|
64
|
+
return this._api;
|
65
|
+
}
|
66
|
+
else {
|
67
|
+
throw Error('worker is not yet initialized. make sure to call the build() function, first');
|
68
|
+
}
|
69
|
+
};
|
70
|
+
this.clone = (numOfTimes) => {
|
71
|
+
const workers = [];
|
72
|
+
const code = this._code;
|
73
|
+
for (let i = 0; i <= numOfTimes; i++) {
|
74
|
+
const { worker, api } = (0, builder_1.buildNodeApiAndWorkerFromCode)(code);
|
75
|
+
workers.push(new NodeOmniWorker(code, worker, api));
|
76
|
+
}
|
77
|
+
return workers;
|
78
|
+
};
|
79
|
+
this.destroy = async () => {
|
80
|
+
await this._worker.terminate();
|
81
|
+
};
|
82
|
+
this._code = code;
|
83
|
+
this._worker = worker;
|
84
|
+
this._api = api;
|
85
|
+
return this;
|
86
|
+
}
|
87
|
+
/**
|
88
|
+
* Handles the building of the necessary resources for an OmniWorker to function.
|
89
|
+
* This usually means, building from the consumer's code, creating the comlink
|
90
|
+
* interface between the worker and the main thread as well as the worker itself.
|
91
|
+
*
|
92
|
+
* @param path Relative path FROM YOUR PROJECT's ROOT to the file to be the worker
|
93
|
+
* @returns An OmniWorker
|
94
|
+
*/
|
95
|
+
static async build(path) {
|
96
|
+
const code = await (0, builder_1.genWorkerCodeFromFile)(path);
|
97
|
+
const { worker, api } = (0, builder_1.buildNodeApiAndWorkerFromCode)(code);
|
98
|
+
return new NodeOmniWorker(code, worker, api);
|
99
|
+
}
|
100
|
+
};
|
101
|
+
__setFunctionName(_classThis, "NodeOmniWorker");
|
102
|
+
(() => {
|
103
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
104
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
105
|
+
NodeOmniWorker = _classThis = _classDescriptor.value;
|
106
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
107
|
+
})();
|
108
|
+
/**
|
109
|
+
* Expose the functions inside the worker to the rest of the application.
|
110
|
+
* After having exposed the functions, the build step can be initiated.
|
111
|
+
* @param exposable A class, object with functions or a single function to be
|
112
|
+
* exposed to the main thread.
|
113
|
+
*/
|
114
|
+
_classThis.expose = (exposable) => {
|
115
|
+
if (worker_threads_1.parentPort) {
|
116
|
+
comlink_1.default.expose(exposable, (0, node_adapter_1.default)(worker_threads_1.parentPort));
|
117
|
+
}
|
118
|
+
};
|
119
|
+
(() => {
|
120
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
121
|
+
})();
|
122
|
+
return NodeOmniWorker = _classThis;
|
123
|
+
})();
|
124
|
+
exports.NodeOmniWorker = NodeOmniWorker;
|
125
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mDAAoE;AACpE,sDAA8B;AAC9B,iFAAyD;AACzD,uCAAiF;AACjF,8CAAoD;AAEpD;;GAEG;IAGU,cAAc;4BAF1B,IAAA,0BAAgB,GAAc,EAC9B,IAAA,0BAAgB,GAAc;;;;;QAO7B,YACE,IAAY,EACZ,MAAoB,EACpB,GAA4B;YAoCvB,kBAAa,GAAG,GAAY,EAAE,CAAC,CACpC,IAAI,CA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