@teambit/insights 1.0.106 → 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.
- package/core-insights-getter.ts +9 -0
- package/dist/all-insights/duplicate-dependencies.d.ts +2 -2
- package/dist/all-insights/find-circulars.js +2 -2
- package/dist/all-insights/find-circulars.js.map +1 -1
- package/dist/insight-manager.d.ts +1 -1
- package/dist/insight.d.ts +3 -3
- package/dist/insights.compositon.d.ts +2 -2
- package/dist/insights.main.runtime.d.ts +1 -1
- package/dist/{preview-1703505948637.js → preview-1703647408454.js} +1 -1
- package/index.ts +5 -0
- package/insight-manager.ts +90 -0
- package/insight.ts +35 -0
- package/insights.aspect.ts +7 -0
- package/insights.cmd.ts +44 -0
- package/insights.main.runtime.ts +63 -0
- package/package.json +16 -23
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
@@ -0,0 +1,9 @@
|
|
1
|
+
import { GraphMain } from '@teambit/graph';
|
2
|
+
|
3
|
+
import DuplicateDependencies from './all-insights/duplicate-dependencies';
|
4
|
+
import FindCycles from './all-insights/find-circulars';
|
5
|
+
|
6
|
+
export default function getCoreInsights(graphBuilder: GraphMain) {
|
7
|
+
const coreInsights = [new FindCycles(graphBuilder), new DuplicateDependencies(graphBuilder)];
|
8
|
+
return coreInsights;
|
9
|
+
}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { GraphMain } from '@teambit/graph';
|
2
2
|
import { Insight, InsightResult } from '../insight';
|
3
3
|
export declare const INSIGHT_NAME = "duplicate dependencies";
|
4
|
-
|
4
|
+
type Dependent = {
|
5
5
|
id: string;
|
6
6
|
usedVersion: string;
|
7
7
|
};
|
8
|
-
|
8
|
+
type VersionWithDependents = {
|
9
9
|
version: string;
|
10
10
|
compId: string;
|
11
11
|
dependents: Dependent[];
|
@@ -30,14 +30,14 @@ class FindCycles {
|
|
30
30
|
this.graphBuilder = graphBuilder;
|
31
31
|
}
|
32
32
|
async runInsight(opts) {
|
33
|
-
const graph = await this.graphBuilder.getGraphIds(opts
|
33
|
+
const graph = await this.graphBuilder.getGraphIds(opts?.ids);
|
34
34
|
if (!graph) {
|
35
35
|
return {
|
36
36
|
message: '',
|
37
37
|
data: undefined
|
38
38
|
};
|
39
39
|
}
|
40
|
-
const cycles = graph.findCycles(undefined, opts
|
40
|
+
const cycles = graph.findCycles(undefined, opts?.includeDeps);
|
41
41
|
if (cycles.length === 1) {
|
42
42
|
return {
|
43
43
|
message: `Found ${cycles.length} cycle.`,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_componentIssues","data","require","_lodash","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","INSIGHT_CIRCULAR_DEPS_NAME","exports","FindCycles","constructor","graphBuilder","runInsight","opts","graph","getGraphIds","ids","message","undefined","cycles","findCycles","includeDeps","length","renderData","string","map","cycle","join","run","bareResult","renderedData","result","metaData","name","description","addAsComponentIssue","components","c","id","allIds","uniq","flat","componentsWithCircular","filter","component","includes","toString","forEach","state","issues","getOrCreate","IssuesClasses","CircularDependencies","default"],"sources":["find-circulars.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport { IssuesClasses } from '@teambit/component-issues';\nimport { GraphMain } from '@teambit/graph';\nimport { uniq } from 'lodash';\nimport { Insight, InsightResult, RawResult } from '../insight';\nimport { RunInsightOptions } from '../insight-manager';\n\nexport const INSIGHT_CIRCULAR_DEPS_NAME = 'circular';\n\nexport default class FindCycles implements Insight {\n name = INSIGHT_CIRCULAR_DEPS_NAME;\n description = 'Get all circular dependencies in component graph';\n graphBuilder: GraphMain;\n constructor(graphBuilder: GraphMain) {\n this.graphBuilder = graphBuilder;\n }\n private async runInsight(opts?: RunInsightOptions): Promise<RawResult> {\n const graph = await this.graphBuilder.getGraphIds(opts?.ids);\n if (!graph) {\n return {\n message: '',\n data: undefined,\n };\n }\n const cycles = graph.findCycles(undefined, opts?.includeDeps);\n if (cycles.length === 1) {\n return {\n message: `Found ${cycles.length} cycle.`,\n data: cycles,\n };\n }\n return {\n message: `Found ${cycles.length} cycles.`,\n data: cycles,\n };\n }\n\n private renderData(data: RawResult) {\n if (data.data.length === 0) {\n return 'No cyclic dependencies';\n }\n const string = data.data\n .map((cycle) => {\n return `\\nCyclic dependency\n-----------------\n- ${cycle.join('\\n- ')}`;\n })\n .join('\\n');\n return string;\n }\n\n async run(opts?: RunInsightOptions): Promise<InsightResult> {\n const bareResult = await this.runInsight(opts);\n const renderedData = this.renderData(bareResult);\n const result: InsightResult = {\n metaData: {\n name: this.name,\n description: this.description,\n },\n data: bareResult.data,\n message: bareResult.message,\n renderedData,\n };\n\n if (bareResult.message) {\n result.message = bareResult.message;\n }\n return result;\n }\n\n async addAsComponentIssue(components: Component[]) {\n const result = await this.runInsight({ ids: components.map((c) => c.id) });\n if (!result.data.length) {\n return; // no circulars\n }\n const allIds = uniq(result.data.flat());\n const componentsWithCircular = components.filter((component) => allIds.includes(component.id.toString()));\n componentsWithCircular.forEach((component) => {\n component.state.issues.getOrCreate(IssuesClasses.CircularDependencies).data = true;\n });\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,iBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,gBAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA8B,SAAAG,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,CAAA,QAAAC,CAAA,GAAAC,YAAA,CAAAF,CAAA,uCAAAC,CAAA,GAAAA,CAAA,GAAAE,MAAA,CAAAF,CAAA;AAAA,SAAAC,aAAAF,CAAA,EAAAI,CAAA,2BAAAJ,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAK,CAAA,GAAAL,CAAA,CAAAM,MAAA,CAAAC,WAAA,kBAAAF,CAAA,QAAAJ,CAAA,GAAAI,CAAA,CAAAG,IAAA,CAAAR,CAAA,EAAAI,CAAA,uCAAAH,CAAA,SAAAA,CAAA,YAAAQ,SAAA,yEAAAL,CAAA,GAAAD,MAAA,GAAAO,MAAA,EAAAV,CAAA;AAIvB,MAAMW,0BAA0B,GAAAC,OAAA,CAAAD,0BAAA,GAAG,UAAU;AAErC,MAAME,UAAU,CAAoB;EAIjDC,WAAWA,CAACC,YAAuB,EAAE;IAAAzB,eAAA,eAH9BqB,0BAA0B;IAAArB,eAAA,sBACnB,kDAAkD;IAAAA,eAAA;IAG9D,IAAI,CAACyB,YAAY,GAAGA,YAAY;EAClC;EACA,MAAcC,UAAUA,CAACC,IAAwB,EAAsB;IACrE,MAAMC,KAAK,GAAG,MAAM,IAAI,CAACH,YAAY,CAACI,WAAW,CAACF,IAAI,
|
1
|
+
{"version":3,"names":["_componentIssues","data","require","_lodash","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","INSIGHT_CIRCULAR_DEPS_NAME","exports","FindCycles","constructor","graphBuilder","runInsight","opts","graph","getGraphIds","ids","message","undefined","cycles","findCycles","includeDeps","length","renderData","string","map","cycle","join","run","bareResult","renderedData","result","metaData","name","description","addAsComponentIssue","components","c","id","allIds","uniq","flat","componentsWithCircular","filter","component","includes","toString","forEach","state","issues","getOrCreate","IssuesClasses","CircularDependencies","default"],"sources":["find-circulars.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport { IssuesClasses } from '@teambit/component-issues';\nimport { GraphMain } from '@teambit/graph';\nimport { uniq } from 'lodash';\nimport { Insight, InsightResult, RawResult } from '../insight';\nimport { RunInsightOptions } from '../insight-manager';\n\nexport const INSIGHT_CIRCULAR_DEPS_NAME = 'circular';\n\nexport default class FindCycles implements Insight {\n name = INSIGHT_CIRCULAR_DEPS_NAME;\n description = 'Get all circular dependencies in component graph';\n graphBuilder: GraphMain;\n constructor(graphBuilder: GraphMain) {\n this.graphBuilder = graphBuilder;\n }\n private async runInsight(opts?: RunInsightOptions): Promise<RawResult> {\n const graph = await this.graphBuilder.getGraphIds(opts?.ids);\n if (!graph) {\n return {\n message: '',\n data: undefined,\n };\n }\n const cycles = graph.findCycles(undefined, opts?.includeDeps);\n if (cycles.length === 1) {\n return {\n message: `Found ${cycles.length} cycle.`,\n data: cycles,\n };\n }\n return {\n message: `Found ${cycles.length} cycles.`,\n data: cycles,\n };\n }\n\n private renderData(data: RawResult) {\n if (data.data.length === 0) {\n return 'No cyclic dependencies';\n }\n const string = data.data\n .map((cycle) => {\n return `\\nCyclic dependency\n-----------------\n- ${cycle.join('\\n- ')}`;\n })\n .join('\\n');\n return string;\n }\n\n async run(opts?: RunInsightOptions): Promise<InsightResult> {\n const bareResult = await this.runInsight(opts);\n const renderedData = this.renderData(bareResult);\n const result: InsightResult = {\n metaData: {\n name: this.name,\n description: this.description,\n },\n data: bareResult.data,\n message: bareResult.message,\n renderedData,\n };\n\n if (bareResult.message) {\n result.message = bareResult.message;\n }\n return result;\n }\n\n async addAsComponentIssue(components: Component[]) {\n const result = await this.runInsight({ ids: components.map((c) => c.id) });\n if (!result.data.length) {\n return; // no circulars\n }\n const allIds = uniq(result.data.flat());\n const componentsWithCircular = components.filter((component) => allIds.includes(component.id.toString()));\n componentsWithCircular.forEach((component) => {\n component.state.issues.getOrCreate(IssuesClasses.CircularDependencies).data =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AACA;MACpB,CAAC;MACDnD,IAAI,EAAE8C,UAAU,CAAC9C,IAAI;MACrBkC,OAAO,EAAEY,UAAU,CAACZ,OAAO;MAC3Ba;IACF,CAAC;IAED,IAAID,UAAU,CAACZ,OAAO,EAAE;MACtBc,MAAM,CAACd,OAAO,GAAGY,UAAU,CAACZ,OAAO;IACrC;IACA,OAAOc,MAAM;EACf;EAEA,MAAMI,mBAAmBA,CAACC,UAAuB,EAAE;IACjD,MAAML,MAAM,GAAG,MAAM,IAAI,CAACnB,UAAU,CAAC;MAAEI,GAAG,EAAEoB,UAAU,CAACX,GAAG,CAAEY,CAAC,IAAKA,CAAC,CAACC,EAAE;IAAE,CAAC,CAAC;IAC1E,IAAI,CAACP,MAAM,CAAChD,IAAI,CAACuC,MAAM,EAAE;MACvB,OAAO,CAAC;IACV;IACA,MAAMiB,MAAM,GAAG,IAAAC,cAAI,EAACT,MAAM,CAAChD,IAAI,CAAC0D,IAAI,CAAC,CAAC,CAAC;IACvC,MAAMC,sBAAsB,GAAGN,UAAU,CAACO,MAAM,CAAEC,SAAS,IAAKL,MAAM,CAACM,QAAQ,CAACD,SAAS,CAACN,EAAE,CAACQ,QAAQ,CAAC,CAAC,CAAC,CAAC;IACzGJ,sBAAsB,CAACK,OAAO,CAAEH,SAAS,IAAK;MAC5CA,SAAS,CAACI,KAAK,CAACC,MAAM,CAACC,WAAW,CAACC,gCAAa,CAACC,oBAAoB,CAAC,CAACrE,IAAI,GAAG,IAAI;IACpF,CAAC,CAAC;EACJ;AACF;AAACyB,OAAA,CAAA6C,OAAA,GAAA5C,UAAA"}
|
package/dist/insight.d.ts
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
import { Component } from '@teambit/component';
|
2
2
|
import { RunInsightOptions } from './insight-manager';
|
3
|
-
export
|
3
|
+
export type InsightMetaData = {
|
4
4
|
name: string;
|
5
5
|
description: string;
|
6
6
|
};
|
7
|
-
export
|
7
|
+
export type InsightResult = {
|
8
8
|
metaData: InsightMetaData;
|
9
9
|
message: string;
|
10
10
|
data: any;
|
11
11
|
renderedData?: string;
|
12
12
|
};
|
13
|
-
export
|
13
|
+
export type RawResult = {
|
14
14
|
message: string;
|
15
15
|
data: any;
|
16
16
|
};
|
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
export declare const Logo: () =>
|
1
|
+
/// <reference types="react" />
|
2
|
+
export declare const Logo: () => JSX.Element;
|
@@ -10,7 +10,7 @@ export declare class InsightsMain {
|
|
10
10
|
runInsights(names: string[], opts: RunInsightOptions): Promise<InsightResult[]>;
|
11
11
|
listInsights(): string[];
|
12
12
|
addInsightsAsComponentIssues(components: Component[], issuesToIgnore: string[]): Promise<void>;
|
13
|
-
static slots:
|
13
|
+
static slots: any[];
|
14
14
|
static dependencies: import("@teambit/harmony").Aspect[];
|
15
15
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
16
16
|
static config: {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
;
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.explorer_insights@1.0.
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.explorer_insights@1.0.108/dist/insights.docs.mdx';
|
3
3
|
|
4
4
|
export const compositions = [];
|
5
5
|
export const overview = [overview_0];
|
package/index.ts
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
export { InsightManager } from './insight-manager';
|
2
|
+
export type { Insight } from './insight';
|
3
|
+
export type { InsightsMain } from './insights.main.runtime';
|
4
|
+
export { InsightsAspect } from './insights.aspect';
|
5
|
+
export { INSIGHT_CIRCULAR_DEPS_NAME } from './all-insights/find-circulars';
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import pMapSeries from 'p-map-series';
|
2
|
+
import { ComponentID } from '@teambit/component-id';
|
3
|
+
import InsightAlreadyExists from './exceptions/insight-already-exists';
|
4
|
+
import InsightNotFound from './exceptions/insight-not-found';
|
5
|
+
import { Insight, InsightResult } from './insight';
|
6
|
+
|
7
|
+
export type RunInsightOptions = {
|
8
|
+
renderData?: boolean;
|
9
|
+
includeDeps?: boolean;
|
10
|
+
ids?: ComponentID[];
|
11
|
+
};
|
12
|
+
export class InsightManager {
|
13
|
+
/** insights is an insight registry */
|
14
|
+
readonly insights: Map<string, Insight> = new Map();
|
15
|
+
constructor(
|
16
|
+
/**
|
17
|
+
* array of registered insights
|
18
|
+
*/
|
19
|
+
insights: Insight[]
|
20
|
+
) {
|
21
|
+
insights.forEach((insight) => {
|
22
|
+
this.register(insight);
|
23
|
+
});
|
24
|
+
}
|
25
|
+
|
26
|
+
/**
|
27
|
+
* registers a new insight and returns the updated insight registry map
|
28
|
+
*/
|
29
|
+
register(insight: Insight) {
|
30
|
+
const name = insight.name;
|
31
|
+
if (this.insights.has(name)) {
|
32
|
+
throw new InsightAlreadyExists(name);
|
33
|
+
}
|
34
|
+
this.insights.set(name, insight);
|
35
|
+
}
|
36
|
+
/**
|
37
|
+
* list of all registered insights
|
38
|
+
*/
|
39
|
+
listInsights(): string[] {
|
40
|
+
return [...this.insights.keys()];
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* gets a specific insight by its name or undefined if doesn't exist
|
45
|
+
*/
|
46
|
+
getByName(insightName: string): Insight | undefined {
|
47
|
+
return this.insights.get(insightName);
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* deletes a specific insight by its name if exists
|
52
|
+
*/
|
53
|
+
delete(insightName: string) {
|
54
|
+
if (!this.insights.has(insightName)) {
|
55
|
+
throw new InsightNotFound(insightName);
|
56
|
+
}
|
57
|
+
this.insights.delete(insightName);
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* execute an array of insights
|
62
|
+
*
|
63
|
+
*/
|
64
|
+
async run(insightNames: string[], opts: RunInsightOptions): Promise<InsightResult[]> {
|
65
|
+
const res: InsightResult[] = [];
|
66
|
+
// the reason for not using Promise.all here is that the current both insights building the graph.
|
67
|
+
// if it happens at the same time, some props are not populated in one of the instances. it obviously
|
68
|
+
// should be fixed in the GraphBuilder class. see "todo" there.
|
69
|
+
await pMapSeries(insightNames, async (insightName) => {
|
70
|
+
const insight = this.getByName(insightName);
|
71
|
+
if (insight) {
|
72
|
+
const insightRes: InsightResult = await insight.run(opts);
|
73
|
+
if (!opts.renderData) {
|
74
|
+
delete insightRes.renderedData;
|
75
|
+
}
|
76
|
+
res.push(insightRes);
|
77
|
+
}
|
78
|
+
});
|
79
|
+
return res;
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* execute all insights in the registry
|
84
|
+
*
|
85
|
+
*/
|
86
|
+
async runAll(opts: RunInsightOptions): Promise<InsightResult[]> {
|
87
|
+
const allInsightNames = this.listInsights();
|
88
|
+
return this.run(allInsightNames, opts);
|
89
|
+
}
|
90
|
+
}
|
package/insight.ts
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
import { Component } from '@teambit/component';
|
2
|
+
import { RunInsightOptions } from './insight-manager';
|
3
|
+
|
4
|
+
export type InsightMetaData = {
|
5
|
+
name: string;
|
6
|
+
description: string;
|
7
|
+
};
|
8
|
+
|
9
|
+
export type InsightResult = {
|
10
|
+
metaData: InsightMetaData;
|
11
|
+
message: string;
|
12
|
+
data: any;
|
13
|
+
renderedData?: string;
|
14
|
+
};
|
15
|
+
|
16
|
+
export type RawResult = {
|
17
|
+
message: string;
|
18
|
+
data: any;
|
19
|
+
};
|
20
|
+
|
21
|
+
export interface Insight {
|
22
|
+
name: string;
|
23
|
+
description: string;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* runs a specific insight using _runInsight, gets a RawResult, and uses _formatData to transform the output to InsightResult.
|
27
|
+
*/
|
28
|
+
run(opts?: RunInsightOptions): Promise<InsightResult>;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* add the results from the insights as a component-issue so then bit-status could show them and bit-tag could block
|
32
|
+
* them.
|
33
|
+
*/
|
34
|
+
addAsComponentIssue?(components: Component[]): Promise<void>;
|
35
|
+
}
|
package/insights.cmd.ts
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
import chalk from 'chalk';
|
2
|
+
import { Command, CommandOptions } from '@teambit/cli';
|
3
|
+
import { InsightResult } from './insight';
|
4
|
+
import { InsightsMain } from './insights.main.runtime';
|
5
|
+
|
6
|
+
export default class InsightsCmd implements Command {
|
7
|
+
name = 'insights [names...]';
|
8
|
+
description = 'Insights on component graph';
|
9
|
+
group = 'development';
|
10
|
+
private = true;
|
11
|
+
options = [
|
12
|
+
['l', 'list', 'list all insights'],
|
13
|
+
['j', 'json', 'return the insights in json format'],
|
14
|
+
['', 'include-deps', 'include component dependencies that are not in this workspace'],
|
15
|
+
] as CommandOptions;
|
16
|
+
constructor(private insights: InsightsMain) {}
|
17
|
+
|
18
|
+
async report([names]: [string[]], options: { list: boolean; includeDeps: boolean }): Promise<string> {
|
19
|
+
if (options.list) {
|
20
|
+
const results = await this.json([names], options);
|
21
|
+
return JSON.stringify(results, null, 2);
|
22
|
+
}
|
23
|
+
const results = await this.insights.runInsights(names, { renderData: true, includeDeps: options.includeDeps });
|
24
|
+
return template(results);
|
25
|
+
}
|
26
|
+
|
27
|
+
async json([names]: [string[]], { list, includeDeps }: { list: boolean; includeDeps: boolean }) {
|
28
|
+
if (list) {
|
29
|
+
const results = this.insights.listInsights();
|
30
|
+
return results;
|
31
|
+
}
|
32
|
+
return this.insights.runInsights(names, { renderData: false, includeDeps });
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
function template(results: InsightResult[]): string {
|
37
|
+
const elements = results
|
38
|
+
.map((result) => {
|
39
|
+
return `\n${chalk.cyan.bold(result.message)}
|
40
|
+
${result.renderedData}`;
|
41
|
+
})
|
42
|
+
.join('\n');
|
43
|
+
return elements;
|
44
|
+
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import { CLIAspect, MainRuntime, CLIMain } from '@teambit/cli';
|
2
|
+
import { GraphAspect, GraphMain } from '@teambit/graph';
|
3
|
+
import { IssuesClasses } from '@teambit/component-issues';
|
4
|
+
import IssuesAspect, { IssuesMain } from '@teambit/issues';
|
5
|
+
import pMapSeries from 'p-map-series';
|
6
|
+
import { Component } from '@teambit/component';
|
7
|
+
import { InsightsAspect } from './insights.aspect';
|
8
|
+
import getCoreInsights from './core-insights-getter';
|
9
|
+
import { Insight, InsightResult } from './insight';
|
10
|
+
import { InsightManager, RunInsightOptions } from './insight-manager';
|
11
|
+
import InsightsCmd from './insights.cmd';
|
12
|
+
|
13
|
+
export class InsightsMain {
|
14
|
+
constructor(private insightManager: InsightManager) {}
|
15
|
+
|
16
|
+
async runInsights(names: string[], opts: RunInsightOptions) {
|
17
|
+
if (names) {
|
18
|
+
let results: InsightResult[] = [];
|
19
|
+
const namesArr = typeof names === 'string' ? [names] : names;
|
20
|
+
results = await this.insightManager.run(namesArr, opts);
|
21
|
+
return results;
|
22
|
+
}
|
23
|
+
const results = await this.insightManager.runAll(opts);
|
24
|
+
return results;
|
25
|
+
}
|
26
|
+
|
27
|
+
listInsights() {
|
28
|
+
return this.insightManager.listInsights();
|
29
|
+
}
|
30
|
+
|
31
|
+
async addInsightsAsComponentIssues(components: Component[], issuesToIgnore: string[]) {
|
32
|
+
const insightNames: string[] = this.listInsights();
|
33
|
+
const insights = insightNames.map((name) => this.insightManager.getByName(name));
|
34
|
+
if (!issuesToIgnore.includes(IssuesClasses.CircularDependencies.name)) {
|
35
|
+
await pMapSeries(insights, async (insight) => {
|
36
|
+
if (insight && insight.addAsComponentIssue) {
|
37
|
+
await insight.addAsComponentIssue(components);
|
38
|
+
}
|
39
|
+
});
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
static slots = [];
|
44
|
+
static dependencies = [GraphAspect, CLIAspect, IssuesAspect];
|
45
|
+
static runtime = MainRuntime;
|
46
|
+
static config = {
|
47
|
+
silence: false,
|
48
|
+
};
|
49
|
+
static async provider([graphMain, cli, issues]: [GraphMain, CLIMain, IssuesMain]) {
|
50
|
+
// get all insights from registry
|
51
|
+
const initialInsights: Insight[] = getCoreInsights(graphMain);
|
52
|
+
// register all insights in cli
|
53
|
+
// TODO - get user-defined insights as well, and use them when instantiating InsightManager and InsightsCmd
|
54
|
+
const insightManager = new InsightManager(initialInsights);
|
55
|
+
const insightsMain = new InsightsMain(insightManager);
|
56
|
+
if (issues) issues.registerAddComponentsIssues(insightsMain.addInsightsAsComponentIssues.bind(insightsMain));
|
57
|
+
const insightsCmd = new InsightsCmd(insightsMain);
|
58
|
+
cli.register(insightsCmd);
|
59
|
+
return insightsMain;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
InsightsAspect.addRuntime(InsightsMain);
|
package/package.json
CHANGED
@@ -1,43 +1,39 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/insights",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.108",
|
4
4
|
"homepage": "https://bit.cloud/teambit/explorer/insights",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.explorer",
|
8
8
|
"name": "insights",
|
9
|
-
"version": "1.0.
|
9
|
+
"version": "1.0.108"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"p-map-series": "2.1.0",
|
13
13
|
"chalk": "2.4.2",
|
14
14
|
"semver": "7.5.2",
|
15
15
|
"lodash": "4.17.21",
|
16
|
-
"core-js": "^3.0.0",
|
17
|
-
"@babel/runtime": "7.20.0",
|
18
16
|
"@teambit/component-id": "1.2.0",
|
19
17
|
"@teambit/harmony": "0.4.6",
|
20
18
|
"@teambit/bit-error": "0.0.404",
|
21
|
-
"@teambit/graph": "1.0.
|
22
|
-
"@teambit/component": "1.0.
|
23
|
-
"@teambit/cli": "0.0.
|
24
|
-
"@teambit/component-issues": "0.0.
|
25
|
-
"@teambit/issues": "1.0.
|
19
|
+
"@teambit/graph": "1.0.108",
|
20
|
+
"@teambit/component": "1.0.108",
|
21
|
+
"@teambit/cli": "0.0.840",
|
22
|
+
"@teambit/component-issues": "0.0.138",
|
23
|
+
"@teambit/issues": "1.0.108"
|
26
24
|
},
|
27
25
|
"devDependencies": {
|
28
|
-
"@types/react": "^17.0.8",
|
29
26
|
"@types/semver": "7.3.4",
|
30
27
|
"@types/lodash": "4.14.165",
|
31
28
|
"@types/mocha": "9.1.0",
|
32
|
-
"@types/
|
33
|
-
"@types/
|
34
|
-
"@
|
35
|
-
"@types/testing-library__jest-dom": "5.9.5"
|
29
|
+
"@types/jest": "^29.2.2",
|
30
|
+
"@types/testing-library__jest-dom": "^5.9.5",
|
31
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.13"
|
36
32
|
},
|
37
33
|
"peerDependencies": {
|
38
|
-
"
|
39
|
-
"react": "^
|
40
|
-
"
|
34
|
+
"react": "^17.0.0 || ^18.0.0",
|
35
|
+
"@types/react": "^18.2.12",
|
36
|
+
"@teambit/legacy": "1.0.624"
|
41
37
|
},
|
42
38
|
"license": "Apache-2.0",
|
43
39
|
"optionalDependencies": {},
|
@@ -51,7 +47,7 @@
|
|
51
47
|
},
|
52
48
|
"private": false,
|
53
49
|
"engines": {
|
54
|
-
"node": ">=
|
50
|
+
"node": ">=16.0.0"
|
55
51
|
},
|
56
52
|
"repository": {
|
57
53
|
"type": "git",
|
@@ -60,12 +56,9 @@
|
|
60
56
|
"keywords": [
|
61
57
|
"bit",
|
62
58
|
"bit-aspect",
|
59
|
+
"bit-core-aspect",
|
63
60
|
"components",
|
64
61
|
"collaboration",
|
65
|
-
"web"
|
66
|
-
"react",
|
67
|
-
"react-components",
|
68
|
-
"angular",
|
69
|
-
"angular-components"
|
62
|
+
"web"
|
70
63
|
]
|
71
64
|
}
|
package/tsconfig.json
CHANGED
@@ -1,38 +1,33 @@
|
|
1
1
|
{
|
2
2
|
"compilerOptions": {
|
3
3
|
"lib": [
|
4
|
-
"
|
5
|
-
"
|
6
|
-
"
|
7
|
-
"DOM.Iterable",
|
8
|
-
"ScriptHost"
|
4
|
+
"esnext",
|
5
|
+
"dom",
|
6
|
+
"dom.Iterable"
|
9
7
|
],
|
10
|
-
"target": "
|
11
|
-
"module": "
|
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
|
-
"
|
14
|
+
"skipLibCheck": true,
|
20
15
|
"moduleResolution": "node",
|
21
16
|
"esModuleInterop": true,
|
22
|
-
"rootDir": ".",
|
23
17
|
"resolveJsonModule": true,
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
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
|
-
"
|
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<
|
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
|
+
}
|