@teambit/component 1.0.108 → 1.0.109
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/artifacts/preview/static/css/teambit.component/component-preview.8360f74e.css +55 -0
- package/artifacts/preview/static/images/348e1dfebd0d5a35a5e6.png +0 -0
- package/artifacts/preview/static/images/37978a86e2f81f41863e.png +0 -0
- package/artifacts/preview/teambit_component_component-preview.js +2 -0
- package/dist/{preview-1703647408454.js → preview-1703698405864.js} +2 -2
- package/package.json +20 -20
- package/aspect-entry.ts +0 -73
- package/aspect-list.ts +0 -132
- package/component-factory.ts +0 -190
- package/component-fs.ts +0 -66
- package/component-interface.ts +0 -26
- package/component-meta.ts +0 -29
- package/component.aspect.ts +0 -9
- package/component.graphql.ts +0 -256
- package/component.main.runtime.ts +0 -170
- package/component.route.ts +0 -38
- package/component.ts +0 -319
- package/config.ts +0 -24
- package/get-component-opts.ts +0 -14
- package/hash.ts +0 -4
- package/head.ts +0 -0
- package/history-graph.ts +0 -1
- package/index.ts +0 -50
- package/on-load.ts +0 -0
- package/state.ts +0 -88
- package/store.ts +0 -3
- package/tag-map.ts +0 -87
package/component.ts
DELETED
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
import { AnyFS } from '@teambit/any-fs';
|
|
2
|
-
import { capitalize } from '@teambit/toolbox.string.capitalize';
|
|
3
|
-
import { SemVer } from 'semver';
|
|
4
|
-
import { ComponentID } from '@teambit/component-id';
|
|
5
|
-
import { BitError } from '@teambit/bit-error';
|
|
6
|
-
import { BuildStatus } from '@teambit/legacy/dist/constants';
|
|
7
|
-
|
|
8
|
-
import { slice } from 'lodash';
|
|
9
|
-
import { ComponentFactory } from './component-factory';
|
|
10
|
-
import ComponentFS from './component-fs';
|
|
11
|
-
// import { NothingToSnap } from './exceptions';
|
|
12
|
-
import { Config as ComponentConfig } from './config';
|
|
13
|
-
// eslint-disable-next-line import/no-cycle
|
|
14
|
-
import { Snap } from './snap';
|
|
15
|
-
import { State } from './state';
|
|
16
|
-
import { TagMap } from './tag-map';
|
|
17
|
-
import { Tag } from './tag';
|
|
18
|
-
import { CouldNotFindLatest } from './exceptions';
|
|
19
|
-
import { IComponent, RawComponentMetadata } from './component-interface';
|
|
20
|
-
// import { Author } from './types';
|
|
21
|
-
|
|
22
|
-
type SnapsIterableOpts = {
|
|
23
|
-
firstParentOnly?: boolean;
|
|
24
|
-
stopFn?: (snap: Snap) => Promise<boolean>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type InvalidComponent = { id: ComponentID; err: Error };
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* in-memory representation of a component.
|
|
31
|
-
*/
|
|
32
|
-
export class Component implements IComponent {
|
|
33
|
-
constructor(
|
|
34
|
-
/**
|
|
35
|
-
* component ID represented by the `ComponentId` type.
|
|
36
|
-
*/
|
|
37
|
-
readonly id: ComponentID,
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* head version of the component. can be `null` for new components.
|
|
41
|
-
*/
|
|
42
|
-
readonly head: Snap | null = null,
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* state of the component.
|
|
46
|
-
*/
|
|
47
|
-
private _state: State,
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* tags of the component.
|
|
51
|
-
*/
|
|
52
|
-
readonly tags: TagMap = new TagMap(),
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* the component factory
|
|
56
|
-
*/
|
|
57
|
-
private factory: ComponentFactory
|
|
58
|
-
) {}
|
|
59
|
-
|
|
60
|
-
get mainFile() {
|
|
61
|
-
return this.state.mainFile;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
get state(): State {
|
|
65
|
-
return this._state;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
set state(state: State) {
|
|
69
|
-
this._state = state;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* component configuration which is later generated to a component `package.json` and `bit.json`.
|
|
74
|
-
*/
|
|
75
|
-
get config(): ComponentConfig {
|
|
76
|
-
return this.state.config;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* in-memory representation of the component current filesystem.
|
|
81
|
-
*/
|
|
82
|
-
get filesystem(): ComponentFS {
|
|
83
|
-
return this.state.filesystem;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* build status of the component
|
|
88
|
-
*/
|
|
89
|
-
get buildStatus(): BuildStatus {
|
|
90
|
-
return this._state._consumer.buildStatus;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get headTag() {
|
|
94
|
-
if (!this.head) return undefined;
|
|
95
|
-
return this.tags.byHash(this.head.hash);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get latest(): string | undefined {
|
|
99
|
-
if (!this.head) return undefined;
|
|
100
|
-
try {
|
|
101
|
-
return this.tags.getLatest();
|
|
102
|
-
} catch (err: any) {
|
|
103
|
-
if (err instanceof CouldNotFindLatest) {
|
|
104
|
-
return this.head.hash;
|
|
105
|
-
}
|
|
106
|
-
throw err;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* get aspect data from current state.
|
|
112
|
-
*/
|
|
113
|
-
get(id: string): RawComponentMetadata | undefined {
|
|
114
|
-
return this.state.aspects.get(id)?.serialize();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async getLogs(filter?: { type?: string; offset?: number; limit?: number; head?: string; sort?: string }) {
|
|
118
|
-
const allLogs = await this.factory.getLogs(this.id, false, filter?.head);
|
|
119
|
-
|
|
120
|
-
if (!filter) return allLogs;
|
|
121
|
-
|
|
122
|
-
const { type, limit, offset, sort } = filter;
|
|
123
|
-
|
|
124
|
-
const typeFilter = (snap) => {
|
|
125
|
-
if (type === 'tag') return snap.tag;
|
|
126
|
-
if (type === 'snap') return !snap.tag;
|
|
127
|
-
return true;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
let filteredLogs = (type && allLogs.filter(typeFilter)) || allLogs;
|
|
131
|
-
if (sort !== 'asc') filteredLogs = filteredLogs.reverse();
|
|
132
|
-
|
|
133
|
-
if (limit) {
|
|
134
|
-
filteredLogs = slice(filteredLogs, offset, limit + (offset || 0));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return filteredLogs;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
stringify(): string {
|
|
141
|
-
return JSON.stringify({
|
|
142
|
-
id: this.id,
|
|
143
|
-
head: this.head,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* record component changes in the `Scope`.
|
|
149
|
-
*/
|
|
150
|
-
// snap(author: Author, message = '') {
|
|
151
|
-
// if (!this.isModified()) throw new NothingToSnap();
|
|
152
|
-
// const snap = new Snap(this, author, message);
|
|
153
|
-
|
|
154
|
-
// return new Component(this.id, snap, snap.state);
|
|
155
|
-
// }
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* display name of the component.
|
|
159
|
-
*/
|
|
160
|
-
get displayName() {
|
|
161
|
-
const tokens = this.id.name.split('-').map((token) => capitalize(token));
|
|
162
|
-
return tokens.join(' ');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* tag a component `Snap` with a semantic version. we follow SemVer specs as defined [here](https://semver.org/)).
|
|
167
|
-
*/
|
|
168
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
169
|
-
tag(version: SemVer) {
|
|
170
|
-
// const snap = this.snap();
|
|
171
|
-
// const tag = new Tag(version, snap);
|
|
172
|
-
// this.tags.set(tag);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* determines whether this component is modified in the workspace.
|
|
177
|
-
*/
|
|
178
|
-
isModified(): Promise<boolean> {
|
|
179
|
-
return this.factory.isModified(this);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* whether a component is marked as deleted.
|
|
184
|
-
*/
|
|
185
|
-
isDeleted(): boolean {
|
|
186
|
-
return this.state._consumer.isRemoved();
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* is component isOutdated
|
|
191
|
-
*/
|
|
192
|
-
isOutdated(): boolean {
|
|
193
|
-
if (!this.latest) return false;
|
|
194
|
-
const latestTag = this.tags.byVersion(this.latest);
|
|
195
|
-
if (!latestTag) return false;
|
|
196
|
-
if (this.head?.hash !== latestTag?.hash) return true;
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* determines whether this component is new.
|
|
202
|
-
*/
|
|
203
|
-
isNew(): Promise<boolean> {
|
|
204
|
-
return Promise.resolve(this.head === null);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// TODO: @david after snap we need to make sure to refactor here.
|
|
208
|
-
loadState(snapId: string): Promise<State> {
|
|
209
|
-
return this.factory.getState(this.id, snapId);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
loadSnap(snapId?: string): Promise<Snap> {
|
|
213
|
-
const snapToGet = snapId || this.head?.hash;
|
|
214
|
-
if (!snapToGet) {
|
|
215
|
-
throw new BitError('could not load snap for new components');
|
|
216
|
-
}
|
|
217
|
-
return this.factory.getSnap(this.id, snapToGet);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Get iterable which iterate over snap parents lazily
|
|
222
|
-
* @param snapId
|
|
223
|
-
* @param options
|
|
224
|
-
*/
|
|
225
|
-
snapsIterable(snapId?: string, options: SnapsIterableOpts = {}): AsyncIterable<Snap> {
|
|
226
|
-
const snapToStart = snapId || this.head?.hash;
|
|
227
|
-
let nextSnaps = [snapToStart];
|
|
228
|
-
let done;
|
|
229
|
-
if (!snapToStart) {
|
|
230
|
-
done = true;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const iterator: AsyncIterator<Snap> = {
|
|
234
|
-
next: async () => {
|
|
235
|
-
if (done) {
|
|
236
|
-
return { value: undefined, done };
|
|
237
|
-
}
|
|
238
|
-
const currSnapId = nextSnaps.shift();
|
|
239
|
-
const snap = await this.loadSnap(currSnapId);
|
|
240
|
-
if (snap.parents && snap.parents.length) {
|
|
241
|
-
if (options.firstParentOnly) {
|
|
242
|
-
nextSnaps.push(snap.parents[0]);
|
|
243
|
-
} else {
|
|
244
|
-
nextSnaps = nextSnaps.concat(snap.parents);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (!nextSnaps.length) {
|
|
248
|
-
done = true;
|
|
249
|
-
} else if (options.stopFn) {
|
|
250
|
-
done = await options.stopFn(snap);
|
|
251
|
-
}
|
|
252
|
-
return { value: snap, done: undefined };
|
|
253
|
-
},
|
|
254
|
-
};
|
|
255
|
-
return {
|
|
256
|
-
[Symbol.asyncIterator]: () => iterator,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* traverse recursively from the provided snap (or head) upwards until it finds a tag
|
|
262
|
-
* @param snapToStartFrom
|
|
263
|
-
*/
|
|
264
|
-
async getClosestTag(snapToStartFrom?: string): Promise<Tag | undefined> {
|
|
265
|
-
const tagsHashMap = this.tags.getHashMap();
|
|
266
|
-
const stopFn = async (snap: Snap) => {
|
|
267
|
-
if (tagsHashMap.has(snap.hash)) {
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
return false;
|
|
271
|
-
};
|
|
272
|
-
const iterable = this.snapsIterable(snapToStartFrom, { firstParentOnly: true, stopFn });
|
|
273
|
-
const snaps: Snap[] = [];
|
|
274
|
-
for await (const snap of iterable) {
|
|
275
|
-
snaps.push(snap);
|
|
276
|
-
}
|
|
277
|
-
if (snaps.length) {
|
|
278
|
-
const hashOfLastSnap = snaps[snaps.length - 1].hash;
|
|
279
|
-
return tagsHashMap.get(hashOfLastSnap);
|
|
280
|
-
}
|
|
281
|
-
return undefined;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* checkout the component to a different version in its working tree.
|
|
286
|
-
*/
|
|
287
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
288
|
-
checkout(version: SemVer) {}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* examine difference between two components.
|
|
292
|
-
*/
|
|
293
|
-
// diff(other: Component): Difference {}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* merge two different components
|
|
297
|
-
*/
|
|
298
|
-
// merge(other: Component): Component {}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* write a component to a given file system.
|
|
302
|
-
* @param path root path to write the component
|
|
303
|
-
* @param fs instance of any fs to use.
|
|
304
|
-
*/
|
|
305
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
306
|
-
write(path: string, fs?: AnyFS) {}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
*
|
|
310
|
-
* Check if 2 components are equal
|
|
311
|
-
* @param {Component} component
|
|
312
|
-
* @returns {boolean}
|
|
313
|
-
* @memberof Component
|
|
314
|
-
*/
|
|
315
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
316
|
-
equals(component: Component): boolean {
|
|
317
|
-
return component.id.toString() === this.id.toString();
|
|
318
|
-
}
|
|
319
|
-
}
|
package/config.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';
|
|
2
|
-
import { PathLinuxRelative, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* in-memory representation of the component configuration.
|
|
6
|
-
*/
|
|
7
|
-
export class Config {
|
|
8
|
-
constructor(private consumerComponent: any) {}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* component main file
|
|
12
|
-
* when loaded from the workspace, it's PathOsBasedRelative. otherwise, PathLinuxRelative.
|
|
13
|
-
*/
|
|
14
|
-
get main(): PathLinuxRelative | PathOsBasedRelative {
|
|
15
|
-
return this.consumerComponent.mainFile;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* configured extensions
|
|
20
|
-
*/
|
|
21
|
-
get extensions(): ExtensionDataList {
|
|
22
|
-
return this.consumerComponent.extensions;
|
|
23
|
-
}
|
|
24
|
-
}
|
package/get-component-opts.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { RouteProps } from 'react-router-dom';
|
|
3
|
-
import type { UseComponentType, Filters } from './ui/use-component';
|
|
4
|
-
|
|
5
|
-
export type GetComponentsOptions = {
|
|
6
|
-
useComponent?: UseComponentType;
|
|
7
|
-
componentId?: string | (() => string | undefined);
|
|
8
|
-
useComponentFilters?: () => Filters;
|
|
9
|
-
path?: string;
|
|
10
|
-
skipRightSide?: boolean;
|
|
11
|
-
RightNode?: React.ReactNode;
|
|
12
|
-
className?: string;
|
|
13
|
-
routes?: RouteProps[];
|
|
14
|
-
};
|
package/hash.ts
DELETED
package/head.ts
DELETED
|
File without changes
|
package/history-graph.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default class HistoryGraph {}
|
package/index.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { ComponentAspect } from './component.aspect';
|
|
2
|
-
|
|
3
|
-
export type { GetComponentsOptions } from './get-component-opts';
|
|
4
|
-
export type { UseComponentType } from './ui/use-component';
|
|
5
|
-
export { useComponentHost } from './host';
|
|
6
|
-
export { Component, InvalidComponent } from './component';
|
|
7
|
-
export { ComponentID } from '@teambit/component-id';
|
|
8
|
-
export { default as ComponentFS } from './component-fs';
|
|
9
|
-
export type { Config as ComponentConfig } from './config';
|
|
10
|
-
export type {
|
|
11
|
-
ComponentFactory,
|
|
12
|
-
ResolveAspectsOptions,
|
|
13
|
-
FilterAspectsOptions,
|
|
14
|
-
LoadAspectsOptions,
|
|
15
|
-
} from './component-factory';
|
|
16
|
-
export type { AspectList } from './aspect-list';
|
|
17
|
-
export { AspectEntry, AspectData, ResolveComponentIdFunc } from './aspect-entry';
|
|
18
|
-
// TODO: check why it's not working when using the index in snap dir like this:
|
|
19
|
-
// export { Snap, Author } from './snap';
|
|
20
|
-
export { Snap, SnapProps } from './snap/snap';
|
|
21
|
-
export type { Author } from './snap/author';
|
|
22
|
-
// TODO: check why it's not working when using the index in tag dir like this:
|
|
23
|
-
// export { Tag } from './tag';
|
|
24
|
-
export { Tag, TagProps } from './tag/tag';
|
|
25
|
-
export type { IComponent } from './component-interface';
|
|
26
|
-
export { State } from './state';
|
|
27
|
-
export type { Hash } from './hash';
|
|
28
|
-
export { TagMap } from './tag-map';
|
|
29
|
-
export { ComponentMap } from './component-map';
|
|
30
|
-
export type { ComponentMain } from './component.main.runtime';
|
|
31
|
-
export type { ComponentUI } from './component.ui.runtime';
|
|
32
|
-
export type { Section } from './section';
|
|
33
|
-
export { ComponentContext, ComponentDescriptorContext, useComponentDescriptor } from './ui/context/component-context';
|
|
34
|
-
export type { ComponentProviderProps, ComponentDescriptorProviderProps } from './ui/context';
|
|
35
|
-
export { ComponentProvider, ComponentDescriptorProvider } from './ui/context';
|
|
36
|
-
export { componentFields, componentIdFields, componentOverviewFields } from './ui';
|
|
37
|
-
export type { NavPlugin, ConsumePlugin, MenuNavProps } from './ui/menu';
|
|
38
|
-
export { CollapsibleMenuNav, ComponentMenu, VersionRelatedDropdowns } from './ui/menu';
|
|
39
|
-
export type { RegisteredComponentRoute, ComponentUrlParams } from './component.route';
|
|
40
|
-
export type { ComponentModelProps } from './ui/component-model';
|
|
41
|
-
export { ComponentModel } from './ui/component-model';
|
|
42
|
-
export { TopBarNav } from './ui/top-bar-nav';
|
|
43
|
-
export type { ShowFragment, ShowRow, ShowJSONRow } from './show';
|
|
44
|
-
export { Config } from './config';
|
|
45
|
-
export { useComponent, useIdFromLocation, useComponentLogs, ComponentLogsResult, Filters } from './ui';
|
|
46
|
-
|
|
47
|
-
// export { AspectList } from './aspect-list';
|
|
48
|
-
// export { AspectEntry } from './aspect-entry';
|
|
49
|
-
export { ComponentAspect };
|
|
50
|
-
export default ComponentAspect;
|
package/on-load.ts
DELETED
|
File without changes
|
package/state.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { IssuesList } from '@teambit/component-issues';
|
|
2
|
-
import { ComponentID } from '@teambit/component-id';
|
|
3
|
-
import ComponentFS from './component-fs';
|
|
4
|
-
import { Config } from './config';
|
|
5
|
-
import { AspectList } from './aspect-list';
|
|
6
|
-
import { MainFileNotFound } from './exceptions';
|
|
7
|
-
|
|
8
|
-
export class State {
|
|
9
|
-
constructor(
|
|
10
|
-
/**
|
|
11
|
-
* component configuration which is later generated to a component `package.json` and `bit.json`.
|
|
12
|
-
* @deprecated please use `aspects` instead.
|
|
13
|
-
*/
|
|
14
|
-
readonly config: Config,
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* list of aspects configured on the component.
|
|
18
|
-
*/
|
|
19
|
-
private _aspects: AspectList,
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* in-memory representation of the component current filesystem.
|
|
23
|
-
*/
|
|
24
|
-
readonly filesystem: ComponentFS,
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* dependency graph of the component current. ideally package dependencies would be also placed here.
|
|
28
|
-
*/
|
|
29
|
-
// readonly dependencies: Dependencies
|
|
30
|
-
readonly dependencies,
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* instance of legacy consumer component.
|
|
34
|
-
*/
|
|
35
|
-
readonly _consumer: any
|
|
36
|
-
) {}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* get the main file of the component.
|
|
40
|
-
*/
|
|
41
|
-
get mainFile() {
|
|
42
|
-
const file = this.filesystem.files.find((componentFile) => {
|
|
43
|
-
return componentFile.relative === this._consumer.mainFile;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
if (!file) throw new MainFileNotFound(ComponentID.fromLegacy(this._consumer.id), this._consumer.mainFile);
|
|
47
|
-
|
|
48
|
-
return file;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* calculate the hash of this state
|
|
53
|
-
*/
|
|
54
|
-
get hash() {
|
|
55
|
-
return '';
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get issues(): IssuesList {
|
|
59
|
-
return (this._consumer.issues ||= new IssuesList());
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @deprecated please use `component.isModified`.
|
|
64
|
-
* the way it's implemented here is unreliable and will only work if in the legacy the "isModified" was calculated.
|
|
65
|
-
*/
|
|
66
|
-
get isModified(): boolean {
|
|
67
|
-
return this._consumer._isModified;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get aspects(): AspectList {
|
|
71
|
-
return this._aspects;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
set aspects(aspects: AspectList) {
|
|
75
|
-
this._aspects = aspects;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// static fromLegacy(consumerComponent: ConsumerComponent) {
|
|
79
|
-
// return new State(
|
|
80
|
-
// new Config(consumerComponent.mainFile, consumerComponent.extensions),
|
|
81
|
-
// consumerComponent.version || 'new',
|
|
82
|
-
// ComponentFS.fromVinyls(consumerComponent.files),
|
|
83
|
-
// Store.fromArray([]),
|
|
84
|
-
// consumerComponent.dependencies,
|
|
85
|
-
// consumerComponent
|
|
86
|
-
// );
|
|
87
|
-
// }
|
|
88
|
-
}
|
package/store.ts
DELETED
package/tag-map.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { getLatestVersion } from '@teambit/legacy/dist/utils/semver-helper';
|
|
2
|
-
import { SemVer, maxSatisfying } from 'semver';
|
|
3
|
-
|
|
4
|
-
import { CouldNotFindLatest } from './exceptions';
|
|
5
|
-
import { Hash } from './hash';
|
|
6
|
-
import { Tag } from './tag';
|
|
7
|
-
|
|
8
|
-
export class TagMap extends Map<SemVer, Tag> {
|
|
9
|
-
/**
|
|
10
|
-
* get snap by hash.
|
|
11
|
-
*/
|
|
12
|
-
byHash(hash: Hash) {
|
|
13
|
-
const tag = Array.from(this.values()).find((currTag) => currTag.hash === hash);
|
|
14
|
-
return tag;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* e.g.
|
|
19
|
-
* {
|
|
20
|
-
* alpha: '1.0.0-alpha.5',
|
|
21
|
-
* dev: '2.2.4-dev.37
|
|
22
|
-
* }
|
|
23
|
-
*/
|
|
24
|
-
getPreReleaseLatestTags(): { [preRelease: string]: string } {
|
|
25
|
-
const preReleaseTagsWithAllVersions = this.toArray().reduce((acc, current) => {
|
|
26
|
-
const preReleases = current.version.prerelease;
|
|
27
|
-
if (!preReleases.length) return acc;
|
|
28
|
-
if (preReleases.length !== 2) {
|
|
29
|
-
// it could be length 1, e.g. 1.0.0-0, we ignore it.
|
|
30
|
-
// it could also be length > 2, e.g. 1.0.0-dev.1.alpha.1, we don't support it for now.
|
|
31
|
-
return acc;
|
|
32
|
-
}
|
|
33
|
-
if (typeof preReleases[0] !== 'string') return acc;
|
|
34
|
-
(acc[preReleases[0]] ||= []).push(current.version.raw);
|
|
35
|
-
return acc;
|
|
36
|
-
}, {});
|
|
37
|
-
return Object.keys(preReleaseTagsWithAllVersions).reduce((acc, current) => {
|
|
38
|
-
acc[current] = maxSatisfying<string>(preReleaseTagsWithAllVersions[current], '*', { includePrerelease: true });
|
|
39
|
-
return acc;
|
|
40
|
-
}, {});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Get a map that map snap hash to tag
|
|
45
|
-
*/
|
|
46
|
-
getHashMap(): Map<Hash, Tag> {
|
|
47
|
-
const res: Map<Hash, Tag> = new Map();
|
|
48
|
-
this.forEach((tag: Tag) => {
|
|
49
|
-
res.set(tag.hash, tag);
|
|
50
|
-
});
|
|
51
|
-
return res;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* get the latest semver from the tag map.
|
|
56
|
-
*/
|
|
57
|
-
getLatest(): string {
|
|
58
|
-
const versions = this.toArray().map((tag) => tag.version.raw);
|
|
59
|
-
if (this.isEmpty()) throw new CouldNotFindLatest(versions);
|
|
60
|
-
return getLatestVersion(versions);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
isEmpty() {
|
|
64
|
-
return this.size === 0;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* get an array of all tags.
|
|
69
|
-
*/
|
|
70
|
-
toArray(): Tag[] {
|
|
71
|
-
return Array.from(this.values());
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
byVersion(version: string): Tag | undefined {
|
|
75
|
-
const versions = this.toArray().map((tag) => tag);
|
|
76
|
-
return versions.find((tag) => tag.version.raw === version);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
static fromArray(tags: Tag[]) {
|
|
80
|
-
const tuples: [SemVer, Tag][] = tags.map((tag) => [tag.version, tag]);
|
|
81
|
-
return new TagMap(tuples);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
static empty() {
|
|
85
|
-
return new TagMap();
|
|
86
|
-
}
|
|
87
|
-
}
|