@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/package.json CHANGED
@@ -1,42 +1,56 @@
1
1
  {
2
2
  "name": "@teambit/harmony",
3
- "version": "0.2.10",
4
- "description": "abstract extension system",
3
+ "version": "0.3.1",
4
+ "homepage": "https://bit.dev/teambit/harmony/harmony",
5
5
  "main": "dist/index.js",
6
- "scripts": {
7
- "test": "mocha --require ts-node/register/transpile-only --require source-map-support/register --recursive src/**/*.spec.ts src/**/**/*.spec.ts",
8
- "start": "node dist/index.js",
9
- "build": "tsc -d",
10
- "clean": "rm -rf dist",
11
- "watch": "tsc -d -w",
12
- "prepublishOnly": "npm run clean && npm run build"
6
+ "componentId": {
7
+ "scope": "teambit.harmony",
8
+ "name": "harmony",
9
+ "version": "0.3.1"
13
10
  },
14
- "files": [
15
- "/dist"
16
- ],
17
- "keywords": [],
18
- "author": "Ran Mizrahi <ran@bit.dev>",
19
- "license": "MIT",
20
11
  "dependencies": {
12
+ "reflect-metadata": "^0.1.13",
21
13
  "cleargraph": "^5.6.0",
22
14
  "comment-json": "^3.0.3",
23
15
  "fs-extra": "^8.1.0",
24
- "lodash": "^4.17.20",
25
- "loud-rejection": "^1.6.0",
26
- "reflect-metadata": "^0.1.13",
27
16
  "user-home": "^2.0.0"
28
17
  },
29
18
  "devDependencies": {
30
19
  "@types/comment-json": "^1.1.1",
31
20
  "@types/fs-extra": "^8.1.0",
32
- "@types/chai": "^4.1.7",
33
- "@types/lodash": "^4.14.159",
34
- "@types/loud-rejection": "^1.6.0",
35
- "@types/node": "^11.9.4",
36
- "@types/semver": "^6.0.1",
37
- "chai": "^4.2.0",
38
- "mocha": "^6.2.2",
39
- "ts-node": "^8.0.2",
40
- "typescript": "^3.8.3"
41
- }
21
+ "@babel/runtime": "7.12.18",
22
+ "@types/node": "12.20.4",
23
+ "@types/jest": "26.0.20"
24
+ },
25
+ "peerDependencies": {},
26
+ "license": "Apache-2.0",
27
+ "bit": {
28
+ "bindingPrefix": "@teambit",
29
+ "env": {},
30
+ "overrides": {
31
+ "devDependencies": {
32
+ "@babel/runtime": "7.12.18",
33
+ "@types/node": "12.20.4",
34
+ "@types/jest": "26.0.20"
35
+ }
36
+ }
37
+ },
38
+ "private": false,
39
+ "engines": {
40
+ "node": ">=12.22.0"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/teambit/harmony"
45
+ },
46
+ "description": "abstract extension system",
47
+ "keywords": [
48
+ "bit",
49
+ "bit-aspect",
50
+ "components",
51
+ "collaboration",
52
+ "harmony",
53
+ "aspects",
54
+ "extensions"
55
+ ]
42
56
  }
@@ -0,0 +1 @@
1
+ export const overview = [require('/Users/giladshoham/Library/Caches/Bit/capsules/0c2e8decf63b913c66a649e2a025161ea05f3ab6/teambit.harmony_harmony@0.3.1/dist/harmony.docs.mdx')]
package/readme.md CHANGED
@@ -1,159 +1,80 @@
1
- # Harmony
2
-
3
- Plugin
4
- Module
5
- Extension
6
- * Feature
7
- Plugin
8
- Trait
9
- * Component (could be a composition of other components)
10
-
11
- Plugability
12
- - Hook
13
- - Slot
14
-
15
- Harmony is the engine that drives Bit extensibility and composability.
16
- It's an abstract extension system you can use to make any software extendable and composable.
17
-
18
- ## composition model
19
- Harmony proposes a graph composition model.
20
- compoisiton model should allow:
21
- - full control over composition including dependency composition.
22
- - easy overrides mechanaism for configs.
23
- - full encapsulation of an extension.
24
-
25
- bit.config.js
26
- ```js
27
- import FlowSchemaPlugin from '@bit/plugins.flow-schema';
28
-
29
- export default () => {
30
- return [ // returns an array of PluginInstance
31
- [FlowScehmaPlugin, {
32
-
33
- }],
34
- [ReactSchemaPlugin, {
35
- eslintrc: './.eslintrc'
36
- }]
37
- ];
38
- }
39
- ```
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.
40
4
 
41
- configured extensions in bit.json
42
- ```json
43
- {
44
- "extensions": {
45
- "bit.envs/eslint@0.0.4": {
46
- "eslintrc": "./.eslintrc"
47
- },
48
- "bit.envs/babel@0.0.1": {
49
- "babelrc": "./.babelrc",
50
- "strict": true,
51
- "__alias": "compile"
52
- },
53
- "bit.envs/webpack@0.0.1": {
54
- "config": "./webpack.config.js",
55
- "mode": "prod",
56
- "__alias": "bundle"
57
- },
58
- "bit.envs/mocha@0.0.1": {
59
- "reporter": "json",
60
- "mochaOptions": "./mocha.opts",
61
- "__alias": "test-mocha"
62
- }
63
- },
64
- "pipes": {
65
- "tag": [""]
66
- },
67
- "dist": {
68
- "target": "",
69
- "entry": ""
70
- }
71
- }
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
72
10
  ```
73
11
 
74
- ### Open questions
75
- - How do I install a Bit extensions? Where the component is configured?
76
- - Is the extension installed with Bit/NPM?
77
- - What's the impl. behind `bit use <plugin/extension name>`
78
- - maybe an composition model can co-exist as json and js? what are the tradeoffs?
12
+ ## Quick start
13
+ ```ts
14
+ import { Harmony, Extension } from 'harmony';
79
15
 
80
- ## extension registration
81
- ```js
82
- import { register } from 'harmony';
83
- import { DocGen } from '@bit/bit.exts.docgen';
16
+ @Extensioin
17
+ class Person {
18
+ sayHello(name = 'world') {
19
+ return `hello ${name}!`;
20
+ }
21
+ }
84
22
 
85
- const extensions = register([DocGen]);
23
+ const person = Harmony.load(Person);
24
+ helloWorld.sayHello(); // returns 'hello world!'
86
25
  ```
87
26
 
88
- ## lifecycle event invocation
89
-
90
- ```js
91
- import { invoke } from 'harmony';
27
+ ## Component composition
92
28
 
93
- invoke('tag', ...data);
94
- ```
29
+ ### DI
30
+ ```ts
31
+ class Dude {
32
+ constructor(
33
+ private person: Person
34
+ ) {}
95
35
 
96
- ## lifecycle event registration
97
- ```js
98
- import { Lifecycle } from 'harmony';
36
+ sayHello() {
37
+ return this.person.sayHello('dude');
38
+ }
39
+ };
99
40
 
100
- @Lifecycle(Tag);
101
- function tag() {
102
-
103
- }
41
+ Harmony.load([Dude]).sayHello(); // echos 'hello dude!'
104
42
  ```
105
43
 
106
- ## state / schema management
44
+ ### Hooks
107
45
  ```ts
108
- @Lifecycle(Tag)
109
- function tag(component: Component) {
110
- const docs = component.get('docs'); // returns `Maybe` type?
111
- const docs: Docs = docs.get();
112
- }
113
- ```
114
-
46
+ @Extension()
47
+ class CLI {
48
+ // @hook('command') commands = Hook.create<Command>();
49
+ static command() {
50
+ return Hook.create<Command>();
51
+ }
115
52
 
116
- ## function extension
53
+ run() {
54
+ const allCommands = this.commands.list(); // outputs all hook subscribers
55
+ }
56
+ }
117
57
 
118
- ```js
119
- export default function foo() {
120
- context.a
58
+ @Extension()
59
+ class Compiler {
60
+
61
+ @command()
62
+ main() {
63
+ return {
64
+ synopsis: 'compile <path>',
65
+ render: () => <Box></Box>
66
+ };
67
+ }
121
68
  }
122
69
  ```
123
70
 
124
- ## configuration
125
- an extension can declaratively ask for configuration type. this can be reflected
126
- - extensions can be configured during instantiation.
127
- - configuration types can be built from multiple sources
128
-
129
- ## context
130
- - standard context can be shared between all extensions in the same instance.
71
+ ## Extension configuration
131
72
 
132
- ## extension composition
133
- - hook invocation from an extension
134
- - extension dependencies? how can an extension declare a dependency as part of its execution?
135
- - contextual/namespaced hooks
136
- - config api
137
-
138
- ## extension resolution
139
- ```js
140
- import { resolve } from 'harmony';
141
-
142
- const extension = resolve('doc-gen');
143
- ```
73
+ ## Extension metadata
144
74
 
145
- ## Questions (?)
146
- - can extensions be added/configured during runtime? DI
147
- - is there a difference between extension composition to registration?
148
- - how to make autocomplete work for hooks?
149
- - how to avoid unintentional hook invocation (decorators?)
150
- - how to declare a new hook..
151
- - schema validator
152
- - dev expereience of an extension.
153
- - how do manage different runtime environments? should I? Why is that relavent?
154
- - runtime capsules?
155
- - how can one extension run from both server and client? how capsule is related?
156
- - in which process extensions will run from? also, what will happen from the backend?
157
- -
75
+ ## API reference
158
76
 
77
+ ## License
78
+ Apache License, Version 2.0
159
79
 
80
+ Made with ❤ to open software by Team Bit.
@@ -0,0 +1,2 @@
1
+ export { RuntimeNotDefined } from './runtime-not-defined';
2
+ export { RuntimeModuleError } from './runtime-module-error';
@@ -0,0 +1,9 @@
1
+ export class RuntimeModuleError extends Error {
2
+ constructor(
3
+ private err: Error
4
+ ) { super(`failed to load Harmony aspect with error message: ${err.message}`) }
5
+
6
+ get stack() {
7
+ return this.err.stack;
8
+ }
9
+ }
@@ -0,0 +1,5 @@
1
+ export class RuntimeNotDefined extends Error {
2
+ constructor(
3
+ name: string
4
+ ) { super(`runtime: '${name}' was not defined by any aspect`) }
5
+ }
@@ -0,0 +1,3 @@
1
+ export { RuntimeManifest } from './runtime-manifest';
2
+ export { Runtimes } from './runtimes';
3
+ export { RuntimeDefinition } from './runtime-definition';
@@ -0,0 +1,32 @@
1
+ import { RuntimeModuleError } from './exceptions';
2
+
3
+ export type RuntimeDefProps = {
4
+ name: string
5
+ };
6
+
7
+ const DEFAULT_PREDICATE = (filePath: string, name: string) => {
8
+ return filePath.includes(`.${name}.`);
9
+ }
10
+
11
+ export class RuntimeDefinition {
12
+ constructor(
13
+ readonly name: string,
14
+ readonly filePredicate: (filePath: string, name: string) => boolean = DEFAULT_PREDICATE
15
+ ) {}
16
+
17
+ getRuntimeFile(paths: string[]): string|undefined {
18
+ return paths.find(path => this.filePredicate(path, this.name));
19
+ }
20
+
21
+ require(file: string) {
22
+ // try {
23
+ // require(file);
24
+ // } catch(err) {
25
+ // throw new RuntimeModuleError(err);
26
+ // }
27
+ }
28
+
29
+ static create(def: RuntimeDefProps) {
30
+ return new RuntimeDefinition(def.name);
31
+ }
32
+ }
@@ -0,0 +1,12 @@
1
+ import { RuntimeDefinition } from './runtime-definition';
2
+ import { ProviderFn } from '../types';
3
+ import { Aspect } from '../aspect';
4
+ import { SlotProvider } from '../slots';
5
+
6
+ export interface RuntimeManifest {
7
+ runtime: RuntimeDefinition|string
8
+ provider: ProviderFn,
9
+ dependencies?: Aspect[],
10
+ slots?: SlotProvider<unknown>[],
11
+ defaultConfig?: {[key: string]: any},
12
+ }
@@ -0,0 +1,34 @@
1
+ import { RuntimeDefinition } from './runtime-definition';
2
+ import DependencyGraph from '../extension-graph/extension-graph';
3
+ import { RuntimeNotDefined } from './exceptions';
4
+
5
+ export class Runtimes {
6
+ constructor(
7
+ readonly runtimeDefinition: {[key: string]: RuntimeDefinition}
8
+ ) {}
9
+
10
+ add(runtime: RuntimeDefinition) {
11
+ this.runtimeDefinition[runtime.name] = runtime;
12
+ return this;
13
+ }
14
+
15
+ get(name: string): RuntimeDefinition {
16
+ const runtime = this.runtimeDefinition[name];
17
+ if (!runtime) throw new RuntimeNotDefined(name);
18
+ return this.runtimeDefinition[name];
19
+ }
20
+
21
+ dispose() {
22
+
23
+ }
24
+
25
+ static async load(graph: DependencyGraph) {
26
+ const runtimes: { [key: string]: RuntimeDefinition } = {};
27
+ graph.extensions.forEach(manifest => {
28
+ if (!manifest.declareRuntime) return;
29
+ runtimes[manifest.declareRuntime.name] = manifest.declareRuntime;
30
+ });
31
+
32
+ return new Runtimes(runtimes);
33
+ }
34
+ }
package/slots/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { Slot, SlotProvider } from './slot';
2
+ export { SlotRegistry } from './registry';
@@ -0,0 +1,36 @@
1
+
2
+ export class SlotRegistry<T> {
3
+ constructor(
4
+ private registerFn: () => string,
5
+ readonly map = new Map<string, T>()
6
+ ) {}
7
+
8
+ /**
9
+ * get a slot value by extension id.
10
+ */
11
+ get(id: string): T|undefined {
12
+ return this.map.get(id);
13
+ }
14
+
15
+ /**
16
+ * return an array of all slots.
17
+ */
18
+ toArray() {
19
+ return Array.from(this.map.entries());
20
+ }
21
+
22
+ /**
23
+ * get all registered values.
24
+ */
25
+ values() {
26
+ return Array.from(this.map.values());
27
+ }
28
+
29
+ /**
30
+ * register a new entry to the slot registry
31
+ */
32
+ register(value: T) {
33
+ const id = this.registerFn();
34
+ this.map.set(id, value);
35
+ }
36
+ }
package/slots/slot.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { SlotRegistry } from './registry';
2
+
3
+ export class Slot {
4
+ static withType<T>() {
5
+ return (registerFn: () => string) => {
6
+ return new SlotRegistry<T>(registerFn);
7
+ }
8
+ }
9
+ }
10
+
11
+ export type SlotProvider<T> = (registerFn: () => string) => SlotRegistry<T>;
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": [
4
+ "es2019",
5
+ "DOM",
6
+ "ES6",
7
+ "DOM.Iterable"
8
+ ],
9
+ "target": "es2015",
10
+ "module": "commonjs",
11
+ "jsx": "react",
12
+ "allowJs": true,
13
+ "composite": true,
14
+ "declaration": true,
15
+ "sourceMap": true,
16
+ "skipLibCheck": true,
17
+ "outDir": "dist",
18
+ "moduleResolution": "node",
19
+ "esModuleInterop": true,
20
+ "rootDir": ".",
21
+ "resolveJsonModule": true
22
+ },
23
+ "exclude": [
24
+ "dist"
25
+ ]
26
+ }
@@ -0,0 +1,29 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
9
+ const src: string;
10
+ export default src;
11
+ }
12
+
13
+ // @TODO Gilad
14
+ declare module '*.jpg' {
15
+ const value: any;
16
+ export = value;
17
+ }
18
+ declare module '*.jpeg' {
19
+ const value: any;
20
+ export = value;
21
+ }
22
+ declare module '*.gif' {
23
+ const value: any;
24
+ export = value;
25
+ }
26
+ declare module '*.bmp' {
27
+ const value: any;
28
+ export = value;
29
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }
package/types.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { Harmony } from './harmony';
2
+ import { SlotRegistry } from './slots';
3
+
4
+ /**
5
+ * type definition for the extension provider function.
6
+ */
7
+ export type ProviderFn = (deps: any, config: any, slots: any, harmony: Harmony) => Promise<any>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * asynchronously iterate an array.
3
+ * :TODO improve function singature
4
+ */
5
+ export async function asyncForEach(array: any[], callback: any) {
6
+ for (let index = 0; index < array.length; index += 1) {
7
+ // eslint-disable-next-line no-await-in-loop
8
+ await callback(array[index], index, array);
9
+ }
10
+ }
package/utils/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { asyncForEach } from './async-for-each';
@@ -1 +0,0 @@
1
- "use strict";
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- describe('extensionFactory', () => {
4
- it('should return new extension from a manifest', () => {
5
- });
6
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const harmony_config_1 = require("./harmony-config");
4
- describe('HarmonyConfig', () => {
5
- it('should parse both files', () => {
6
- harmony_config_1.HarmonyConfig.load('workspace.json');
7
- });
8
- });
@@ -1 +0,0 @@
1
- export {};