@teambit/harmony 0.0.0-19ea14143ef7d5f4e4daa6e8ac8a8c97c9d683d5

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 (248) 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 +27 -0
  6. package/dist/aspect.js +33 -0
  7. package/dist/aspect.js.map +1 -0
  8. package/dist/config/config.d.ts +22 -0
  9. package/dist/config/config.js +37 -0
  10. package/dist/config/config.js.map +1 -0
  11. package/dist/config/index.d.ts +1 -0
  12. package/dist/config/index.js +6 -0
  13. package/dist/config/index.js.map +1 -0
  14. package/dist/container.d.ts +8 -0
  15. package/dist/container.js +22 -0
  16. package/dist/container.js.map +1 -0
  17. package/dist/exceptions/extension-init-error.d.ts +2 -0
  18. package/dist/exceptions/extension-init-error.js +7 -0
  19. package/dist/exceptions/extension-init-error.js.map +1 -0
  20. package/dist/exceptions/extension-load-error.d.ts +29 -0
  21. package/dist/exceptions/extension-load-error.js +29 -0
  22. package/dist/exceptions/extension-load-error.js.map +1 -0
  23. package/dist/exceptions/extension-potential-circular.d.ts +22 -0
  24. package/dist/exceptions/extension-potential-circular.js +25 -0
  25. package/dist/exceptions/extension-potential-circular.js.map +1 -0
  26. package/dist/exceptions/harmony-already-running.d.ts +2 -0
  27. package/dist/exceptions/harmony-already-running.js +7 -0
  28. package/dist/exceptions/harmony-already-running.js.map +1 -0
  29. package/dist/exceptions/harmony-error.d.ts +2 -0
  30. package/dist/exceptions/harmony-error.js +7 -0
  31. package/dist/exceptions/harmony-error.js.map +1 -0
  32. package/dist/exceptions/hook-not-found.d.ts +2 -0
  33. package/dist/exceptions/hook-not-found.js +7 -0
  34. package/dist/exceptions/hook-not-found.js.map +1 -0
  35. package/dist/exceptions/index.d.ts +5 -0
  36. package/dist/exceptions/index.js +17 -0
  37. package/dist/exceptions/index.js.map +1 -0
  38. package/dist/exceptions/runtime-not-defined.d.ts +0 -0
  39. package/dist/exceptions/runtime-not-defined.js +1 -0
  40. package/dist/exceptions/runtime-not-defined.js.map +1 -0
  41. package/dist/extension/any-extension.d.ts +5 -0
  42. package/dist/extension/any-extension.js +8 -0
  43. package/dist/extension/any-extension.js.map +1 -0
  44. package/dist/extension/decorator.d.ts +27 -0
  45. package/dist/extension/decorator.js +109 -0
  46. package/dist/extension/decorator.js.map +1 -0
  47. package/dist/extension/extension-manifest.d.ts +41 -0
  48. package/dist/extension/extension-manifest.js +3 -0
  49. package/dist/extension/extension-manifest.js.map +1 -0
  50. package/dist/extension/extension.d.ts +50 -0
  51. package/dist/extension/extension.js +128 -0
  52. package/dist/extension/extension.js.map +1 -0
  53. package/dist/extension/index.d.ts +3 -0
  54. package/dist/extension/index.js +13 -0
  55. package/dist/extension/index.js.map +1 -0
  56. package/dist/extension-graph/extension-graph.d.ts +34 -0
  57. package/dist/extension-graph/extension-graph.js +152 -0
  58. package/dist/extension-graph/extension-graph.js.map +1 -0
  59. package/dist/extension-graph/from-extension.d.ts +31 -0
  60. package/dist/extension-graph/from-extension.js +63 -0
  61. package/dist/extension-graph/from-extension.js.map +1 -0
  62. package/dist/extension-graph/index.d.ts +1 -0
  63. package/dist/extension-graph/index.js +9 -0
  64. package/dist/extension-graph/index.js.map +1 -0
  65. package/dist/factory/extension-factory.d.ts +3 -0
  66. package/dist/factory/extension-factory.js +11 -0
  67. package/dist/factory/extension-factory.js.map +1 -0
  68. package/dist/factory/index.d.ts +1 -0
  69. package/dist/factory/index.js +6 -0
  70. package/dist/factory/index.js.map +1 -0
  71. package/dist/fixtures/aspects/babel/babel.aspect.d.ts +5 -0
  72. package/dist/fixtures/aspects/babel/babel.aspect.js +13 -0
  73. package/dist/fixtures/aspects/babel/babel.aspect.js.map +1 -0
  74. package/dist/fixtures/aspects/babel/babel.cli.d.ts +5 -0
  75. package/dist/fixtures/aspects/babel/babel.cli.js +28 -0
  76. package/dist/fixtures/aspects/babel/babel.cli.js.map +1 -0
  77. package/dist/fixtures/aspects/react/react.aspect.d.ts +6 -0
  78. package/dist/fixtures/aspects/react/react.aspect.js +19 -0
  79. package/dist/fixtures/aspects/react/react.aspect.js.map +1 -0
  80. package/dist/fixtures/aspects/react/react.cli.d.ts +11 -0
  81. package/dist/fixtures/aspects/react/react.cli.js +71 -0
  82. package/dist/fixtures/aspects/react/react.cli.js.map +1 -0
  83. package/dist/fixtures/aspects/react/react.ui.d.ts +5 -0
  84. package/dist/fixtures/aspects/react/react.ui.js +31 -0
  85. package/dist/fixtures/aspects/react/react.ui.js.map +1 -0
  86. package/dist/fixtures/aspects/ui/ui.aspect.d.ts +4 -0
  87. package/dist/fixtures/aspects/ui/ui.aspect.js +15 -0
  88. package/dist/fixtures/aspects/ui/ui.aspect.js.map +1 -0
  89. package/dist/fixtures/aspects/ui/ui.ui.d.ts +4 -0
  90. package/dist/fixtures/aspects/ui/ui.ui.js +24 -0
  91. package/dist/fixtures/aspects/ui/ui.ui.js.map +1 -0
  92. package/dist/fixtures/babel/babel.extension.d.ts +9 -0
  93. package/dist/fixtures/babel/babel.extension.js +30 -0
  94. package/dist/fixtures/babel/babel.extension.js.map +1 -0
  95. package/dist/fixtures/babel/index.d.ts +0 -0
  96. package/dist/fixtures/babel/index.js +1 -0
  97. package/dist/fixtures/babel/index.js.map +1 -0
  98. package/dist/fixtures/base-compiler/base-compiler.extension.d.ts +13 -0
  99. package/dist/fixtures/base-compiler/base-compiler.extension.js +30 -0
  100. package/dist/fixtures/base-compiler/base-compiler.extension.js.map +1 -0
  101. package/dist/fixtures/base-compiler/index.d.ts +1 -0
  102. package/dist/fixtures/base-compiler/index.js +6 -0
  103. package/dist/fixtures/base-compiler/index.js.map +1 -0
  104. package/dist/fixtures/cli/cli.extension.d.ts +18 -0
  105. package/dist/fixtures/cli/cli.extension.js +24 -0
  106. package/dist/fixtures/cli/cli.extension.js.map +1 -0
  107. package/dist/fixtures/cli/command.d.ts +6 -0
  108. package/dist/fixtures/cli/command.js +1 -0
  109. package/dist/fixtures/cli/command.js.map +1 -0
  110. package/dist/fixtures/cli/index.d.ts +1 -0
  111. package/dist/fixtures/cli/index.js +18 -0
  112. package/dist/fixtures/cli/index.js.map +1 -0
  113. package/dist/fixtures/typescript/index.d.ts +0 -0
  114. package/dist/fixtures/typescript/index.js +1 -0
  115. package/dist/fixtures/typescript/index.js.map +1 -0
  116. package/dist/fixtures/typescript/typescript.d.ts +7 -0
  117. package/dist/fixtures/typescript/typescript.js +31 -0
  118. package/dist/fixtures/typescript/typescript.js.map +1 -0
  119. package/dist/harmony-config/config-reader.d.ts +1 -0
  120. package/dist/harmony-config/config-reader.js +21 -0
  121. package/dist/harmony-config/config-reader.js.map +1 -0
  122. package/dist/harmony-config/exceptions/index.d.ts +1 -0
  123. package/dist/harmony-config/exceptions/index.js +6 -0
  124. package/dist/harmony-config/exceptions/index.js.map +1 -0
  125. package/dist/harmony-config/exceptions/read-config-error.d.ts +5 -0
  126. package/dist/harmony-config/exceptions/read-config-error.js +14 -0
  127. package/dist/harmony-config/exceptions/read-config-error.js.map +1 -0
  128. package/dist/harmony-config/harmony-config.d.ts +17 -0
  129. package/dist/harmony-config/harmony-config.js +36 -0
  130. package/dist/harmony-config/harmony-config.js.map +1 -0
  131. package/dist/harmony-config/index.d.ts +1 -0
  132. package/dist/harmony-config/index.js +6 -0
  133. package/dist/harmony-config/index.js.map +1 -0
  134. package/dist/harmony-config/locator.d.ts +0 -0
  135. package/dist/harmony-config/locator.js +1 -0
  136. package/dist/harmony-config/locator.js.map +1 -0
  137. package/dist/harmony.d.ts +63 -0
  138. package/dist/harmony.docs.mdx +250 -0
  139. package/dist/harmony.js +151 -0
  140. package/dist/harmony.js.map +1 -0
  141. package/dist/harmony.spec.old.d.ts +1 -0
  142. package/dist/harmony.spec.old.js +144 -0
  143. package/dist/harmony.spec.old.js.map +1 -0
  144. package/dist/index.d.ts +9 -0
  145. package/dist/index.js +32 -0
  146. package/dist/index.js.map +1 -0
  147. package/dist/preview-1782314412027.js +7 -0
  148. package/dist/readme.md +80 -0
  149. package/dist/runtimes/exceptions/index.d.ts +2 -0
  150. package/dist/runtimes/exceptions/index.js +8 -0
  151. package/dist/runtimes/exceptions/index.js.map +1 -0
  152. package/dist/runtimes/exceptions/runtime-module-error.d.ts +5 -0
  153. package/dist/runtimes/exceptions/runtime-module-error.js +14 -0
  154. package/dist/runtimes/exceptions/runtime-module-error.js.map +1 -0
  155. package/dist/runtimes/exceptions/runtime-not-defined.d.ts +3 -0
  156. package/dist/runtimes/exceptions/runtime-not-defined.js +8 -0
  157. package/dist/runtimes/exceptions/runtime-not-defined.js.map +1 -0
  158. package/dist/runtimes/index.d.ts +3 -0
  159. package/dist/runtimes/index.js +8 -0
  160. package/dist/runtimes/index.js.map +1 -0
  161. package/dist/runtimes/runtime-definition.d.ts +11 -0
  162. package/dist/runtimes/runtime-definition.js +27 -0
  163. package/dist/runtimes/runtime-definition.js.map +1 -0
  164. package/dist/runtimes/runtime-manifest.d.ts +13 -0
  165. package/dist/runtimes/runtime-manifest.js +3 -0
  166. package/dist/runtimes/runtime-manifest.js.map +1 -0
  167. package/dist/runtimes/runtimes.d.ts +14 -0
  168. package/dist/runtimes/runtimes.js +43 -0
  169. package/dist/runtimes/runtimes.js.map +1 -0
  170. package/dist/slots/index.d.ts +2 -0
  171. package/dist/slots/index.js +8 -0
  172. package/dist/slots/index.js.map +1 -0
  173. package/dist/slots/registry.d.ts +21 -0
  174. package/dist/slots/registry.js +36 -0
  175. package/dist/slots/registry.js.map +1 -0
  176. package/dist/slots/slot.d.ts +5 -0
  177. package/dist/slots/slot.js +13 -0
  178. package/dist/slots/slot.js.map +1 -0
  179. package/dist/types.d.ts +5 -0
  180. package/dist/types.js +3 -0
  181. package/dist/types.js.map +1 -0
  182. package/dist/utils/async-for-each.d.ts +5 -0
  183. package/dist/utils/async-for-each.js +25 -0
  184. package/dist/utils/async-for-each.js.map +1 -0
  185. package/dist/utils/index.d.ts +1 -0
  186. package/dist/utils/index.js +6 -0
  187. package/dist/utils/index.js.map +1 -0
  188. package/exceptions/extension-init-error.ts +1 -0
  189. package/exceptions/extension-load-error.ts +28 -0
  190. package/exceptions/extension-potential-circular.ts +24 -0
  191. package/exceptions/harmony-already-running.ts +1 -0
  192. package/exceptions/harmony-error.ts +1 -0
  193. package/exceptions/hook-not-found.ts +1 -0
  194. package/exceptions/index.ts +5 -0
  195. package/exceptions/runtime-not-defined.ts +0 -0
  196. package/extension/any-extension.ts +8 -0
  197. package/extension/decorator.ts +126 -0
  198. package/extension/extension-manifest.ts +51 -0
  199. package/extension/extension.ts +142 -0
  200. package/extension/index.ts +3 -0
  201. package/extension-graph/extension-graph.ts +165 -0
  202. package/extension-graph/from-extension.ts +72 -0
  203. package/extension-graph/index.ts +1 -0
  204. package/factory/extension-factory.ts +8 -0
  205. package/factory/index.ts +1 -0
  206. package/fixtures/aspects/babel/babel.aspect.ts +14 -0
  207. package/fixtures/aspects/babel/babel.cli.ts +16 -0
  208. package/fixtures/aspects/react/react.aspect.ts +22 -0
  209. package/fixtures/aspects/react/react.cli.ts +26 -0
  210. package/fixtures/aspects/react/react.ui.ts +16 -0
  211. package/fixtures/aspects/ui/ui.aspect.ts +13 -0
  212. package/fixtures/aspects/ui/ui.ui.ts +11 -0
  213. package/fixtures/babel/babel.extension.ts +20 -0
  214. package/fixtures/babel/index.ts +0 -0
  215. package/fixtures/base-compiler/base-compiler.extension.ts +31 -0
  216. package/fixtures/base-compiler/index.ts +1 -0
  217. package/fixtures/cli/cli.extension.ts +25 -0
  218. package/fixtures/cli/command.ts +6 -0
  219. package/fixtures/cli/index.ts +1 -0
  220. package/fixtures/typescript/index.ts +0 -0
  221. package/fixtures/typescript/typescript.ts +20 -0
  222. package/harmony-config/config-reader.ts +18 -0
  223. package/harmony-config/exceptions/index.ts +1 -0
  224. package/harmony-config/exceptions/read-config-error.ts +9 -0
  225. package/harmony-config/harmony-config.ts +49 -0
  226. package/harmony-config/index.ts +1 -0
  227. package/harmony-config/locator.ts +0 -0
  228. package/harmony.docs.mdx +250 -0
  229. package/harmony.spec.old.ts +177 -0
  230. package/harmony.ts +148 -0
  231. package/index.ts +13 -0
  232. package/package.json +68 -0
  233. package/readme.md +80 -0
  234. package/runtimes/exceptions/index.ts +2 -0
  235. package/runtimes/exceptions/runtime-module-error.ts +9 -0
  236. package/runtimes/exceptions/runtime-not-defined.ts +5 -0
  237. package/runtimes/index.ts +3 -0
  238. package/runtimes/runtime-definition.ts +32 -0
  239. package/runtimes/runtime-manifest.ts +12 -0
  240. package/runtimes/runtimes.ts +34 -0
  241. package/slots/index.ts +2 -0
  242. package/slots/registry.ts +36 -0
  243. package/slots/slot.ts +11 -0
  244. package/types/asset.d.ts +29 -0
  245. package/types/style.d.ts +42 -0
  246. package/types.ts +7 -0
  247. package/utils/async-for-each.ts +10 -0
  248. package/utils/index.ts +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../fixtures/typescript/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { BaseCompiler } from '../base-compiler';
2
+ export declare class TypeScript {
3
+ private compiler;
4
+ constructor(compiler: string);
5
+ compile(): string;
6
+ static provider([baseCompiler]: [BaseCompiler]): Promise<TypeScript>;
7
+ }
@@ -0,0 +1,31 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TypeScript = void 0;
13
+ // @Extension({
14
+ // name: 'typescript',
15
+ // dependencies: [BaseCompiler]
16
+ // })
17
+ class TypeScript {
18
+ constructor(compiler) {
19
+ this.compiler = compiler;
20
+ }
21
+ compile() {
22
+ return this.compiler;
23
+ }
24
+ static provider(_a) {
25
+ return __awaiter(this, arguments, void 0, function* ([baseCompiler]) {
26
+ return new TypeScript(baseCompiler.compile());
27
+ });
28
+ }
29
+ }
30
+ exports.TypeScript = TypeScript;
31
+ //# sourceMappingURL=typescript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../../fixtures/typescript/typescript.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,eAAe;AACf,wBAAwB;AACxB,iCAAiC;AACjC,KAAK;AACL,MAAa,UAAU;IACrB,YACU,QAAgB;QAAhB,aAAQ,GAAR,QAAQ,CAAQ;IACvB,CAAC;IAEJ,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,MAAM,CAAO,QAAQ;6DAAC,CAAC,YAAY,CAAiB;YAClD,OAAO,IAAI,UAAU,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC;QAChD,CAAC;KAAA;CACF;AAZD,gCAYC"}
@@ -0,0 +1 @@
1
+ export declare function readConfigFile(path: string, mustExist?: boolean): Record<string, any>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readConfigFile = readConfigFile;
4
+ const comment_json_1 = require("comment-json");
5
+ const fs_1 = require("fs");
6
+ const read_config_error_1 = require("./exceptions/read-config-error");
7
+ function readConfigFile(path, mustExist = true) {
8
+ if (!mustExist && !(0, fs_1.existsSync)(path)) {
9
+ return {};
10
+ }
11
+ try {
12
+ const parsed = (0, comment_json_1.parse)((0, fs_1.readFileSync)(path, 'utf8'));
13
+ const json = parsed && typeof parsed === 'object' ? parsed : {};
14
+ delete json['$schema'];
15
+ return json;
16
+ }
17
+ catch (err) {
18
+ throw new read_config_error_1.ReadConfigError(path, err instanceof Error ? err : new Error(String(err)));
19
+ }
20
+ }
21
+ //# sourceMappingURL=config-reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-reader.js","sourceRoot":"","sources":["../../harmony-config/config-reader.ts"],"names":[],"mappings":";;AAIA,wCAaC;AAjBD,+CAAqC;AACrC,2BAA8C;AAC9C,sEAAiE;AAEjE,SAAgB,cAAc,CAAC,IAAY,EAAE,SAAS,GAAG,IAAI;IAC3D,IAAI,CAAC,SAAS,IAAI,CAAC,IAAA,eAAU,EAAC,IAAI,CAAC,EAAE,CAAC;QACpC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAA,oBAAK,EAAC,IAAA,iBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QACjD,MAAM,IAAI,GAAwB,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAE,MAA8B,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9G,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,mCAAe,CAAC,IAAI,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvF,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export { ReadConfigError } from './read-config-error';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReadConfigError = void 0;
4
+ var read_config_error_1 = require("./read-config-error");
5
+ Object.defineProperty(exports, "ReadConfigError", { enumerable: true, get: function () { return read_config_error_1.ReadConfigError; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../harmony-config/exceptions/index.ts"],"names":[],"mappings":";;;AAAA,yDAAsD;AAA7C,oHAAA,eAAe,OAAA"}
@@ -0,0 +1,5 @@
1
+ export declare class ReadConfigError extends Error {
2
+ private err;
3
+ constructor(path: string, err: Error);
4
+ get stack(): string;
5
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReadConfigError = void 0;
4
+ class ReadConfigError extends Error {
5
+ constructor(path, err) {
6
+ super(`failed to read config from path: ${path}`);
7
+ this.err = err;
8
+ }
9
+ get stack() {
10
+ return this.err.stack;
11
+ }
12
+ }
13
+ exports.ReadConfigError = ReadConfigError;
14
+ //# sourceMappingURL=read-config-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-config-error.js","sourceRoot":"","sources":["../../../harmony-config/exceptions/read-config-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAgB,SAAQ,KAAK;IACxC,YAAY,IAAY,EAAU,GAAU;QAC1C,KAAK,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAC;QADlB,QAAG,GAAH,GAAG,CAAO;IAE5C,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;IACxB,CAAC;CACF;AARD,0CAQC"}
@@ -0,0 +1,17 @@
1
+ export type ConfigOptions = {
2
+ cwd?: string;
3
+ global?: GlobalConfigOpts;
4
+ shouldThrow?: boolean;
5
+ };
6
+ export type GlobalConfigOpts = {
7
+ dir?: string;
8
+ name: string;
9
+ };
10
+ export declare class HarmonyConfig {
11
+ private raw;
12
+ constructor(raw: Record<string, any>);
13
+ toObject(): Record<string, any>;
14
+ toString(): string;
15
+ static load(fileName: string, opts?: ConfigOptions): HarmonyConfig;
16
+ static loadGlobal(globalOpts: GlobalConfigOpts, config?: any): HarmonyConfig;
17
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HarmonyConfig = void 0;
4
+ const comment_json_1 = require("comment-json");
5
+ const path_1 = require("path");
6
+ const config_reader_1 = require("./config-reader");
7
+ const userHome = require('user-home');
8
+ const defaultConfig = {
9
+ cwd: process.cwd(),
10
+ shouldThrow: true,
11
+ };
12
+ class HarmonyConfig {
13
+ constructor(raw) {
14
+ this.raw = raw;
15
+ }
16
+ toObject() {
17
+ return this.raw;
18
+ }
19
+ toString() {
20
+ return (0, comment_json_1.stringify)(this.raw);
21
+ }
22
+ static load(fileName, opts) {
23
+ const mergedOpts = Object.assign(defaultConfig, opts);
24
+ const config = (0, config_reader_1.readConfigFile)((0, path_1.join)(mergedOpts.cwd, fileName), mergedOpts.shouldThrow);
25
+ if (mergedOpts.global) {
26
+ return HarmonyConfig.loadGlobal(mergedOpts.global, config);
27
+ }
28
+ return new HarmonyConfig(config);
29
+ }
30
+ static loadGlobal(globalOpts, config = {}) {
31
+ const globalConfig = (0, config_reader_1.readConfigFile)((0, path_1.join)(globalOpts.dir || userHome, globalOpts.name), false);
32
+ return new HarmonyConfig((0, comment_json_1.assign)(config, globalConfig));
33
+ }
34
+ }
35
+ exports.HarmonyConfig = HarmonyConfig;
36
+ //# sourceMappingURL=harmony-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harmony-config.js","sourceRoot":"","sources":["../../harmony-config/harmony-config.ts"],"names":[],"mappings":";;;AAAA,+CAAiD;AACjD,+BAA4B;AAC5B,mDAAiD;AAEjD,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAatC,MAAM,aAAa,GAAG;IACpB,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;IAClB,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF,MAAa,aAAa;IACxB,YAAoB,GAAwB;QAAxB,QAAG,GAAH,GAAG,CAAqB;IAAG,CAAC;IAEhD,QAAQ;QACN,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,QAAQ;QACN,OAAO,IAAA,wBAAS,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,QAAgB,EAAE,IAAoB;QAChD,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,IAAA,8BAAc,EAAC,IAAA,WAAI,EAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;QAEtF,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;YACtB,OAAO,aAAa,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,UAA4B,EAAE,SAAc,EAAE;QAC9D,MAAM,YAAY,GAAG,IAAA,8BAAc,EAAC,IAAA,WAAI,EAAC,UAAU,CAAC,GAAG,IAAI,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;QAC9F,OAAO,IAAI,aAAa,CAAC,IAAA,qBAAM,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IACzD,CAAC;CACF;AA1BD,sCA0BC"}
@@ -0,0 +1 @@
1
+ export { HarmonyConfig as Config, ConfigOptions } from './harmony-config';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Config = void 0;
4
+ var harmony_config_1 = require("./harmony-config");
5
+ Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return harmony_config_1.HarmonyConfig; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../harmony-config/index.ts"],"names":[],"mappings":";;;AAAA,mDAA0E;AAAjE,wGAAA,aAAa,OAAU"}
File without changes
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=locator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locator.js","sourceRoot":"","sources":["../../harmony-config/locator.ts"],"names":[],"mappings":""}
@@ -0,0 +1,63 @@
1
+ import 'reflect-metadata';
2
+ import ExtensionGraph, { DependencyGraphOptions } from './extension-graph/extension-graph';
3
+ import { Extension, ExtensionManifest } from './extension';
4
+ import { Config } from './config';
5
+ import { Aspect } from './aspect';
6
+ import { Runtimes } from './runtimes/runtimes';
7
+ import { RuntimeDefinition } from './runtimes/runtime-definition';
8
+ export type GlobalConfig = {
9
+ [key: string]: object;
10
+ };
11
+ export type RequireFn = (aspect: Extension, runtime: RuntimeDefinition) => Promise<void>;
12
+ export declare class Harmony {
13
+ /**
14
+ * extension graph
15
+ */
16
+ readonly graph: ExtensionGraph;
17
+ /**
18
+ * harmony top level config
19
+ */
20
+ readonly config: Config;
21
+ readonly runtimes: Runtimes;
22
+ readonly activeRuntime: string;
23
+ private depOptions;
24
+ constructor(
25
+ /**
26
+ * extension graph
27
+ */
28
+ graph: ExtensionGraph,
29
+ /**
30
+ * harmony top level config
31
+ */
32
+ config: Config, runtimes: Runtimes, activeRuntime: string, depOptions: DependencyGraphOptions);
33
+ current: string | null;
34
+ private runtime;
35
+ /**
36
+ * list all registered extensions
37
+ */
38
+ get extensions(): Map<string, Extension>;
39
+ /**
40
+ * list all registered extensions ids
41
+ */
42
+ get extensionsIds(): string[];
43
+ /**
44
+ * load an Aspect into the dependency graph.
45
+ */
46
+ load(extensions: ExtensionManifest[]): Promise<void>;
47
+ /**
48
+ * set extensions during Harmony runtime.
49
+ * hack!
50
+ */
51
+ set(extensions: ExtensionManifest[]): Promise<void>;
52
+ private runOne;
53
+ getDependencies(aspect: Extension): Extension[];
54
+ initExtension(id: string): void;
55
+ endExtension(): void;
56
+ /**
57
+ * get an extension from harmony.
58
+ */
59
+ get<T>(id: string): T;
60
+ resolveRuntime(name: string): RuntimeDefinition;
61
+ run(requireFn?: RequireFn): Promise<void>;
62
+ static load(aspects: Aspect[], runtime: string, globalConfig: GlobalConfig, options?: DependencyGraphOptions): Promise<Harmony>;
63
+ }
@@ -0,0 +1,250 @@
1
+ ---
2
+ description: Harmony is an abstract extension system you can use to make any software extendable and composable. It is the engine that drives Bit extensibility and composability.
3
+ labels: ['aspect', 'composition', 'extendability']
4
+ ---
5
+
6
+ ## Basic features
7
+
8
+ Harmony allows you to implement Aspects as the main building blocks that compose your software. Each Aspect has:
9
+
10
+ * Dependency declaration - Where you declare other Aspects as dependencies.
11
+ * Dependency injection - An Aspect gets providers for all its dependencies.
12
+ * Slots - An easy way for an Aspect to provide API for another aspect to hook into any of its processes.
13
+ * Multiple runtimes - Aspect can annotate in which runtimes it can run (for example providing functionality to run on the server and on the browser).
14
+
15
+ ## Harmony config file
16
+
17
+ Use a config file to describe your desired composition of Aspects and their configuration. Harmony uses a basic JSON syntax, where each key is an aspect.
18
+
19
+ ```json
20
+ {
21
+ "teambit.dependencies/dependency-resolver": {}, // load an Aspect without providing configuration
22
+ "teambit.workspace/workspace": { // Load an Aspect with configuration
23
+ "name": "bit",
24
+ "icon": "https://static.bit.dev/bit-logo.svg",
25
+ }
26
+ ```
27
+
28
+ ## Define an aspect
29
+
30
+ Harmony Aspect is an object that implements the `ExtensionManifest` interface
31
+
32
+ ```js
33
+ export type ExtensionManifest = {
34
+ /**
35
+ * Aspect's name.
36
+ */
37
+ name: string;
38
+
39
+ /**
40
+ * Aspect unique ID.
41
+ */
42
+ id?: string;
43
+
44
+ /**
45
+ * Array of dependencies.
46
+ * These other Aspects to be installed and resolved prior to this Aspect activation.
47
+ */
48
+ dependencies?: ExtensionManifest[];
49
+
50
+ /**
51
+ * Reference to the Aspect factory function.
52
+ */
53
+ provider?: ProviderFn;
54
+
55
+ /**
56
+ * Default Aspect configuration.
57
+ */
58
+ defaultConfig?: object;
59
+
60
+ /**
61
+ * Alias to the provider.
62
+ */
63
+ provide?: ProviderFn;
64
+
65
+ /**
66
+ * Array of slots the Aspect exposes.
67
+ */
68
+ slots?: SlotProvider<unknown>[],
69
+
70
+ /**
71
+ * Additional keys which might be expected by other Aspects.
72
+ */
73
+ [key: string]: any;
74
+ }
75
+ ```
76
+
77
+ ## Programmatic API
78
+
79
+ ### Static API
80
+
81
+ ```js
82
+ // Create instance of harmony with the provided aspects, on specific runtime, with provided config
83
+ static async load(aspects: Aspect[], runtime: string, globalConfig: GlobalConfig) {
84
+ ```
85
+
86
+ ### Instance API
87
+
88
+ ```js
89
+ // load an Aspect into the dependency graph
90
+ async load(extensions: ExtensionManifest[])
91
+
92
+ // set extensions during Harmony runtime.
93
+ async set(extensions: ExtensionManifest[])
94
+
95
+ export type RequireFn = (aspect: Extension, runtime: RuntimeDefinition) => Promise<void>;
96
+
97
+ // Start harmony.
98
+ // The require function is a function that get's the aspect and its runtime, and knows to require/load it
99
+ async run(requireFn?: RequireFn)
100
+ ```
101
+
102
+ ## Assumptions
103
+
104
+ * Harmony does not allow circular dependencies between Aspects.
105
+
106
+ {/*
107
+
108
+ -------------------------for reference only - to remove ------------------
109
+
110
+ ## composition model
111
+ Harmony proposes a graph composition model.
112
+ composition model should allow:
113
+
114
+ - full control over composition including dependency composition.
115
+ - easy overrides mechanism for configs.
116
+ - full encapsulation of an extension.
117
+
118
+ bit.config.js
119
+ ```js
120
+ import FlowSchemaPlugin from '@bit/plugins.flow-schema';
121
+
122
+ export default () => {
123
+ return [ // returns an array of PluginInstance
124
+ [FlowSchemaPlugin, {
125
+
126
+ }],
127
+ [ReactSchemaPlugin, {
128
+ eslintrc: './.eslintrc'
129
+ }]
130
+ ];
131
+ }
132
+ ```
133
+
134
+ configured extensions in bit.json
135
+ ```json
136
+ {
137
+ "extensions": {
138
+ "bit.envs/eslint@0.0.4": {
139
+ "eslintrc": "./.eslintrc"
140
+ },
141
+ "bit.envs/babel@0.0.1": {
142
+ "babelrc": "./.babelrc",
143
+ "strict": true,
144
+ "__alias": "compile"
145
+ },
146
+ "bit.envs/webpack@0.0.1": {
147
+ "config": "./webpack.config.js",
148
+ "mode": "prod",
149
+ "__alias": "bundle"
150
+ },
151
+ "bit.envs/mocha@0.0.1": {
152
+ "reporter": "json",
153
+ "mochaOptions": "./mocha.opts",
154
+ "__alias": "test-mocha"
155
+ }
156
+ },
157
+ "pipes": {
158
+ "tag": [""]
159
+ },
160
+ "dist": {
161
+ "target": "",
162
+ "entry": ""
163
+ }
164
+ }
165
+ ```
166
+
167
+ ### Open questions
168
+ - How do I install a Bit extensions? Where the component is configured?
169
+ - Is the extension installed with Bit/NPM?
170
+ - What's the impl. behind `bit use <plugin/extension name>`
171
+ - maybe an composition model can co-exist as json and js? what are the tradeoffs?
172
+
173
+ ## extension registration
174
+ ```js
175
+ import { register } from 'harmony';
176
+ import { DocGen } from '@bit/bit.exts.doc-gen';
177
+
178
+ const extensions = register([DocGen]);
179
+ ```
180
+
181
+ ## lifecycle event invocation
182
+
183
+ ```js
184
+ import { invoke } from 'harmony';
185
+
186
+ invoke('tag', ...data);
187
+ ```
188
+
189
+ ## lifecycle event registration
190
+ ```js
191
+ import { Lifecycle } from 'harmony';
192
+
193
+ @Lifecycle(Tag);
194
+ function tag() {
195
+
196
+ }
197
+ ```
198
+
199
+ ## state / schema management
200
+ ```ts
201
+ @Lifecycle(Tag)
202
+ function tag(component: Component) {
203
+ const docs = component.get('docs'); // returns `Maybe` type?
204
+ const docs: Docs = docs.get();
205
+ }
206
+ ```
207
+
208
+ ## function extension
209
+
210
+ ```js
211
+ export default function foo() {
212
+ context.a
213
+ }
214
+ ```
215
+
216
+ ## configuration
217
+ an extension can declaratively ask for configuration type. this can be reflected
218
+ - extensions can be configured during instantiation.
219
+ - configuration types can be built from multiple sources
220
+
221
+ ## context
222
+ - standard context can be shared between all extensions in the same instance.
223
+
224
+ ## extension composition
225
+ - hook invocation from an extension
226
+ - extension dependencies? how can an extension declare a dependency as part of its execution?
227
+ - contextual/namespaced hooks
228
+ - config api
229
+
230
+ ## extension resolution
231
+ ```js
232
+ import { resolve } from 'harmony';
233
+
234
+ const extension = resolve('doc-gen');
235
+ ```
236
+
237
+ ## Questions (?)
238
+ - can extensions be added/configured during runtime? DI
239
+ - is there a difference between extension composition to registration?
240
+ - how to make autocomplete work for hooks?
241
+ - how to avoid unintentional hook invocation (decorators?)
242
+ - how to declare a new hook..
243
+ - schema validator
244
+ - dev experience of an extension.
245
+ - how do manage different runtime environments? should I? Why is that relevant?
246
+ - runtime capsules?
247
+ - how can one extension run from both server and client? how capsule is related?
248
+ - in which process extensions will run from? also, what will happen from the backend?
249
+ -
250
+ */}
@@ -0,0 +1,151 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Harmony = void 0;
16
+ require("reflect-metadata");
17
+ const extension_graph_1 = __importDefault(require("./extension-graph/extension-graph"));
18
+ const exceptions_1 = require("./exceptions");
19
+ const utils_1 = require("./utils");
20
+ const config_1 = require("./config");
21
+ const runtimes_1 = require("./runtimes/runtimes");
22
+ const exceptions_2 = require("./runtimes/exceptions");
23
+ class Harmony {
24
+ constructor(
25
+ /**
26
+ * extension graph
27
+ */
28
+ graph,
29
+ /**
30
+ * harmony top level config
31
+ */
32
+ config, runtimes, activeRuntime, depOptions) {
33
+ this.graph = graph;
34
+ this.config = config;
35
+ this.runtimes = runtimes;
36
+ this.activeRuntime = activeRuntime;
37
+ this.depOptions = depOptions;
38
+ this.current = null;
39
+ }
40
+ /**
41
+ * list all registered extensions
42
+ */
43
+ get extensions() {
44
+ return this.graph.nodes;
45
+ }
46
+ /**
47
+ * list all registered extensions ids
48
+ */
49
+ get extensionsIds() {
50
+ return [...this.graph.nodes.keys()];
51
+ }
52
+ /**
53
+ * load an Aspect into the dependency graph.
54
+ */
55
+ load(extensions) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ return this.set(extensions);
58
+ });
59
+ }
60
+ /**
61
+ * set extensions during Harmony runtime.
62
+ * hack!
63
+ */
64
+ set(extensions) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ this.graph.load(extensions);
67
+ // Only load new extensions and their dependencies
68
+ const extensionsToLoad = extensions.map((ext) => {
69
+ // @ts-ignore
70
+ return Reflect.getMetadata('harmony:name', ext) || ext.id || ext.name;
71
+ });
72
+ // @ts-ignore
73
+ yield this.graph.enrichRuntime(this.runtime, this.runtimes, () => { });
74
+ // @ts-ignore
75
+ const subgraphs = this.graph.successorsSubgraph(extensionsToLoad);
76
+ if (subgraphs) {
77
+ const executionOrder = subgraphs.toposort(true);
78
+ yield (0, utils_1.asyncForEach)(executionOrder, (ext) => __awaiter(this, void 0, void 0, function* () {
79
+ if (!this.runtime)
80
+ throw new exceptions_2.RuntimeNotDefined(this.activeRuntime);
81
+ yield this.runOne(ext, this.runtime);
82
+ }));
83
+ }
84
+ });
85
+ }
86
+ runOne(extension, runtime) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ if (extension.loaded)
89
+ return;
90
+ // create an index of all vertices in dependency graph
91
+ const deps = this.graph.getRuntimeDependencies(extension, runtime, this.depOptions);
92
+ const instances = deps.map(extension => extension.instance);
93
+ try {
94
+ return extension.__run(instances, this, runtime);
95
+ }
96
+ catch (err) {
97
+ throw new exceptions_1.ExtensionLoadError(extension, err instanceof Error ? err : new Error(String(err)));
98
+ }
99
+ });
100
+ }
101
+ getDependencies(aspect) {
102
+ if (!this.runtime)
103
+ throw new exceptions_2.RuntimeNotDefined(this.activeRuntime);
104
+ return this.graph.getRuntimeDependencies(aspect, this.runtime, this.depOptions);
105
+ }
106
+ initExtension(id) {
107
+ this.current = id;
108
+ }
109
+ endExtension() {
110
+ this.current = null;
111
+ }
112
+ /**
113
+ * get an extension from harmony.
114
+ */
115
+ get(id) {
116
+ const extension = this.graph.get(id);
117
+ if (!extension || !extension.instance)
118
+ throw new Error(`failed loading extension ${id}`);
119
+ return extension.instance;
120
+ }
121
+ resolveRuntime(name) {
122
+ return this.runtimes.get(name);
123
+ }
124
+ run(requireFn) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ const runtime = this.resolveRuntime(this.activeRuntime);
127
+ this.runtime = runtime;
128
+ const defaultRequireFn = (aspect, runtime) => __awaiter(this, void 0, void 0, function* () {
129
+ const runtimeFile = runtime.getRuntimeFile(aspect.files);
130
+ if (!runtimeFile)
131
+ return;
132
+ // runtime.require(runtimeFile);
133
+ });
134
+ // requireFn ? await requireFn(aspect, runtime) : defaultRequireFn(this.graph);
135
+ yield this.graph.enrichRuntime(runtime, this.runtimes, requireFn || defaultRequireFn, this.depOptions);
136
+ const executionOrder = this.graph.byExecutionOrder();
137
+ yield (0, utils_1.asyncForEach)(executionOrder, (ext) => __awaiter(this, void 0, void 0, function* () {
138
+ yield this.runOne(ext, runtime);
139
+ }));
140
+ });
141
+ }
142
+ static load(aspects_1, runtime_1, globalConfig_1) {
143
+ return __awaiter(this, arguments, void 0, function* (aspects, runtime, globalConfig, options = {}) {
144
+ const aspectGraph = extension_graph_1.default.from(aspects, options);
145
+ const runtimes = yield runtimes_1.Runtimes.load(aspectGraph);
146
+ return new Harmony(aspectGraph, config_1.Config.from(globalConfig), runtimes, runtime, options);
147
+ });
148
+ }
149
+ }
150
+ exports.Harmony = Harmony;
151
+ //# sourceMappingURL=harmony.js.map