@teambit/harmony 0.2.10 → 0.3.1

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 (206) hide show
  1. package/aspect.ts +52 -0
  2. package/config/config.ts +36 -0
  3. package/config/index.ts +1 -0
  4. package/container.ts +22 -0
  5. package/dist/aspect.d.ts +3 -2
  6. package/dist/aspect.js +4 -0
  7. package/dist/aspect.js.map +1 -0
  8. package/dist/config/config.d.ts +2 -1
  9. package/dist/config/config.js +7 -0
  10. package/dist/config/config.js.map +1 -0
  11. package/dist/config/index.js +2 -0
  12. package/dist/config/index.js.map +1 -0
  13. package/dist/container.js +1 -0
  14. package/dist/container.js.map +1 -0
  15. package/dist/exceptions/extension-init-error.js +1 -0
  16. package/dist/exceptions/extension-init-error.js.map +1 -0
  17. package/dist/exceptions/extension-load-error.d.ts +1 -1
  18. package/dist/exceptions/extension-load-error.js +1 -0
  19. package/dist/exceptions/extension-load-error.js.map +1 -0
  20. package/dist/exceptions/extension-potential-circular.js +1 -0
  21. package/dist/exceptions/extension-potential-circular.js.map +1 -0
  22. package/dist/exceptions/harmony-already-running.js +1 -0
  23. package/dist/exceptions/harmony-already-running.js.map +1 -0
  24. package/dist/exceptions/harmony-error.js +1 -0
  25. package/dist/exceptions/harmony-error.js.map +1 -0
  26. package/dist/exceptions/hook-not-found.js +1 -0
  27. package/dist/exceptions/hook-not-found.js.map +1 -0
  28. package/dist/exceptions/index.js +7 -2
  29. package/dist/exceptions/index.js.map +1 -0
  30. package/dist/exceptions/runtime-not-defined.js +1 -1
  31. package/dist/exceptions/runtime-not-defined.js.map +1 -0
  32. package/dist/extension/any-extension.js +1 -0
  33. package/dist/extension/any-extension.js.map +1 -0
  34. package/dist/extension/decorator.d.ts +2 -2
  35. package/dist/extension/decorator.js +1 -0
  36. package/dist/extension/decorator.js.map +1 -0
  37. package/dist/extension/extension-manifest.js +1 -0
  38. package/dist/extension/extension-manifest.js.map +1 -0
  39. package/dist/extension/extension.d.ts +3 -2
  40. package/dist/extension/extension.js +4 -0
  41. package/dist/extension/extension.js.map +1 -0
  42. package/dist/extension/index.js +2 -0
  43. package/dist/extension/index.js.map +1 -0
  44. package/dist/extension-graph/extension-graph.d.ts +2 -2
  45. package/dist/extension-graph/extension-graph.js +5 -4
  46. package/dist/extension-graph/extension-graph.js.map +1 -0
  47. package/dist/extension-graph/from-extension.js +3 -2
  48. package/dist/extension-graph/from-extension.js.map +1 -0
  49. package/dist/extension-graph/index.js +6 -1
  50. package/dist/extension-graph/index.js.map +1 -0
  51. package/dist/factory/extension-factory.js +1 -0
  52. package/dist/factory/extension-factory.js.map +1 -0
  53. package/dist/factory/index.js +2 -0
  54. package/dist/factory/index.js.map +1 -0
  55. package/dist/fixtures/aspects/babel/babel.aspect.js +1 -0
  56. package/dist/fixtures/aspects/babel/babel.aspect.js.map +1 -0
  57. package/dist/fixtures/aspects/babel/babel.cli.js +1 -0
  58. package/dist/fixtures/aspects/babel/babel.cli.js.map +1 -0
  59. package/dist/fixtures/aspects/react/react.aspect.js +1 -0
  60. package/dist/fixtures/aspects/react/react.aspect.js.map +1 -0
  61. package/dist/fixtures/aspects/react/react.cli.js +2 -1
  62. package/dist/fixtures/aspects/react/react.cli.js.map +1 -0
  63. package/dist/fixtures/aspects/react/react.ui.js +1 -0
  64. package/dist/fixtures/aspects/react/react.ui.js.map +1 -0
  65. package/dist/fixtures/aspects/ui/ui.aspect.js +1 -0
  66. package/dist/fixtures/aspects/ui/ui.aspect.js.map +1 -0
  67. package/dist/fixtures/aspects/ui/ui.ui.js +1 -0
  68. package/dist/fixtures/aspects/ui/ui.ui.js.map +1 -0
  69. package/dist/fixtures/babel/babel.extension.d.ts +1 -1
  70. package/dist/fixtures/babel/babel.extension.js +8 -26
  71. package/dist/fixtures/babel/babel.extension.js.map +1 -0
  72. package/dist/fixtures/babel/index.js +1 -1
  73. package/dist/fixtures/babel/index.js.map +1 -0
  74. package/dist/fixtures/base-compiler/base-compiler.extension.js +5 -23
  75. package/dist/fixtures/base-compiler/base-compiler.extension.js.map +1 -0
  76. package/dist/fixtures/base-compiler/index.js +2 -0
  77. package/dist/fixtures/base-compiler/index.js.map +1 -0
  78. package/dist/fixtures/cli/cli.extension.js +5 -12
  79. package/dist/fixtures/cli/cli.extension.js.map +1 -0
  80. package/dist/fixtures/cli/command.js +1 -1
  81. package/dist/fixtures/cli/command.js.map +1 -0
  82. package/dist/fixtures/cli/index.js +2 -1
  83. package/dist/fixtures/cli/index.js.map +1 -0
  84. package/dist/fixtures/typescript/index.js +1 -1
  85. package/dist/fixtures/typescript/index.js.map +1 -0
  86. package/dist/fixtures/typescript/typescript.js +8 -22
  87. package/dist/fixtures/typescript/typescript.js.map +1 -0
  88. package/dist/harmony-config/config-reader.js +3 -2
  89. package/dist/harmony-config/config-reader.js.map +1 -0
  90. package/dist/harmony-config/exceptions/index.js +2 -0
  91. package/dist/harmony-config/exceptions/index.js.map +1 -0
  92. package/dist/harmony-config/exceptions/read-config-error.d.ts +1 -1
  93. package/dist/harmony-config/exceptions/read-config-error.js +1 -0
  94. package/dist/harmony-config/exceptions/read-config-error.js.map +1 -0
  95. package/dist/harmony-config/harmony-config.js +5 -4
  96. package/dist/harmony-config/harmony-config.js.map +1 -0
  97. package/dist/harmony-config/index.js +2 -0
  98. package/dist/harmony-config/index.js.map +1 -0
  99. package/dist/harmony-config/locator.js +1 -1
  100. package/dist/harmony-config/locator.js.map +1 -0
  101. package/dist/harmony.docs.mdx +250 -0
  102. package/dist/harmony.js +3 -2
  103. package/dist/harmony.js.map +1 -0
  104. package/dist/{factory/extension-factory.spec.d.ts → harmony.spec.old.d.ts} +0 -0
  105. package/dist/{harmony.spec.js → harmony.spec.old.js} +12 -23
  106. package/dist/harmony.spec.old.js.map +1 -0
  107. package/dist/index.js +6 -1
  108. package/dist/index.js.map +1 -0
  109. package/dist/readme.md +80 -0
  110. package/dist/runtimes/exceptions/index.js +2 -0
  111. package/dist/runtimes/exceptions/index.js.map +1 -0
  112. package/dist/runtimes/exceptions/runtime-module-error.d.ts +1 -1
  113. package/dist/runtimes/exceptions/runtime-module-error.js +1 -0
  114. package/dist/runtimes/exceptions/runtime-module-error.js.map +1 -0
  115. package/dist/runtimes/exceptions/runtime-not-defined.js +1 -0
  116. package/dist/runtimes/exceptions/runtime-not-defined.js.map +1 -0
  117. package/dist/runtimes/index.js +2 -0
  118. package/dist/runtimes/index.js.map +1 -0
  119. package/dist/runtimes/runtime-definition.js +1 -0
  120. package/dist/runtimes/runtime-definition.js.map +1 -0
  121. package/dist/runtimes/runtime-manifest.js +1 -0
  122. package/dist/runtimes/runtime-manifest.js.map +1 -0
  123. package/dist/runtimes/runtimes.js +1 -0
  124. package/dist/runtimes/runtimes.js.map +1 -0
  125. package/dist/slots/index.js +2 -0
  126. package/dist/slots/index.js.map +1 -0
  127. package/dist/slots/registry.js +1 -0
  128. package/dist/slots/registry.js.map +1 -0
  129. package/dist/slots/slot.js +1 -0
  130. package/dist/slots/slot.js.map +1 -0
  131. package/dist/types.js +1 -0
  132. package/dist/types.js.map +1 -0
  133. package/dist/utils/async-for-each.js +1 -0
  134. package/dist/utils/async-for-each.js.map +1 -0
  135. package/dist/utils/index.js +2 -0
  136. package/dist/utils/index.js.map +1 -0
  137. package/exceptions/extension-init-error.ts +1 -0
  138. package/exceptions/extension-load-error.ts +28 -0
  139. package/exceptions/extension-potential-circular.ts +24 -0
  140. package/exceptions/harmony-already-running.ts +1 -0
  141. package/exceptions/harmony-error.ts +1 -0
  142. package/exceptions/hook-not-found.ts +1 -0
  143. package/exceptions/index.ts +5 -0
  144. package/{dist/extension-graph/extension-graph.spec.d.ts → exceptions/runtime-not-defined.ts} +0 -0
  145. package/extension/any-extension.ts +8 -0
  146. package/extension/decorator.ts +126 -0
  147. package/extension/extension-manifest.ts +51 -0
  148. package/extension/extension.ts +142 -0
  149. package/extension/index.ts +3 -0
  150. package/extension-graph/extension-graph.ts +151 -0
  151. package/extension-graph/from-extension.ts +72 -0
  152. package/extension-graph/index.ts +1 -0
  153. package/factory/extension-factory.ts +8 -0
  154. package/factory/index.ts +1 -0
  155. package/fixtures/aspects/babel/babel.aspect.ts +14 -0
  156. package/fixtures/aspects/babel/babel.cli.ts +16 -0
  157. package/fixtures/aspects/react/react.aspect.ts +22 -0
  158. package/fixtures/aspects/react/react.cli.ts +26 -0
  159. package/fixtures/aspects/react/react.ui.ts +16 -0
  160. package/fixtures/aspects/ui/ui.aspect.ts +13 -0
  161. package/fixtures/aspects/ui/ui.ui.ts +11 -0
  162. package/fixtures/babel/babel.extension.ts +20 -0
  163. package/{dist/extension/extension.spec.d.ts → fixtures/babel/index.ts} +0 -0
  164. package/fixtures/base-compiler/base-compiler.extension.ts +31 -0
  165. package/fixtures/base-compiler/index.ts +1 -0
  166. package/fixtures/cli/cli.extension.ts +25 -0
  167. package/fixtures/cli/command.ts +6 -0
  168. package/fixtures/cli/index.ts +1 -0
  169. package/fixtures/typescript/index.ts +0 -0
  170. package/fixtures/typescript/typescript.ts +20 -0
  171. package/harmony-config/config-reader.ts +17 -0
  172. package/harmony-config/exceptions/index.ts +1 -0
  173. package/harmony-config/exceptions/read-config-error.ts +9 -0
  174. package/harmony-config/harmony-config.ts +49 -0
  175. package/harmony-config/index.ts +1 -0
  176. package/harmony-config/locator.ts +0 -0
  177. package/harmony.docs.mdx +250 -0
  178. package/harmony.spec.old.ts +177 -0
  179. package/harmony.ts +146 -0
  180. package/index.ts +10 -0
  181. package/package-tar/teambit-harmony-0.3.1.tgz +0 -0
  182. package/package.json +42 -28
  183. package/preview-1649151063005.js +1 -0
  184. package/readme.md +58 -137
  185. package/runtimes/exceptions/index.ts +2 -0
  186. package/runtimes/exceptions/runtime-module-error.ts +9 -0
  187. package/runtimes/exceptions/runtime-not-defined.ts +5 -0
  188. package/runtimes/index.ts +3 -0
  189. package/runtimes/runtime-definition.ts +32 -0
  190. package/runtimes/runtime-manifest.ts +12 -0
  191. package/runtimes/runtimes.ts +34 -0
  192. package/slots/index.ts +2 -0
  193. package/slots/registry.ts +36 -0
  194. package/slots/slot.ts +11 -0
  195. package/tsconfig.json +26 -0
  196. package/types/asset.d.ts +29 -0
  197. package/types/style.d.ts +42 -0
  198. package/types.ts +7 -0
  199. package/utils/async-for-each.ts +10 -0
  200. package/utils/index.ts +1 -0
  201. package/dist/extension/extension.spec.js +0 -1
  202. package/dist/extension-graph/extension-graph.spec.js +0 -1
  203. package/dist/factory/extension-factory.spec.js +0 -6
  204. package/dist/harmony-config/harmony-config.spec.d.ts +0 -1
  205. package/dist/harmony-config/harmony-config.spec.js +0 -8
  206. package/dist/harmony.spec.d.ts +0 -1
package/dist/harmony.js CHANGED
@@ -74,7 +74,7 @@ class Harmony {
74
74
  const subgraphs = this.graph.successorsSubgraph(extensionsToLoad);
75
75
  if (subgraphs) {
76
76
  const executionOrder = subgraphs.toposort(true);
77
- yield utils_1.asyncForEach(executionOrder, (ext) => __awaiter(this, void 0, void 0, function* () {
77
+ yield (0, utils_1.asyncForEach)(executionOrder, (ext) => __awaiter(this, void 0, void 0, function* () {
78
78
  if (!this.runtime)
79
79
  throw new exceptions_2.RuntimeNotDefined(this.activeRuntime);
80
80
  yield this.runOne(ext, this.runtime);
@@ -133,7 +133,7 @@ class Harmony {
133
133
  // requireFn ? await requireFn(aspect, runtime) : defaultRequireFn(this.graph);
134
134
  yield this.graph.enrichRuntime(runtime, this.runtimes, requireFn || defaultRequireFn);
135
135
  const executionOrder = this.graph.byExecutionOrder();
136
- yield utils_1.asyncForEach(executionOrder, (ext) => __awaiter(this, void 0, void 0, function* () {
136
+ yield (0, utils_1.asyncForEach)(executionOrder, (ext) => __awaiter(this, void 0, void 0, function* () {
137
137
  yield this.runOne(ext, runtime);
138
138
  }));
139
139
  });
@@ -147,3 +147,4 @@ class Harmony {
147
147
  }
148
148
  }
149
149
  exports.Harmony = Harmony;
150
+ //# sourceMappingURL=harmony.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harmony.js","sourceRoot":"","sources":["../harmony.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CAAA,CAAC,CAAC;QACL,CAAC;KAAA;IAED,MAAM,CAAO,IAAI,CAAC,OAAiB,EAAE,OAAe,EAAE,YAA0B;;YAC9E,MAAM,WAAW,GAAG,yBAAc,CAAC,IAAI,CAAC,OAAc,CAAC,CAAC;YACxD,MAAM,QAAQ,GAAG,MAAM,mBAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAClD,OAAO,IAAI,OAAO,CAAC,WAAW,EAAE,eAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAChF,CAAC;KAAA;CACF;AAhID,0BAgIC"}
@@ -1,17 +1,5 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const harmony_1 = require("./harmony");
13
- const chai_1 = require("chai");
14
- const react_aspect_1 = require("./fixtures/aspects/react/react.aspect");
15
3
  describe('Harmony', () => {
16
4
  describe('run()', () => {
17
5
  // it('should return a string', async () => {
@@ -140,16 +128,17 @@ describe('Harmony', () => {
140
128
  // it('should register during run', async () => {
141
129
  // const compiler = await harmony.run(Babel);
142
130
  // });
143
- it('should execute an aspect in the cli runtime', () => __awaiter(void 0, void 0, void 0, function* () {
144
- const harmony = yield harmony_1.Harmony.load([react_aspect_1.ReactAspect], 'cli', {});
145
- yield harmony.run();
146
- const react = harmony.get('@teambit/react');
147
- }));
148
- it('should execute an aspect in the ui runtime', () => __awaiter(void 0, void 0, void 0, function* () {
149
- const harmony = yield harmony_1.Harmony.load([react_aspect_1.ReactAspect], 'ui', {});
150
- yield harmony.run();
151
- const react = harmony.get('@teambit/react');
152
- chai_1.expect(react.render()).to.exist;
153
- }));
131
+ // it('should execute an aspect in the cli runtime', async() => {
132
+ // const harmony = await Harmony.load([ReactAspect], 'cli', {});
133
+ // await harmony.run();
134
+ // const react = harmony.get<ReactCLI>('@teambit/react');
135
+ // })
136
+ // it('should execute an aspect in the ui runtime', async() => {
137
+ // const harmony = await Harmony.load([ReactAspect], 'ui', {});
138
+ // await harmony.run();
139
+ // const react = harmony.get<ReactUI>('@teambit/react');
140
+ // expect(react.render()).toBeTruthy;
141
+ // })
154
142
  });
155
143
  });
144
+ //# sourceMappingURL=harmony.spec.old.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harmony.spec.old.js","sourceRoot":"","sources":["../harmony.spec.old.ts"],"names":[],"mappings":";;AAYA,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;QACvB,+CAA+C;QAC/C,yBAAyB;QACzB,4BAA4B;QAC5B,4CAA4C;QAC5C,SAAS;QACT,mCAAmC;QACnC,4DAA4D;QAC5D,QAAQ;QAER,qEAAqE;QACrE,qDAAqD;QACrD,iEAAiE;QACjE,qEAAqE;QAErE,yDAAyD;QACzD,uDAAuD;QACvD,QAAQ;QAER,0DAA0D;QAC1D,kBAAkB;QAClB,mBAAmB;QACnB,gCAAgC;QAChC,UAAU;QACV,QAAQ;QAER,kEAAkE;QAClE,yBAAyB;QACzB,mCAAmC;QACnC,4BAA4B;QAC5B,mCAAmC;QACnC,iBAAiB;QAEjB,oCAAoC;QACpC,sDAAsD;QACtD,4CAA4C;QAC5C,UAAU;QAEV,yCAAyC;QACzC,gCAAgC;QAChC,uCAAuC;QACvC,yFAAyF;QACzF,mBAAmB;QACnB,sCAAsC;QACtC,qCAAqC;QACrC,eAAe;QAEf,sBAAsB;QACtB,w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DAA2D;QAC3D,KAAK;QAEL,gEAAgE;QAChE,iEAAiE;QACjE,yBAAyB;QACzB,0DAA0D;QAC1D,uCAAuC;QACvC,KAAK;IACP,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AspectGraph = exports.RuntimeDefinition = exports.Aspect = exports.HarmonyError = exports.SlotRegistry = exports.Slot = exports.Harmony = exports.createHook = exports.provider = exports.hook = exports.HookRegistry = exports.register = exports.Extension = void 0;
3
7
  var extension_1 = require("./extension");
4
8
  Object.defineProperty(exports, "Extension", { enumerable: true, get: function () { return extension_1.ExtensionDecorator; } });
5
9
  Object.defineProperty(exports, "register", { enumerable: true, get: function () { return extension_1.register; } });
@@ -19,4 +23,5 @@ Object.defineProperty(exports, "Aspect", { enumerable: true, get: function () {
19
23
  var runtimes_1 = require("./runtimes");
20
24
  Object.defineProperty(exports, "RuntimeDefinition", { enumerable: true, get: function () { return runtimes_1.RuntimeDefinition; } });
21
25
  var extension_graph_1 = require("./extension-graph/extension-graph");
22
- Object.defineProperty(exports, "AspectGraph", { enumerable: true, get: function () { return extension_graph_1.default; } });
26
+ Object.defineProperty(exports, "AspectGraph", { enumerable: true, get: function () { return __importDefault(extension_graph_1).default; } });
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAkH;AAAzG,sGAAA,kBAAkB,OAAa;AAAE,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAAE,iGAAA,IAAI,OAAA;AAAE,qGAAA,QAAQ,OAAA;AAAE,uGAAA,UAAU,OAAA;AAC5F,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,iCAA6C;AAApC,6FAAA,IAAI,OAAA;AAAE,qGAAA,YAAY,OAAA;AAG3B,4DAA0D;AAAjD,6GAAA,YAAY,OAAA;AACrB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,uCAAgE;AAAvD,6GAAA,iBAAiB,OAAA;AAC1B,qEAA2E;AAAlE,+HAAA,OAAO,OAAe"}
package/dist/readme.md ADDED
@@ -0,0 +1,80 @@
1
+ # Harmony
2
+ Harmony is the engine that drives Bit extensibility and composability.
3
+ It's an abstract extension system indended to make any software extendable and composable.
4
+
5
+ Harmony takes a "micro-kernel" approach and implements the near-minimum amount of software required to build any JavaScript system from independent components through composition.
6
+
7
+ ## Installation
8
+ ```bash
9
+ $ bit install @teambit/harmony
10
+ ```
11
+
12
+ ## Quick start
13
+ ```ts
14
+ import { Harmony, Extension } from 'harmony';
15
+
16
+ @Extensioin
17
+ class Person {
18
+ sayHello(name = 'world') {
19
+ return `hello ${name}!`;
20
+ }
21
+ }
22
+
23
+ const person = Harmony.load(Person);
24
+ helloWorld.sayHello(); // returns 'hello world!'
25
+ ```
26
+
27
+ ## Component composition
28
+
29
+ ### DI
30
+ ```ts
31
+ class Dude {
32
+ constructor(
33
+ private person: Person
34
+ ) {}
35
+
36
+ sayHello() {
37
+ return this.person.sayHello('dude');
38
+ }
39
+ };
40
+
41
+ Harmony.load([Dude]).sayHello(); // echos 'hello dude!'
42
+ ```
43
+
44
+ ### Hooks
45
+ ```ts
46
+ @Extension()
47
+ class CLI {
48
+ // @hook('command') commands = Hook.create<Command>();
49
+ static command() {
50
+ return Hook.create<Command>();
51
+ }
52
+
53
+ run() {
54
+ const allCommands = this.commands.list(); // outputs all hook subscribers
55
+ }
56
+ }
57
+
58
+ @Extension()
59
+ class Compiler {
60
+
61
+ @command()
62
+ main() {
63
+ return {
64
+ synopsis: 'compile <path>',
65
+ render: () => <Box></Box>
66
+ };
67
+ }
68
+ }
69
+ ```
70
+
71
+ ## Extension configuration
72
+
73
+ ## Extension metadata
74
+
75
+ ## API reference
76
+
77
+ ## License
78
+ Apache License, Version 2.0
79
+
80
+ Made with ❤ to open software by Team Bit.
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RuntimeModuleError = exports.RuntimeNotDefined = void 0;
3
4
  var runtime_not_defined_1 = require("./runtime-not-defined");
4
5
  Object.defineProperty(exports, "RuntimeNotDefined", { enumerable: true, get: function () { return runtime_not_defined_1.RuntimeNotDefined; } });
5
6
  var runtime_module_error_1 = require("./runtime-module-error");
6
7
  Object.defineProperty(exports, "RuntimeModuleError", { enumerable: true, get: function () { return runtime_module_error_1.RuntimeModuleError; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtimes/exceptions/index.ts"],"names":[],"mappings":";;;AAAA,6DAA0D;AAAjD,wHAAA,iBAAiB,OAAA;AAC1B,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA"}
@@ -1,5 +1,5 @@
1
1
  export declare class RuntimeModuleError extends Error {
2
2
  private err;
3
3
  constructor(err: Error);
4
- get stack(): string | undefined;
4
+ get stack(): string;
5
5
  }
@@ -11,3 +11,4 @@ class RuntimeModuleError extends Error {
11
11
  }
12
12
  }
13
13
  exports.RuntimeModuleError = RuntimeModuleError;
14
+ //# sourceMappingURL=runtime-module-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-module-error.js","sourceRoot":"","sources":["../../../runtimes/exceptions/runtime-module-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YACU,GAAU;QAChB,KAAK,CAAC,qDAAqD,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;QADnE,QAAG,GAAH,GAAG,CAAO;IAC0D,CAAC;IAE/E,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;IACxB,CAAC;CACF;AARD,gDAQC"}
@@ -5,3 +5,4 @@ class RuntimeNotDefined extends Error {
5
5
  constructor(name) { super(`runtime: '${name}' was not defined by any aspect`); }
6
6
  }
7
7
  exports.RuntimeNotDefined = RuntimeNotDefined;
8
+ //# sourceMappingURL=runtime-not-defined.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-not-defined.js","sourceRoot":"","sources":["../../../runtimes/exceptions/runtime-not-defined.ts"],"names":[],"mappings":";;;AAAA,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YACE,IAAY,IACV,KAAK,CAAC,aAAa,IAAI,iCAAiC,CAAC,CAAA,CAAC,CAAC;CAChE;AAJD,8CAIC"}
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RuntimeDefinition = exports.Runtimes = void 0;
3
4
  var runtimes_1 = require("./runtimes");
4
5
  Object.defineProperty(exports, "Runtimes", { enumerable: true, get: function () { return runtimes_1.Runtimes; } });
5
6
  var runtime_definition_1 = require("./runtime-definition");
6
7
  Object.defineProperty(exports, "RuntimeDefinition", { enumerable: true, get: function () { return runtime_definition_1.RuntimeDefinition; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../runtimes/index.ts"],"names":[],"mappings":";;;AACA,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,2DAAyD;AAAhD,uHAAA,iBAAiB,OAAA"}
@@ -24,3 +24,4 @@ class RuntimeDefinition {
24
24
  }
25
25
  }
26
26
  exports.RuntimeDefinition = RuntimeDefinition;
27
+ //# sourceMappingURL=runtime-definition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-definition.js","sourceRoot":"","sources":["../../runtimes/runtime-definition.ts"],"names":[],"mappings":";;;AAMA,MAAM,iBAAiB,GAAG,CAAC,QAAgB,EAAE,IAAY,EAAE,EAAE;IAC3D,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC;AACxC,CAAC,CAAA;AAED,MAAa,iBAAiB;IAC5B,YACW,IAAY,EACZ,gBAA6D,iBAAiB;QAD9E,SAAI,GAAJ,IAAI,CAAQ;QACZ,kBAAa,GAAb,aAAa,CAAiE;IACtF,CAAC;IAEJ,cAAc,CAAC,KAAe;QAC5B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,CAAC,IAAY;QAClB,QAAQ;QACR,mBAAmB;QACnB,iBAAiB;QACjB,uCAAuC;QACvC,IAAI;IACN,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,GAAoB;QAChC,OAAO,IAAI,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;CACF;AArBD,8CAqBC"}
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=runtime-manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-manifest.js","sourceRoot":"","sources":["../../runtimes/runtime-manifest.ts"],"names":[],"mappings":""}
@@ -40,3 +40,4 @@ class Runtimes {
40
40
  }
41
41
  }
42
42
  exports.Runtimes = Runtimes;
43
+ //# sourceMappingURL=runtimes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimes.js","sourceRoot":"","sources":["../../runtimes/runtimes.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,6CAAiD;AAEjD,MAAa,QAAQ;IACnB,YACW,iBAAqD;QAArD,sBAAiB,GAAjB,iBAAiB,CAAoC;IAC7D,CAAC;IAEJ,GAAG,CAAC,OAA0B;QAC5B,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG,CAAC,IAAY;QACd,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,8BAAiB,CAAC,IAAI,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,OAAO;IAEP,CAAC;IAED,MAAM,CAAO,IAAI,CAAC,KAAsB;;YACtC,MAAM,QAAQ,GAAyC,EAAE,CAAC;YAC1D,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAClC,IAAI,CAAC,QAAQ,CAAC,cAAc;oBAAE,OAAO;gBACrC,QAAQ,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,cAAc,CAAC;YACnE,CAAC,CAAC,CAAC;YAEH,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC;KAAA;CACF;AA7BD,4BA6BC"}
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SlotRegistry = exports.Slot = void 0;
3
4
  var slot_1 = require("./slot");
4
5
  Object.defineProperty(exports, "Slot", { enumerable: true, get: function () { return slot_1.Slot; } });
5
6
  var registry_1 = require("./registry");
6
7
  Object.defineProperty(exports, "SlotRegistry", { enumerable: true, get: function () { return registry_1.SlotRegistry; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../slots/index.ts"],"names":[],"mappings":";;;AAAA,+BAA4C;AAAnC,4FAAA,IAAI,OAAA;AACb,uCAA0C;AAAjC,wGAAA,YAAY,OAAA"}
@@ -33,3 +33,4 @@ class SlotRegistry {
33
33
  }
34
34
  }
35
35
  exports.SlotRegistry = SlotRegistry;
36
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../slots/registry.ts"],"names":[],"mappings":";;;AACA,MAAa,YAAY;IACvB,YACU,UAAwB,EACvB,MAAM,IAAI,GAAG,EAAa;QAD3B,eAAU,GAAV,UAAU,CAAc;QACvB,QAAG,GAAH,GAAG,CAAuB;IAClC,CAAC;IAEJ;;OAEG;IACH,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,KAAQ;QACf,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IAC1B,CAAC;CACF;AAlCD,oCAkCC"}
@@ -10,3 +10,4 @@ class Slot {
10
10
  }
11
11
  }
12
12
  exports.Slot = Slot;
13
+ //# sourceMappingURL=slot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slot.js","sourceRoot":"","sources":["../../slots/slot.ts"],"names":[],"mappings":";;;AAAA,yCAA0C;AAE1C,MAAa,IAAI;IACf,MAAM,CAAC,QAAQ;QACb,OAAO,CAAC,UAAwB,EAAE,EAAE;YAClC,OAAO,IAAI,uBAAY,CAAI,UAAU,CAAC,CAAC;QACzC,CAAC,CAAA;IACH,CAAC;CACF;AAND,oBAMC"}
package/dist/types.js CHANGED
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":""}
@@ -23,3 +23,4 @@ function asyncForEach(array, callback) {
23
23
  });
24
24
  }
25
25
  exports.asyncForEach = asyncForEach;
26
+ //# sourceMappingURL=async-for-each.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-for-each.js","sourceRoot":"","sources":["../../utils/async-for-each.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;GAGG;AACH,SAAsB,YAAY,CAAC,KAAY,EAAE,QAAa;;QAC5D,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE;YACpD,4CAA4C;YAC5C,MAAM,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;SAC5C;IACH,CAAC;CAAA;AALD,oCAKC"}
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asyncForEach = void 0;
3
4
  var async_for_each_1 = require("./async-for-each");
4
5
  Object.defineProperty(exports, "asyncForEach", { enumerable: true, get: function () { return async_for_each_1.asyncForEach; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAAvC,8GAAA,YAAY,OAAA"}
@@ -0,0 +1 @@
1
+ export class ExtensionInstantiationException extends Error {}
@@ -0,0 +1,28 @@
1
+ import { Extension } from '../extension/extension';
2
+
3
+ export default class ExtensionLoadError extends Error {
4
+ constructor(
5
+ /**
6
+ * failed extension
7
+ */
8
+ private extension: Extension,
9
+
10
+ /**
11
+ * extension error
12
+ */
13
+ private originalError: Error,
14
+
15
+ /**
16
+ * extension formatted / handled error message
17
+ */
18
+ private msg?: string
19
+ ) {
20
+ super();
21
+ }
22
+
23
+ toString() {
24
+ return `failed to load extension: ${this.extension.name} with error:
25
+
26
+ ${this.msg || this.originalError.stack}`;
27
+ }
28
+ }
@@ -0,0 +1,24 @@
1
+ import { Extension } from '../extension/extension';
2
+ import { HarmonyError } from './harmony-error';
3
+
4
+ export default class ExtensionPotentialCircular extends HarmonyError {
5
+ constructor(
6
+ /**
7
+ * failed extension
8
+ */
9
+ private extension: Extension,
10
+
11
+ /**
12
+ * valid extensions dependencies
13
+ */
14
+ private validDeps: Extension[]
15
+ ) {
16
+ super();
17
+ }
18
+
19
+ toString() {
20
+ return `Failed to load the dependencies for extension .
21
+ This may result from a wrong import or from circular dependencies in imports.
22
+ The following dependencies succeeded loading:`;
23
+ }
24
+ }
@@ -0,0 +1 @@
1
+ export class HarmonyAlreadyRunning extends Error {}
@@ -0,0 +1 @@
1
+ export class HarmonyError extends Error {}
@@ -0,0 +1 @@
1
+ export class HookNotFound extends Error {}
@@ -0,0 +1,5 @@
1
+ export { default as ExtensionLoadError } from './extension-load-error';
2
+ export { default as ExtensionPotentialCircular } from './extension-potential-circular';
3
+ export { HarmonyAlreadyRunning } from './harmony-already-running';
4
+ export { HookNotFound } from './hook-not-found';
5
+ export { ExtensionInstantiationException } from './extension-init-error';
@@ -0,0 +1,8 @@
1
+ import { Extension } from '../index';
2
+
3
+ /**
4
+ * Class extension of type any. this class is indended for use inside Harmony
5
+ * where extension generics type relevance is low.
6
+ */
7
+
8
+ // export class AnyExtension extends Extension {}
@@ -0,0 +1,126 @@
1
+ import { HookNotFound } from '../exceptions';
2
+ import { ExtensionManifest } from "./extension-manifest";
3
+ // :TODO refactor this file asap
4
+
5
+ export type ExtensionOptions = {
6
+ dependencies?: ExtensionManifest[],
7
+ name?: string
8
+ }
9
+
10
+ const map: any = {};
11
+
12
+ /**
13
+ * decorator for an Harmony extension.
14
+ */
15
+ export function ExtensionDecorator({ name, dependencies }: ExtensionOptions = {}) {
16
+ function classDecorator<T extends {new(...args:any[]): {}}>(constructor:T) {
17
+ Reflect.defineMetadata('harmony:name', name || constructor.name, constructor);
18
+ Reflect.defineMetadata('harmony:dependencies', calculateDependnecies(constructor, dependencies), constructor)
19
+ }
20
+
21
+ return classDecorator;
22
+ }
23
+
24
+ export function provider() {
25
+ return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
26
+ const keys = Reflect.getMetadata('design:paramtypes', descriptor);
27
+ }
28
+ }
29
+
30
+ // @hack todo: must be defined and assigned from a single location
31
+ function providerFn(classExtension: any) {
32
+ return classExtension.provide ? classExtension.provide : classExtension.provider;
33
+ }
34
+
35
+ function calculateDependnecies(classExtension: any, deps?: ExtensionManifest[]): ExtensionManifest[] {
36
+ function fromMetadata() {
37
+ const provider = providerFn(classExtension)
38
+ if (provider) {
39
+ // // TODO: check why Reflect.getMetadataKeys(provider) is empty and how to access method param types.
40
+ // console.log(Reflect.getMetadataKeys(classExtension.provide))
41
+ return [];
42
+ }
43
+
44
+ return Reflect.getMetadata('design:paramtypes', classExtension);
45
+ }
46
+
47
+ const dependnecies = deps ? deps : fromMetadata() || [];
48
+ const hookDeps = classExtension.__hookDeps ? classExtension.__hookDeps : [];
49
+ return dependnecies.concat(hookDeps) || [];
50
+ }
51
+
52
+ // :TODO refactor this asap to handle harmony objects properly
53
+ export function register(extension: ExtensionManifest, name?: string) {
54
+ return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
55
+ // if (!target.constructor.__hookDeps) Reflect.defineMetadata('harmony:subscriptions', [extension], target.constructor);
56
+ // else target.constructor.__hookDeps.push(extension);
57
+
58
+ const extensionName = Reflect.getMetadata('harmony:name', extension);
59
+ if (!map[extensionName]) {
60
+ map[extensionName] = {};
61
+ }
62
+
63
+ const hook = map[extensionName][name || propertyKey];
64
+ // if (!hook) throw new HookNotFound();
65
+ if (!hook) return;
66
+ hook.register(target[propertyKey]);
67
+ }
68
+ }
69
+
70
+ export function createHook() {
71
+ const randomId = Math.random().toString(36).substring(2);
72
+ map[randomId] = HookRegistry.create();
73
+ const decorator = function(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
74
+ const registry = map[randomId];
75
+ registry.register(descriptor.value);
76
+ }
77
+
78
+ decorator.hash = randomId;
79
+
80
+ return decorator;
81
+ }
82
+
83
+ export function hook(name?: string) {
84
+ return function(target: any, propertyKey: string) {
85
+ let instance = HookRegistry.create();
86
+ const extensionName = Reflect.getMetadata('harmony:name', target.constructor);
87
+ const hookName = name || propertyKey;
88
+
89
+ if (!map[extensionName]) map[extensionName] = {[hookName]: instance};
90
+ else map[extensionName][hookName] = instance;
91
+
92
+ Object.defineProperty(target, propertyKey, {
93
+ get: () => {
94
+ return instance;
95
+ },
96
+ set: (value) => {
97
+ instance = value;
98
+ }
99
+ });
100
+ }
101
+ }
102
+
103
+ export class HookRegistry<T> {
104
+ constructor(
105
+ private fillers: T[],
106
+ readonly hash?: string
107
+ ) {}
108
+
109
+ register(filler: T) {
110
+ this.fillers.push(filler);
111
+ }
112
+
113
+ list() {
114
+ // return map[this.name][name] || [];
115
+ return this.fillers;
116
+ }
117
+
118
+ static of<T>(hook: any): HookRegistry<T> {
119
+ return map[hook.hash];
120
+ }
121
+
122
+ // hack due to https://github.com/microsoft/TypeScript/issues/4881
123
+ static create<T>() {
124
+ return new HookRegistry<T>([]);
125
+ }
126
+ }
@@ -0,0 +1,51 @@
1
+ import { ProviderFn } from '../types';
2
+ import { Slot, SlotProvider } from '../slots';
3
+
4
+ export type ExtensionManifest = {
5
+ /**
6
+ * extension name.
7
+ */
8
+ name: string;
9
+
10
+ /**
11
+ * extension unique ID.
12
+ */
13
+ id?: string;
14
+
15
+ /**
16
+ * version of the extension
17
+ */
18
+ // version: string;
19
+
20
+ /**
21
+ * array of extension dependencies.
22
+ * these other extensions will be installed and resolved prior to this extension activation.
23
+ */
24
+ dependencies?: ExtensionManifest[];
25
+
26
+ /**
27
+ * reference to the extension factory function.
28
+ */
29
+ provider?: ProviderFn;
30
+
31
+ /**
32
+ *
33
+ * default config of the extension.
34
+ */
35
+ defaultConfig?: object;
36
+
37
+ /**
38
+ * alias to provider.
39
+ */
40
+ provide?: ProviderFn;
41
+
42
+ /**
43
+ * array of slots the extension is exposing.
44
+ */
45
+ slots?: SlotProvider<unknown>[],
46
+
47
+ /**
48
+ * any further keys which might be expected by other extensions.
49
+ */
50
+ [key: string]: any;
51
+ }