@teambit/worker 0.0.881 → 0.0.882

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/expose.js CHANGED
@@ -1,44 +1,34 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.expose = expose;
9
8
  exports.setFunctionHandlers = setFunctionHandlers;
10
-
11
9
  function _worker_threads() {
12
10
  const data = require("worker_threads");
13
-
14
11
  _worker_threads = function () {
15
12
  return data;
16
13
  };
17
-
18
14
  return data;
19
15
  }
20
-
21
16
  function _comlink() {
22
17
  const data = require("comlink");
23
-
24
18
  _comlink = function () {
25
19
  return data;
26
20
  };
27
-
28
21
  return data;
29
22
  }
30
-
31
23
  function _nodeEndpoint() {
32
24
  const data = _interopRequireDefault(require("./node-endpoint"));
33
-
34
25
  _nodeEndpoint = function () {
35
26
  return data;
36
27
  };
37
-
38
28
  return data;
39
29
  }
40
-
41
30
  // eslint-disable-next-line import/no-unresolved
31
+
42
32
  function setFunctionHandlers() {
43
33
  // Override comlink's default proxy handler to use Node endpoints
44
34
  _comlink().transferHandlers.set('proxy', {
@@ -58,9 +48,7 @@ function setFunctionHandlers() {
58
48
  }
59
49
  });
60
50
  }
61
-
62
51
  setFunctionHandlers();
63
-
64
52
  function expose(object) {
65
53
  return (0, _comlink().expose)(object, (0, _nodeEndpoint().default)(_worker_threads().parentPort));
66
54
  }
@@ -1 +1 @@
1
- {"version":3,"names":["setFunctionHandlers","transferHandlers","set","canHandle","obj","proxyMarker","serialize","port1","port2","MessageChannel","comlinkExpose","nodeEndpoint","deserialize","port","start","wrap","expose","object","parentPort"],"sources":["expose.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unresolved\nimport { parentPort, MessageChannel } from 'worker_threads';\nimport { expose as comlinkExpose, proxyMarker, wrap, transferHandlers } from 'comlink';\nimport nodeEndpoint from './node-endpoint';\n\nexport function setFunctionHandlers() {\n // Override comlink's default proxy handler to use Node endpoints\n transferHandlers.set('proxy', {\n canHandle: (obj) => obj && obj[proxyMarker],\n serialize: (obj) => {\n const { port1, port2 } = new MessageChannel();\n comlinkExpose(obj, nodeEndpoint(port1));\n return [port2, [port2]];\n },\n deserialize: (port: any) => {\n port = nodeEndpoint(port);\n port.start();\n return wrap(port);\n },\n } as any);\n}\n\nsetFunctionHandlers();\n\nexport function expose(object: any) {\n return comlinkExpose(object, nodeEndpoint(parentPort));\n}\n"],"mappings":";;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAHA;AAKO,SAASA,mBAAT,GAA+B;EACpC;EACAC,2BAAA,CAAiBC,GAAjB,CAAqB,OAArB,EAA8B;IAC5BC,SAAS,EAAGC,GAAD,IAASA,GAAG,IAAIA,GAAG,CAACC,sBAAD,CADF;IAE5BC,SAAS,EAAGF,GAAD,IAAS;MAClB,MAAM;QAAEG,KAAF;QAASC;MAAT,IAAmB,KAAIC,gCAAJ,GAAzB;MACA,IAAAC,iBAAA,EAAcN,GAAd,EAAmB,IAAAO,uBAAA,EAAaJ,KAAb,CAAnB;MACA,OAAO,CAACC,KAAD,EAAQ,CAACA,KAAD,CAAR,CAAP;IACD,CAN2B;IAO5BI,WAAW,EAAGC,IAAD,IAAe;MAC1BA,IAAI,GAAG,IAAAF,uBAAA,EAAaE,IAAb,CAAP;MACAA,IAAI,CAACC,KAAL;MACA,OAAO,IAAAC,eAAA,EAAKF,IAAL,CAAP;IACD;EAX2B,CAA9B;AAaD;;AAEDb,mBAAmB;;AAEZ,SAASgB,MAAT,CAAgBC,MAAhB,EAA6B;EAClC,OAAO,IAAAP,iBAAA,EAAcO,MAAd,EAAsB,IAAAN,uBAAA,EAAaO,4BAAb,CAAtB,CAAP;AACD"}
1
+ {"version":3,"names":["setFunctionHandlers","transferHandlers","set","canHandle","obj","proxyMarker","serialize","port1","port2","MessageChannel","comlinkExpose","nodeEndpoint","deserialize","port","start","wrap","expose","object","parentPort"],"sources":["expose.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unresolved\nimport { parentPort, MessageChannel } from 'worker_threads';\nimport { expose as comlinkExpose, proxyMarker, wrap, transferHandlers } from 'comlink';\nimport nodeEndpoint from './node-endpoint';\n\nexport function setFunctionHandlers() {\n // Override comlink's default proxy handler to use Node endpoints\n transferHandlers.set('proxy', {\n canHandle: (obj) => obj && obj[proxyMarker],\n serialize: (obj) => {\n const { port1, port2 } = new MessageChannel();\n comlinkExpose(obj, nodeEndpoint(port1));\n return [port2, [port2]];\n },\n deserialize: (port: any) => {\n port = nodeEndpoint(port);\n port.start();\n return wrap(port);\n },\n } as any);\n}\n\nsetFunctionHandlers();\n\nexport function expose(object: any) {\n return comlinkExpose(object, nodeEndpoint(parentPort));\n}\n"],"mappings":";;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAHA;;AAKO,SAASA,mBAAmB,GAAG;EACpC;EACAC,2BAAgB,CAACC,GAAG,CAAC,OAAO,EAAE;IAC5BC,SAAS,EAAGC,GAAG,IAAKA,GAAG,IAAIA,GAAG,CAACC,sBAAW,CAAC;IAC3CC,SAAS,EAAGF,GAAG,IAAK;MAClB,MAAM;QAAEG,KAAK;QAAEC;MAAM,CAAC,GAAG,KAAIC,gCAAc,GAAE;MAC7C,IAAAC,iBAAa,EAACN,GAAG,EAAE,IAAAO,uBAAY,EAACJ,KAAK,CAAC,CAAC;MACvC,OAAO,CAACC,KAAK,EAAE,CAACA,KAAK,CAAC,CAAC;IACzB,CAAC;IACDI,WAAW,EAAGC,IAAS,IAAK;MAC1BA,IAAI,GAAG,IAAAF,uBAAY,EAACE,IAAI,CAAC;MACzBA,IAAI,CAACC,KAAK,EAAE;MACZ,OAAO,IAAAC,eAAI,EAACF,IAAI,CAAC;IACnB;EACF,CAAC,CAAQ;AACX;AAEAb,mBAAmB,EAAE;AAEd,SAASgB,MAAM,CAACC,MAAW,EAAE;EAClC,OAAO,IAAAP,iBAAa,EAACO,MAAM,EAAE,IAAAN,uBAAY,EAACO,4BAAU,CAAC,CAAC;AACxD"}
@@ -1,55 +1,41 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  require("core-js/modules/es.promise.js");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports.HarmonyWorker = void 0;
11
-
12
9
  function _defineProperty2() {
13
10
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
-
15
11
  _defineProperty2 = function () {
16
12
  return data;
17
13
  };
18
-
19
14
  return data;
20
15
  }
21
-
22
16
  function _worker_threads() {
23
17
  const data = require("worker_threads");
24
-
25
18
  _worker_threads = function () {
26
19
  return data;
27
20
  };
28
-
29
21
  return data;
30
22
  }
31
-
32
23
  function _comlink() {
33
24
  const data = require("comlink");
34
-
35
25
  _comlink = function () {
36
26
  return data;
37
27
  };
38
-
39
28
  return data;
40
29
  }
41
-
42
30
  function _nodeEndpoint() {
43
31
  const data = _interopRequireDefault(require("./node-endpoint"));
44
-
45
32
  _nodeEndpoint = function () {
46
33
  return data;
47
34
  };
48
-
49
35
  return data;
50
36
  }
51
-
52
37
  // eslint-disable-next-line import/no-unresolved
38
+
53
39
  class HarmonyWorker {
54
40
  constructor(name, workerPath) {
55
41
  this.name = name;
@@ -57,25 +43,18 @@ class HarmonyWorker {
57
43
  (0, _defineProperty2().default)(this, "remoteWorker", void 0);
58
44
  (0, _defineProperty2().default)(this, "worker", void 0);
59
45
  }
60
-
61
46
  get stdout() {
62
47
  var _this$worker;
63
-
64
48
  return (_this$worker = this.worker) === null || _this$worker === void 0 ? void 0 : _this$worker.stdout;
65
49
  }
66
-
67
50
  get stderr() {
68
51
  var _this$worker2;
69
-
70
52
  return (_this$worker2 = this.worker) === null || _this$worker2 === void 0 ? void 0 : _this$worker2.stderr;
71
53
  }
72
-
73
54
  get stdin() {
74
55
  var _this$worker3;
75
-
76
56
  return (_this$worker3 = this.worker) === null || _this$worker3 === void 0 ? void 0 : _this$worker3.stdin;
77
57
  }
78
-
79
58
  getOptions(targetOptions) {
80
59
  const defaultOptions = {
81
60
  stdout: true,
@@ -84,7 +63,6 @@ class HarmonyWorker {
84
63
  };
85
64
  return Object.assign(defaultOptions, targetOptions);
86
65
  }
87
-
88
66
  initiate(options) {
89
67
  const worker = new (_worker_threads().Worker)(this.workerPath, this.getOptions(options));
90
68
  this.worker = worker;
@@ -92,18 +70,14 @@ class HarmonyWorker {
92
70
  this.remoteWorker = remoteWorker;
93
71
  return remoteWorker;
94
72
  }
95
-
96
73
  get() {
97
74
  return this.remoteWorker;
98
75
  }
99
-
100
76
  async terminate() {
101
77
  if (!this.worker) return;
102
78
  await this.worker.terminate();
103
79
  }
104
-
105
80
  }
106
-
107
81
  exports.HarmonyWorker = HarmonyWorker;
108
82
 
109
83
  //# sourceMappingURL=harmony-worker.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["HarmonyWorker","constructor","name","workerPath","stdout","worker","stderr","stdin","getOptions","targetOptions","defaultOptions","Object","assign","initiate","options","Worker","remoteWorker","wrap","nodeEndpoint","get","terminate"],"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":";;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAHA;AA0BO,MAAMA,aAAN,CAAuB;EAC5BC,WAAW,CAAUC,IAAV,EAAiCC,UAAjC,EAAqD;IAAA,KAA3CD,IAA2C,GAA3CA,IAA2C;IAAA,KAApBC,UAAoB,GAApBA,UAAoB;IAAA;IAAA;EAAE;;EAMxD,IAANC,MAAM,GAAG;IAAA;;IACX,uBAAO,KAAKC,MAAZ,iDAAO,aAAaD,MAApB;EACD;;EAES,IAANE,MAAM,GAAG;IAAA;;IACX,wBAAO,KAAKD,MAAZ,kDAAO,cAAaC,MAApB;EACD;;EAEQ,IAALC,KAAK,GAAG;IAAA;;IACV,wBAAO,KAAKF,MAAZ,kDAAO,cAAaE,KAApB;EACD;;EAEOC,UAAU,CAACC,aAAD,EAAsC;IACtD,MAAMC,cAAc,GAAG;MACrBN,MAAM,EAAE,IADa;MAErBE,MAAM,EAAE,IAFa;MAGrBC,KAAK,EAAE;IAHc,CAAvB;IAMA,OAAOI,MAAM,CAACC,MAAP,CAAcF,cAAd,EAA8BD,aAA9B,CAAP;EACD;;EAEDI,QAAQ,CAACC,OAAD,EAA2C;IACjD,MAAMT,MAAM,GAAG,KAAIU,wBAAJ,EAAW,KAAKZ,UAAhB,EAA4B,KAAKK,UAAL,CAAgBM,OAAhB,CAA5B,CAAf;IACA,KAAKT,MAAL,GAAcA,MAAd;IACA,MAAMW,YAAY,GAAG,IAAAC,eAAA,EAAQ,IAAAC,uBAAA,EAAab,MAAb,CAAR,CAArB;IACA,KAAKW,YAAL,GAAoBA,YAApB;IACA,OAAOA,YAAP;EACD;;EAEDG,GAAG,GAAG;IACJ,OAAO,KAAKH,YAAZ;EACD;;EAEc,MAATI,SAAS,GAAG;IAChB,IAAI,CAAC,KAAKf,MAAV,EAAkB;IAClB,MAAM,KAAKA,MAAL,CAAYe,SAAZ,EAAN;EACD;;AA5C2B"}
1
+ {"version":3,"names":["HarmonyWorker","constructor","name","workerPath","stdout","worker","stderr","stdin","getOptions","targetOptions","defaultOptions","Object","assign","initiate","options","Worker","remoteWorker","wrap","nodeEndpoint","get","terminate"],"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":";;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAHA;;AA0BO,MAAMA,aAAa,CAAI;EAC5BC,WAAW,CAAUC,IAAY,EAAWC,UAAkB,EAAE;IAAA,KAA3CD,IAAY,GAAZA,IAAY;IAAA,KAAWC,UAAkB,GAAlBA,UAAkB;IAAA;IAAA;EAAG;EAMjE,IAAIC,MAAM,GAAG;IAAA;IACX,uBAAO,IAAI,CAACC,MAAM,iDAAX,aAAaD,MAAM;EAC5B;EAEA,IAAIE,MAAM,GAAG;IAAA;IACX,wBAAO,IAAI,CAACD,MAAM,kDAAX,cAAaC,MAAM;EAC5B;EAEA,IAAIC,KAAK,GAAG;IAAA;IACV,wBAAO,IAAI,CAACF,MAAM,kDAAX,cAAaE,KAAK;EAC3B;EAEQC,UAAU,CAACC,aAAmC,EAAE;IACtD,MAAMC,cAAc,GAAG;MACrBN,MAAM,EAAE,IAAI;MACZE,MAAM,EAAE,IAAI;MACZC,KAAK,EAAE;IACT,CAAC;IAED,OAAOI,MAAM,CAACC,MAAM,CAACF,cAAc,EAAED,aAAa,CAAC;EACrD;EAEAI,QAAQ,CAACC,OAA6B,EAAa;IACjD,MAAMT,MAAM,GAAG,KAAIU,wBAAM,EAAC,IAAI,CAACZ,UAAU,EAAE,IAAI,CAACK,UAAU,CAACM,OAAO,CAAC,CAAC;IACpE,IAAI,CAACT,MAAM,GAAGA,MAAM;IACpB,MAAMW,YAAY,GAAG,IAAAC,eAAI,EAAI,IAAAC,uBAAY,EAACb,MAAM,CAAC,CAAC;IAClD,IAAI,CAACW,YAAY,GAAGA,YAAY;IAChC,OAAOA,YAAY;EACrB;EAEAG,GAAG,GAAG;IACJ,OAAO,IAAI,CAACH,YAAY;EAC1B;EAEA,MAAMI,SAAS,GAAG;IAChB,IAAI,CAAC,IAAI,CAACf,MAAM,EAAE;IAClB,MAAM,IAAI,CAACA,MAAM,CAACe,SAAS,EAAE;EAC/B;AACF;AAAC"}
package/dist/index.js CHANGED
@@ -16,31 +16,22 @@ Object.defineProperty(exports, "expose", {
16
16
  return _expose().expose;
17
17
  }
18
18
  });
19
-
20
19
  function _worker() {
21
20
  const data = require("./worker.aspect");
22
-
23
21
  _worker = function () {
24
22
  return data;
25
23
  };
26
-
27
24
  return data;
28
25
  }
29
-
30
26
  function _expose() {
31
27
  const data = require("./expose");
32
-
33
28
  _expose = function () {
34
29
  return data;
35
30
  };
36
-
37
31
  return data;
38
32
  }
39
-
40
33
  (0, _expose().setFunctionHandlers)();
41
-
42
34
  var _default = _worker().WorkerAspect;
43
-
44
35
  exports.default = _default;
45
36
 
46
37
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["setFunctionHandlers","WorkerAspect"],"sources":["index.ts"],"sourcesContent":["import { WorkerAspect } from './worker.aspect';\nimport { setFunctionHandlers } from './expose';\n\nsetFunctionHandlers();\n\nexport { WorkerAspect };\nexport type { WorkerMain } from './worker.main.runtime';\nexport type { HarmonyWorker } from './harmony-worker';\nexport { expose } from './expose';\nexport default WorkerAspect;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA,IAAAA,6BAAA;;eAMeC,sB"}
1
+ {"version":3,"names":["setFunctionHandlers","WorkerAspect"],"sources":["index.ts"],"sourcesContent":["import { WorkerAspect } from './worker.aspect';\nimport { setFunctionHandlers } from './expose';\n\nsetFunctionHandlers();\n\nexport { WorkerAspect };\nexport type { WorkerMain } from './worker.main.runtime';\nexport type { HarmonyWorker } from './harmony-worker';\nexport { expose } from './expose';\nexport default WorkerAspect;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA,IAAAA,6BAAmB,GAAE;AAAC,eAMPC,sBAAY;AAAA"}
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
 
3
3
  require("core-js/modules/es.array.iterator.js");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  function nodeEndpoint(nep) {
11
9
  const listeners = new WeakMap();
12
10
  return {
@@ -23,24 +21,20 @@ function nodeEndpoint(nep) {
23
21
  });
24
22
  }
25
23
  };
26
-
27
24
  nep.on('message', l);
28
25
  listeners.set(eh, l);
29
26
  },
30
27
  removeEventListener: (_, eh) => {
31
28
  const l = listeners.get(eh);
32
-
33
29
  if (!l) {
34
30
  return;
35
31
  }
36
-
37
32
  nep.off('message', l);
38
33
  listeners.delete(eh);
39
34
  },
40
35
  start: nep.start && nep.start.bind(nep)
41
36
  };
42
37
  }
43
-
44
38
  var _default = nodeEndpoint;
45
39
  exports.default = _default;
46
40
 
@@ -1 +1 @@
1
- {"version":3,"names":["nodeEndpoint","nep","listeners","WeakMap","postMessage","bind","addEventListener","_","eh","l","data","handleEvent","on","set","removeEventListener","get","off","delete","start"],"sources":["node-endpoint.ts"],"sourcesContent":["function nodeEndpoint(nep) {\n const listeners = new WeakMap();\n return {\n postMessage: nep.postMessage.bind(nep),\n addEventListener: (_, eh) => {\n const l = (data) => {\n if ('handleEvent' in eh) {\n eh.handleEvent({ data });\n } else {\n eh({ data });\n }\n };\n nep.on('message', l);\n listeners.set(eh, l);\n },\n removeEventListener: (_, eh) => {\n const l = listeners.get(eh);\n if (!l) {\n return;\n }\n nep.off('message', l);\n listeners.delete(eh);\n },\n start: nep.start && nep.start.bind(nep),\n };\n}\n\nexport default nodeEndpoint;\n"],"mappings":";;;;;;;;;AAAA,SAASA,YAAT,CAAsBC,GAAtB,EAA2B;EACzB,MAAMC,SAAS,GAAG,IAAIC,OAAJ,EAAlB;EACA,OAAO;IACLC,WAAW,EAAEH,GAAG,CAACG,WAAJ,CAAgBC,IAAhB,CAAqBJ,GAArB,CADR;IAELK,gBAAgB,EAAE,CAACC,CAAD,EAAIC,EAAJ,KAAW;MAC3B,MAAMC,CAAC,GAAIC,IAAD,IAAU;QAClB,IAAI,iBAAiBF,EAArB,EAAyB;UACvBA,EAAE,CAACG,WAAH,CAAe;YAAED;UAAF,CAAf;QACD,CAFD,MAEO;UACLF,EAAE,CAAC;YAAEE;UAAF,CAAD,CAAF;QACD;MACF,CAND;;MAOAT,GAAG,CAACW,EAAJ,CAAO,SAAP,EAAkBH,CAAlB;MACAP,SAAS,CAACW,GAAV,CAAcL,EAAd,EAAkBC,CAAlB;IACD,CAZI;IAaLK,mBAAmB,EAAE,CAACP,CAAD,EAAIC,EAAJ,KAAW;MAC9B,MAAMC,CAAC,GAAGP,SAAS,CAACa,GAAV,CAAcP,EAAd,CAAV;;MACA,IAAI,CAACC,CAAL,EAAQ;QACN;MACD;;MACDR,GAAG,CAACe,GAAJ,CAAQ,SAAR,EAAmBP,CAAnB;MACAP,SAAS,CAACe,MAAV,CAAiBT,EAAjB;IACD,CApBI;IAqBLU,KAAK,EAAEjB,GAAG,CAACiB,KAAJ,IAAajB,GAAG,CAACiB,KAAJ,CAAUb,IAAV,CAAeJ,GAAf;EArBf,CAAP;AAuBD;;eAEcD,Y"}
1
+ {"version":3,"names":["nodeEndpoint","nep","listeners","WeakMap","postMessage","bind","addEventListener","_","eh","l","data","handleEvent","on","set","removeEventListener","get","off","delete","start"],"sources":["node-endpoint.ts"],"sourcesContent":["function nodeEndpoint(nep) {\n const listeners = new WeakMap();\n return {\n postMessage: nep.postMessage.bind(nep),\n addEventListener: (_, eh) => {\n const l = (data) => {\n if ('handleEvent' in eh) {\n eh.handleEvent({ data });\n } else {\n eh({ data });\n }\n };\n nep.on('message', l);\n listeners.set(eh, l);\n },\n removeEventListener: (_, eh) => {\n const l = listeners.get(eh);\n if (!l) {\n return;\n }\n nep.off('message', l);\n listeners.delete(eh);\n },\n start: nep.start && nep.start.bind(nep),\n };\n}\n\nexport default nodeEndpoint;\n"],"mappings":";;;;;;;AAAA,SAASA,YAAY,CAACC,GAAG,EAAE;EACzB,MAAMC,SAAS,GAAG,IAAIC,OAAO,EAAE;EAC/B,OAAO;IACLC,WAAW,EAAEH,GAAG,CAACG,WAAW,CAACC,IAAI,CAACJ,GAAG,CAAC;IACtCK,gBAAgB,EAAE,CAACC,CAAC,EAAEC,EAAE,KAAK;MAC3B,MAAMC,CAAC,GAAIC,IAAI,IAAK;QAClB,IAAI,aAAa,IAAIF,EAAE,EAAE;UACvBA,EAAE,CAACG,WAAW,CAAC;YAAED;UAAK,CAAC,CAAC;QAC1B,CAAC,MAAM;UACLF,EAAE,CAAC;YAAEE;UAAK,CAAC,CAAC;QACd;MACF,CAAC;MACDT,GAAG,CAACW,EAAE,CAAC,SAAS,EAAEH,CAAC,CAAC;MACpBP,SAAS,CAACW,GAAG,CAACL,EAAE,EAAEC,CAAC,CAAC;IACtB,CAAC;IACDK,mBAAmB,EAAE,CAACP,CAAC,EAAEC,EAAE,KAAK;MAC9B,MAAMC,CAAC,GAAGP,SAAS,CAACa,GAAG,CAACP,EAAE,CAAC;MAC3B,IAAI,CAACC,CAAC,EAAE;QACN;MACF;MACAR,GAAG,CAACe,GAAG,CAAC,SAAS,EAAEP,CAAC,CAAC;MACrBP,SAAS,CAACe,MAAM,CAACT,EAAE,CAAC;IACtB,CAAC;IACDU,KAAK,EAAEjB,GAAG,CAACiB,KAAK,IAAIjB,GAAG,CAACiB,KAAK,CAACb,IAAI,CAACJ,GAAG;EACxC,CAAC;AACH;AAAC,eAEcD,YAAY;AAAA"}
@@ -4,21 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.WorkerAspect = void 0;
7
-
8
7
  function _harmony() {
9
8
  const data = require("@teambit/harmony");
10
-
11
9
  _harmony = function () {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  const WorkerAspect = _harmony().Aspect.create({
19
15
  id: 'teambit.harmony/worker'
20
16
  });
21
-
22
17
  exports.WorkerAspect = WorkerAspect;
23
18
 
24
19
  //# sourceMappingURL=worker.aspect.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WorkerAspect","Aspect","create","id"],"sources":["worker.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const WorkerAspect = Aspect.create({\n id: 'teambit.harmony/worker',\n});\n"],"mappings":";;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,YAAY,GAAGC,iBAAA,CAAOC,MAAP,CAAc;EACxCC,EAAE,EAAE;AADoC,CAAd,CAArB"}
1
+ {"version":3,"names":["WorkerAspect","Aspect","create","id"],"sources":["worker.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const WorkerAspect = Aspect.create({\n id: 'teambit.harmony/worker',\n});\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,YAAY,GAAGC,iBAAM,CAACC,MAAM,CAAC;EACxCC,EAAE,EAAE;AACN,CAAC,CAAC;AAAC"}
@@ -1,22 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.Logo = void 0;
9
-
10
8
  function _react() {
11
9
  const data = _interopRequireDefault(require("react"));
12
-
13
10
  _react = function () {
14
11
  return data;
15
12
  };
16
-
17
13
  return data;
18
14
  }
19
-
20
15
  const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
21
16
  style: {
22
17
  height: '100%',
@@ -29,7 +24,6 @@ const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
29
24
  },
30
25
  src: "https://static.bit.dev/extensions-icons/worker.svg"
31
26
  }));
32
-
33
27
  exports.Logo = Logo;
34
28
 
35
29
  //# sourceMappingURL=worker.composition.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Logo","height","display","justifyContent","width"],"sources":["worker.composition.tsx"],"sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/worker.svg\" />\n </div>\n);\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,IAAI,GAAG,mBAClB;EAAK,KAAK,EAAE;IAAEC,MAAM,EAAE,MAAV;IAAkBC,OAAO,EAAE,MAA3B;IAAmCC,cAAc,EAAE;EAAnD;AAAZ,gBACE;EAAK,KAAK,EAAE;IAAEC,KAAK,EAAE;EAAT,CAAZ;EAA2B,GAAG,EAAC;AAA/B,EADF,CADK"}
1
+ {"version":3,"names":["Logo","height","display","justifyContent","width"],"sources":["worker.composition.tsx"],"sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/worker.svg\" />\n </div>\n);\n"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,IAAI,GAAG,mBAClB;EAAK,KAAK,EAAE;IAAEC,MAAM,EAAE,MAAM;IAAEC,OAAO,EAAE,MAAM;IAAEC,cAAc,EAAE;EAAS;AAAE,gBACxE;EAAK,KAAK,EAAE;IAAEC,KAAK,EAAE;EAAG,CAAE;EAAC,GAAG,EAAC;AAAoD,EAAG,CAEzF;AAAC"}
@@ -1,96 +1,68 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  require("core-js/modules/es.array.iterator.js");
6
-
7
5
  require("core-js/modules/es.promise.js");
8
-
9
6
  Object.defineProperty(exports, "__esModule", {
10
7
  value: true
11
8
  });
12
9
  exports.WorkerMain = void 0;
13
-
14
10
  function _defineProperty2() {
15
11
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
-
17
12
  _defineProperty2 = function () {
18
13
  return data;
19
14
  };
20
-
21
15
  return data;
22
16
  }
23
-
24
17
  function _path() {
25
18
  const data = require("path");
26
-
27
19
  _path = function () {
28
20
  return data;
29
21
  };
30
-
31
22
  return data;
32
23
  }
33
-
34
24
  function _cli() {
35
25
  const data = require("@teambit/cli");
36
-
37
26
  _cli = function () {
38
27
  return data;
39
28
  };
40
-
41
29
  return data;
42
30
  }
43
-
44
31
  function _component() {
45
32
  const data = require("@teambit/component");
46
-
47
33
  _component = function () {
48
34
  return data;
49
35
  };
50
-
51
36
  return data;
52
37
  }
53
-
54
38
  function _pkg() {
55
39
  const data = require("@teambit/pkg");
56
-
57
40
  _pkg = function () {
58
41
  return data;
59
42
  };
60
-
61
43
  return data;
62
44
  }
63
-
64
45
  function _harmony() {
65
46
  const data = require("@teambit/harmony");
66
-
67
47
  _harmony = function () {
68
48
  return data;
69
49
  };
70
-
71
50
  return data;
72
51
  }
73
-
74
52
  function _worker() {
75
53
  const data = require("./worker.aspect");
76
-
77
54
  _worker = function () {
78
55
  return data;
79
56
  };
80
-
81
57
  return data;
82
58
  }
83
-
84
59
  function _harmonyWorker() {
85
60
  const data = require("./harmony-worker");
86
-
87
61
  _harmonyWorker = function () {
88
62
  return data;
89
63
  };
90
-
91
64
  return data;
92
65
  }
93
-
94
66
  class WorkerMain {
95
67
  constructor(workerSlot, componentAspect, pkg, workerNameSlot) {
96
68
  this.workerSlot = workerSlot;
@@ -98,54 +70,46 @@ class WorkerMain {
98
70
  this.pkg = pkg;
99
71
  this.workerNameSlot = workerNameSlot;
100
72
  }
101
-
102
73
  listWorkers() {
103
74
  return this.workerSlot.values();
104
75
  }
76
+
105
77
  /**
106
78
  * create a new worker.
107
79
  */
108
-
109
-
110
80
  async declareWorker(name, path) {
111
81
  this.workerNameSlot.register(name);
112
82
  const maybeAspectId = this.workerNameSlot.toArray().find(([, workerName]) => {
113
83
  return workerName === name;
114
84
  });
115
- if (!maybeAspectId) throw new Error(`could not create a worker ${name}`); // const scriptPath = path || await this.resolveWorkerScript(name, aspectId);
116
-
85
+ if (!maybeAspectId) throw new Error(`could not create a worker ${name}`);
86
+ // const scriptPath = path || await this.resolveWorkerScript(name, aspectId);
117
87
  const scriptPath = path;
118
88
  const systemWorker = new (_harmonyWorker().HarmonyWorker)(name, scriptPath);
119
89
  this.workerSlot.register(systemWorker);
120
90
  return systemWorker;
121
91
  }
122
-
123
92
  async resolveWorkerScript(name, aspectId) {
124
93
  const host = this.componentAspect.getHost();
125
94
  const id = await host.resolveComponentId(aspectId);
126
95
  const component = await host.get(id);
127
96
  if (!component) throw new Error(`[worker] could not resolve component for aspect ID: ${aspectId}`);
128
- const packageName = this.pkg.getPackageName(component); // const workerFile = component.state.filesystem.files.find((file) => file.relative.includes(`${name}.worker`));
97
+ const packageName = this.pkg.getPackageName(component);
98
+ // const workerFile = component.state.filesystem.files.find((file) => file.relative.includes(`${name}.worker`));
129
99
  // if (!workerFile) throw new Error(`[worker] aspect declaring a worker must contain a ${name}.worker. file`);
130
-
131
100
  return require.resolve((0, _path().join)(packageName, 'dist', `${name}.worker.js`));
132
101
  }
133
-
134
102
  getWorker(id) {
135
103
  return this.workerSlot.get(id);
136
104
  }
137
-
138
105
  static async provider([componentAspect, pkg], config, [workerSlot, workerNameSlot]) {
139
106
  return new WorkerMain(workerSlot, componentAspect, pkg, workerNameSlot);
140
107
  }
141
-
142
108
  }
143
-
144
109
  exports.WorkerMain = WorkerMain;
145
110
  (0, _defineProperty2().default)(WorkerMain, "runtime", _cli().MainRuntime);
146
111
  (0, _defineProperty2().default)(WorkerMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType()]);
147
112
  (0, _defineProperty2().default)(WorkerMain, "dependencies", [_component().ComponentAspect, _pkg().PkgAspect]);
148
-
149
113
  _worker().WorkerAspect.addRuntime(WorkerMain);
150
114
 
151
115
  //# sourceMappingURL=worker.main.runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WorkerMain","constructor","workerSlot","componentAspect","pkg","workerNameSlot","listWorkers","values","declareWorker","name","path","register","maybeAspectId","toArray","find","workerName","Error","scriptPath","systemWorker","HarmonyWorker","resolveWorkerScript","aspectId","host","getHost","id","resolveComponentId","component","get","packageName","getPackageName","require","resolve","join","getWorker","provider","config","MainRuntime","Slot","withType","ComponentAspect","PkgAspect","WorkerAspect","addRuntime"],"sources":["worker.main.runtime.ts"],"sourcesContent":["import { join } from 'path';\nimport { MainRuntime } from '@teambit/cli';\nimport { ComponentAspect, ComponentMain } from '@teambit/component';\nimport { PkgAspect, PkgMain } from '@teambit/pkg';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { WorkerAspect } from './worker.aspect';\nimport { HarmonyWorker } from './harmony-worker';\n\nexport type WorkerSlot = SlotRegistry<HarmonyWorker<unknown>>;\n\nexport type WorkerNameSlot = SlotRegistry<string>;\n\nexport class WorkerMain {\n constructor(\n private workerSlot: WorkerSlot,\n private componentAspect: ComponentMain,\n private pkg: PkgMain,\n private workerNameSlot: WorkerNameSlot\n ) {}\n\n static runtime = MainRuntime;\n\n listWorkers(): HarmonyWorker<any>[] {\n return this.workerSlot.values();\n }\n\n /**\n * create a new worker.\n */\n async declareWorker<T>(name: string, path: string): Promise<HarmonyWorker<T>> {\n this.workerNameSlot.register(name);\n\n const maybeAspectId = this.workerNameSlot.toArray().find(([, workerName]) => {\n return workerName === name;\n });\n\n if (!maybeAspectId) throw new Error(`could not create a worker ${name}`);\n // const scriptPath = path || await this.resolveWorkerScript(name, aspectId);\n const scriptPath = path;\n const systemWorker = new HarmonyWorker<T>(name, scriptPath);\n this.workerSlot.register(systemWorker);\n\n return systemWorker;\n }\n\n private async resolveWorkerScript(name: string, aspectId: string): Promise<string> {\n const host = this.componentAspect.getHost();\n const id = await host.resolveComponentId(aspectId);\n const component = await host.get(id);\n if (!component) throw new Error(`[worker] could not resolve component for aspect ID: ${aspectId}`);\n const packageName = this.pkg.getPackageName(component);\n // const workerFile = component.state.filesystem.files.find((file) => file.relative.includes(`${name}.worker`));\n // if (!workerFile) throw new Error(`[worker] aspect declaring a worker must contain a ${name}.worker. file`);\n return require.resolve(join(packageName, 'dist', `${name}.worker.js`));\n }\n\n getWorker<T>(id: string): HarmonyWorker<T> {\n return this.workerSlot.get(id) as HarmonyWorker<T>;\n }\n\n static slots = [Slot.withType<HarmonyWorker<unknown>>(), Slot.withType<string>()];\n\n static dependencies = [ComponentAspect, PkgAspect];\n\n static async provider(\n [componentAspect, pkg]: [ComponentMain, PkgMain],\n config,\n [workerSlot, workerNameSlot]: [WorkerSlot, WorkerNameSlot]\n ) {\n return new WorkerMain(workerSlot, componentAspect, pkg, workerNameSlot);\n }\n}\n\nWorkerAspect.addRuntime(WorkerMain);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAMO,MAAMA,UAAN,CAAiB;EACtBC,WAAW,CACDC,UADC,EAEDC,eAFC,EAGDC,GAHC,EAIDC,cAJC,EAKT;IAAA,KAJQH,UAIR,GAJQA,UAIR;IAAA,KAHQC,eAGR,GAHQA,eAGR;IAAA,KAFQC,GAER,GAFQA,GAER;IAAA,KADQC,cACR,GADQA,cACR;EAAE;;EAIJC,WAAW,GAAyB;IAClC,OAAO,KAAKJ,UAAL,CAAgBK,MAAhB,EAAP;EACD;EAED;AACF;AACA;;;EACqB,MAAbC,aAAa,CAAIC,IAAJ,EAAkBC,IAAlB,EAA2D;IAC5E,KAAKL,cAAL,CAAoBM,QAApB,CAA6BF,IAA7B;IAEA,MAAMG,aAAa,GAAG,KAAKP,cAAL,CAAoBQ,OAApB,GAA8BC,IAA9B,CAAmC,CAAC,GAAGC,UAAH,CAAD,KAAoB;MAC3E,OAAOA,UAAU,KAAKN,IAAtB;IACD,CAFqB,CAAtB;IAIA,IAAI,CAACG,aAAL,EAAoB,MAAM,IAAII,KAAJ,CAAW,6BAA4BP,IAAK,EAA5C,CAAN,CAPwD,CAQ5E;;IACA,MAAMQ,UAAU,GAAGP,IAAnB;IACA,MAAMQ,YAAY,GAAG,KAAIC,8BAAJ,EAAqBV,IAArB,EAA2BQ,UAA3B,CAArB;IACA,KAAKf,UAAL,CAAgBS,QAAhB,CAAyBO,YAAzB;IAEA,OAAOA,YAAP;EACD;;EAEgC,MAAnBE,mBAAmB,CAACX,IAAD,EAAeY,QAAf,EAAkD;IACjF,MAAMC,IAAI,GAAG,KAAKnB,eAAL,CAAqBoB,OAArB,EAAb;IACA,MAAMC,EAAE,GAAG,MAAMF,IAAI,CAACG,kBAAL,CAAwBJ,QAAxB,CAAjB;IACA,MAAMK,SAAS,GAAG,MAAMJ,IAAI,CAACK,GAAL,CAASH,EAAT,CAAxB;IACA,IAAI,CAACE,SAAL,EAAgB,MAAM,IAAIV,KAAJ,CAAW,uDAAsDK,QAAS,EAA1E,CAAN;IAChB,MAAMO,WAAW,GAAG,KAAKxB,GAAL,CAASyB,cAAT,CAAwBH,SAAxB,CAApB,CALiF,CAMjF;IACA;;IACA,OAAOI,OAAO,CAACC,OAAR,CAAgB,IAAAC,YAAA,EAAKJ,WAAL,EAAkB,MAAlB,EAA2B,GAAEnB,IAAK,YAAlC,CAAhB,CAAP;EACD;;EAEDwB,SAAS,CAAIT,EAAJ,EAAkC;IACzC,OAAO,KAAKtB,UAAL,CAAgByB,GAAhB,CAAoBH,EAApB,CAAP;EACD;;EAMoB,aAARU,QAAQ,CACnB,CAAC/B,eAAD,EAAkBC,GAAlB,CADmB,EAEnB+B,MAFmB,EAGnB,CAACjC,UAAD,EAAaG,cAAb,CAHmB,EAInB;IACA,OAAO,IAAIL,UAAJ,CAAeE,UAAf,EAA2BC,eAA3B,EAA4CC,GAA5C,EAAiDC,cAAjD,CAAP;EACD;;AA1DqB;;;gCAAXL,U,aAQMoC,kB;gCARNpC,U,WAgDI,CAACqC,eAAA,CAAKC,QAAL,EAAD,EAA0CD,eAAA,CAAKC,QAAL,EAA1C,C;gCAhDJtC,U,kBAkDW,CAACuC,4BAAD,EAAkBC,gBAAlB,C;;AAWxBC,sBAAA,CAAaC,UAAb,CAAwB1C,UAAxB"}
1
+ {"version":3,"names":["WorkerMain","constructor","workerSlot","componentAspect","pkg","workerNameSlot","listWorkers","values","declareWorker","name","path","register","maybeAspectId","toArray","find","workerName","Error","scriptPath","systemWorker","HarmonyWorker","resolveWorkerScript","aspectId","host","getHost","id","resolveComponentId","component","get","packageName","getPackageName","require","resolve","join","getWorker","provider","config","MainRuntime","Slot","withType","ComponentAspect","PkgAspect","WorkerAspect","addRuntime"],"sources":["worker.main.runtime.ts"],"sourcesContent":["import { join } from 'path';\nimport { MainRuntime } from '@teambit/cli';\nimport { ComponentAspect, ComponentMain } from '@teambit/component';\nimport { PkgAspect, PkgMain } from '@teambit/pkg';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { WorkerAspect } from './worker.aspect';\nimport { HarmonyWorker } from './harmony-worker';\n\nexport type WorkerSlot = SlotRegistry<HarmonyWorker<unknown>>;\n\nexport type WorkerNameSlot = SlotRegistry<string>;\n\nexport class WorkerMain {\n constructor(\n private workerSlot: WorkerSlot,\n private componentAspect: ComponentMain,\n private pkg: PkgMain,\n private workerNameSlot: WorkerNameSlot\n ) {}\n\n static runtime = MainRuntime;\n\n listWorkers(): HarmonyWorker<any>[] {\n return this.workerSlot.values();\n }\n\n /**\n * create a new worker.\n */\n async declareWorker<T>(name: string, path: string): Promise<HarmonyWorker<T>> {\n this.workerNameSlot.register(name);\n\n const maybeAspectId = this.workerNameSlot.toArray().find(([, workerName]) => {\n return workerName === name;\n });\n\n if (!maybeAspectId) throw new Error(`could not create a worker ${name}`);\n // const scriptPath = path || await this.resolveWorkerScript(name, aspectId);\n const scriptPath = path;\n const systemWorker = new HarmonyWorker<T>(name, scriptPath);\n this.workerSlot.register(systemWorker);\n\n return systemWorker;\n }\n\n private async resolveWorkerScript(name: string, aspectId: string): Promise<string> {\n const host = this.componentAspect.getHost();\n const id = await host.resolveComponentId(aspectId);\n const component = await host.get(id);\n if (!component) throw new Error(`[worker] could not resolve component for aspect ID: ${aspectId}`);\n const packageName = this.pkg.getPackageName(component);\n // const workerFile = component.state.filesystem.files.find((file) => file.relative.includes(`${name}.worker`));\n // if (!workerFile) throw new Error(`[worker] aspect declaring a worker must contain a ${name}.worker. file`);\n return require.resolve(join(packageName, 'dist', `${name}.worker.js`));\n }\n\n getWorker<T>(id: string): HarmonyWorker<T> {\n return this.workerSlot.get(id) as HarmonyWorker<T>;\n }\n\n static slots = [Slot.withType<HarmonyWorker<unknown>>(), Slot.withType<string>()];\n\n static dependencies = [ComponentAspect, PkgAspect];\n\n static async provider(\n [componentAspect, pkg]: [ComponentMain, PkgMain],\n config,\n [workerSlot, workerNameSlot]: [WorkerSlot, WorkerNameSlot]\n ) {\n return new WorkerMain(workerSlot, componentAspect, pkg, workerNameSlot);\n }\n}\n\nWorkerAspect.addRuntime(WorkerMain);\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAMO,MAAMA,UAAU,CAAC;EACtBC,WAAW,CACDC,UAAsB,EACtBC,eAA8B,EAC9BC,GAAY,EACZC,cAA8B,EACtC;IAAA,KAJQH,UAAsB,GAAtBA,UAAsB;IAAA,KACtBC,eAA8B,GAA9BA,eAA8B;IAAA,KAC9BC,GAAY,GAAZA,GAAY;IAAA,KACZC,cAA8B,GAA9BA,cAA8B;EACrC;EAIHC,WAAW,GAAyB;IAClC,OAAO,IAAI,CAACJ,UAAU,CAACK,MAAM,EAAE;EACjC;;EAEA;AACF;AACA;EACE,MAAMC,aAAa,CAAIC,IAAY,EAAEC,IAAY,EAA6B;IAC5E,IAAI,CAACL,cAAc,CAACM,QAAQ,CAACF,IAAI,CAAC;IAElC,MAAMG,aAAa,GAAG,IAAI,CAACP,cAAc,CAACQ,OAAO,EAAE,CAACC,IAAI,CAAC,CAAC,GAAGC,UAAU,CAAC,KAAK;MAC3E,OAAOA,UAAU,KAAKN,IAAI;IAC5B,CAAC,CAAC;IAEF,IAAI,CAACG,aAAa,EAAE,MAAM,IAAII,KAAK,CAAE,6BAA4BP,IAAK,EAAC,CAAC;IACxE;IACA,MAAMQ,UAAU,GAAGP,IAAI;IACvB,MAAMQ,YAAY,GAAG,KAAIC,8BAAa,EAAIV,IAAI,EAAEQ,UAAU,CAAC;IAC3D,IAAI,CAACf,UAAU,CAACS,QAAQ,CAACO,YAAY,CAAC;IAEtC,OAAOA,YAAY;EACrB;EAEA,MAAcE,mBAAmB,CAACX,IAAY,EAAEY,QAAgB,EAAmB;IACjF,MAAMC,IAAI,GAAG,IAAI,CAACnB,eAAe,CAACoB,OAAO,EAAE;IAC3C,MAAMC,EAAE,GAAG,MAAMF,IAAI,CAACG,kBAAkB,CAACJ,QAAQ,CAAC;IAClD,MAAMK,SAAS,GAAG,MAAMJ,IAAI,CAACK,GAAG,CAACH,EAAE,CAAC;IACpC,IAAI,CAACE,SAAS,EAAE,MAAM,IAAIV,KAAK,CAAE,uDAAsDK,QAAS,EAAC,CAAC;IAClG,MAAMO,WAAW,GAAG,IAAI,CAACxB,GAAG,CAACyB,cAAc,CAACH,SAAS,CAAC;IACtD;IACA;IACA,OAAOI,OAAO,CAACC,OAAO,CAAC,IAAAC,YAAI,EAACJ,WAAW,EAAE,MAAM,EAAG,GAAEnB,IAAK,YAAW,CAAC,CAAC;EACxE;EAEAwB,SAAS,CAAIT,EAAU,EAAoB;IACzC,OAAO,IAAI,CAACtB,UAAU,CAACyB,GAAG,CAACH,EAAE,CAAC;EAChC;EAMA,aAAaU,QAAQ,CACnB,CAAC/B,eAAe,EAAEC,GAAG,CAA2B,EAChD+B,MAAM,EACN,CAACjC,UAAU,EAAEG,cAAc,CAA+B,EAC1D;IACA,OAAO,IAAIL,UAAU,CAACE,UAAU,EAAEC,eAAe,EAAEC,GAAG,EAAEC,cAAc,CAAC;EACzE;AACF;AAAC;AAAA,gCA3DYL,UAAU,aAQJoC,kBAAW;AAAA,gCARjBpC,UAAU,WAgDN,CAACqC,eAAI,CAACC,QAAQ,EAA0B,EAAED,eAAI,CAACC,QAAQ,EAAU,CAAC;AAAA,gCAhDtEtC,UAAU,kBAkDC,CAACuC,4BAAe,EAAEC,gBAAS,CAAC;AAWpDC,sBAAY,CAACC,UAAU,CAAC1C,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/worker",
3
- "version": "0.0.881",
3
+ "version": "0.0.882",
4
4
  "homepage": "https://bit.dev/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.881"
9
+ "version": "0.0.882"
10
10
  },
11
11
  "dependencies": {
12
12
  "comlink": "4.3.0",
@@ -14,8 +14,8 @@
14
14
  "core-js": "^3.0.0",
15
15
  "@teambit/harmony": "0.3.3",
16
16
  "@teambit/cli": "0.0.591",
17
- "@teambit/component": "0.0.881",
18
- "@teambit/pkg": "0.0.881"
17
+ "@teambit/component": "0.0.882",
18
+ "@teambit/pkg": "0.0.882"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/react": "^17.0.8",
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_worker@0.0.881/dist/worker.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_worker@0.0.881/dist/worker.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_worker@0.0.882/dist/worker.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_worker@0.0.882/dist/worker.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];