@anonaddy/omni-worker 0.0.1 → 0.1.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.
Files changed (73) hide show
  1. package/README.md +80 -24
  2. package/dist/cjs/index.js +5 -81
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/node/builder/constants.js +19 -0
  5. package/dist/cjs/node/builder/constants.js.map +1 -0
  6. package/dist/cjs/node/builder/helpers.js +158 -0
  7. package/dist/cjs/node/builder/helpers.js.map +1 -0
  8. package/dist/cjs/node/builder/index.js +25 -0
  9. package/dist/cjs/node/builder/index.js.map +1 -0
  10. package/dist/cjs/{builder → node/builder}/node.js +6 -32
  11. package/dist/cjs/node/builder/node.js.map +1 -0
  12. package/dist/cjs/node/index.js +66 -0
  13. package/dist/cjs/node/index.js.map +1 -0
  14. package/dist/cjs/node/pool.js +86 -0
  15. package/dist/cjs/node/pool.js.map +1 -0
  16. package/dist/mjs/index.js +2 -43
  17. package/dist/mjs/index.js.map +1 -1
  18. package/dist/mjs/node/builder/constants.js +13 -0
  19. package/dist/mjs/node/builder/constants.js.map +1 -0
  20. package/dist/mjs/node/builder/helpers.js +151 -0
  21. package/dist/mjs/node/builder/helpers.js.map +1 -0
  22. package/dist/mjs/node/builder/index.js +17 -0
  23. package/dist/mjs/node/builder/index.js.map +1 -0
  24. package/dist/mjs/node/builder/node.js +14 -0
  25. package/dist/mjs/node/builder/node.js.map +1 -0
  26. package/dist/mjs/node/index.js +59 -0
  27. package/dist/mjs/node/index.js.map +1 -0
  28. package/dist/mjs/node/pool.js +82 -0
  29. package/dist/mjs/node/pool.js.map +1 -0
  30. package/dist/types/index.d.ts +3 -25
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/node/builder/constants.d.ts +5 -0
  33. package/dist/types/node/builder/constants.d.ts.map +1 -0
  34. package/dist/types/node/builder/helpers.d.ts +3 -0
  35. package/dist/types/node/builder/helpers.d.ts.map +1 -0
  36. package/dist/types/node/builder/index.d.ts +8 -0
  37. package/dist/types/node/builder/index.d.ts.map +1 -0
  38. package/dist/types/node/builder/node.d.ts +7 -0
  39. package/dist/types/node/builder/node.d.ts.map +1 -0
  40. package/dist/types/node/index.d.ts +30 -0
  41. package/dist/types/node/index.d.ts.map +1 -0
  42. package/dist/types/node/pool.d.ts +30 -0
  43. package/dist/types/node/pool.d.ts.map +1 -0
  44. package/package.json +16 -9
  45. package/dist/cjs/builder/helpers.js +0 -22
  46. package/dist/cjs/builder/helpers.js.map +0 -1
  47. package/dist/cjs/builder/node.js.map +0 -1
  48. package/dist/cjs/builder/plugins/external-imports.js +0 -44
  49. package/dist/cjs/builder/plugins/external-imports.js.map +0 -1
  50. package/dist/cjs/builder/plugins/native-module.js +0 -18
  51. package/dist/cjs/builder/plugins/native-module.js.map +0 -1
  52. package/dist/cjs/types/omni-worker.js +0 -3
  53. package/dist/cjs/types/omni-worker.js.map +0 -1
  54. package/dist/mjs/builder/helpers.js +0 -16
  55. package/dist/mjs/builder/helpers.js.map +0 -1
  56. package/dist/mjs/builder/node.js +0 -40
  57. package/dist/mjs/builder/node.js.map +0 -1
  58. package/dist/mjs/builder/plugins/external-imports.js +0 -39
  59. package/dist/mjs/builder/plugins/external-imports.js.map +0 -1
  60. package/dist/mjs/builder/plugins/native-module.js +0 -15
  61. package/dist/mjs/builder/plugins/native-module.js.map +0 -1
  62. package/dist/mjs/types/omni-worker.js +0 -2
  63. package/dist/mjs/types/omni-worker.js.map +0 -1
  64. package/dist/types/builder/helpers.d.ts +0 -2
  65. package/dist/types/builder/helpers.d.ts.map +0 -1
  66. package/dist/types/builder/node.d.ts +0 -3
  67. package/dist/types/builder/node.d.ts.map +0 -1
  68. package/dist/types/builder/plugins/external-imports.d.ts +0 -4
  69. package/dist/types/builder/plugins/external-imports.d.ts.map +0 -1
  70. package/dist/types/builder/plugins/native-module.d.ts +0 -3
  71. package/dist/types/builder/plugins/native-module.d.ts.map +0 -1
  72. package/dist/types/types/omni-worker.d.ts +0 -21
  73. 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 limiting in their application, since the code that runs on a worker needs to be serializable. Therefore interfaces aren't fully supported, and also 3rd party libraries usually don't work.
2
+ Webworkers (browser) and thread workers (NodeJS) are usually limiting in their application, since the code that runs on a worker needs to be serializable. Therefore, most interfaces aren't fully supported, and also 3rd party modules usually don't work or give you a serious headache when implementing them...
3
3
 
4
- Enter the stage, OmniWorkers! These workers allow you to simply declare any interface with functions that will actually run inside a worker. Whether it be on the web (webworker) or as a thread worker in NodeJS, these workers will run your code, no matter what.
4
+ Enter the stage, OmniWorkers! These workers allow you to simply declare any interface with functions 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, period.
5
5
 
6
6
  ## How does it Work?
7
- In the case of jsDOM, the UI will block at certain tasks if it's too heavy. Alternatively, in case of Node, load times will take longer since the JavaScript V8 engine only runs one event loop thread. Even when using asynchronous code, the event loop can easily get overloaded.
7
+ In the case of using typescript for front-end projects, a UI will simply block at certain tasks if they're too heavy. Alternatively, in case of Node, 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 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, is that we now have more than one event loop thread to work on. The drawback of course, is that all code executed inside these (contexed) workers needs to be serializable, since your code is basically shipped into the worker for execution. If you have code that depends on other 3rd party libraries, your code will most-likely not build, since the code inside the worker context is closed off.
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 will most-likely not execute, since the code inside the worker context is mostly closed off.
11
13
 
12
14
  ### 👷 OmniWorkers
13
- So how do OmniWorkers stand out from normal workers? First off, the simplicity. Simply declare your code and expose it to the main event loop. Then, build the OmniWorker by referencing you file. Now, the OmniWorker will expose the object with functions 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 look at an example:
15
+ So how do OmniWorkers stand out from normal workers? 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 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 look at an example:
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
@@ -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
  setTimeout(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,83 @@ setTimeout(async () => {
54
61
  The result of my sum is: ${sum}!
55
62
  Aren't Omniworkers just awesome?!
56
63
  `);
64
+
65
+ // Release resources once you're done!
66
+ await worker.destroy();
57
67
  }, 0);
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
- ### Under the Hood
62
- This modules leverages [Comlink](https://github.com/GoogleChromeLabs/comlink) and [Esbuild](https://github.com/evanw/esbuild) to parse your container code, build it and wire it up to the main event loop using Comlink.
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:
75
+
76
+ #### `🏊‍♂️ pool.ts`
77
+ ```javascript
78
+ import { NodeOmniWorkerPool } from '@anonaddy/omni-worker';
79
+ import { IMyOmniWorkerFunctions } from "./worker-model";
80
+
81
+ setTimeout(async () => {
63
82
 
64
- ### Tests
65
- Tests are included inside this library. If you would like to learn how to build and instantiate your workers, you can find examples inside the test code, for node inside `__tests_node__` and for web `__tests_dom__` respectively.
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
+ }, 0);
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.
111
+
112
+ ### Under the Hood
113
+ 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
114
 
67
115
  # Potential Issues
68
- There's cases where building the worker could lead to errors. Especially when working with packages that use bindings for other languages such as C or C++ for example and that are built to `*.node` binary files using node-gyp. One could experience situations like:
116
+ 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
117
  ```
70
- ❌ Module did not self-register: /path/to/node-gyp/built/binary.node
118
+ ❌ Module did not self-register: /path/to/native/binary.node
71
119
  ```
72
- The root cause is assumed to be a mismatch on either the build or the initialization stage of the binary. Oftentimes, performing these steps, helps:
120
+ 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).
121
+
122
+ 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
123
  ``` bash
74
- # first, retry the rebuild
124
+ # rebuild the .node native code
75
125
  npm rebuild <your lib>
76
126
 
77
- # if that didn't work
127
+ # if that didn't work try deleting package info
78
128
  rm -rf node_modules
79
129
  mv package-lock.json package-lock.json.backup # make sure to make a backup!
80
130
  npm i
81
131
  ```
82
- Should you run into the issue above, or similar other issues, please drop me an email on the address mentioned at the bottom of this doc.
132
+ Should you not be able to solve your issue, please drop me an email so we can try and analyze the issue together.
83
133
 
84
134
  # Project Status
85
- Currently, only `NodeOmniWorker`s are available. The `WebOmniWorker`s will also be available soon. Please stay tuned! In case you have any questions, make sure to drop me an [email](mailto:7ebr7fa0@anonaddy.com) and I will try to get back to you asap.
135
+ Currently, only `NodeOmniWorker`s and `NodeOmniWorkerPool`s are available. The `WebOmniWorker`s along with their pools will also be available soon. Please stay tuned! In case you have any questions, make sure to drop me an [email](mailto:7ebr7fa0@anonaddy.com) and I will try to get back to you asap.
136
+
137
+ ## Change Log
138
+ |Version|Description|
139
+ |:-:|-|
140
+ |**v0.1.0**|Switched from ESBuild to Webpack for NodeJS and introduced the NodeOmniWorkerPool|
141
+ |**v0.0.1**|Basic of single NodeOmniWorker with code having native dependencies still crashing|
86
142
 
87
- 🏗️ **Happy (Omni)Working!!** 🏗️
143
+ ### 🏗️ Happy (Omni)Working!! 🏗️
package/dist/cjs/index.js CHANGED
@@ -1,84 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.NodeOmniWorker = void 0;
40
- const worker_threads_1 = require("worker_threads");
41
- const Comlink = __importStar(require("comlink"));
42
- const node_adapter_js_1 = __importDefault(require("comlink/dist/umd/node-adapter.js"));
43
- const node_1 = require("./builder/node");
44
- class NodeOmniWorker {
45
- constructor(api) {
46
- this.isInitialized = () => (this._api !== undefined);
47
- this.use = () => {
48
- const isInitialized = this.isInitialized();
49
- if (isInitialized) {
50
- return this._api;
51
- }
52
- else {
53
- throw Error('worker is not yet initialized. make sure to call the .set() function, first');
54
- }
55
- };
56
- this._api = api;
57
- return this;
58
- }
59
- /**
60
- * Build the OmniWorker from a worker file. Please note that the functions
61
- * on the worker file need to first be exposed using the expose({ <functions> })
62
- * functions, in order to start this build step.
63
- *
64
- * @param path The relative path to where the worker module is located
65
- * @returns A new Node OmniWorker
66
- */
67
- static async build(path) {
68
- const api = await (0, node_1.buildApiNode)(path);
69
- return new NodeOmniWorker(api);
70
- }
71
- }
72
- exports.NodeOmniWorker = NodeOmniWorker;
73
- /**
74
- * Expose the functions inside the worker to the rest of the application.
75
- * After having exposed the functions, the build step can be initiated.
76
- * @param functions An object with functions inside the worker to be exposed to
77
- * the rest of the application.
78
- */
79
- NodeOmniWorker.expose = (functions) => {
80
- if (worker_threads_1.parentPort) {
81
- Comlink.expose(functions, (0, node_adapter_js_1.default)(worker_threads_1.parentPort));
82
- }
83
- };
3
+ exports.NodeOmniWorkerPool = exports.NodeOmniWorker = void 0;
4
+ var node_1 = require("./node");
5
+ Object.defineProperty(exports, "NodeOmniWorker", { enumerable: true, get: function () { return node_1.NodeOmniWorker; } });
6
+ var pool_1 = require("./node/pool");
7
+ Object.defineProperty(exports, "NodeOmniWorkerPool", { enumerable: true, get: function () { return pool_1.NodeOmniWorkerPool; } });
84
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,mDAA4C;AAC5C,iDAAmC;AACnC,uFAA4D;AAC5D,yCAA8C;AAE9C,MAAa,cAAc;IAGzB,YAAoB,GAAsB;QAgCnC,kBAAa,GAAG,GAAY,EAAE,CAAC,CACpC,IAAI,CAAC,IAAI,KAAK,SAAS,CACxB,CAAC;QAEK,QAAG,GAAG,GAAG,EAAE;YAChB,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YAC3C,IAAI,aAAa,EAAE,CAAC;gBAClB,OAAO,IAAI,CAAC,IAAK,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,CAAC,6EAA6E,CAAC,CAAC;YAC7F,CAAC;QACH,CAAC,CAAA;QA1CC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAcD;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAAC,KAAK,CACvB,IAAY;QAEZ,MAAM,GAAG,GAAG,MAAM,IAAA,mBAAY,EAAI,IAAI,CAAC,CAAC;QACxC,OAAO,IAAI,cAAc,CAAI,GAAG,CAAC,CAAC;IACpC,CAAC;;AAjCH,wCA+CC;AAvCC;;;;;GAKG;AACW,qBAAM,GAAG,CAAI,SAAY,EAAE,EAAE;IACzC,IAAI,2BAAU,EAAE,CAAC;QACf,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,IAAA,yBAAY,EAAC,2BAAU,CAAC,CAAC,CAAC;IACtD,CAAC;AACH,CAAC,AAJmB,CAInB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAKA,+BAEgB;AADd,sGAAA,cAAc,OAAA;AAGhB,oCAEqB;AADnB,0GAAA,kBAAkB,OAAA"}
@@ -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,158 @@
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.getCallerDir = getCallerDir;
7
+ exports.buildWorkerCode = buildWorkerCode;
8
+ const webpack_node_externals_1 = __importDefault(require("webpack-node-externals"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const webpack_1 = require("webpack");
12
+ const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
13
+ const BUILD_PATH = path_1.default.join(__dirname, '.out');
14
+ const BUILD_FILENAME = 'bundle.js';
15
+ const BUILD_FILE_PATH = path_1.default.join(BUILD_PATH, BUILD_FILENAME);
16
+ function getCallerDir() {
17
+ try {
18
+ const stack = new Error().stack;
19
+ const line = stack.split('\n')[1].trim();
20
+ const segment = line.split(' ')[1];
21
+ const part = segment.split(':')[0];
22
+ const dirName = path_1.default.dirname(part);
23
+ return dirName;
24
+ }
25
+ catch (e) {
26
+ // console.error('building caller path failed', e);
27
+ return './';
28
+ }
29
+ }
30
+ function buildWorkerCode(entryFile) {
31
+ return new Promise((resolve, reject) => {
32
+ if (!fs_1.default.existsSync(BUILD_PATH)) {
33
+ fs_1.default.mkdirSync(BUILD_PATH, { recursive: true });
34
+ }
35
+ const config = getWebpackConfig(entryFile);
36
+ const compiler = (0, webpack_1.webpack)(config);
37
+ compiler.run((err, stats) => {
38
+ if (err) {
39
+ reject(err);
40
+ return;
41
+ }
42
+ /*
43
+ console.log(stats?.toString({
44
+ chunks: false,
45
+ colors: true
46
+ }));
47
+ */
48
+ const bundledCode = fs_1.default
49
+ .readFileSync(BUILD_FILE_PATH, 'utf8');
50
+ resolve(bundledCode);
51
+ // clean up the build folder
52
+ fs_1.default.rm(BUILD_PATH, { recursive: true, force: true }, (err) => {
53
+ if (err) {
54
+ reject(err);
55
+ }
56
+ });
57
+ });
58
+ });
59
+ }
60
+ const resolveNodeModules = (packageName) => require.resolve(packageName, {
61
+ paths: [
62
+ path_1.default.resolve(__dirname, 'node_modules')
63
+ ]
64
+ });
65
+ const getWebpackConfig = (entry) => ({
66
+ entry,
67
+ output: {
68
+ filename: BUILD_FILENAME,
69
+ path: BUILD_PATH,
70
+ libraryTarget: 'commonjs2',
71
+ module: false,
72
+ iife: false,
73
+ umdNamedDefine: true,
74
+ },
75
+ resolve: {
76
+ extensions: ['.ts', '.js'],
77
+ fallback: {
78
+ assert: false,
79
+ buffer: false,
80
+ console: false,
81
+ constants: false,
82
+ crypto: false,
83
+ domain: false,
84
+ events: false,
85
+ fs: false,
86
+ http: false,
87
+ https: false,
88
+ module: false,
89
+ net: false,
90
+ os: false,
91
+ path: false,
92
+ process: false,
93
+ punycode: false,
94
+ querystring: false,
95
+ readline: false,
96
+ stream: false,
97
+ string_decoder: false,
98
+ sys: false,
99
+ timers: false,
100
+ tls: false,
101
+ tty: false,
102
+ url: false,
103
+ util: false,
104
+ vm: false,
105
+ worker_threads: false,
106
+ zlib: false,
107
+ },
108
+ },
109
+ resolveLoader: {
110
+ modules: [
111
+ path_1.default.resolve(process.cwd(), 'node_modules')
112
+ ]
113
+ },
114
+ mode: 'production',
115
+ optimization: {
116
+ minimize: true,
117
+ minimizer: [
118
+ new terser_webpack_plugin_1.default({
119
+ terserOptions: {
120
+ compress: {
121
+ drop_console: true,
122
+ drop_debugger: true
123
+ },
124
+ }
125
+ })
126
+ ]
127
+ },
128
+ target: 'node',
129
+ module: {
130
+ rules: [
131
+ {
132
+ test: /\.ts$/,
133
+ use: [
134
+ {
135
+ loader: resolveNodeModules('babel-loader'),
136
+ options: {
137
+ presets: [
138
+ resolveNodeModules('@babel/preset-env'),
139
+ resolveNodeModules('@babel/preset-typescript')
140
+ ],
141
+ plugins: [
142
+ resolveNodeModules('@babel/plugin-transform-modules-commonjs')
143
+ ]
144
+ },
145
+ }
146
+ ],
147
+ exclude: /node_modules/
148
+ }
149
+ ],
150
+ },
151
+ devtool: 'source-map',
152
+ stats: 'verbose',
153
+ externals: [(0, webpack_node_externals_1.default)({
154
+ importType: 'commonjs',
155
+ })],
156
+ cache: false
157
+ });
158
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../src/node/builder/helpers.ts"],"names":[],"mappings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C,CAAC;6BAC/D;yBACF;qBACF;iBACF;gBACD,OAAO,EAAE,cAAc;aACxB;SACF;KACF;IACD,OAAO,EAAE,YAAY;IACrB,KAAK,EAAE,SAAS;IAChB,SAAS,EAAE,CAAC,IAAA,gCAAa,EAAC;YACxB,UAAU,EAAE,UAAU;SACvB,CAAC,CAAC;IACH,KAAK,EAAE,KAAK;CACb,CAAC,CAAC"}
@@ -0,0 +1,25 @@
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 genWorkerCodeFromFile = async (workerPath) => {
13
+ const callerDir = (0, helpers_1.getCallerDir)();
14
+ const resolvedPath = path_1.default.resolve(callerDir, workerPath);
15
+ const code = await (0, helpers_1.buildWorkerCode)(resolvedPath);
16
+ return code;
17
+ };
18
+ exports.genWorkerCodeFromFile = genWorkerCodeFromFile;
19
+ const buildNodeApiAndWorkerFromCode = (code) => {
20
+ const worker = new worker_threads_1.Worker(code, { eval: true });
21
+ const api = comlink_1.default.wrap((0, node_adapter_js_1.default)(worker));
22
+ return { worker, api };
23
+ };
24
+ exports.buildNodeApiAndWorkerFromCode = buildNodeApiAndWorkerFromCode;
25
+ //# 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,mDAAwC;AACxC,uFAA4D;AAC5D,uCAA0D;AAC1D,gDAAwB;AAEjB,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,EACsC,EAAE;IAEpD,MAAM,MAAM,GAAG,IAAI,uBAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,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"}
@@ -38,43 +38,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.buildApiNode = void 0;
40
40
  const Comlink = __importStar(require("comlink"));
41
- const esbuild = __importStar(require("esbuild"));
42
- const external_imports_1 = __importDefault(require("./plugins/external-imports"));
43
41
  const worker_threads_1 = require("worker_threads");
44
42
  const node_adapter_js_1 = __importDefault(require("comlink/dist/umd/node-adapter.js"));
45
- const _path = __importStar(require("path"));
46
- const native_module_1 = require("../builder/plugins/native-module");
47
43
  const helpers_1 = require("./helpers");
48
- const buildApiNode = async (path) => {
44
+ const path_1 = __importDefault(require("path"));
45
+ const buildApiNode = async (workerPath) => {
49
46
  const callerDir = (0, helpers_1.getCallerDir)();
50
- const resolvedPath = _path.resolve(callerDir, path);
51
- const result = await esbuild.build({
52
- entryPoints: [resolvedPath],
53
- loader: {
54
- ".ts": "ts",
55
- ".js": "js",
56
- ".node": "binary"
57
- },
58
- format: "cjs",
59
- bundle: true,
60
- minify: true,
61
- write: false,
62
- plugins: [
63
- native_module_1.nativeModulePlugin,
64
- external_imports_1.default,
65
- ]
66
- });
67
- const outputFiles = result.outputFiles;
68
- if (!outputFiles ||
69
- result.outputFiles.length < 1 ||
70
- result.outputFiles[0].text === undefined ||
71
- result.outputFiles[0].text === "") {
72
- throw Error("no build output for worker");
73
- }
74
- const scriptData = result.outputFiles[0].text.trim();
75
- const worker = new worker_threads_1.Worker(scriptData, { eval: true });
47
+ const resolvedPath = path_1.default.resolve(callerDir, workerPath);
48
+ const js = await (0, helpers_1.buildWorkerCode)(resolvedPath);
49
+ const worker = new worker_threads_1.Worker(js, { eval: true });
76
50
  const api = Comlink.wrap((0, node_adapter_js_1.default)(worker));
77
- return api;
51
+ return { api, worker };
78
52
  };
79
53
  exports.buildApiNode = buildApiNode;
80
54
  //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../../src/node/builder/node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AACnC,mDAAwC;AACxC,uFAA4D;AAC5D,uCAA0D;AAC1D,gDAAwB;AAEjB,MAAM,YAAY,GAAG,KAAK,EAC/B,UAAkB,EACkC,EAAE;IAEtD,MAAM,SAAS,GAAG,IAAA,sBAAY,GAAE,CAAC;IACjC,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAEzD,MAAM,EAAE,GAAG,MAAM,IAAA,yBAAe,EAAC,YAAY,CAAC,CAAC;IAE/C,MAAM,MAAM,GAAG,IAAI,uBAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAI,IAAA,yBAAY,EAAC,MAAM,CAAC,CAAC,CAAC;IAElD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACzB,CAAC,CAAA;AAbY,QAAA,YAAY,gBAaxB"}
@@ -0,0 +1,66 @@
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.NodeOmniWorker = void 0;
7
+ const worker_threads_1 = require("worker_threads");
8
+ const comlink_1 = __importDefault(require("comlink"));
9
+ const node_adapter_1 = __importDefault(require("comlink/dist/umd/node-adapter"));
10
+ const builder_1 = require("./builder");
11
+ class NodeOmniWorker {
12
+ constructor(code, worker, api) {
13
+ this.isInitialized = () => (this._api !== undefined);
14
+ this.use = () => {
15
+ const isInitialized = this.isInitialized();
16
+ if (isInitialized) {
17
+ return this._api;
18
+ }
19
+ else {
20
+ throw Error('worker is not yet initialized. make sure to call the .set() function, first');
21
+ }
22
+ };
23
+ this.clone = (numOfTimes) => {
24
+ const workers = [];
25
+ for (let i = 0; i <= numOfTimes; i++) {
26
+ const code = this._code;
27
+ const { worker, api } = (0, builder_1.buildNodeApiAndWorkerFromCode)(code);
28
+ workers.push(new NodeOmniWorker(code, worker, api));
29
+ }
30
+ return workers;
31
+ };
32
+ this.destroy = async () => {
33
+ await this._worker.terminate();
34
+ };
35
+ this._code = code;
36
+ this._worker = worker;
37
+ this._api = api;
38
+ return this;
39
+ }
40
+ /**
41
+ * Build the OmniWorker from a worker file. Please note that the functions
42
+ * on the worker file need to first be exposed using the expose({ <functions> })
43
+ * functions, in order to start this build step.
44
+ *
45
+ * @param path The relative path to where the worker module is located
46
+ * @returns A new Node OmniWorker
47
+ */
48
+ static async build(path) {
49
+ const code = await (0, builder_1.genWorkerCodeFromFile)(path);
50
+ const { worker, api } = (0, builder_1.buildNodeApiAndWorkerFromCode)(code);
51
+ return new NodeOmniWorker(code, worker, api);
52
+ }
53
+ }
54
+ exports.NodeOmniWorker = NodeOmniWorker;
55
+ /**
56
+ * Expose the functions inside the worker to the rest of the application.
57
+ * After having exposed the functions, the build step can be initiated.
58
+ * @param functions An object with functions inside the worker to be exposed to
59
+ * the rest of the application.
60
+ */
61
+ NodeOmniWorker.expose = (functions) => {
62
+ if (worker_threads_1.parentPort) {
63
+ comlink_1.default.expose(functions, (0, node_adapter_1.default)(worker_threads_1.parentPort));
64
+ }
65
+ };
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":";;;;;;AACA,mDAAoD;AACpD,sDAA8B;AAC9B,iFAAyD;AACzD,uCAAiF;AAGjF,MAAa,cAAc;IAKzB,YACE,IAAY,EACZ,MAAc,EACd,GAA4B;QAoCvB,kBAAa,GAAG,GAAY,EAAE,CAAC,CACpC,IAAI,CAAC,IAAI,KAAK,SAAS,CACxB,CAAC;QAEK,QAAG,GAAG,GAAG,EAAE;YAChB,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YAC3C,IAAI,aAAa,EAAE,CAAC;gBAClB,OAAO,IAAI,CAAC,IAAK,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,CAAC,6EAA6E,CAAC,CAAC;YAC7F,CAAC;QACH,CAAC,CAAA;QAEM,UAAK,GAAG,CAAC,UAAkB,EAAE,EAAE;YACpC,MAAM,OAAO,GAAwB,EAAE,CAAC;YACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;gBACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;gBACxB,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,uCAA6B,EAAI,IAAI,CAAC,CAAC;gBAC/D,OAAO,CAAC,IAAI,CAAC,IAAI,cAAc,CAAI,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;YACzD,CA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