@teambit/insights 1.0.921 → 1.0.923
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.
|
@@ -1,129 +1,10 @@
|
|
|
1
1
|
import type { Component } from '@teambit/component';
|
|
2
|
-
import { IssuesClasses } from '@teambit/component-issues';
|
|
2
|
+
import { IssuesClasses, renderCycles } from '@teambit/component-issues';
|
|
3
3
|
import type { GraphMain } from '@teambit/graph';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
4
|
import { uniq } from 'lodash';
|
|
6
5
|
import type { Insight, InsightResult, RawResult } from '../insight';
|
|
7
6
|
import type { RunInsightOptions } from '../insight-manager';
|
|
8
7
|
|
|
9
|
-
const MAX_HORIZONTAL_WIDTH = 90;
|
|
10
|
-
const ARROW = ' ───> ';
|
|
11
|
-
const ARROW_LEN = 8;
|
|
12
|
-
|
|
13
|
-
type ShortenedInfo = {
|
|
14
|
-
names: string[];
|
|
15
|
-
scope: string | undefined;
|
|
16
|
-
version: string | undefined;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
function shortenNames(cycle: string[]): ShortenedInfo {
|
|
20
|
-
// cycle has the first element duplicated at the end; work with unique entries
|
|
21
|
-
const unique = cycle.slice(0, -1);
|
|
22
|
-
|
|
23
|
-
// extract scope: everything up to and including the last '/' before the component name
|
|
24
|
-
// e.g. "my-org.scope/ui/button@0.0.1" → scope "my-org.scope/ui", name "button", ver "0.0.1"
|
|
25
|
-
const parsed = unique.map((id) => {
|
|
26
|
-
const atIdx = id.lastIndexOf('@');
|
|
27
|
-
const version = atIdx > 0 ? id.slice(atIdx + 1) : undefined;
|
|
28
|
-
const withoutVer = atIdx > 0 ? id.slice(0, atIdx) : id;
|
|
29
|
-
const slashIdx = withoutVer.lastIndexOf('/');
|
|
30
|
-
const scope = slashIdx > 0 ? withoutVer.slice(0, slashIdx) : undefined;
|
|
31
|
-
const name = slashIdx > 0 ? withoutVer.slice(slashIdx + 1) : withoutVer;
|
|
32
|
-
return { scope, name, version };
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// common scope: only if ALL entries share the same scope
|
|
36
|
-
const scopes = new Set(parsed.map((p) => p.scope));
|
|
37
|
-
const commonScope = scopes.size === 1 ? parsed[0].scope : undefined;
|
|
38
|
-
|
|
39
|
-
// common version: only if ALL entries share the same version
|
|
40
|
-
const versions = new Set(parsed.map((p) => p.version));
|
|
41
|
-
const commonVersion = versions.size === 1 ? parsed[0].version : undefined;
|
|
42
|
-
|
|
43
|
-
const names = parsed.map((p) => {
|
|
44
|
-
let display = commonScope ? p.name : p.scope ? `${p.scope}/${p.name}` : p.name;
|
|
45
|
-
if (!commonVersion && p.version) {
|
|
46
|
-
display += `@${p.version}`;
|
|
47
|
-
}
|
|
48
|
-
return display;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
return { names, scope: commonScope, version: commonVersion };
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function renderHeader(
|
|
55
|
-
cycleIndex: number | undefined,
|
|
56
|
-
totalCycles: number,
|
|
57
|
-
componentCount: number,
|
|
58
|
-
scope: string | undefined,
|
|
59
|
-
version: string | undefined
|
|
60
|
-
): string {
|
|
61
|
-
const isSelf = componentCount === 1;
|
|
62
|
-
let header = '';
|
|
63
|
-
|
|
64
|
-
if (totalCycles > 1 && cycleIndex !== undefined) {
|
|
65
|
-
header += `Cycle ${cycleIndex + 1} of ${totalCycles}`;
|
|
66
|
-
} else {
|
|
67
|
-
header += 'Cycle';
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
header += isSelf ? ' - self-dependency' : ` - ${componentCount} components`;
|
|
71
|
-
|
|
72
|
-
if (scope) header += ` (scope: ${scope})`;
|
|
73
|
-
if (version) header += ` @${version}`;
|
|
74
|
-
|
|
75
|
-
return chalk.bold(header);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function renderSelfCycle(name: string): string {
|
|
79
|
-
return ` ${chalk.cyan(name)} ⟲`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function renderHorizontal(names: string[]): string {
|
|
83
|
-
// build chain: name0 ───> name1 ───> name2
|
|
84
|
-
const chainParts: string[] = [];
|
|
85
|
-
const plainParts: string[] = [];
|
|
86
|
-
for (let i = 0; i < names.length; i++) {
|
|
87
|
-
chainParts.push(chalk.cyan(names[i]));
|
|
88
|
-
plainParts.push(names[i]);
|
|
89
|
-
if (i < names.length - 1) {
|
|
90
|
-
chainParts.push(chalk.dim(ARROW));
|
|
91
|
-
plainParts.push(ARROW);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const chainStr = chainParts.join('');
|
|
96
|
-
const plainLen = plainParts.join('').length;
|
|
97
|
-
|
|
98
|
-
// the last segment connects to the closing edge: ───┘
|
|
99
|
-
const closingSuffix = chalk.red(' ───┘');
|
|
100
|
-
const closingSuffixLen = 6; // " ───┘"
|
|
101
|
-
|
|
102
|
-
const totalWidth = plainLen + closingSuffixLen;
|
|
103
|
-
|
|
104
|
-
// top bar spans from above ▼ (column 0) to the ┐ (at totalWidth - 1)
|
|
105
|
-
const topBar = chalk.red('┌') + chalk.red('─'.repeat(totalWidth - 2)) + chalk.red('┐');
|
|
106
|
-
const sideLine = ' '.repeat(totalWidth - 1) + chalk.red('│');
|
|
107
|
-
const entryArrow = chalk.red('▼') + ' '.repeat(totalWidth - 2) + chalk.red('│');
|
|
108
|
-
|
|
109
|
-
const lines = [topBar, sideLine, entryArrow, chainStr + closingSuffix];
|
|
110
|
-
return lines.join('\n');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function renderVertical(names: string[]): string {
|
|
114
|
-
const lines: string[] = [];
|
|
115
|
-
for (let i = 0; i < names.length; i++) {
|
|
116
|
-
lines.push(chalk.cyan(names[i]));
|
|
117
|
-
if (i < names.length - 1) {
|
|
118
|
-
lines.push(chalk.dim(' │'));
|
|
119
|
-
lines.push(chalk.dim(' ▼'));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
// back-edge to start
|
|
123
|
-
lines.push(chalk.red(` ╰───▶ `) + chalk.cyan(names[0]) + chalk.dim(' (back to start)'));
|
|
124
|
-
return lines.join('\n');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
8
|
export const INSIGHT_CIRCULAR_DEPS_NAME = 'circular';
|
|
128
9
|
|
|
129
10
|
export default class FindCycles implements Insight {
|
|
@@ -157,34 +38,7 @@ export default class FindCycles implements Insight {
|
|
|
157
38
|
}
|
|
158
39
|
|
|
159
40
|
private renderData(data: RawResult) {
|
|
160
|
-
|
|
161
|
-
return 'No cyclic dependencies';
|
|
162
|
-
}
|
|
163
|
-
const totalCycles = data.data.length;
|
|
164
|
-
const blocks = data.data.map((cycle: string[], idx: number) => {
|
|
165
|
-
const componentCount = cycle.length - 1; // last entry is duplicate of first
|
|
166
|
-
const { names, scope, version } = shortenNames(cycle);
|
|
167
|
-
const cycleIndex = totalCycles > 1 ? idx : undefined;
|
|
168
|
-
const header = renderHeader(cycleIndex, totalCycles, componentCount, scope, version);
|
|
169
|
-
|
|
170
|
-
let body: string;
|
|
171
|
-
if (componentCount === 1) {
|
|
172
|
-
body = renderSelfCycle(names[0]);
|
|
173
|
-
} else {
|
|
174
|
-
// measure horizontal width
|
|
175
|
-
const chainPlainLen = names.reduce((sum, n) => sum + n.length, 0) + (names.length - 1) * ARROW_LEN;
|
|
176
|
-
const horizontalWidth = chainPlainLen + 6; // + closing " ───┘"
|
|
177
|
-
if (horizontalWidth <= MAX_HORIZONTAL_WIDTH) {
|
|
178
|
-
body = renderHorizontal(names);
|
|
179
|
-
} else {
|
|
180
|
-
body = renderVertical(names);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return `${header}\n\n${body}`;
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
return '\n' + blocks.join('\n\n') + '\n';
|
|
41
|
+
return renderCycles(data.data ?? []);
|
|
188
42
|
}
|
|
189
43
|
|
|
190
44
|
async run(opts?: RunInsightOptions): Promise<InsightResult> {
|
|
@@ -11,13 +11,6 @@ function _componentIssues() {
|
|
|
11
11
|
};
|
|
12
12
|
return data;
|
|
13
13
|
}
|
|
14
|
-
function _chalk() {
|
|
15
|
-
const data = _interopRequireDefault(require("chalk"));
|
|
16
|
-
_chalk = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
14
|
function _lodash() {
|
|
22
15
|
const data = require("lodash");
|
|
23
16
|
_lodash = function () {
|
|
@@ -25,110 +18,9 @@ function _lodash() {
|
|
|
25
18
|
};
|
|
26
19
|
return data;
|
|
27
20
|
}
|
|
28
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
29
21
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
30
22
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
31
23
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
32
|
-
const MAX_HORIZONTAL_WIDTH = 90;
|
|
33
|
-
const ARROW = ' ───> ';
|
|
34
|
-
const ARROW_LEN = 8;
|
|
35
|
-
function shortenNames(cycle) {
|
|
36
|
-
// cycle has the first element duplicated at the end; work with unique entries
|
|
37
|
-
const unique = cycle.slice(0, -1);
|
|
38
|
-
|
|
39
|
-
// extract scope: everything up to and including the last '/' before the component name
|
|
40
|
-
// e.g. "my-org.scope/ui/button@0.0.1" → scope "my-org.scope/ui", name "button", ver "0.0.1"
|
|
41
|
-
const parsed = unique.map(id => {
|
|
42
|
-
const atIdx = id.lastIndexOf('@');
|
|
43
|
-
const version = atIdx > 0 ? id.slice(atIdx + 1) : undefined;
|
|
44
|
-
const withoutVer = atIdx > 0 ? id.slice(0, atIdx) : id;
|
|
45
|
-
const slashIdx = withoutVer.lastIndexOf('/');
|
|
46
|
-
const scope = slashIdx > 0 ? withoutVer.slice(0, slashIdx) : undefined;
|
|
47
|
-
const name = slashIdx > 0 ? withoutVer.slice(slashIdx + 1) : withoutVer;
|
|
48
|
-
return {
|
|
49
|
-
scope,
|
|
50
|
-
name,
|
|
51
|
-
version
|
|
52
|
-
};
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// common scope: only if ALL entries share the same scope
|
|
56
|
-
const scopes = new Set(parsed.map(p => p.scope));
|
|
57
|
-
const commonScope = scopes.size === 1 ? parsed[0].scope : undefined;
|
|
58
|
-
|
|
59
|
-
// common version: only if ALL entries share the same version
|
|
60
|
-
const versions = new Set(parsed.map(p => p.version));
|
|
61
|
-
const commonVersion = versions.size === 1 ? parsed[0].version : undefined;
|
|
62
|
-
const names = parsed.map(p => {
|
|
63
|
-
let display = commonScope ? p.name : p.scope ? `${p.scope}/${p.name}` : p.name;
|
|
64
|
-
if (!commonVersion && p.version) {
|
|
65
|
-
display += `@${p.version}`;
|
|
66
|
-
}
|
|
67
|
-
return display;
|
|
68
|
-
});
|
|
69
|
-
return {
|
|
70
|
-
names,
|
|
71
|
-
scope: commonScope,
|
|
72
|
-
version: commonVersion
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function renderHeader(cycleIndex, totalCycles, componentCount, scope, version) {
|
|
76
|
-
const isSelf = componentCount === 1;
|
|
77
|
-
let header = '';
|
|
78
|
-
if (totalCycles > 1 && cycleIndex !== undefined) {
|
|
79
|
-
header += `Cycle ${cycleIndex + 1} of ${totalCycles}`;
|
|
80
|
-
} else {
|
|
81
|
-
header += 'Cycle';
|
|
82
|
-
}
|
|
83
|
-
header += isSelf ? ' - self-dependency' : ` - ${componentCount} components`;
|
|
84
|
-
if (scope) header += ` (scope: ${scope})`;
|
|
85
|
-
if (version) header += ` @${version}`;
|
|
86
|
-
return _chalk().default.bold(header);
|
|
87
|
-
}
|
|
88
|
-
function renderSelfCycle(name) {
|
|
89
|
-
return ` ${_chalk().default.cyan(name)} ⟲`;
|
|
90
|
-
}
|
|
91
|
-
function renderHorizontal(names) {
|
|
92
|
-
// build chain: name0 ───> name1 ───> name2
|
|
93
|
-
const chainParts = [];
|
|
94
|
-
const plainParts = [];
|
|
95
|
-
for (let i = 0; i < names.length; i++) {
|
|
96
|
-
chainParts.push(_chalk().default.cyan(names[i]));
|
|
97
|
-
plainParts.push(names[i]);
|
|
98
|
-
if (i < names.length - 1) {
|
|
99
|
-
chainParts.push(_chalk().default.dim(ARROW));
|
|
100
|
-
plainParts.push(ARROW);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const chainStr = chainParts.join('');
|
|
104
|
-
const plainLen = plainParts.join('').length;
|
|
105
|
-
|
|
106
|
-
// the last segment connects to the closing edge: ───┘
|
|
107
|
-
const closingSuffix = _chalk().default.red(' ───┘');
|
|
108
|
-
const closingSuffixLen = 6; // " ───┘"
|
|
109
|
-
|
|
110
|
-
const totalWidth = plainLen + closingSuffixLen;
|
|
111
|
-
|
|
112
|
-
// top bar spans from above ▼ (column 0) to the ┐ (at totalWidth - 1)
|
|
113
|
-
const topBar = _chalk().default.red('┌') + _chalk().default.red('─'.repeat(totalWidth - 2)) + _chalk().default.red('┐');
|
|
114
|
-
const sideLine = ' '.repeat(totalWidth - 1) + _chalk().default.red('│');
|
|
115
|
-
const entryArrow = _chalk().default.red('▼') + ' '.repeat(totalWidth - 2) + _chalk().default.red('│');
|
|
116
|
-
const lines = [topBar, sideLine, entryArrow, chainStr + closingSuffix];
|
|
117
|
-
return lines.join('\n');
|
|
118
|
-
}
|
|
119
|
-
function renderVertical(names) {
|
|
120
|
-
const lines = [];
|
|
121
|
-
for (let i = 0; i < names.length; i++) {
|
|
122
|
-
lines.push(_chalk().default.cyan(names[i]));
|
|
123
|
-
if (i < names.length - 1) {
|
|
124
|
-
lines.push(_chalk().default.dim(' │'));
|
|
125
|
-
lines.push(_chalk().default.dim(' ▼'));
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// back-edge to start
|
|
129
|
-
lines.push(_chalk().default.red(` ╰───▶ `) + _chalk().default.cyan(names[0]) + _chalk().default.dim(' (back to start)'));
|
|
130
|
-
return lines.join('\n');
|
|
131
|
-
}
|
|
132
24
|
const INSIGHT_CIRCULAR_DEPS_NAME = exports.INSIGHT_CIRCULAR_DEPS_NAME = 'circular';
|
|
133
25
|
class FindCycles {
|
|
134
26
|
constructor(graphBuilder) {
|
|
@@ -160,35 +52,7 @@ class FindCycles {
|
|
|
160
52
|
};
|
|
161
53
|
}
|
|
162
54
|
renderData(data) {
|
|
163
|
-
|
|
164
|
-
return 'No cyclic dependencies';
|
|
165
|
-
}
|
|
166
|
-
const totalCycles = data.data.length;
|
|
167
|
-
const blocks = data.data.map((cycle, idx) => {
|
|
168
|
-
const componentCount = cycle.length - 1; // last entry is duplicate of first
|
|
169
|
-
const {
|
|
170
|
-
names,
|
|
171
|
-
scope,
|
|
172
|
-
version
|
|
173
|
-
} = shortenNames(cycle);
|
|
174
|
-
const cycleIndex = totalCycles > 1 ? idx : undefined;
|
|
175
|
-
const header = renderHeader(cycleIndex, totalCycles, componentCount, scope, version);
|
|
176
|
-
let body;
|
|
177
|
-
if (componentCount === 1) {
|
|
178
|
-
body = renderSelfCycle(names[0]);
|
|
179
|
-
} else {
|
|
180
|
-
// measure horizontal width
|
|
181
|
-
const chainPlainLen = names.reduce((sum, n) => sum + n.length, 0) + (names.length - 1) * ARROW_LEN;
|
|
182
|
-
const horizontalWidth = chainPlainLen + 6; // + closing " ───┘"
|
|
183
|
-
if (horizontalWidth <= MAX_HORIZONTAL_WIDTH) {
|
|
184
|
-
body = renderHorizontal(names);
|
|
185
|
-
} else {
|
|
186
|
-
body = renderVertical(names);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return `${header}\n\n${body}`;
|
|
190
|
-
});
|
|
191
|
-
return '\n' + blocks.join('\n\n') + '\n';
|
|
55
|
+
return (0, _componentIssues().renderCycles)(data.data ?? []);
|
|
192
56
|
}
|
|
193
57
|
async run(opts) {
|
|
194
58
|
const bareResult = await this.runInsight(opts);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_componentIssues","data","require","_chalk","_interopRequireDefault","_lodash","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","MAX_HORIZONTAL_WIDTH","ARROW","ARROW_LEN","shortenNames","cycle","unique","slice","parsed","map","id","atIdx","lastIndexOf","version","undefined","withoutVer","slashIdx","scope","name","scopes","Set","p","commonScope","size","versions","commonVersion","names","display","renderHeader","cycleIndex","totalCycles","componentCount","isSelf","header","chalk","bold","renderSelfCycle","cyan","renderHorizontal","chainParts","plainParts","length","push","dim","chainStr","join","plainLen","closingSuffix","red","closingSuffixLen","totalWidth","topBar","repeat","sideLine","entryArrow","lines","renderVertical","INSIGHT_CIRCULAR_DEPS_NAME","exports","FindCycles","constructor","graphBuilder","runInsight","opts","graph","getGraphIds","ids","message","cycles","findCycles","includeDeps","forEach","renderData","blocks","idx","body","chainPlainLen","reduce","sum","n","horizontalWidth","run","bareResult","renderedData","result","metaData","description","addAsComponentIssue","components","c","allIds","uniq","flat","componentsWithCircular","filter","component","includes","toString","state","issues","getOrCreate","IssuesClasses","CircularDependencies"],"sources":["find-circulars.ts"],"sourcesContent":["import type { Component } from '@teambit/component';\nimport { IssuesClasses } from '@teambit/component-issues';\nimport type { GraphMain } from '@teambit/graph';\nimport chalk from 'chalk';\nimport { uniq } from 'lodash';\nimport type { Insight, InsightResult, RawResult } from '../insight';\nimport type { RunInsightOptions } from '../insight-manager';\n\nconst MAX_HORIZONTAL_WIDTH = 90;\nconst ARROW = ' ───> ';\nconst ARROW_LEN = 8;\n\ntype ShortenedInfo = {\n names: string[];\n scope: string | undefined;\n version: string | undefined;\n};\n\nfunction shortenNames(cycle: string[]): ShortenedInfo {\n // cycle has the first element duplicated at the end; work with unique entries\n const unique = cycle.slice(0, -1);\n\n // extract scope: everything up to and including the last '/' before the component name\n // e.g. \"my-org.scope/ui/button@0.0.1\" → scope \"my-org.scope/ui\", name \"button\", ver \"0.0.1\"\n const parsed = unique.map((id) => {\n const atIdx = id.lastIndexOf('@');\n const version = atIdx > 0 ? id.slice(atIdx + 1) : undefined;\n const withoutVer = atIdx > 0 ? id.slice(0, atIdx) : id;\n const slashIdx = withoutVer.lastIndexOf('/');\n const scope = slashIdx > 0 ? withoutVer.slice(0, slashIdx) : undefined;\n const name = slashIdx > 0 ? withoutVer.slice(slashIdx + 1) : withoutVer;\n return { scope, name, version };\n });\n\n // common scope: only if ALL entries share the same scope\n const scopes = new Set(parsed.map((p) => p.scope));\n const commonScope = scopes.size === 1 ? parsed[0].scope : undefined;\n\n // common version: only if ALL entries share the same version\n const versions = new Set(parsed.map((p) => p.version));\n const commonVersion = versions.size === 1 ? parsed[0].version : undefined;\n\n const names = parsed.map((p) => {\n let display = commonScope ? p.name : p.scope ? `${p.scope}/${p.name}` : p.name;\n if (!commonVersion && p.version) {\n display += `@${p.version}`;\n }\n return display;\n });\n\n return { names, scope: commonScope, version: commonVersion };\n}\n\nfunction renderHeader(\n cycleIndex: number | undefined,\n totalCycles: number,\n componentCount: number,\n scope: string | undefined,\n version: string | undefined\n): string {\n const isSelf = componentCount === 1;\n let header = '';\n\n if (totalCycles > 1 && cycleIndex !== undefined) {\n header += `Cycle ${cycleIndex + 1} of ${totalCycles}`;\n } else {\n header += 'Cycle';\n }\n\n header += isSelf ? ' - self-dependency' : ` - ${componentCount} components`;\n\n if (scope) header += ` (scope: ${scope})`;\n if (version) header += ` @${version}`;\n\n return chalk.bold(header);\n}\n\nfunction renderSelfCycle(name: string): string {\n return ` ${chalk.cyan(name)} ⟲`;\n}\n\nfunction renderHorizontal(names: string[]): string {\n // build chain: name0 ───> name1 ───> name2\n const chainParts: string[] = [];\n const plainParts: string[] = [];\n for (let i = 0; i < names.length; i++) {\n chainParts.push(chalk.cyan(names[i]));\n plainParts.push(names[i]);\n if (i < names.length - 1) {\n chainParts.push(chalk.dim(ARROW));\n plainParts.push(ARROW);\n }\n }\n\n const chainStr = chainParts.join('');\n const plainLen = plainParts.join('').length;\n\n // the last segment connects to the closing edge: ───┘\n const closingSuffix = chalk.red(' ───┘');\n const closingSuffixLen = 6; // \" ───┘\"\n\n const totalWidth = plainLen + closingSuffixLen;\n\n // top bar spans from above ▼ (column 0) to the ┐ (at totalWidth - 1)\n const topBar = chalk.red('┌') + chalk.red('─'.repeat(totalWidth - 2)) + chalk.red('┐');\n const sideLine = ' '.repeat(totalWidth - 1) + chalk.red('│');\n const entryArrow = chalk.red('▼') + ' '.repeat(totalWidth - 2) + chalk.red('│');\n\n const lines = [topBar, sideLine, entryArrow, chainStr + closingSuffix];\n return lines.join('\\n');\n}\n\nfunction renderVertical(names: string[]): string {\n const lines: string[] = [];\n for (let i = 0; i < names.length; i++) {\n lines.push(chalk.cyan(names[i]));\n if (i < names.length - 1) {\n lines.push(chalk.dim(' │'));\n lines.push(chalk.dim(' ▼'));\n }\n }\n // back-edge to start\n lines.push(chalk.red(` ╰───▶ `) + chalk.cyan(names[0]) + chalk.dim(' (back to start)'));\n return lines.join('\\n');\n}\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 // add the first component to the end to make the circular visible in the output\n cycles.forEach((cycle) => cycle.push(cycle[0]));\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 || data.data.length === 0) {\n return 'No cyclic dependencies';\n }\n const totalCycles = data.data.length;\n const blocks = data.data.map((cycle: string[], idx: number) => {\n const componentCount = cycle.length - 1; // last entry is duplicate of first\n const { names, scope, version } = shortenNames(cycle);\n const cycleIndex = totalCycles > 1 ? idx : undefined;\n const header = renderHeader(cycleIndex, totalCycles, componentCount, scope, version);\n\n let body: string;\n if (componentCount === 1) {\n body = renderSelfCycle(names[0]);\n } else {\n // measure horizontal width\n const chainPlainLen = names.reduce((sum, n) => sum + n.length, 0) + (names.length - 1) * ARROW_LEN;\n const horizontalWidth = chainPlainLen + 6; // + closing \" ───┘\"\n if (horizontalWidth <= MAX_HORIZONTAL_WIDTH) {\n body = renderHorizontal(names);\n } else {\n body = renderVertical(names);\n }\n }\n\n return `${header}\\n\\n${body}`;\n });\n\n return '\\n' + blocks.join('\\n\\n') + '\\n';\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 || !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,O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,IAAI,EAAE,IAAI,CAACA,IAAI;QACfoE,WAAW,EAAE,IAAI,CAACA;MACpB,CAAC;MACD/G,IAAI,EAAE2G,UAAU,CAAC3G,IAAI;MACrB4F,OAAO,EAAEe,UAAU,CAACf,OAAO;MAC3BgB;IACF,CAAC;IAED,IAAID,UAAU,CAACf,OAAO,EAAE;MACtBiB,MAAM,CAACjB,OAAO,GAAGe,UAAU,CAACf,OAAO;IACrC;IACA,OAAOiB,MAAM;EACf;EAEA,MAAMG,mBAAmBA,CAACC,UAAuB,EAAE;IACjD,MAAMJ,MAAM,GAAG,MAAM,IAAI,CAACtB,UAAU,CAAC;MAAEI,GAAG,EAAEsB,UAAU,CAAC/E,GAAG,CAAEgF,CAAC,IAAKA,CAAC,CAAC/E,EAAE;IAAE,CAAC,CAAC;IAC1E,IAAI,CAAC0E,MAAM,CAAC7G,IAAI,IAAI,CAAC6G,MAAM,CAAC7G,IAAI,CAACkE,MAAM,EAAE;MACvC,OAAO,CAAC;IACV;IACA,MAAMiD,MAAM,GAAG,IAAAC,cAAI,EAACP,MAAM,CAAC7G,IAAI,CAACqH,IAAI,CAAC,CAAC,CAAC;IACvC,MAAMC,sBAAsB,GAAGL,UAAU,CAACM,MAAM,CAAEC,SAAS,IAAKL,MAAM,CAACM,QAAQ,CAACD,SAAS,CAACrF,EAAE,CAACuF,QAAQ,CAAC,CAAC,CAAC,CAAC;IACzGJ,sBAAsB,CAACtB,OAAO,CAAEwB,SAAS,IAAK;MAC5CA,SAAS,CAACG,KAAK,CAACC,MAAM,CAACC,WAAW,CAACC,gCAAa,CAACC,oBAAoB,CAAC,CAAC/H,IAAI,GAAG,IAAI;IACpF,CAAC,CAAC;EACJ;AACF;AAACmF,OAAA,CAAA5E,OAAA,GAAA6E,UAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_componentIssues","data","require","_lodash","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","INSIGHT_CIRCULAR_DEPS_NAME","exports","FindCycles","constructor","graphBuilder","runInsight","opts","graph","getGraphIds","ids","message","undefined","cycles","findCycles","includeDeps","forEach","cycle","push","length","renderData","renderCycles","run","bareResult","renderedData","result","metaData","name","description","addAsComponentIssue","components","map","c","id","allIds","uniq","flat","componentsWithCircular","filter","component","includes","toString","state","issues","getOrCreate","IssuesClasses","CircularDependencies","default"],"sources":["find-circulars.ts"],"sourcesContent":["import type { Component } from '@teambit/component';\nimport { IssuesClasses, renderCycles } from '@teambit/component-issues';\nimport type { GraphMain } from '@teambit/graph';\nimport { uniq } from 'lodash';\nimport type { Insight, InsightResult, RawResult } from '../insight';\nimport type { 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 // add the first component to the end to make the circular visible in the output\n cycles.forEach((cycle) => cycle.push(cycle[0]));\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 return renderCycles(data.data ?? []);\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 || !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,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAT,CAAA,CAAAC,CAAA,IAAAC,CAAA,EAAAF,CAAA;AAAA,SAAAG,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAT,CAAA,EAAAD,CAAA,2BAAAC,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAF,CAAA,GAAAE,CAAA,CAAAU,MAAA,CAAAC,WAAA,kBAAAb,CAAA,QAAAU,CAAA,GAAAV,CAAA,CAAAc,IAAA,CAAAZ,CAAA,EAAAD,CAAA,uCAAAS,CAAA,SAAAA,CAAA,YAAAK,SAAA,yEAAAd,CAAA,GAAAe,MAAA,GAAAC,MAAA,EAAAf,CAAA;AAIvB,MAAMgB,0BAA0B,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AQ,EAAE;QACRC,IAAI,EAAE,IAAI,CAACA,IAAI;QACfC,WAAW,EAAE,IAAI,CAACA;MACpB,CAAC;MACDjD,IAAI,EAAE4C,UAAU,CAAC5C,IAAI;MACrBgC,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,CAACC,GAAG,CAAEC,CAAC,IAAKA,CAAC,CAACC,EAAE;IAAE,CAAC,CAAC;IAC1E,IAAI,CAACR,MAAM,CAAC9C,IAAI,IAAI,CAAC8C,MAAM,CAAC9C,IAAI,CAACwC,MAAM,EAAE;MACvC,OAAO,CAAC;IACV;IACA,MAAMe,MAAM,GAAG,IAAAC,cAAI,EAACV,MAAM,CAAC9C,IAAI,CAACyD,IAAI,CAAC,CAAC,CAAC;IACvC,MAAMC,sBAAsB,GAAGP,UAAU,CAACQ,MAAM,CAAEC,SAAS,IAAKL,MAAM,CAACM,QAAQ,CAACD,SAAS,CAACN,EAAE,CAACQ,QAAQ,CAAC,CAAC,CAAC,CAAC;IACzGJ,sBAAsB,CAACrB,OAAO,CAAEuB,SAAS,IAAK;MAC5CA,SAAS,CAACG,KAAK,CAACC,MAAM,CAACC,WAAW,CAACC,gCAAa,CAACC,oBAAoB,CAAC,CAACnE,IAAI,GAAG,IAAI;IACpF,CAAC,CAAC;EACJ;AACF;AAACuB,OAAA,CAAA6C,OAAA,GAAA5C,UAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
;
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.explorer_insights@1.0.
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.explorer_insights@1.0.923/dist/insights.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [];
|
|
5
5
|
export const overview = [overview_0];
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/insights",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.923",
|
|
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.923"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"p-map-series": "2.1.0",
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"lodash": "4.17.21",
|
|
16
16
|
"@teambit/component-id": "1.2.4",
|
|
17
17
|
"@teambit/harmony": "0.4.7",
|
|
18
|
-
"@teambit/cli": "0.0.1304",
|
|
19
|
-
"@teambit/component-issues": "0.0.170",
|
|
20
18
|
"@teambit/bit-error": "0.0.404",
|
|
21
|
-
"@teambit/graph": "1.0.
|
|
22
|
-
"@teambit/component": "1.0.
|
|
23
|
-
"@teambit/
|
|
19
|
+
"@teambit/graph": "1.0.922",
|
|
20
|
+
"@teambit/component": "1.0.922",
|
|
21
|
+
"@teambit/cli": "0.0.1305",
|
|
22
|
+
"@teambit/component-issues": "0.0.171",
|
|
23
|
+
"@teambit/issues": "1.0.922"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/semver": "7.5.8",
|