@teambit/status 1.0.107 → 1.0.108

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.
@@ -0,0 +1,260 @@
1
+ import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
2
+ import pMapSeries from 'p-map-series';
3
+ import { LaneId } from '@teambit/lane-id';
4
+ import { IssuesClasses, IssuesList } from '@teambit/component-issues';
5
+ import WorkspaceAspect, { OutsideWorkspaceError, Workspace } from '@teambit/workspace';
6
+ import LanesAspect, { LanesMain } from '@teambit/lanes';
7
+ import { ComponentID } from '@teambit/component-id';
8
+ import { Component, InvalidComponent } from '@teambit/component';
9
+ import { Analytics } from '@teambit/legacy/dist/analytics/analytics';
10
+ import loader from '@teambit/legacy/dist/cli/loader';
11
+ import { BEFORE_STATUS } from '@teambit/legacy/dist/cli/loader/loader-messages';
12
+ import { RemoveAspect, RemoveMain } from '@teambit/remove';
13
+ import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
14
+ import ComponentsPendingImport from '@teambit/legacy/dist/consumer/component-ops/exceptions/components-pending-import';
15
+ import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
16
+ import { ModelComponent } from '@teambit/legacy/dist/scope/models';
17
+ import { InsightsAspect, InsightsMain } from '@teambit/insights';
18
+ import { SnapsDistance } from '@teambit/legacy/dist/scope/component-ops/snaps-distance';
19
+ import IssuesAspect, { IssuesMain } from '@teambit/issues';
20
+ import { StatusCmd } from './status-cmd';
21
+ import { StatusAspect } from './status.aspect';
22
+ import { MiniStatusCmd, MiniStatusOpts } from './mini-status-cmd';
23
+
24
+ type DivergeDataPerId = { id: ComponentID; divergeData: SnapsDistance };
25
+
26
+ export type StatusResult = {
27
+ newComponents: ComponentID[];
28
+ modifiedComponents: ComponentID[];
29
+ stagedComponents: { id: ComponentID; versions: string[] }[];
30
+ componentsWithIssues: { id: ComponentID; issues: IssuesList }[];
31
+ importPendingComponents: ComponentID[];
32
+ autoTagPendingComponents: ComponentID[];
33
+ invalidComponents: { id: ComponentID; error: Error }[];
34
+ locallySoftRemoved: ComponentID[];
35
+ remotelySoftRemoved: ComponentID[];
36
+ outdatedComponents: { id: ComponentID; headVersion: string; latestVersion?: string }[];
37
+ mergePendingComponents: DivergeDataPerId[];
38
+ componentsDuringMergeState: ComponentID[];
39
+ softTaggedComponents: ComponentID[];
40
+ snappedComponents: ComponentID[];
41
+ pendingUpdatesFromMain: DivergeDataPerId[];
42
+ updatesFromForked: DivergeDataPerId[];
43
+ unavailableOnMain: ComponentID[];
44
+ currentLaneId: LaneId;
45
+ forkedLaneId?: LaneId;
46
+ workspaceIssues: string[];
47
+ };
48
+
49
+ export type MiniStatusResults = {
50
+ modified: ComponentID[];
51
+ newComps: ComponentID[];
52
+ compWithIssues?: Component[];
53
+ };
54
+
55
+ export class StatusMain {
56
+ constructor(
57
+ private workspace: Workspace,
58
+ private issues: IssuesMain,
59
+ private insights: InsightsMain,
60
+ private remove: RemoveMain,
61
+ private lanes: LanesMain
62
+ ) {}
63
+
64
+ async status({
65
+ lanes,
66
+ ignoreCircularDependencies,
67
+ }: {
68
+ lanes?: boolean;
69
+ ignoreCircularDependencies?: boolean;
70
+ }): Promise<StatusResult> {
71
+ if (!this.workspace) throw new OutsideWorkspaceError();
72
+ loader.start(BEFORE_STATUS);
73
+ const loadOpts = {
74
+ loadDocs: false,
75
+ loadCompositions: false,
76
+ };
77
+ const { components: allComps, invalidComponents: allInvalidComponents } = await this.workspace.listWithInvalid(
78
+ loadOpts
79
+ );
80
+ const consumer = this.workspace.consumer;
81
+ const laneObj = await consumer.getCurrentLaneObject();
82
+ const componentsList = new ComponentsList(consumer);
83
+ const newComponents: ConsumerComponent[] = (await componentsList.listNewComponents(
84
+ true,
85
+ loadOpts
86
+ )) as ConsumerComponent[];
87
+ const modifiedComponents = (await componentsList.listModifiedComponents(true, loadOpts)) as ConsumerComponent[];
88
+ const stagedComponents: ModelComponent[] = await componentsList.listExportPendingComponents(laneObj);
89
+ await this.addRemovedStagedIfNeeded(stagedComponents);
90
+ const stagedComponentsWithVersions = await pMapSeries(stagedComponents, async (stagedComp) => {
91
+ const versions = await stagedComp.getLocalTagsOrHashes(consumer.scope.objects);
92
+ return {
93
+ id: stagedComp.toComponentId(),
94
+ versions,
95
+ };
96
+ });
97
+
98
+ const unavailableOnMain = await this.workspace.getUnavailableOnMainComponents();
99
+ const autoTagPendingComponents = await componentsList.listAutoTagPendingComponents();
100
+ const autoTagPendingComponentsIds = autoTagPendingComponents.map((component) => component.id);
101
+ const locallySoftRemoved = await componentsList.listLocallySoftRemoved();
102
+ const remotelySoftRemoved = await componentsList.listRemotelySoftRemoved();
103
+ const importPendingComponents = allInvalidComponents
104
+ .filter((c) => c.err instanceof ComponentsPendingImport)
105
+ .map((i) => i.id);
106
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
107
+ const invalidComponents = allInvalidComponents.filter((c) => !(c.error instanceof ComponentsPendingImport));
108
+ const divergeInvalid = await this.divergeDataErrorsToInvalidComp(allComps);
109
+ invalidComponents.push(...divergeInvalid);
110
+ const outdatedComponents = await componentsList.listOutdatedComponents();
111
+ const idsDuringMergeState = componentsList.listDuringMergeStateComponents();
112
+ const mergePendingComponents = await componentsList.listMergePendingComponents();
113
+ if (allComps.length) {
114
+ const issuesFromFlag = ignoreCircularDependencies ? [IssuesClasses.CircularDependencies.name] : [];
115
+ const issuesToIgnore = [...this.issues.getIssuesToIgnoreGlobally(), ...issuesFromFlag];
116
+ await this.issues.triggerAddComponentIssues(allComps, issuesToIgnore);
117
+ this.issues.removeIgnoredIssuesFromComponents(allComps);
118
+ }
119
+ const componentsWithIssues = allComps.filter((component) => !component.state.issues.isEmpty());
120
+ const softTaggedComponents = this.workspace.filter.bySoftTagged();
121
+ const snappedComponents = await this.workspace.filter.bySnappedOnMain();
122
+ const pendingUpdatesFromMain = lanes ? await componentsList.listUpdatesFromMainPending() : [];
123
+ const updatesFromForked = lanes ? await this.lanes.listUpdatesFromForked(componentsList) : [];
124
+ const currentLaneId = consumer.getCurrentLaneId();
125
+ const currentLane = await consumer.getCurrentLaneObject();
126
+ const forkedLaneId = currentLane?.forkedFrom;
127
+ const workspaceIssues = this.workspace.getWorkspaceIssues();
128
+ Analytics.setExtraData('new_components', newComponents.length);
129
+ Analytics.setExtraData('staged_components', stagedComponents.length);
130
+ Analytics.setExtraData('num_components_with_missing_dependencies', componentsWithIssues.length);
131
+ Analytics.setExtraData('autoTagPendingComponents', autoTagPendingComponents.length);
132
+ Analytics.setExtraData('deleted', invalidComponents.length);
133
+
134
+ const convertBitIdToComponentIdsAndSort = async (ids: ComponentID[]) =>
135
+ ComponentID.sortIds(await this.workspace.resolveMultipleComponentIds(ids));
136
+
137
+ const convertObjToComponentIdsAndSort = async <T>(
138
+ objectsWithId: Array<T & { id: ComponentID }>
139
+ ): Promise<Array<T & { id: ComponentID }>> => {
140
+ const results = await Promise.all(
141
+ objectsWithId.map(async (obj) => {
142
+ return {
143
+ ...obj,
144
+ id: await this.workspace.resolveComponentId(obj.id),
145
+ };
146
+ })
147
+ );
148
+ return results.sort((a, b) => a.id.toString().localeCompare(b.id.toString()));
149
+ };
150
+
151
+ const sortObjectsWithId = <T>(objectsWithId: Array<T & { id: ComponentID }>): Array<T & { id: ComponentID }> => {
152
+ return objectsWithId.sort((a, b) => a.id.toString().localeCompare(b.id.toString()));
153
+ };
154
+
155
+ await consumer.onDestroy('status');
156
+ return {
157
+ newComponents: await convertBitIdToComponentIdsAndSort(newComponents.map((c) => c.id)),
158
+ modifiedComponents: await convertBitIdToComponentIdsAndSort(modifiedComponents.map((c) => c.id)),
159
+ stagedComponents: await convertObjToComponentIdsAndSort(stagedComponentsWithVersions),
160
+ componentsWithIssues: sortObjectsWithId(componentsWithIssues.map((c) => ({ id: c.id, issues: c.state.issues }))),
161
+ importPendingComponents, // no need to sort, we use only its length
162
+ autoTagPendingComponents: await convertBitIdToComponentIdsAndSort(autoTagPendingComponentsIds),
163
+ invalidComponents: sortObjectsWithId(invalidComponents.map((c) => ({ id: c.id, error: c.err }))),
164
+ locallySoftRemoved: await convertBitIdToComponentIdsAndSort(locallySoftRemoved),
165
+ remotelySoftRemoved: await convertBitIdToComponentIdsAndSort(remotelySoftRemoved.map((c) => c.id)),
166
+ outdatedComponents: await convertObjToComponentIdsAndSort(
167
+ outdatedComponents.map((c) => ({
168
+ id: c.id,
169
+ headVersion: c.headVersion,
170
+ latestVersion: c.latestVersion,
171
+ }))
172
+ ),
173
+ mergePendingComponents: await convertObjToComponentIdsAndSort(
174
+ mergePendingComponents.map((c) => ({ id: c.id, divergeData: c.diverge }))
175
+ ),
176
+ componentsDuringMergeState: await convertBitIdToComponentIdsAndSort(idsDuringMergeState),
177
+ softTaggedComponents: ComponentID.sortIds(softTaggedComponents),
178
+ snappedComponents: await convertBitIdToComponentIdsAndSort(snappedComponents),
179
+ pendingUpdatesFromMain: await convertObjToComponentIdsAndSort(pendingUpdatesFromMain),
180
+ updatesFromForked: await convertObjToComponentIdsAndSort(updatesFromForked),
181
+ unavailableOnMain,
182
+ currentLaneId,
183
+ forkedLaneId,
184
+ workspaceIssues: workspaceIssues.map((err) => err.message),
185
+ };
186
+ }
187
+
188
+ async statusMini(componentPattern?: string, opts: MiniStatusOpts = {}): Promise<MiniStatusResults> {
189
+ const ids = componentPattern ? await this.workspace.idsByPattern(componentPattern) : await this.workspace.listIds();
190
+ const compFiles = await pMapSeries(ids, (id) => this.workspace.getFilesModification(id));
191
+ const modified: ComponentID[] = [];
192
+ const newComps: ComponentID[] = [];
193
+ compFiles.forEach((comp) => {
194
+ if (!comp.id.hasVersion()) newComps.push(comp.id);
195
+ if (comp.isModified()) modified.push(comp.id);
196
+ });
197
+ const loadOpts = {
198
+ loadDocs: false,
199
+ loadCompositions: false,
200
+ };
201
+ const comps = opts.showIssues ? await this.workspace.getMany(ids, loadOpts) : [];
202
+ if (opts.showIssues) {
203
+ const issuesFromFlag = opts.ignoreCircularDependencies ? [IssuesClasses.CircularDependencies.name] : [];
204
+ const issuesToIgnore = [...this.issues.getIssuesToIgnoreGlobally(), ...issuesFromFlag];
205
+ await this.issues.triggerAddComponentIssues(comps, issuesToIgnore);
206
+ this.issues.removeIgnoredIssuesFromComponents(comps);
207
+ }
208
+ const compWithIssues = comps.filter((c) => !c.state.issues.isEmpty());
209
+
210
+ return { modified, newComps, compWithIssues };
211
+ }
212
+
213
+ private async addRemovedStagedIfNeeded(stagedComponents: ModelComponent[]) {
214
+ const removedStagedIds = await this.remove.getRemovedStaged();
215
+ if (!removedStagedIds.length) return;
216
+ const removedStagedBitIds = removedStagedIds.map((id) => id);
217
+ const nonExistsInStaged = removedStagedBitIds.filter(
218
+ (id) => !stagedComponents.find((c) => c.toComponentId().isEqualWithoutVersion(id))
219
+ );
220
+ if (!nonExistsInStaged.length) return;
221
+ const modelComps = await Promise.all(
222
+ nonExistsInStaged.map((id) => this.workspace.scope.legacyScope.getModelComponent(id))
223
+ );
224
+ stagedComponents.push(...modelComps);
225
+ }
226
+
227
+ private async divergeDataErrorsToInvalidComp(components: Component[]): Promise<InvalidComponent[]> {
228
+ const invalidComponents: InvalidComponent[] = [];
229
+ await Promise.all(
230
+ components.map(async (component) => {
231
+ const comp = component.state._consumer as ConsumerComponent;
232
+ if (!comp.modelComponent) return;
233
+ await comp.modelComponent.setDivergeData(this.workspace.scope.legacyScope.objects, false);
234
+ const divergeData = comp.modelComponent.getDivergeData();
235
+ if (divergeData.err) {
236
+ invalidComponents.push({ id: component.id, err: divergeData.err });
237
+ }
238
+ })
239
+ );
240
+ return invalidComponents;
241
+ }
242
+
243
+ static slots = [];
244
+ static dependencies = [CLIAspect, WorkspaceAspect, InsightsAspect, IssuesAspect, RemoveAspect, LanesAspect];
245
+ static runtime = MainRuntime;
246
+ static async provider([cli, workspace, insights, issues, remove, lanes]: [
247
+ CLIMain,
248
+ Workspace,
249
+ InsightsMain,
250
+ IssuesMain,
251
+ RemoveMain,
252
+ LanesMain
253
+ ]) {
254
+ const statusMain = new StatusMain(workspace, issues, insights, remove, lanes);
255
+ cli.register(new StatusCmd(statusMain), new MiniStatusCmd(statusMain));
256
+ return statusMain;
257
+ }
258
+ }
259
+
260
+ StatusAspect.addRuntime(StatusMain);
package/tsconfig.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
4
+ "esnext",
5
+ "dom",
6
+ "dom.Iterable"
9
7
  ],
10
- "target": "es2015",
11
- "module": "CommonJS",
12
- "jsx": "react",
13
- "allowJs": true,
14
- "composite": true,
8
+ "target": "es2020",
9
+ "module": "es2020",
10
+ "jsx": "react-jsx",
15
11
  "declaration": true,
16
12
  "sourceMap": true,
17
- "skipLibCheck": true,
18
13
  "experimentalDecorators": true,
19
- "outDir": "dist",
14
+ "skipLibCheck": true,
20
15
  "moduleResolution": "node",
21
16
  "esModuleInterop": true,
22
- "rootDir": ".",
23
17
  "resolveJsonModule": true,
24
- "emitDeclarationOnly": true,
25
- "emitDecoratorMetadata": true,
26
- "allowSyntheticDefaultImports": true,
27
- "strictPropertyInitialization": false,
28
- "strict": true,
29
- "noImplicitAny": false,
30
- "preserveConstEnums": true
18
+ "allowJs": true,
19
+ "outDir": "dist",
20
+ "emitDeclarationOnly": true
31
21
  },
32
22
  "exclude": [
23
+ "artifacts",
24
+ "public",
33
25
  "dist",
26
+ "node_modules",
27
+ "package.json",
34
28
  "esm.mjs",
35
- "package.json"
29
+ "**/*.cjs",
30
+ "./dist"
36
31
  ],
37
32
  "include": [
38
33
  "**/*",
package/types/asset.d.ts CHANGED
@@ -5,12 +5,12 @@ declare module '*.png' {
5
5
  declare module '*.svg' {
6
6
  import type { FunctionComponent, SVGProps } from 'react';
7
7
 
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
9
11
  const src: string;
10
12
  export default src;
11
13
  }
12
-
13
- // @TODO Gilad
14
14
  declare module '*.jpg' {
15
15
  const value: any;
16
16
  export = value;
@@ -27,3 +27,15 @@ declare module '*.bmp' {
27
27
  const value: any;
28
28
  export = value;
29
29
  }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }