@teambit/insights 0.0.566 → 0.0.570
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/all-insights/duplicate-dependencies.ts +149 -0
- package/all-insights/find-cycles.ts +66 -0
- package/exceptions/insight-already-exists.ts +7 -0
- package/exceptions/insight-not-found.ts +7 -0
- package/exceptions/no-data-for-insight.ts +7 -0
- package/package-tar/teambit-insights-0.0.570.tgz +0 -0
- package/package.json +8 -23
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { GraphBuilder, VersionSubgraph } from '@teambit/graph';
|
|
3
|
+
import { rcompare } from 'semver';
|
|
4
|
+
// import { ComponentID } from '../../../component/component-id';
|
|
5
|
+
import { ComponentID } from '@teambit/component';
|
|
6
|
+
import { Insight, InsightResult, RawResult } from '../insight';
|
|
7
|
+
// import NoDataForInsight from '../exceptions/no-data-for-insight';
|
|
8
|
+
|
|
9
|
+
export const INSIGHT_NAME = 'duplicate dependencies';
|
|
10
|
+
|
|
11
|
+
type Dependent = {
|
|
12
|
+
id: string;
|
|
13
|
+
usedVersion: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type VersionWithDependents = {
|
|
17
|
+
version: string;
|
|
18
|
+
compId: string;
|
|
19
|
+
dependents: Dependent[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type FormattedEntry = {
|
|
23
|
+
dependencyId: string;
|
|
24
|
+
latestVersion: string;
|
|
25
|
+
totalOutdatedDependents: string;
|
|
26
|
+
dependentsByVersion: VersionWithDependents[];
|
|
27
|
+
};
|
|
28
|
+
export default class DuplicateDependencies implements Insight {
|
|
29
|
+
name = INSIGHT_NAME;
|
|
30
|
+
description = 'Get all duplicate dependencies in component graph';
|
|
31
|
+
graphBuilder: GraphBuilder;
|
|
32
|
+
constructor(graphBuilder: GraphBuilder) {
|
|
33
|
+
this.graphBuilder = graphBuilder;
|
|
34
|
+
}
|
|
35
|
+
private async runInsight(): Promise<RawResult> {
|
|
36
|
+
const graph = await this.graphBuilder.getGraph();
|
|
37
|
+
if (!graph) {
|
|
38
|
+
return {
|
|
39
|
+
message: 'No graph found',
|
|
40
|
+
data: undefined,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const duplicates = graph.findDuplicateDependencies();
|
|
44
|
+
const lenDependencies = [...duplicates.keys()].length;
|
|
45
|
+
if (lenDependencies === 1) {
|
|
46
|
+
return {
|
|
47
|
+
message: `Found ${lenDependencies} duplicate dependency.`,
|
|
48
|
+
data: duplicates,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
message: `Found ${lenDependencies} duplicate dependencies.`,
|
|
53
|
+
data: duplicates,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private formatData(data: any): FormattedEntry[] {
|
|
58
|
+
const formatted: FormattedEntry[] = [];
|
|
59
|
+
for (const [dependency, depData] of data.entries()) {
|
|
60
|
+
const { totalOutdatedDependents, dependentsByVersion } = this.getDependents(depData.priorVersions);
|
|
61
|
+
formatted.push({
|
|
62
|
+
dependencyId: dependency,
|
|
63
|
+
latestVersion: depData.latestVersionId,
|
|
64
|
+
totalOutdatedDependents: totalOutdatedDependents.toString(),
|
|
65
|
+
dependentsByVersion,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return formatted;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private getDependents(
|
|
72
|
+
priorVersions: VersionSubgraph[]
|
|
73
|
+
): { totalOutdatedDependents: number; dependentsByVersion: VersionWithDependents[] } {
|
|
74
|
+
let totalOutdatedDependents = 0;
|
|
75
|
+
const dependentsByVersion: VersionWithDependents[] = [];
|
|
76
|
+
priorVersions.forEach((pVersion: VersionSubgraph) => {
|
|
77
|
+
const dependents: Dependent[] = [];
|
|
78
|
+
const version = ComponentID.fromString(pVersion.versionId).version || pVersion.versionId.split('@')[1];
|
|
79
|
+
pVersion.immediateDependents.forEach((dependent: string) => {
|
|
80
|
+
dependents.push({
|
|
81
|
+
id: dependent,
|
|
82
|
+
usedVersion: pVersion.versionId,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
dependentsByVersion.push({
|
|
86
|
+
compId: pVersion.versionId,
|
|
87
|
+
version,
|
|
88
|
+
dependents,
|
|
89
|
+
});
|
|
90
|
+
totalOutdatedDependents += pVersion.immediateDependents.length;
|
|
91
|
+
});
|
|
92
|
+
dependentsByVersion.sort(this.revreseCompareVersions);
|
|
93
|
+
return { totalOutdatedDependents, dependentsByVersion };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
revreseCompareVersions(v1: VersionWithDependents, v2: VersionWithDependents) {
|
|
97
|
+
return rcompare(v1.version, v2.version);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private stringifyDependents(dependents: Dependent[]): string {
|
|
101
|
+
const string = dependents
|
|
102
|
+
.map((dependent) => {
|
|
103
|
+
return `- ${dependent.id} => ${dependent.usedVersion}`;
|
|
104
|
+
})
|
|
105
|
+
.join('\n');
|
|
106
|
+
return string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private stringifyDependentsByVersion(versions: VersionWithDependents[]): string {
|
|
110
|
+
const string = versions
|
|
111
|
+
.map((version) => {
|
|
112
|
+
return `- ${version.compId} has ${version.dependents.length} dependents`;
|
|
113
|
+
})
|
|
114
|
+
.join('\n');
|
|
115
|
+
return string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private renderData(data: FormattedEntry[]) {
|
|
119
|
+
const string = data
|
|
120
|
+
.map((obj) => {
|
|
121
|
+
return `\n\nFound ${obj.totalOutdatedDependents} outdated dependents for ${obj.dependencyId}
|
|
122
|
+
The latest version is "${obj.latestVersion}"
|
|
123
|
+
Outdated dependents:
|
|
124
|
+
${this.stringifyDependentsByVersion(obj.dependentsByVersion)}`;
|
|
125
|
+
})
|
|
126
|
+
.join('\n');
|
|
127
|
+
return string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async run(): Promise<InsightResult> {
|
|
131
|
+
const bareResult = await this.runInsight();
|
|
132
|
+
const formattedData = this.formatData(bareResult.data);
|
|
133
|
+
const renderedData = this.renderData(formattedData);
|
|
134
|
+
const result: InsightResult = {
|
|
135
|
+
metaData: {
|
|
136
|
+
name: this.name,
|
|
137
|
+
description: this.description,
|
|
138
|
+
},
|
|
139
|
+
data: formattedData,
|
|
140
|
+
message: bareResult.message,
|
|
141
|
+
renderedData,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
if (bareResult.message) {
|
|
145
|
+
result.message = bareResult.message;
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { GraphBuilder } from '@teambit/graph';
|
|
2
|
+
import { Insight, InsightResult, RawResult } from '../insight';
|
|
3
|
+
|
|
4
|
+
export const INSIGHT_NAME = 'cyclic dependencies';
|
|
5
|
+
|
|
6
|
+
export default class FindCycles implements Insight {
|
|
7
|
+
name = INSIGHT_NAME;
|
|
8
|
+
description = 'Get all cyclic dependencies in component graph';
|
|
9
|
+
graphBuilder: GraphBuilder;
|
|
10
|
+
constructor(graphBuilder: GraphBuilder) {
|
|
11
|
+
this.graphBuilder = graphBuilder;
|
|
12
|
+
}
|
|
13
|
+
private async runInsight(): Promise<RawResult> {
|
|
14
|
+
const graph = await this.graphBuilder.getGraph();
|
|
15
|
+
if (!graph) {
|
|
16
|
+
return {
|
|
17
|
+
message: '',
|
|
18
|
+
data: undefined,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const cycles = graph.findCycles();
|
|
22
|
+
if (cycles.length === 1) {
|
|
23
|
+
return {
|
|
24
|
+
message: `Found ${cycles.length} cycle.`,
|
|
25
|
+
data: cycles,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
message: `Found ${cycles.length} cycles.`,
|
|
30
|
+
data: cycles,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private renderData(data: RawResult) {
|
|
35
|
+
if (data.data.length === 0) {
|
|
36
|
+
return 'No cyclic dependencies';
|
|
37
|
+
}
|
|
38
|
+
const string = data.data
|
|
39
|
+
.map((cycle) => {
|
|
40
|
+
return `\nCyclic dependency
|
|
41
|
+
-----------------
|
|
42
|
+
- ${cycle.join('\n- ')}`;
|
|
43
|
+
})
|
|
44
|
+
.join('\n');
|
|
45
|
+
return string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async run(): Promise<InsightResult> {
|
|
49
|
+
const bareResult = await this.runInsight();
|
|
50
|
+
const renderedData = this.renderData(bareResult);
|
|
51
|
+
const result: InsightResult = {
|
|
52
|
+
metaData: {
|
|
53
|
+
name: this.name,
|
|
54
|
+
description: this.description,
|
|
55
|
+
},
|
|
56
|
+
data: bareResult.data,
|
|
57
|
+
message: bareResult.message,
|
|
58
|
+
renderedData,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
if (bareResult.message) {
|
|
62
|
+
result.message = bareResult.message;
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/insights",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.570",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/explorer/insights",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.explorer",
|
|
8
8
|
"name": "insights",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.570"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/harmony": "0.2.11",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"semver": "7.3.4",
|
|
15
15
|
"@babel/runtime": "7.12.18",
|
|
16
16
|
"core-js": "^3.0.0",
|
|
17
|
-
"@teambit/graph": "0.0.
|
|
18
|
-
"@teambit/cli": "0.0.
|
|
19
|
-
"@teambit/component": "0.0.
|
|
20
|
-
"@teambit/bit-error": "0.0.
|
|
17
|
+
"@teambit/graph": "0.0.570",
|
|
18
|
+
"@teambit/cli": "0.0.395",
|
|
19
|
+
"@teambit/component": "0.0.570",
|
|
20
|
+
"@teambit/bit-error": "0.0.381"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/semver": "7.3.4",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@types/node": "12.20.4"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@teambit/legacy": "1.0.
|
|
32
|
+
"@teambit/legacy": "1.0.181",
|
|
33
33
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
34
34
|
"react": "^16.8.0 || ^17.0.0"
|
|
35
35
|
},
|
|
@@ -57,27 +57,12 @@
|
|
|
57
57
|
"react": "-"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@teambit/legacy": "1.0.
|
|
60
|
+
"@teambit/legacy": "1.0.181",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
62
62
|
"react": "^16.8.0 || ^17.0.0"
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"files": [
|
|
67
|
-
"dist",
|
|
68
|
-
"!dist/tsconfig.tsbuildinfo",
|
|
69
|
-
"**/*.md",
|
|
70
|
-
"**/*.mdx",
|
|
71
|
-
"**/*.js",
|
|
72
|
-
"**/*.json",
|
|
73
|
-
"**/*.sass",
|
|
74
|
-
"**/*.scss",
|
|
75
|
-
"**/*.less",
|
|
76
|
-
"**/*.css",
|
|
77
|
-
"**/*.css",
|
|
78
|
-
"**/*.jpeg",
|
|
79
|
-
"**/*.gif"
|
|
80
|
-
],
|
|
81
66
|
"private": false,
|
|
82
67
|
"engines": {
|
|
83
68
|
"node": ">=12.22.0"
|
package/types/asset.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare module '*.png' {
|
|
2
|
+
const value: any;
|
|
3
|
+
export = value;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.svg' {
|
|
6
|
+
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
+
|
|
8
|
+
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
|
9
|
+
const src: string;
|
|
10
|
+
export default src;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// @TODO Gilad
|
|
14
|
+
declare module '*.jpg' {
|
|
15
|
+
const value: any;
|
|
16
|
+
export = value;
|
|
17
|
+
}
|
|
18
|
+
declare module '*.jpeg' {
|
|
19
|
+
const value: any;
|
|
20
|
+
export = value;
|
|
21
|
+
}
|
|
22
|
+
declare module '*.gif' {
|
|
23
|
+
const value: any;
|
|
24
|
+
export = value;
|
|
25
|
+
}
|
|
26
|
+
declare module '*.bmp' {
|
|
27
|
+
const value: any;
|
|
28
|
+
export = value;
|
|
29
|
+
}
|
package/types/style.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '*.module.css' {
|
|
2
|
+
const classes: { readonly [key: string]: string };
|
|
3
|
+
export default classes;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.module.scss' {
|
|
6
|
+
const classes: { readonly [key: string]: string };
|
|
7
|
+
export default classes;
|
|
8
|
+
}
|
|
9
|
+
declare module '*.module.sass' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.module.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.less' {
|
|
20
|
+
const classes: { readonly [key: string]: string };
|
|
21
|
+
export default classes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.css' {
|
|
25
|
+
const classes: { readonly [key: string]: string };
|
|
26
|
+
export default classes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.sass' {
|
|
30
|
+
const classes: { readonly [key: string]: string };
|
|
31
|
+
export default classes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.scss' {
|
|
35
|
+
const classes: { readonly [key: string]: string };
|
|
36
|
+
export default classes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.mdx' {
|
|
40
|
+
const component: any;
|
|
41
|
+
export default component;
|
|
42
|
+
}
|