@teambit/worker 0.0.1143 → 0.0.1144
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/dist/harmony-worker.d.ts +5 -5
- package/dist/harmony-worker.js +3 -6
- package/dist/harmony-worker.js.map +1 -1
- package/dist/{preview-1703505948637.js → preview-1703647408454.js} +2 -2
- package/dist/worker.composition.d.ts +2 -2
- package/dist/worker.main.runtime.d.ts +3 -3
- package/expose.ts +27 -0
- package/harmony-worker.ts +72 -0
- package/index.ts +10 -0
- package/node-endpoint.ts +28 -0
- package/package.json +12 -19
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
- package/worker-manifest.ts +6 -0
- package/worker.aspect.ts +5 -0
- package/worker.main.runtime.ts +62 -0
package/dist/harmony-worker.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Remote } from 'comlink';
|
|
3
|
-
export
|
|
3
|
+
export type InitOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Determines whether stdout should be piped into the parent process.
|
|
6
6
|
* If this is set to true, then worker.stdout is NOT automatically piped through to process.stdout in the parent.
|
|
@@ -24,11 +24,11 @@ export declare class HarmonyWorker<T> {
|
|
|
24
24
|
constructor(name: string, workerPath: string);
|
|
25
25
|
private remoteWorker;
|
|
26
26
|
private worker;
|
|
27
|
-
get stdout(): import("stream").Readable
|
|
28
|
-
get stderr(): import("stream").Readable
|
|
29
|
-
get stdin(): import("stream").Writable
|
|
27
|
+
get stdout(): import("stream").Readable;
|
|
28
|
+
get stderr(): import("stream").Readable;
|
|
29
|
+
get stdin(): import("stream").Writable;
|
|
30
30
|
private getOptions;
|
|
31
31
|
initiate(options: Partial<InitOptions>): Remote<T>;
|
|
32
|
-
get(): Remote<T
|
|
32
|
+
get(): Remote<T>;
|
|
33
33
|
terminate(): Promise<void>;
|
|
34
34
|
}
|
package/dist/harmony-worker.js
CHANGED
|
@@ -37,16 +37,13 @@ class HarmonyWorker {
|
|
|
37
37
|
_defineProperty(this, "worker", void 0);
|
|
38
38
|
}
|
|
39
39
|
get stdout() {
|
|
40
|
-
|
|
41
|
-
return (_this$worker = this.worker) === null || _this$worker === void 0 ? void 0 : _this$worker.stdout;
|
|
40
|
+
return this.worker?.stdout;
|
|
42
41
|
}
|
|
43
42
|
get stderr() {
|
|
44
|
-
|
|
45
|
-
return (_this$worker2 = this.worker) === null || _this$worker2 === void 0 ? void 0 : _this$worker2.stderr;
|
|
43
|
+
return this.worker?.stderr;
|
|
46
44
|
}
|
|
47
45
|
get stdin() {
|
|
48
|
-
|
|
49
|
-
return (_this$worker3 = this.worker) === null || _this$worker3 === void 0 ? void 0 : _this$worker3.stdin;
|
|
46
|
+
return this.worker?.stdin;
|
|
50
47
|
}
|
|
51
48
|
getOptions(targetOptions) {
|
|
52
49
|
const defaultOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_worker_threads","data","require","_comlink","_nodeEndpoint","_interopRequireDefault","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","HarmonyWorker","constructor","name","workerPath","stdout","
|
|
1
|
+
{"version":3,"names":["_worker_threads","data","require","_comlink","_nodeEndpoint","_interopRequireDefault","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","HarmonyWorker","constructor","name","workerPath","stdout","worker","stderr","stdin","getOptions","targetOptions","defaultOptions","assign","initiate","options","Worker","remoteWorker","wrap","nodeEndpoint","get","terminate","exports"],"sources":["harmony-worker.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unresolved\nimport { Worker } from 'worker_threads';\nimport { wrap, Remote } from 'comlink';\nimport nodeEndpoint from './node-endpoint';\n\nexport type InitOptions = {\n /**\n * Determines whether stdout should be piped into the parent process.\n * If this is set to true, then worker.stdout is NOT automatically piped through to process.stdout in the parent.\n */\n stdout: boolean;\n\n /**\n * Determines whether stderr should be piped into the parent process.\n * If this is set to true, then worker.stderr is NOT automatically piped through to process.stderr in the parent.\n */\n stderr: boolean;\n\n /**\n * Determines whether stdin should be piped into the parent process.\n * If this is set to true, then worker.stdin provides a writable stream whose contents appear as process.stdin inside\n * the Worker. By default, no data is provided.\n */\n stdin: boolean;\n};\n\nexport class HarmonyWorker<T> {\n constructor(readonly name: string, readonly workerPath: string) {}\n\n private remoteWorker: undefined | Remote<T>;\n\n private worker: Worker | undefined;\n\n get stdout() {\n return this.worker?.stdout;\n }\n\n get stderr() {\n return this.worker?.stderr;\n }\n\n get stdin() {\n return this.worker?.stdin;\n }\n\n private getOptions(targetOptions: Partial<InitOptions>) {\n const defaultOptions = {\n stdout: true,\n stderr: true,\n stdin: true,\n };\n\n return Object.assign(defaultOptions, targetOptions);\n }\n\n initiate(options: Partial<InitOptions>): Remote<T> {\n const worker = new Worker(this.workerPath, this.getOptions(options));\n this.worker = worker;\n const remoteWorker = wrap<T>(nodeEndpoint(worker));\n this.remoteWorker = remoteWorker;\n return remoteWorker;\n }\n\n get() {\n return this.remoteWorker;\n }\n\n async terminate() {\n if (!this.worker) return;\n await this.worker.terminate();\n }\n}\n"],"mappings":"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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_worker@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_worker@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_worker@0.0.1144/dist/worker.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_worker@0.0.1144/dist/worker.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const Logo: () =>
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const Logo: () => JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SlotRegistry } from '@teambit/harmony';
|
|
2
2
|
import { HarmonyWorker } from './harmony-worker';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export type WorkerSlot = SlotRegistry<HarmonyWorker<unknown>>;
|
|
4
|
+
export type WorkerNameSlot = SlotRegistry<string>;
|
|
5
5
|
export declare class WorkerMain {
|
|
6
6
|
private workerSlot;
|
|
7
7
|
private workerNameSlot;
|
|
@@ -14,6 +14,6 @@ export declare class WorkerMain {
|
|
|
14
14
|
declareWorker<T>(name: string, path: string): HarmonyWorker<T>;
|
|
15
15
|
getWorker<T>(id: string): HarmonyWorker<T>;
|
|
16
16
|
static slots: (((registerFn: () => string) => SlotRegistry<HarmonyWorker<unknown>>) | ((registerFn: () => string) => SlotRegistry<string>))[];
|
|
17
|
-
static dependencies:
|
|
17
|
+
static dependencies: any[];
|
|
18
18
|
static provider(_deps: any, _config: any, [workerSlot, workerNameSlot]: [WorkerSlot, WorkerNameSlot]): Promise<WorkerMain>;
|
|
19
19
|
}
|
package/expose.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-unresolved
|
|
2
|
+
import { parentPort, MessageChannel } from 'worker_threads';
|
|
3
|
+
import { expose as comlinkExpose, proxyMarker, wrap, transferHandlers } from 'comlink';
|
|
4
|
+
import nodeEndpoint from './node-endpoint';
|
|
5
|
+
|
|
6
|
+
export function setFunctionHandlers() {
|
|
7
|
+
// Override comlink's default proxy handler to use Node endpoints
|
|
8
|
+
transferHandlers.set('proxy', {
|
|
9
|
+
canHandle: (obj) => obj && obj[proxyMarker],
|
|
10
|
+
serialize: (obj) => {
|
|
11
|
+
const { port1, port2 } = new MessageChannel();
|
|
12
|
+
comlinkExpose(obj, nodeEndpoint(port1));
|
|
13
|
+
return [port2, [port2]];
|
|
14
|
+
},
|
|
15
|
+
deserialize: (port: any) => {
|
|
16
|
+
port = nodeEndpoint(port);
|
|
17
|
+
port.start();
|
|
18
|
+
return wrap(port);
|
|
19
|
+
},
|
|
20
|
+
} as any);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setFunctionHandlers();
|
|
24
|
+
|
|
25
|
+
export function expose(object: any) {
|
|
26
|
+
return comlinkExpose(object, nodeEndpoint(parentPort));
|
|
27
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-unresolved
|
|
2
|
+
import { Worker } from 'worker_threads';
|
|
3
|
+
import { wrap, Remote } from 'comlink';
|
|
4
|
+
import nodeEndpoint from './node-endpoint';
|
|
5
|
+
|
|
6
|
+
export type InitOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Determines whether stdout should be piped into the parent process.
|
|
9
|
+
* If this is set to true, then worker.stdout is NOT automatically piped through to process.stdout in the parent.
|
|
10
|
+
*/
|
|
11
|
+
stdout: boolean;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Determines whether stderr should be piped into the parent process.
|
|
15
|
+
* If this is set to true, then worker.stderr is NOT automatically piped through to process.stderr in the parent.
|
|
16
|
+
*/
|
|
17
|
+
stderr: boolean;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Determines whether stdin should be piped into the parent process.
|
|
21
|
+
* If this is set to true, then worker.stdin provides a writable stream whose contents appear as process.stdin inside
|
|
22
|
+
* the Worker. By default, no data is provided.
|
|
23
|
+
*/
|
|
24
|
+
stdin: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export class HarmonyWorker<T> {
|
|
28
|
+
constructor(readonly name: string, readonly workerPath: string) {}
|
|
29
|
+
|
|
30
|
+
private remoteWorker: undefined | Remote<T>;
|
|
31
|
+
|
|
32
|
+
private worker: Worker | undefined;
|
|
33
|
+
|
|
34
|
+
get stdout() {
|
|
35
|
+
return this.worker?.stdout;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get stderr() {
|
|
39
|
+
return this.worker?.stderr;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get stdin() {
|
|
43
|
+
return this.worker?.stdin;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private getOptions(targetOptions: Partial<InitOptions>) {
|
|
47
|
+
const defaultOptions = {
|
|
48
|
+
stdout: true,
|
|
49
|
+
stderr: true,
|
|
50
|
+
stdin: true,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return Object.assign(defaultOptions, targetOptions);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
initiate(options: Partial<InitOptions>): Remote<T> {
|
|
57
|
+
const worker = new Worker(this.workerPath, this.getOptions(options));
|
|
58
|
+
this.worker = worker;
|
|
59
|
+
const remoteWorker = wrap<T>(nodeEndpoint(worker));
|
|
60
|
+
this.remoteWorker = remoteWorker;
|
|
61
|
+
return remoteWorker;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get() {
|
|
65
|
+
return this.remoteWorker;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async terminate() {
|
|
69
|
+
if (!this.worker) return;
|
|
70
|
+
await this.worker.terminate();
|
|
71
|
+
}
|
|
72
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WorkerAspect } from './worker.aspect';
|
|
2
|
+
import { setFunctionHandlers } from './expose';
|
|
3
|
+
|
|
4
|
+
setFunctionHandlers();
|
|
5
|
+
|
|
6
|
+
export { WorkerAspect };
|
|
7
|
+
export type { WorkerMain } from './worker.main.runtime';
|
|
8
|
+
export type { HarmonyWorker } from './harmony-worker';
|
|
9
|
+
export { expose } from './expose';
|
|
10
|
+
export default WorkerAspect;
|
package/node-endpoint.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function nodeEndpoint(nep) {
|
|
2
|
+
const listeners = new WeakMap();
|
|
3
|
+
return {
|
|
4
|
+
postMessage: nep.postMessage.bind(nep),
|
|
5
|
+
addEventListener: (_, eh) => {
|
|
6
|
+
const l = (data) => {
|
|
7
|
+
if ('handleEvent' in eh) {
|
|
8
|
+
eh.handleEvent({ data });
|
|
9
|
+
} else {
|
|
10
|
+
eh({ data });
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
nep.on('message', l);
|
|
14
|
+
listeners.set(eh, l);
|
|
15
|
+
},
|
|
16
|
+
removeEventListener: (_, eh) => {
|
|
17
|
+
const l = listeners.get(eh);
|
|
18
|
+
if (!l) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
nep.off('message', l);
|
|
22
|
+
listeners.delete(eh);
|
|
23
|
+
},
|
|
24
|
+
start: nep.start && nep.start.bind(nep),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default nodeEndpoint;
|
package/package.json
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/worker",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1144",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/harmony/worker",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.harmony",
|
|
8
8
|
"name": "worker",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.1144"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"comlink": "4.3.0",
|
|
13
|
-
"core-js": "^3.0.0",
|
|
14
|
-
"@babel/runtime": "7.20.0",
|
|
15
13
|
"@teambit/harmony": "0.4.6",
|
|
16
|
-
"@teambit/cli": "0.0.
|
|
14
|
+
"@teambit/cli": "0.0.840"
|
|
17
15
|
},
|
|
18
16
|
"devDependencies": {
|
|
19
|
-
"@types/react": "^17.0.8",
|
|
20
17
|
"@types/mocha": "9.1.0",
|
|
21
|
-
"@types/
|
|
22
|
-
"@types/
|
|
23
|
-
"@
|
|
24
|
-
"@types/testing-library__jest-dom": "5.9.5"
|
|
18
|
+
"@types/jest": "^29.2.2",
|
|
19
|
+
"@types/testing-library__jest-dom": "^5.9.5",
|
|
20
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.13"
|
|
25
21
|
},
|
|
26
22
|
"peerDependencies": {
|
|
27
|
-
"
|
|
28
|
-
"react": "^
|
|
29
|
-
"
|
|
23
|
+
"react": "^17.0.0 || ^18.0.0",
|
|
24
|
+
"@types/react": "^18.2.12",
|
|
25
|
+
"@teambit/legacy": "1.0.624"
|
|
30
26
|
},
|
|
31
27
|
"license": "Apache-2.0",
|
|
32
28
|
"optionalDependencies": {},
|
|
@@ -40,7 +36,7 @@
|
|
|
40
36
|
},
|
|
41
37
|
"private": false,
|
|
42
38
|
"engines": {
|
|
43
|
-
"node": ">=
|
|
39
|
+
"node": ">=16.0.0"
|
|
44
40
|
},
|
|
45
41
|
"repository": {
|
|
46
42
|
"type": "git",
|
|
@@ -49,12 +45,9 @@
|
|
|
49
45
|
"keywords": [
|
|
50
46
|
"bit",
|
|
51
47
|
"bit-aspect",
|
|
48
|
+
"bit-core-aspect",
|
|
52
49
|
"components",
|
|
53
50
|
"collaboration",
|
|
54
|
-
"web"
|
|
55
|
-
"react",
|
|
56
|
-
"react-components",
|
|
57
|
-
"angular",
|
|
58
|
-
"angular-components"
|
|
51
|
+
"web"
|
|
59
52
|
]
|
|
60
53
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"lib": [
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"DOM.Iterable",
|
|
8
|
-
"ScriptHost"
|
|
4
|
+
"esnext",
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.Iterable"
|
|
9
7
|
],
|
|
10
|
-
"target": "
|
|
11
|
-
"module": "
|
|
12
|
-
"jsx": "react",
|
|
13
|
-
"allowJs": true,
|
|
14
|
-
"composite": true,
|
|
8
|
+
"target": "es2020",
|
|
9
|
+
"module": "es2020",
|
|
10
|
+
"jsx": "react-jsx",
|
|
15
11
|
"declaration": true,
|
|
16
12
|
"sourceMap": true,
|
|
17
|
-
"skipLibCheck": true,
|
|
18
13
|
"experimentalDecorators": true,
|
|
19
|
-
"
|
|
14
|
+
"skipLibCheck": true,
|
|
20
15
|
"moduleResolution": "node",
|
|
21
16
|
"esModuleInterop": true,
|
|
22
|
-
"rootDir": ".",
|
|
23
17
|
"resolveJsonModule": true,
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"strictPropertyInitialization": false,
|
|
28
|
-
"strict": true,
|
|
29
|
-
"noImplicitAny": false,
|
|
30
|
-
"preserveConstEnums": true
|
|
18
|
+
"allowJs": true,
|
|
19
|
+
"outDir": "dist",
|
|
20
|
+
"emitDeclarationOnly": true
|
|
31
21
|
},
|
|
32
22
|
"exclude": [
|
|
23
|
+
"artifacts",
|
|
24
|
+
"public",
|
|
33
25
|
"dist",
|
|
26
|
+
"node_modules",
|
|
27
|
+
"package.json",
|
|
34
28
|
"esm.mjs",
|
|
35
|
-
"
|
|
29
|
+
"**/*.cjs",
|
|
30
|
+
"./dist"
|
|
36
31
|
],
|
|
37
32
|
"include": [
|
|
38
33
|
"**/*",
|
package/types/asset.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ declare module '*.png' {
|
|
|
5
5
|
declare module '*.svg' {
|
|
6
6
|
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
7
|
|
|
8
|
-
export const ReactComponent: FunctionComponent<
|
|
8
|
+
export const ReactComponent: FunctionComponent<
|
|
9
|
+
SVGProps<SVGSVGElement> & { title?: string }
|
|
10
|
+
>;
|
|
9
11
|
const src: string;
|
|
10
12
|
export default src;
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
// @TODO Gilad
|
|
14
14
|
declare module '*.jpg' {
|
|
15
15
|
const value: any;
|
|
16
16
|
export = value;
|
|
@@ -27,3 +27,15 @@ declare module '*.bmp' {
|
|
|
27
27
|
const value: any;
|
|
28
28
|
export = value;
|
|
29
29
|
}
|
|
30
|
+
declare module '*.otf' {
|
|
31
|
+
const value: any;
|
|
32
|
+
export = value;
|
|
33
|
+
}
|
|
34
|
+
declare module '*.woff' {
|
|
35
|
+
const value: any;
|
|
36
|
+
export = value;
|
|
37
|
+
}
|
|
38
|
+
declare module '*.woff2' {
|
|
39
|
+
const value: any;
|
|
40
|
+
export = value;
|
|
41
|
+
}
|
package/worker.aspect.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { MainRuntime } from '@teambit/cli';
|
|
2
|
+
import { Slot, SlotRegistry } from '@teambit/harmony';
|
|
3
|
+
import { WorkerAspect } from './worker.aspect';
|
|
4
|
+
import { HarmonyWorker } from './harmony-worker';
|
|
5
|
+
|
|
6
|
+
export type WorkerSlot = SlotRegistry<HarmonyWorker<unknown>>;
|
|
7
|
+
|
|
8
|
+
export type WorkerNameSlot = SlotRegistry<string>;
|
|
9
|
+
|
|
10
|
+
export class WorkerMain {
|
|
11
|
+
constructor(private workerSlot: WorkerSlot, private workerNameSlot: WorkerNameSlot) {}
|
|
12
|
+
|
|
13
|
+
static runtime = MainRuntime;
|
|
14
|
+
|
|
15
|
+
listWorkers(): HarmonyWorker<any>[] {
|
|
16
|
+
return this.workerSlot.values();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* create a new worker.
|
|
21
|
+
*/
|
|
22
|
+
declareWorker<T>(name: string, path: string): HarmonyWorker<T> {
|
|
23
|
+
this.workerNameSlot.register(name);
|
|
24
|
+
|
|
25
|
+
const maybeAspectId = this.workerNameSlot.toArray().find(([, workerName]) => {
|
|
26
|
+
return workerName === name;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (!maybeAspectId) throw new Error(`could not create a worker ${name}`);
|
|
30
|
+
// const scriptPath = path || await this.resolveWorkerScript(name, aspectId);
|
|
31
|
+
const scriptPath = path;
|
|
32
|
+
const systemWorker = new HarmonyWorker<T>(name, scriptPath);
|
|
33
|
+
this.workerSlot.register(systemWorker);
|
|
34
|
+
|
|
35
|
+
return systemWorker;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// private async resolveWorkerScript(name: string, aspectId: string): Promise<string> {
|
|
39
|
+
// const host = this.componentAspect.getHost();
|
|
40
|
+
// const id = await host.resolveComponentId(aspectId);
|
|
41
|
+
// const component = await host.get(id);
|
|
42
|
+
// if (!component) throw new Error(`[worker] could not resolve component for aspect ID: ${aspectId}`);
|
|
43
|
+
// const packageName = this.pkg.getPackageName(component);
|
|
44
|
+
// // const workerFile = component.state.filesystem.files.find((file) => file.relative.includes(`${name}.worker`));
|
|
45
|
+
// // if (!workerFile) throw new Error(`[worker] aspect declaring a worker must contain a ${name}.worker. file`);
|
|
46
|
+
// return require.resolve(join(packageName, 'dist', `${name}.worker.js`));
|
|
47
|
+
// }
|
|
48
|
+
|
|
49
|
+
getWorker<T>(id: string): HarmonyWorker<T> {
|
|
50
|
+
return this.workerSlot.get(id) as HarmonyWorker<T>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static slots = [Slot.withType<HarmonyWorker<unknown>>(), Slot.withType<string>()];
|
|
54
|
+
|
|
55
|
+
static dependencies = [];
|
|
56
|
+
|
|
57
|
+
static async provider(_deps, _config, [workerSlot, workerNameSlot]: [WorkerSlot, WorkerNameSlot]) {
|
|
58
|
+
return new WorkerMain(workerSlot, workerNameSlot);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
WorkerAspect.addRuntime(WorkerMain);
|