@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.
- package/aspect.ts +52 -0
- package/config/config.ts +36 -0
- package/config/index.ts +1 -0
- package/container.ts +22 -0
- package/dist/aspect.d.ts +27 -0
- package/dist/aspect.js +33 -0
- package/dist/aspect.js.map +1 -0
- package/dist/config/config.d.ts +22 -0
- package/dist/config/config.js +37 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +6 -0
- package/dist/config/index.js.map +1 -0
- package/dist/container.d.ts +8 -0
- package/dist/container.js +22 -0
- package/dist/container.js.map +1 -0
- package/dist/exceptions/extension-init-error.d.ts +2 -0
- package/dist/exceptions/extension-init-error.js +7 -0
- package/dist/exceptions/extension-init-error.js.map +1 -0
- package/dist/exceptions/extension-load-error.d.ts +29 -0
- package/dist/exceptions/extension-load-error.js +29 -0
- package/dist/exceptions/extension-load-error.js.map +1 -0
- package/dist/exceptions/extension-potential-circular.d.ts +22 -0
- package/dist/exceptions/extension-potential-circular.js +25 -0
- package/dist/exceptions/extension-potential-circular.js.map +1 -0
- package/dist/exceptions/harmony-already-running.d.ts +2 -0
- package/dist/exceptions/harmony-already-running.js +7 -0
- package/dist/exceptions/harmony-already-running.js.map +1 -0
- package/dist/exceptions/harmony-error.d.ts +2 -0
- package/dist/exceptions/harmony-error.js +7 -0
- package/dist/exceptions/harmony-error.js.map +1 -0
- package/dist/exceptions/hook-not-found.d.ts +2 -0
- package/dist/exceptions/hook-not-found.js +7 -0
- package/dist/exceptions/hook-not-found.js.map +1 -0
- package/dist/exceptions/index.d.ts +5 -0
- package/dist/exceptions/index.js +17 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/exceptions/runtime-not-defined.d.ts +0 -0
- package/dist/exceptions/runtime-not-defined.js +1 -0
- package/dist/exceptions/runtime-not-defined.js.map +1 -0
- package/dist/extension/any-extension.d.ts +5 -0
- package/dist/extension/any-extension.js +8 -0
- package/dist/extension/any-extension.js.map +1 -0
- package/dist/extension/decorator.d.ts +27 -0
- package/dist/extension/decorator.js +109 -0
- package/dist/extension/decorator.js.map +1 -0
- package/dist/extension/extension-manifest.d.ts +41 -0
- package/dist/extension/extension-manifest.js +3 -0
- package/dist/extension/extension-manifest.js.map +1 -0
- package/dist/extension/extension.d.ts +50 -0
- package/dist/extension/extension.js +128 -0
- package/dist/extension/extension.js.map +1 -0
- package/dist/extension/index.d.ts +3 -0
- package/dist/extension/index.js +13 -0
- package/dist/extension/index.js.map +1 -0
- package/dist/extension-graph/extension-graph.d.ts +34 -0
- package/dist/extension-graph/extension-graph.js +152 -0
- package/dist/extension-graph/extension-graph.js.map +1 -0
- package/dist/extension-graph/from-extension.d.ts +31 -0
- package/dist/extension-graph/from-extension.js +63 -0
- package/dist/extension-graph/from-extension.js.map +1 -0
- package/dist/extension-graph/index.d.ts +1 -0
- package/dist/extension-graph/index.js +9 -0
- package/dist/extension-graph/index.js.map +1 -0
- package/dist/factory/extension-factory.d.ts +3 -0
- package/dist/factory/extension-factory.js +11 -0
- package/dist/factory/extension-factory.js.map +1 -0
- package/dist/factory/index.d.ts +1 -0
- package/dist/factory/index.js +6 -0
- package/dist/factory/index.js.map +1 -0
- package/dist/fixtures/aspects/babel/babel.aspect.d.ts +5 -0
- package/dist/fixtures/aspects/babel/babel.aspect.js +13 -0
- package/dist/fixtures/aspects/babel/babel.aspect.js.map +1 -0
- package/dist/fixtures/aspects/babel/babel.cli.d.ts +5 -0
- package/dist/fixtures/aspects/babel/babel.cli.js +28 -0
- package/dist/fixtures/aspects/babel/babel.cli.js.map +1 -0
- package/dist/fixtures/aspects/react/react.aspect.d.ts +6 -0
- package/dist/fixtures/aspects/react/react.aspect.js +19 -0
- package/dist/fixtures/aspects/react/react.aspect.js.map +1 -0
- package/dist/fixtures/aspects/react/react.cli.d.ts +11 -0
- package/dist/fixtures/aspects/react/react.cli.js +71 -0
- package/dist/fixtures/aspects/react/react.cli.js.map +1 -0
- package/dist/fixtures/aspects/react/react.ui.d.ts +5 -0
- package/dist/fixtures/aspects/react/react.ui.js +31 -0
- package/dist/fixtures/aspects/react/react.ui.js.map +1 -0
- package/dist/fixtures/aspects/ui/ui.aspect.d.ts +4 -0
- package/dist/fixtures/aspects/ui/ui.aspect.js +15 -0
- package/dist/fixtures/aspects/ui/ui.aspect.js.map +1 -0
- package/dist/fixtures/aspects/ui/ui.ui.d.ts +4 -0
- package/dist/fixtures/aspects/ui/ui.ui.js +24 -0
- package/dist/fixtures/aspects/ui/ui.ui.js.map +1 -0
- package/dist/fixtures/babel/babel.extension.d.ts +9 -0
- package/dist/fixtures/babel/babel.extension.js +30 -0
- package/dist/fixtures/babel/babel.extension.js.map +1 -0
- package/dist/fixtures/babel/index.d.ts +0 -0
- package/dist/fixtures/babel/index.js +1 -0
- package/dist/fixtures/babel/index.js.map +1 -0
- package/dist/fixtures/base-compiler/base-compiler.extension.d.ts +13 -0
- package/dist/fixtures/base-compiler/base-compiler.extension.js +30 -0
- package/dist/fixtures/base-compiler/base-compiler.extension.js.map +1 -0
- package/dist/fixtures/base-compiler/index.d.ts +1 -0
- package/dist/fixtures/base-compiler/index.js +6 -0
- package/dist/fixtures/base-compiler/index.js.map +1 -0
- package/dist/fixtures/cli/cli.extension.d.ts +18 -0
- package/dist/fixtures/cli/cli.extension.js +24 -0
- package/dist/fixtures/cli/cli.extension.js.map +1 -0
- package/dist/fixtures/cli/command.d.ts +6 -0
- package/dist/fixtures/cli/command.js +1 -0
- package/dist/fixtures/cli/command.js.map +1 -0
- package/dist/fixtures/cli/index.d.ts +1 -0
- package/dist/fixtures/cli/index.js +18 -0
- package/dist/fixtures/cli/index.js.map +1 -0
- package/dist/fixtures/typescript/index.d.ts +0 -0
- package/dist/fixtures/typescript/index.js +1 -0
- package/dist/fixtures/typescript/index.js.map +1 -0
- package/dist/fixtures/typescript/typescript.d.ts +7 -0
- package/dist/fixtures/typescript/typescript.js +31 -0
- package/dist/fixtures/typescript/typescript.js.map +1 -0
- package/dist/harmony-config/config-reader.d.ts +1 -0
- package/dist/harmony-config/config-reader.js +21 -0
- package/dist/harmony-config/config-reader.js.map +1 -0
- package/dist/harmony-config/exceptions/index.d.ts +1 -0
- package/dist/harmony-config/exceptions/index.js +6 -0
- package/dist/harmony-config/exceptions/index.js.map +1 -0
- package/dist/harmony-config/exceptions/read-config-error.d.ts +5 -0
- package/dist/harmony-config/exceptions/read-config-error.js +14 -0
- package/dist/harmony-config/exceptions/read-config-error.js.map +1 -0
- package/dist/harmony-config/harmony-config.d.ts +17 -0
- package/dist/harmony-config/harmony-config.js +36 -0
- package/dist/harmony-config/harmony-config.js.map +1 -0
- package/dist/harmony-config/index.d.ts +1 -0
- package/dist/harmony-config/index.js +6 -0
- package/dist/harmony-config/index.js.map +1 -0
- package/dist/harmony-config/locator.d.ts +0 -0
- package/dist/harmony-config/locator.js +1 -0
- package/dist/harmony-config/locator.js.map +1 -0
- package/dist/harmony.d.ts +63 -0
- package/dist/harmony.docs.mdx +250 -0
- package/dist/harmony.js +151 -0
- package/dist/harmony.js.map +1 -0
- package/dist/harmony.spec.old.d.ts +1 -0
- package/dist/harmony.spec.old.js +144 -0
- package/dist/harmony.spec.old.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/preview-1782314412027.js +7 -0
- package/dist/readme.md +80 -0
- package/dist/runtimes/exceptions/index.d.ts +2 -0
- package/dist/runtimes/exceptions/index.js +8 -0
- package/dist/runtimes/exceptions/index.js.map +1 -0
- package/dist/runtimes/exceptions/runtime-module-error.d.ts +5 -0
- package/dist/runtimes/exceptions/runtime-module-error.js +14 -0
- package/dist/runtimes/exceptions/runtime-module-error.js.map +1 -0
- package/dist/runtimes/exceptions/runtime-not-defined.d.ts +3 -0
- package/dist/runtimes/exceptions/runtime-not-defined.js +8 -0
- package/dist/runtimes/exceptions/runtime-not-defined.js.map +1 -0
- package/dist/runtimes/index.d.ts +3 -0
- package/dist/runtimes/index.js +8 -0
- package/dist/runtimes/index.js.map +1 -0
- package/dist/runtimes/runtime-definition.d.ts +11 -0
- package/dist/runtimes/runtime-definition.js +27 -0
- package/dist/runtimes/runtime-definition.js.map +1 -0
- package/dist/runtimes/runtime-manifest.d.ts +13 -0
- package/dist/runtimes/runtime-manifest.js +3 -0
- package/dist/runtimes/runtime-manifest.js.map +1 -0
- package/dist/runtimes/runtimes.d.ts +14 -0
- package/dist/runtimes/runtimes.js +43 -0
- package/dist/runtimes/runtimes.js.map +1 -0
- package/dist/slots/index.d.ts +2 -0
- package/dist/slots/index.js +8 -0
- package/dist/slots/index.js.map +1 -0
- package/dist/slots/registry.d.ts +21 -0
- package/dist/slots/registry.js +36 -0
- package/dist/slots/registry.js.map +1 -0
- package/dist/slots/slot.d.ts +5 -0
- package/dist/slots/slot.js +13 -0
- package/dist/slots/slot.js.map +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/async-for-each.d.ts +5 -0
- package/dist/utils/async-for-each.js +25 -0
- package/dist/utils/async-for-each.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -0
- package/exceptions/extension-init-error.ts +1 -0
- package/exceptions/extension-load-error.ts +28 -0
- package/exceptions/extension-potential-circular.ts +24 -0
- package/exceptions/harmony-already-running.ts +1 -0
- package/exceptions/harmony-error.ts +1 -0
- package/exceptions/hook-not-found.ts +1 -0
- package/exceptions/index.ts +5 -0
- package/exceptions/runtime-not-defined.ts +0 -0
- package/extension/any-extension.ts +8 -0
- package/extension/decorator.ts +126 -0
- package/extension/extension-manifest.ts +51 -0
- package/extension/extension.ts +142 -0
- package/extension/index.ts +3 -0
- package/extension-graph/extension-graph.ts +165 -0
- package/extension-graph/from-extension.ts +72 -0
- package/extension-graph/index.ts +1 -0
- package/factory/extension-factory.ts +8 -0
- package/factory/index.ts +1 -0
- package/fixtures/aspects/babel/babel.aspect.ts +14 -0
- package/fixtures/aspects/babel/babel.cli.ts +16 -0
- package/fixtures/aspects/react/react.aspect.ts +22 -0
- package/fixtures/aspects/react/react.cli.ts +26 -0
- package/fixtures/aspects/react/react.ui.ts +16 -0
- package/fixtures/aspects/ui/ui.aspect.ts +13 -0
- package/fixtures/aspects/ui/ui.ui.ts +11 -0
- package/fixtures/babel/babel.extension.ts +20 -0
- package/fixtures/babel/index.ts +0 -0
- package/fixtures/base-compiler/base-compiler.extension.ts +31 -0
- package/fixtures/base-compiler/index.ts +1 -0
- package/fixtures/cli/cli.extension.ts +25 -0
- package/fixtures/cli/command.ts +6 -0
- package/fixtures/cli/index.ts +1 -0
- package/fixtures/typescript/index.ts +0 -0
- package/fixtures/typescript/typescript.ts +20 -0
- package/harmony-config/config-reader.ts +18 -0
- package/harmony-config/exceptions/index.ts +1 -0
- package/harmony-config/exceptions/read-config-error.ts +9 -0
- package/harmony-config/harmony-config.ts +49 -0
- package/harmony-config/index.ts +1 -0
- package/harmony-config/locator.ts +0 -0
- package/harmony.docs.mdx +250 -0
- package/harmony.spec.old.ts +177 -0
- package/harmony.ts +148 -0
- package/index.ts +13 -0
- package/package.json +68 -0
- package/readme.md +80 -0
- package/runtimes/exceptions/index.ts +2 -0
- package/runtimes/exceptions/runtime-module-error.ts +9 -0
- package/runtimes/exceptions/runtime-not-defined.ts +5 -0
- package/runtimes/index.ts +3 -0
- package/runtimes/runtime-definition.ts +32 -0
- package/runtimes/runtime-manifest.ts +12 -0
- package/runtimes/runtimes.ts +34 -0
- package/slots/index.ts +2 -0
- package/slots/registry.ts +36 -0
- package/slots/slot.ts +11 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
- package/types.ts +7 -0
- package/utils/async-for-each.ts +10 -0
- package/utils/index.ts +1 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ExtensionManifest } from '../extension';
|
|
2
|
+
import { extensionFactory } from '../factory';
|
|
3
|
+
import ExtensionPotentialCircular from '../exceptions/extension-potential-circular';
|
|
4
|
+
import { Extension } from '../extension';
|
|
5
|
+
import { DependencyGraphOptions, Edge } from './extension-graph';
|
|
6
|
+
|
|
7
|
+
function getName(manifest: any) {
|
|
8
|
+
return Reflect.getMetadata('harmony:name', manifest) || manifest.id || manifest.name;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* build vertices and edges from the given extension
|
|
13
|
+
*/
|
|
14
|
+
export function fromExtension(extension: ExtensionManifest, options: DependencyGraphOptions = {}) {
|
|
15
|
+
const vertices: { [id: string]: Extension } = {};
|
|
16
|
+
let edges: { sourceId: string; targetId: string; edge: Edge }[] = [];
|
|
17
|
+
|
|
18
|
+
function iterate(root: ExtensionManifest) {
|
|
19
|
+
const id = options.getName ? options.getName(root) : getName(root);
|
|
20
|
+
if (vertices[id]) return;
|
|
21
|
+
|
|
22
|
+
const instance = extensionFactory(root);
|
|
23
|
+
const validDeps = instance.dependencies.filter(dep => dep).map(dep => extensionFactory(dep));
|
|
24
|
+
if (instance.dependencies.length > validDeps.length) {
|
|
25
|
+
throw new ExtensionPotentialCircular(instance, validDeps);
|
|
26
|
+
}
|
|
27
|
+
vertices[id] = instance;
|
|
28
|
+
const newEdges = validDeps.map(dep => {
|
|
29
|
+
return {
|
|
30
|
+
sourceId: id,
|
|
31
|
+
targetId: dep.name,
|
|
32
|
+
edge: {
|
|
33
|
+
type: 'dependency'
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
edges = edges.concat(newEdges);
|
|
39
|
+
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
instance.dependencies.forEach(dep => iterate(dep));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
iterate(extension);
|
|
45
|
+
|
|
46
|
+
let vertexArray: { id: string; node: Extension }[] = [];
|
|
47
|
+
for (let [key, value] of Object.entries(vertices)) {
|
|
48
|
+
vertexArray.push({ id: key, node: value });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
vertices: vertexArray,
|
|
53
|
+
edges
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* build vertices and edges from the given list of extensions
|
|
59
|
+
*/
|
|
60
|
+
export function fromExtensions(extensions: ExtensionManifest[], options: DependencyGraphOptions = {}) {
|
|
61
|
+
const perExtension = extensions.map(ext => fromExtension(ext, options));
|
|
62
|
+
|
|
63
|
+
return perExtension.reduce(
|
|
64
|
+
(acc, subgraph) => {
|
|
65
|
+
acc.edges = acc.edges.concat(subgraph.edges);
|
|
66
|
+
acc.vertices = acc.vertices.concat(subgraph.vertices);
|
|
67
|
+
|
|
68
|
+
return acc;
|
|
69
|
+
},
|
|
70
|
+
{ vertices: [], edges: [] }
|
|
71
|
+
);
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as DependencyGraph } from './extension-graph';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExtensionManifest } from '../extension/extension-manifest';
|
|
2
|
+
import { Extension } from '../extension/extension';
|
|
3
|
+
|
|
4
|
+
export function extensionFactory(manifest: ExtensionManifest) {
|
|
5
|
+
// to allow the use of `provide` as an alias to `provider` in ExtensionManifest
|
|
6
|
+
if (manifest.provide) manifest.provider = manifest.provide;
|
|
7
|
+
return new Extension(manifest);
|
|
8
|
+
}
|
package/factory/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { extensionFactory } from './extension-factory';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BabelCLI } from './babel.cli';
|
|
2
|
+
import { Aspect } from '../../../aspect';
|
|
3
|
+
|
|
4
|
+
export type { BabelCLI };
|
|
5
|
+
|
|
6
|
+
export const BabelAspect = Aspect.create({
|
|
7
|
+
id: '@teambit/babel',
|
|
8
|
+
dependencies: [],
|
|
9
|
+
files: [
|
|
10
|
+
require.resolve('./babel.cli')
|
|
11
|
+
]
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export default BabelAspect;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BabelAspect } from './babel.aspect';
|
|
2
|
+
import { CLIRuntime } from '../react/react.aspect';
|
|
3
|
+
|
|
4
|
+
export class BabelCLI {
|
|
5
|
+
compile() {
|
|
6
|
+
console.log('compiled!');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static runtime = CLIRuntime;
|
|
10
|
+
|
|
11
|
+
static async provider() {
|
|
12
|
+
return new BabelCLI();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
BabelAspect.addRuntime(BabelCLI);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BabelAspect } from '../babel/babel.aspect';
|
|
2
|
+
import { Aspect } from '../../../aspect';
|
|
3
|
+
import { Slot } from '../../../slots';
|
|
4
|
+
import { RuntimeDefinition } from '../../../runtimes';
|
|
5
|
+
import { UIAspect } from '../ui/ui.aspect';
|
|
6
|
+
|
|
7
|
+
export type Config = {};
|
|
8
|
+
|
|
9
|
+
export const CLIRuntime = RuntimeDefinition.create({ name: 'cli' })
|
|
10
|
+
|
|
11
|
+
export const ReactAspect = Aspect.create({
|
|
12
|
+
id: '@teambit/react',
|
|
13
|
+
dependencies: [UIAspect],
|
|
14
|
+
defaultConfig: {},
|
|
15
|
+
declareRuntime: CLIRuntime,
|
|
16
|
+
files: [
|
|
17
|
+
require.resolve('./react.cli'),
|
|
18
|
+
require.resolve('./react.ui')
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export default ReactAspect;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import ReactAspect, { CLIRuntime } from './react.aspect';
|
|
2
|
+
import BabelAspect, { BabelCLI } from '../babel/babel.aspect';
|
|
3
|
+
import { Slot, SlotRegistry } from '../../../slots';
|
|
4
|
+
|
|
5
|
+
export class ReactCLI {
|
|
6
|
+
constructor(
|
|
7
|
+
private babel: BabelCLI
|
|
8
|
+
) {}
|
|
9
|
+
|
|
10
|
+
static runtime = CLIRuntime;
|
|
11
|
+
|
|
12
|
+
hello() {
|
|
13
|
+
return this.babel.compile();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static dependencies = [BabelAspect];
|
|
17
|
+
|
|
18
|
+
static slots = [Slot.withType<string>()];
|
|
19
|
+
|
|
20
|
+
static async provider([babelCli]: [BabelCLI], config: {}, [stringSlot]: [SlotRegistry<string>]) {
|
|
21
|
+
stringSlot.register('hi there');
|
|
22
|
+
return new ReactCLI(babelCli);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
ReactAspect.addRuntime(ReactCLI);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ReactAspect from './react.aspect';
|
|
2
|
+
import { UIRuntime } from '../ui/ui.aspect';
|
|
3
|
+
|
|
4
|
+
export class ReactUI {
|
|
5
|
+
static runtime = UIRuntime;
|
|
6
|
+
|
|
7
|
+
render() {
|
|
8
|
+
return 'rendering something!';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static async provider() {
|
|
12
|
+
return new ReactUI();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
ReactAspect.addRuntime(ReactUI);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Aspect } from '../../../aspect';
|
|
2
|
+
import { RuntimeDefinition } from '../../../runtimes';
|
|
3
|
+
|
|
4
|
+
export const UIRuntime = RuntimeDefinition.create({ name: 'ui' });
|
|
5
|
+
|
|
6
|
+
export const UIAspect = Aspect.create({
|
|
7
|
+
id: '@teambit/ui',
|
|
8
|
+
dependencies: [],
|
|
9
|
+
declareRuntime: UIRuntime,
|
|
10
|
+
files: [
|
|
11
|
+
require.resolve('./ui.ui')
|
|
12
|
+
]
|
|
13
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Extension, provider } from '../..';
|
|
2
|
+
import { BaseCompiler } from '../base-compiler';
|
|
3
|
+
|
|
4
|
+
class Mock {
|
|
5
|
+
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// @Extension({
|
|
9
|
+
// dependencies: [BaseCompiler]
|
|
10
|
+
// })
|
|
11
|
+
export class Babel {
|
|
12
|
+
constructor(
|
|
13
|
+
private mock?: Mock
|
|
14
|
+
) {}
|
|
15
|
+
|
|
16
|
+
// @provider()
|
|
17
|
+
async provide([baseCompiler]: [BaseCompiler]) {
|
|
18
|
+
return new Babel();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Extension } from "../..";
|
|
2
|
+
import { CLI, Command } from '../cli';
|
|
3
|
+
|
|
4
|
+
// @Extension()
|
|
5
|
+
export class BaseCompiler {
|
|
6
|
+
constructor(
|
|
7
|
+
private cli: CLI
|
|
8
|
+
) {}
|
|
9
|
+
|
|
10
|
+
// @Config()
|
|
11
|
+
config() {
|
|
12
|
+
return {
|
|
13
|
+
cjs: 'blue/green'
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// @Command
|
|
18
|
+
main() {
|
|
19
|
+
return {
|
|
20
|
+
synopsis: 'compile <id>',
|
|
21
|
+
report: () => {
|
|
22
|
+
return 'compiled in 0.1 secs';
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
compile() {
|
|
28
|
+
this.cli.run();
|
|
29
|
+
return 'hello world';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BaseCompiler } from './base-compiler.extension';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Extension, createHook } from '../..';
|
|
2
|
+
import { HookRegistry, hook } from '../..';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* hook for registering new CLI commands.
|
|
6
|
+
*/
|
|
7
|
+
export const Command = createHook();
|
|
8
|
+
|
|
9
|
+
export type CommandDefinition = {
|
|
10
|
+
synopsis: string,
|
|
11
|
+
report: string
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// @Extension()
|
|
15
|
+
export class CLI {
|
|
16
|
+
/**
|
|
17
|
+
* registry for the commands hook
|
|
18
|
+
*/
|
|
19
|
+
private commands = HookRegistry.of<CommandDefinition>(Command);
|
|
20
|
+
|
|
21
|
+
run() {
|
|
22
|
+
const commands = this.commands.list();
|
|
23
|
+
return commands;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cli.extension';
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Extension } from '../..';
|
|
2
|
+
import { BaseCompiler } from '../base-compiler';
|
|
3
|
+
|
|
4
|
+
// @Extension({
|
|
5
|
+
// name: 'typescript',
|
|
6
|
+
// dependencies: [BaseCompiler]
|
|
7
|
+
// })
|
|
8
|
+
export class TypeScript {
|
|
9
|
+
constructor(
|
|
10
|
+
private compiler: string
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
compile() {
|
|
14
|
+
return this.compiler;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static async provider([baseCompiler]: [BaseCompiler]) {
|
|
18
|
+
return new TypeScript(baseCompiler.compile());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { parse } from 'comment-json';
|
|
2
|
+
import { readFileSync, existsSync } from 'fs';
|
|
3
|
+
import { ReadConfigError } from './exceptions/read-config-error';
|
|
4
|
+
|
|
5
|
+
export function readConfigFile(path: string, mustExist = true): Record<string, any> {
|
|
6
|
+
if (!mustExist && !existsSync(path)) {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
const parsed = parse(readFileSync(path, 'utf8'));
|
|
12
|
+
const json: Record<string, any> = parsed && typeof parsed === 'object' ? (parsed as Record<string, any>) : {};
|
|
13
|
+
delete json['$schema'];
|
|
14
|
+
return json;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
throw new ReadConfigError(path, err instanceof Error ? err : new Error(String(err)));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ReadConfigError } from './read-config-error';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { stringify, assign } from 'comment-json';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { readConfigFile } from './config-reader';
|
|
4
|
+
|
|
5
|
+
const userHome = require('user-home');
|
|
6
|
+
|
|
7
|
+
export type ConfigOptions = {
|
|
8
|
+
cwd?: string;
|
|
9
|
+
global?: GlobalConfigOpts;
|
|
10
|
+
shouldThrow?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type GlobalConfigOpts = {
|
|
14
|
+
dir?: string;
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const defaultConfig = {
|
|
19
|
+
cwd: process.cwd(),
|
|
20
|
+
shouldThrow: true,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class HarmonyConfig {
|
|
24
|
+
constructor(private raw: Record<string, any>) {}
|
|
25
|
+
|
|
26
|
+
toObject() {
|
|
27
|
+
return this.raw;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
toString() {
|
|
31
|
+
return stringify(this.raw);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static load(fileName: string, opts?: ConfigOptions) {
|
|
35
|
+
const mergedOpts = Object.assign(defaultConfig, opts);
|
|
36
|
+
const config = readConfigFile(join(mergedOpts.cwd, fileName), mergedOpts.shouldThrow);
|
|
37
|
+
|
|
38
|
+
if (mergedOpts.global) {
|
|
39
|
+
return HarmonyConfig.loadGlobal(mergedOpts.global, config);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return new HarmonyConfig(config);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static loadGlobal(globalOpts: GlobalConfigOpts, config: any = {}) {
|
|
46
|
+
const globalConfig = readConfigFile(join(globalOpts.dir || userHome, globalOpts.name), false);
|
|
47
|
+
return new HarmonyConfig(assign(config, globalConfig));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HarmonyConfig as Config, ConfigOptions } from './harmony-config';
|
|
File without changes
|
package/harmony.docs.mdx
ADDED
|
@@ -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
|
+
*/}
|