@teambit/component 0.0.554 → 0.0.558

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 (105) hide show
  1. package/dist/aspect-list.d.ts +18 -0
  2. package/dist/component-factory.d.ts +49 -0
  3. package/dist/component-fs.d.ts +20 -1
  4. package/dist/component-map/component-map.d.ts +32 -0
  5. package/dist/component-meta.d.ts +11 -1
  6. package/dist/component.d.ts +96 -1
  7. package/dist/component.graphql.d.ts +1 -1
  8. package/dist/component.main.runtime.d.ts +30 -1
  9. package/dist/component.ui.runtime.d.ts +21 -1
  10. package/dist/config.d.ts +18 -1
  11. package/dist/dependencies/dependencies.d.ts +18 -0
  12. package/dist/exceptions/host-not-found.d.ts +8 -1
  13. package/dist/hash.d.ts +3 -0
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +12 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/show/show-fragment.d.ts +23 -0
  18. package/dist/snap/author.d.ts +12 -0
  19. package/dist/snap/snap.d.ts +39 -1
  20. package/dist/state.d.ts +44 -1
  21. package/dist/tag/tag.d.ts +21 -1
  22. package/dist/tag-map.d.ts +19 -0
  23. package/dist/ui/component-error/component-error.d.ts +15 -1
  24. package/dist/ui/component-model/component-model.d.ts +102 -1
  25. package/dist/ui/component.d.ts +3 -0
  26. package/dist/ui/context/component-provider.d.ts +6 -0
  27. package/dist/ui/menu/menu.d.ts +12 -0
  28. package/dist/ui/use-component-query.d.ts +1 -0
  29. package/package.json +42 -34
  30. package/tsconfig.json +1 -2
  31. package/aspect-entry.ts +0 -67
  32. package/aspect-list.ts +0 -100
  33. package/aspect.section.tsx +0 -16
  34. package/component-factory.ts +0 -106
  35. package/component-fs.ts +0 -60
  36. package/component-map/component-map.ts +0 -106
  37. package/component-map/index.ts +0 -1
  38. package/component-meta.ts +0 -29
  39. package/component.aspect.ts +0 -9
  40. package/component.docs.mdx +0 -8
  41. package/component.graphql.ts +0 -202
  42. package/component.main.runtime.ts +0 -162
  43. package/component.route.ts +0 -26
  44. package/component.ts +0 -278
  45. package/component.ui.runtime.tsx +0 -216
  46. package/config.ts +0 -34
  47. package/dependencies/dependencies.ts +0 -74
  48. package/dependencies/index.ts +0 -1
  49. package/exceptions/could-not-find-latest.ts +0 -8
  50. package/exceptions/host-not-found.ts +0 -14
  51. package/exceptions/index.ts +0 -4
  52. package/exceptions/nothing-to-snap.ts +0 -1
  53. package/hash.ts +0 -4
  54. package/head.ts +0 -0
  55. package/history-graph.ts +0 -1
  56. package/host/component-host-model.ts +0 -9
  57. package/host/index.ts +0 -2
  58. package/host/use-component-host.ts +0 -39
  59. package/index.ts +0 -32
  60. package/on-load.ts +0 -0
  61. package/package-tar/teambit-component-0.0.554.tgz +0 -0
  62. package/section/index.ts +0 -1
  63. package/section/section.tsx +0 -8
  64. package/show/extensions.fragment.ts +0 -23
  65. package/show/files.fragment.ts +0 -24
  66. package/show/id.fragment.ts +0 -20
  67. package/show/index.ts +0 -8
  68. package/show/main-file.fragment.ts +0 -13
  69. package/show/name.fragment.ts +0 -13
  70. package/show/scope.fragment.ts +0 -15
  71. package/show/show-fragment.ts +0 -44
  72. package/show/show.cmd.ts +0 -85
  73. package/snap/author.ts +0 -19
  74. package/snap/index.ts +0 -2
  75. package/snap/snap.ts +0 -63
  76. package/state.ts +0 -73
  77. package/store.ts +0 -3
  78. package/tag/index.ts +0 -1
  79. package/tag/tag.ts +0 -37
  80. package/tag-map.ts +0 -87
  81. package/types/asset.d.ts +0 -29
  82. package/types/style.d.ts +0 -42
  83. package/ui/aspect-page/aspect-page.module.scss +0 -20
  84. package/ui/aspect-page/aspect-page.tsx +0 -64
  85. package/ui/aspect-page/index.ts +0 -1
  86. package/ui/component-error/component-error.tsx +0 -22
  87. package/ui/component-error/index.ts +0 -1
  88. package/ui/component-model/component-model.ts +0 -169
  89. package/ui/component-model/index.ts +0 -1
  90. package/ui/component.module.scss +0 -7
  91. package/ui/component.tsx +0 -48
  92. package/ui/context/component-context.ts +0 -5
  93. package/ui/context/component-provider.tsx +0 -20
  94. package/ui/context/index.ts +0 -2
  95. package/ui/index.ts +0 -3
  96. package/ui/menu/index.ts +0 -2
  97. package/ui/menu/menu-nav.tsx +0 -37
  98. package/ui/menu/menu.module.scss +0 -62
  99. package/ui/menu/menu.tsx +0 -94
  100. package/ui/menu/nav-plugin.tsx +0 -9
  101. package/ui/top-bar-nav/index.ts +0 -1
  102. package/ui/top-bar-nav/top-bar-nav.module.scss +0 -52
  103. package/ui/top-bar-nav/top-bar-nav.tsx +0 -26
  104. package/ui/use-component-query.ts +0 -195
  105. package/ui/use-component.tsx +0 -34
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import { MenuWidgetIcon } from '@teambit/ui-foundation.ui.menu-widget-icon';
3
- import { Section } from './section';
4
- import { AspectPage } from './ui/aspect-page';
5
-
6
- export class AspectSection implements Section {
7
- route = {
8
- path: '~aspect',
9
- children: <AspectPage />,
10
- };
11
- navigationLink = {
12
- href: '~aspect',
13
- children: <MenuWidgetIcon icon="configuration" tooltipContent="Configuration" />,
14
- };
15
- order = 50;
16
- }
@@ -1,106 +0,0 @@
1
- import { BitId } from '@teambit/legacy-bit-id';
2
- import LegacyGraph from '@teambit/legacy/dist/scope/graph/graph';
3
- import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
4
- import type { ComponentLog } from '@teambit/legacy/dist/scope/models/model-component';
5
- import type { AspectDefinition } from '@teambit/aspect-loader';
6
- import { ComponentID } from '@teambit/component-id';
7
- import { Component, InvalidComponent } from './component';
8
- import { State } from './state';
9
- import { Snap } from './snap';
10
-
11
- export interface ComponentFactory {
12
- /**
13
- * name of the component host.
14
- */
15
- name: string;
16
-
17
- /**
18
- * path to the component host.
19
- */
20
- path: string;
21
-
22
- isLegacy: boolean;
23
-
24
- /**
25
- * resolve a `string` component ID to an instance of a ComponentID.
26
- */
27
- resolveComponentId(id: string | ComponentID | BitId): Promise<ComponentID>;
28
-
29
- /**
30
- * resolve multiple `string` component ID to an instance of a ComponentID.
31
- */
32
- resolveMultipleComponentIds(ids: (string | ComponentID | BitId)[]): Promise<ComponentID[]>;
33
-
34
- /**
35
- * returns a component by ID.
36
- */
37
- get(
38
- id: ComponentID | string,
39
- withState?: boolean,
40
- consumerComponent?: ConsumerComponent
41
- ): Promise<Component | undefined>;
42
-
43
- /**
44
- * returns many components by ids.
45
- */
46
- getMany(ids: ComponentID[]): Promise<Component[]>;
47
-
48
- /**
49
- * returns many components by their legacy representation.
50
- */
51
- getManyByLegacy(components: ConsumerComponent[]): Promise<Component[]>;
52
-
53
- /**
54
- * get a component from a remote without importing it
55
- */
56
- getRemoteComponent?: (id: ComponentID) => Promise<Component>;
57
-
58
- getLegacyGraph(ids?: ComponentID[]): Promise<LegacyGraph>;
59
-
60
- getLogs(id: ComponentID): Promise<ComponentLog[]>;
61
-
62
- /**
63
- * returns a specific state of a component by hash or semver.
64
- */
65
- getState(id: ComponentID, snapId: string): Promise<State>;
66
-
67
- /**
68
- * returns a specific snap of a component by hash.
69
- */
70
- getSnap(id: ComponentID, snapId: string): Promise<Snap>;
71
-
72
- /**
73
- * load extension.
74
- */
75
- loadAspects: (ids: string[], throwOnError: boolean) => Promise<void>;
76
-
77
- /**
78
- * Resolve dirs for aspects
79
- */
80
- resolveAspects: (runtimeName?: string, componentIds?: ComponentID[]) => Promise<AspectDefinition[]>;
81
-
82
- /**
83
- * list all components in the host.
84
- */
85
- list(filter?: { offset: number; limit: number }): Promise<Component[]>;
86
-
87
- /**
88
- * list invalid components, such as components with missing files on the fs.
89
- */
90
- listInvalid(): Promise<InvalidComponent[]>;
91
-
92
- listIds(): Promise<ComponentID[]>;
93
-
94
- hasId(componentId: ComponentID): Promise<boolean>;
95
-
96
- /**
97
- * Check if the host has the id, if no, search for the id in inner host (for example, workspace will search in the scope)
98
- * @param componentId
99
- */
100
- hasIdNested(componentId: ComponentID, includeCache?: boolean): Promise<boolean>;
101
-
102
- /**
103
- * determine whether host should be the prior one in case multiple hosts persist.
104
- */
105
- priority?: boolean;
106
- }
package/component-fs.ts DELETED
@@ -1,60 +0,0 @@
1
- import { MemoryFS } from '@teambit/any-fs';
2
- import type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
3
- import { auto } from '@teambit/legacy/dist/utils/eol';
4
- import path from 'path';
5
- import minimatch from 'minimatch';
6
-
7
- /**
8
- * The virtual component filesystem
9
- */
10
- export default class ComponentFS extends MemoryFS {
11
- constructor(
12
- /**
13
- * array of all fs files.
14
- */
15
- readonly files: AbstractVinyl[]
16
- ) {
17
- super();
18
- }
19
- /**
20
- * hash to represent all contents within this filesystem volume.
21
- */
22
- get hash() {
23
- return '';
24
- }
25
-
26
- /**
27
- * filter all component files by regex.
28
- */
29
- byRegex(extension: RegExp): AbstractVinyl[] {
30
- return this.files.filter((file) => file.path.match(extension));
31
- }
32
-
33
- /**
34
- * filter all files using an array of glob patterns.
35
- */
36
- byGlob(patterns: string[]) {
37
- return this.files.filter((file) => {
38
- return patterns.find((pattern) => {
39
- const match = minimatch(file.relative, pattern);
40
- return match;
41
- });
42
- });
43
- }
44
-
45
- toObject() {}
46
-
47
- toJSON() {}
48
-
49
- static fromVinyls(files: AbstractVinyl[]) {
50
- const fs = new ComponentFS(files);
51
- files.forEach((file) => {
52
- let dirPath = file.relativeDir;
53
- if (!dirPath.startsWith('/')) dirPath = path.join('/', dirPath);
54
- fs.mkdirpSync(dirPath);
55
- fs.writeFileSync(`/${file.relative}`, auto(file.contents || ''));
56
- });
57
-
58
- return fs;
59
- }
60
- }
@@ -1,106 +0,0 @@
1
- import { ComponentID } from '@teambit/component-id';
2
- import { Component } from '../component';
3
-
4
- /**
5
- * allows to index components -> values.
6
- */
7
- export class ComponentMap<T> {
8
- constructor(readonly hashMap: Map<string, [Component, T]>) {}
9
-
10
- /**
11
- * @deprecated please use `get` instead
12
- */
13
- byComponent(component: Component) {
14
- return this.hashMap.get(component.id.toString());
15
- }
16
-
17
- get components() {
18
- return this.toArray().map(([component]) => component);
19
- }
20
-
21
- /**
22
- * get a value for a component.
23
- */
24
- get(component: Component) {
25
- return this.hashMap.get(component.id.toString());
26
- }
27
-
28
- /**
29
- * get a value by the component-id
30
- */
31
- getValueByComponentId(componentId: ComponentID): T | null {
32
- const tuple = this.hashMap.get(componentId.toString());
33
- if (!tuple) return null;
34
- return tuple[1];
35
- }
36
-
37
- /**
38
- * returns an array.
39
- */
40
- toArray() {
41
- return Array.from(this.hashMap.values());
42
- }
43
-
44
- /**
45
- * map entries and return a new component map.
46
- */
47
- map<NewType>(predicate: (value: T, component: Component) => NewType): ComponentMap<NewType> {
48
- const tuples: [string, [Component, NewType]][] = this.toArray().map(([component, value]) => {
49
- const newValue = predicate(value, component);
50
- return [component.id.toString(), [component, newValue]];
51
- });
52
-
53
- return new ComponentMap(new Map(tuples));
54
- }
55
- /**
56
- * flatten values of all components into a single array.
57
- */
58
- flattenValue(): T[] {
59
- return this.toArray().reduce((acc: T[], [, value]) => {
60
- acc = acc.concat(value);
61
- return acc;
62
- }, []);
63
- }
64
-
65
- /**
66
- * filter all components with empty values and return a new map.
67
- */
68
- filter(predicate: (value: T) => boolean): ComponentMap<T> {
69
- const tuples = this.toArray().filter(([, value]) => {
70
- return predicate(value);
71
- });
72
-
73
- const asMap: [string, [Component, T]][] = tuples.map(([component, value]) => {
74
- return [component.id.toString(), [component, value]];
75
- });
76
-
77
- return new ComponentMap(new Map(asMap));
78
- }
79
-
80
- /**
81
- * get all component ids.
82
- */
83
- keys() {
84
- return this.hashMap.keys();
85
- }
86
-
87
- static create<U>(rawMap: [Component, U][]) {
88
- const newMap: [string, [Component, U]][] = rawMap.map(([component, data]) => {
89
- return [component.id.toString(), [component, data]];
90
- });
91
- return new ComponentMap(new Map(newMap));
92
- }
93
-
94
- /**
95
- * create a component map from components and a value predicate.
96
- * @param components components to zip into the map.
97
- * @param predicate predicate for returning desired value.
98
- */
99
- static as<U>(components: Component[], predicate: (component: Component) => U): ComponentMap<U> {
100
- const tuples: [string, [Component, U]][] = components.map((component) => {
101
- return [component.id.toString(), [component, predicate(component)]];
102
- });
103
-
104
- return new ComponentMap(new Map(tuples));
105
- }
106
- }
@@ -1 +0,0 @@
1
- export { ComponentMap } from './component-map';
package/component-meta.ts DELETED
@@ -1,29 +0,0 @@
1
- import { capitalize } from '@teambit/toolbox.string.capitalize';
2
- import { ComponentID } from '@teambit/component-id';
3
-
4
- export class ComponentMeta {
5
- constructor(
6
- /**
7
- * id the component.
8
- */
9
- readonly id: ComponentID
10
- ) {}
11
-
12
- /**
13
- * display name of the component.
14
- */
15
- get displayName() {
16
- const tokens = this.id.name.split('-').map((token) => capitalize(token));
17
- return tokens.join(' ');
18
- }
19
-
20
- toObject() {
21
- return {
22
- id: this.id.toObject(),
23
- };
24
- }
25
-
26
- static from(object: { [key: string]: any }) {
27
- return new ComponentMeta(ComponentID.fromObject(object.id));
28
- }
29
- }
@@ -1,9 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const ComponentAspect = Aspect.create({
4
- id: 'teambit.component/component',
5
- dependencies: [],
6
- defaultConfig: {},
7
- });
8
-
9
- export default ComponentAspect;
@@ -1,8 +0,0 @@
1
- ---
2
- description: Component aspect for Bit components
3
- labels: ['component', 'bit', 'extension', 'aspect']
4
- ---
5
-
6
- import { Component } from '@teambit/component.aspect-docs.component';
7
-
8
- <Component />
@@ -1,202 +0,0 @@
1
- import stripAnsi from 'strip-ansi';
2
- import gql from 'graphql-tag';
3
- import { GraphQLJSONObject } from 'graphql-type-json';
4
- import { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';
5
-
6
- import { Component } from './component';
7
- import { ComponentFactory } from './component-factory';
8
- import { ComponentMain } from './component.main.runtime';
9
-
10
- export function componentSchema(componentExtension: ComponentMain) {
11
- return {
12
- typeDefs: gql`
13
- scalar JSON
14
- scalar JSONObject
15
-
16
- type ComponentID {
17
- name: String!
18
- version: String
19
- scope: String
20
- }
21
-
22
- type Tag {
23
- # semver assigned to the tag.
24
- version: String!
25
-
26
- # tag hash.
27
- hash: String!
28
- }
29
-
30
- type Snap {
31
- # hash of the snapshot.
32
- hash: String!
33
-
34
- # time of the snapshot.
35
- timestamp: String!
36
-
37
- # parents of the snap
38
- parents: [Snap]!
39
-
40
- # snapper
41
- author: Author!
42
-
43
- # snapshot message
44
- message: String
45
- }
46
-
47
- type LogEntry {
48
- message: String!
49
- username: String
50
- email: String
51
- date: String
52
- hash: String!
53
- tag: String
54
- # id: String!
55
- }
56
-
57
- type Author {
58
- # display name of the snapper.
59
- displayName: String!
60
-
61
- # author of the snapper.
62
- email: String!
63
- }
64
-
65
- type Component {
66
- # id of the component.
67
- id: ComponentID!
68
-
69
- # head snap of the component.
70
- head: Snap
71
-
72
- # head tag of the component.
73
- headTag: Tag
74
-
75
- # list of all relative component paths.
76
- fs: [String]
77
-
78
- # relative path to the main file of the component
79
- mainFile: String
80
-
81
- # return specific file contents by relative file path.
82
- getFile(path: String): String
83
-
84
- # latest version of the component.
85
- latest: String
86
-
87
- # display name of the component
88
- displayName: String!
89
-
90
- # component buildStatus
91
- buildStatus: String
92
-
93
- # list of component releases.
94
- tags: [Tag]!
95
-
96
- aspects: [Aspect]
97
- }
98
-
99
- type Aspect {
100
- id: String!
101
- icon: String
102
- config: JSONObject
103
- data: JSONObject
104
- }
105
-
106
- type InvalidComponent {
107
- id: ComponentID!
108
- errorName: String!
109
- errorMessage: String!
110
- }
111
-
112
- type ComponentHost {
113
- id: ID!
114
- name: String!
115
-
116
- # load a component.
117
- get(id: String!, withState: Boolean): Component
118
-
119
- # list components
120
- list(offset: Int, limit: Int): [Component]!
121
-
122
- # list invalid components and their errors
123
- listInvalid: [InvalidComponent]!
124
-
125
- # get component logs(snaps) by component id
126
- snaps(id: String!): [LogEntry]!
127
- }
128
-
129
- type Query {
130
- getHost(id: String): ComponentHost
131
- }
132
- `,
133
- resolvers: {
134
- JSONObject: GraphQLJSONObject,
135
- Component: {
136
- id: (component: Component) => component.id.toObject(),
137
- displayName: (component: Component) => component.displayName,
138
- fs: (component: Component) => {
139
- return component.state.filesystem.files.map((file) => file.relative);
140
- },
141
- getFile: (component: Component, { path }: { path: string }) => {
142
- const maybeFile = component.state.filesystem.files.find(
143
- (file) => pathNormalizeToLinux(file.relative) === path
144
- );
145
- if (!maybeFile) return undefined;
146
- return maybeFile.contents.toString('utf-8');
147
- },
148
- mainFile: (component: Component) => {
149
- return component.state._consumer.mainFile;
150
- },
151
- headTag: (component: Component) => component.headTag?.toObject(),
152
- latest: (component: Component) => component.latest,
153
- tags: (component) => {
154
- // graphql doesn't support map types
155
- return component.tags.toArray().map((tag) => tag.toObject());
156
- },
157
- aspects: (component: Component) => {
158
- const aspects = component.state.aspects.serialize();
159
- return aspects;
160
- },
161
- },
162
- ComponentHost: {
163
- get: async (host: ComponentFactory, { id }: { id: string }) => {
164
- try {
165
- const componentId = await host.resolveComponentId(id);
166
- const component = await host.get(componentId);
167
- return component;
168
- } catch (error: any) {
169
- return null;
170
- }
171
- },
172
- snaps: async (host: ComponentFactory, { id }: { id: string }) => {
173
- const componentId = await host.resolveComponentId(id);
174
- // return (await host.getLogs(componentId)).map(log => ({...log, id: log.hash}))
175
- return host.getLogs(componentId);
176
- },
177
- list: async (host: ComponentFactory, filter?: { offset: number; limit: number }) => {
178
- return host.list(filter);
179
- },
180
- listInvalid: async (host: ComponentFactory) => {
181
- const invalidComps = await host.listInvalid();
182
- return invalidComps.map(({ id, err }) => ({
183
- id,
184
- errorName: err.name,
185
- errorMessage: err.message ? stripAnsi(err.message) : err.name,
186
- }));
187
- },
188
- id: async (host: ComponentFactory) => {
189
- return host.name;
190
- },
191
- name: async (host: ComponentFactory) => {
192
- return host.name;
193
- },
194
- },
195
- Query: {
196
- getHost: (componentExt: ComponentMain, { id }: { id: string }) => {
197
- return componentExtension.getHost(id);
198
- },
199
- },
200
- },
201
- };
202
- }
@@ -1,162 +0,0 @@
1
- import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
2
- import { ExpressAspect, ExpressMain, Route } from '@teambit/express';
3
- import { GraphqlAspect, GraphqlMain } from '@teambit/graphql';
4
- import { Slot, SlotRegistry } from '@teambit/harmony';
5
- import { ConfigAspect, Config } from '@teambit/config';
6
- import { ComponentID } from '@teambit/component-id';
7
- import { flatten, orderBy } from 'lodash';
8
- import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config';
9
- import { ComponentFactory } from './component-factory';
10
- import { ComponentAspect } from './component.aspect';
11
- import { componentSchema } from './component.graphql';
12
- import { ComponentRoute } from './component.route';
13
- import { AspectList } from './aspect-list';
14
- import { HostNotFound } from './exceptions';
15
- import { AspectEntry } from './aspect-entry';
16
- import {
17
- ShowCmd,
18
- ShowFragment,
19
- NameFragment,
20
- MainFileFragment,
21
- IDFragment,
22
- ScopeFragment,
23
- FilesFragment,
24
- ExtensionsFragment,
25
- } from './show';
26
-
27
- export type ComponentHostSlot = SlotRegistry<ComponentFactory>;
28
-
29
- export type ShowFragmentSlot = SlotRegistry<ShowFragment[]>;
30
-
31
- export class ComponentMain {
32
- constructor(
33
- /**
34
- * slot for component hosts to register.
35
- */
36
- private hostSlot: ComponentHostSlot,
37
-
38
- /**
39
- * Express Extension
40
- */
41
- private express: ExpressMain,
42
-
43
- private showFragmentSlot: ShowFragmentSlot
44
- ) {}
45
-
46
- /**
47
- * register a new component host.
48
- */
49
- registerHost(host: ComponentFactory) {
50
- this.hostSlot.register(host);
51
- return this;
52
- }
53
-
54
- createAspectList(legacyExtensionDataList: ExtensionDataList, scope?: string) {
55
- return AspectList.fromLegacyExtensions(legacyExtensionDataList, scope);
56
- }
57
-
58
- createAspectListFromEntries(entries: AspectEntry[]) {
59
- return new AspectList(entries);
60
- }
61
-
62
- registerRoute(routes: Route[]) {
63
- const routeEntries = routes.map((route: Route) => {
64
- return new ComponentRoute(route, this);
65
- });
66
-
67
- this.express.register(flatten(routeEntries));
68
- return this;
69
- }
70
-
71
- /**
72
- * set the prior host.
73
- */
74
- setHostPriority(id: string) {
75
- const host = this.hostSlot.get(id);
76
- if (!host) {
77
- throw new HostNotFound(id);
78
- }
79
-
80
- this._priorHost = host;
81
- return this;
82
- }
83
-
84
- /**
85
- * get component host by extension ID.
86
- */
87
- getHost(id?: string): ComponentFactory {
88
- if (id) {
89
- const host = this.hostSlot.get(id);
90
- if (!host) throw new HostNotFound(id);
91
- return host;
92
- }
93
-
94
- return this.getPriorHost();
95
- }
96
-
97
- getRoute(id: ComponentID, routeName: string) {
98
- return `/api/${id.toString()}/~aspect/${routeName}`;
99
- }
100
-
101
- /**
102
- * get the prior host.
103
- */
104
- private getPriorHost() {
105
- if (this._priorHost) return this._priorHost;
106
-
107
- const hosts = this.hostSlot.values();
108
- const priorityHost = hosts.find((host) => host.priority);
109
- return priorityHost || hosts[0];
110
- }
111
-
112
- getShowFragments() {
113
- const fragments = orderBy(flatten(this.showFragmentSlot.values()), ['weight', ['asc']]);
114
- return fragments;
115
- }
116
-
117
- isHost(name: string) {
118
- return !!this.hostSlot.get(name);
119
- }
120
-
121
- /**
122
- * register a show fragment to display further information in the `bit show` command.
123
- */
124
- registerShowFragments(showFragments: ShowFragment[]) {
125
- this.showFragmentSlot.register(showFragments);
126
- return this;
127
- }
128
-
129
- private _priorHost: ComponentFactory | undefined;
130
-
131
- static slots = [Slot.withType<ComponentFactory>(), Slot.withType<Route[]>(), Slot.withType<ShowFragment[]>()];
132
-
133
- static runtime = MainRuntime;
134
- static dependencies = [GraphqlAspect, ExpressAspect, CLIAspect, ConfigAspect];
135
-
136
- static async provider(
137
- [graphql, express, cli, configAspect]: [GraphqlMain, ExpressMain, CLIMain, Config],
138
- config,
139
- [hostSlot, showFragmentSlot]: [ComponentHostSlot, ShowFragmentSlot]
140
- ) {
141
- const componentExtension = new ComponentMain(hostSlot, express, showFragmentSlot);
142
-
143
- if ((configAspect.workspaceConfig && !configAspect.workspaceConfig.isLegacy) || configAspect.type === 'scope') {
144
- cli.unregister('show');
145
- cli.register(new ShowCmd(componentExtension));
146
- }
147
-
148
- componentExtension.registerShowFragments([
149
- new NameFragment(),
150
- new MainFileFragment(),
151
- new IDFragment(),
152
- new ScopeFragment(),
153
- new FilesFragment(),
154
- new ExtensionsFragment(),
155
- ]);
156
- graphql.register(componentSchema(componentExtension));
157
-
158
- return componentExtension;
159
- }
160
- }
161
-
162
- ComponentAspect.addRuntime(ComponentMain);