@teambit/insights 0.0.555 → 0.0.556

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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/insights",
3
- "version": "0.0.555",
3
+ "version": "0.0.556",
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.555"
9
+ "version": "0.0.556"
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.555",
18
- "@teambit/cli": "0.0.386",
19
- "@teambit/component": "0.0.555",
20
- "@teambit/bit-error": "0.0.372"
17
+ "@teambit/graph": "0.0.556",
18
+ "@teambit/cli": "0.0.387",
19
+ "@teambit/component": "0.0.556",
20
+ "@teambit/bit-error": "0.0.373"
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.172",
32
+ "@teambit/legacy": "1.0.173",
33
33
  "react-dom": "^16.8.0 || ^17.0.0",
34
34
  "react": "^16.8.0 || ^17.0.0"
35
35
  },
@@ -57,12 +57,18 @@
57
57
  "react": "-"
58
58
  },
59
59
  "peerDependencies": {
60
- "@teambit/legacy": "1.0.172",
60
+ "@teambit/legacy": "1.0.173",
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
+ "README.md",
70
+ "README.mdx"
71
+ ],
66
72
  "private": false,
67
73
  "engines": {
68
74
  "node": ">=12.22.0"
@@ -1,149 +0,0 @@
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
- }
@@ -1,66 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
1
- import { GraphBuilder } from '@teambit/graph';
2
-
3
- import DuplicateDependencies from './all-insights/duplicate-dependencies';
4
- import FindCycles from './all-insights/find-cycles';
5
-
6
- export default function getCoreInsights(graphBuilder: GraphBuilder) {
7
- const coreInsights = [new FindCycles(graphBuilder), new DuplicateDependencies(graphBuilder)];
8
- return coreInsights;
9
- }
@@ -1,7 +0,0 @@
1
- import { BitError } from '@teambit/bit-error';
2
-
3
- export default class InsightAlreadyExists extends BitError {
4
- constructor(readonly insightName: string) {
5
- super(`Insight ${insightName} already exists`);
6
- }
7
- }
@@ -1,7 +0,0 @@
1
- import { BitError } from '@teambit/bit-error';
2
-
3
- export default class InsightNotFound extends BitError {
4
- constructor(readonly insightName: string) {
5
- super(`Insight ${insightName} not found`);
6
- }
7
- }
@@ -1,7 +0,0 @@
1
- import { BitError } from '@teambit/bit-error';
2
-
3
- export default class NoDataForInsight extends BitError {
4
- constructor(readonly insightName: string) {
5
- super(`No data for ${insightName}`);
6
- }
7
- }
package/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export { InsightManager } from './insight-manager';
2
- export { Insight } from './insight';
3
- export type { InsightsMain } from './insights.main.runtime';
4
- export { InsightsAspect } from './insights.aspect';
@@ -1,85 +0,0 @@
1
- import InsightAlreadyExists from './exceptions/insight-already-exists';
2
- import InsightNotFound from './exceptions/insight-not-found';
3
- import { Insight, InsightResult } from './insight';
4
-
5
- export type RunInsightOptions = {
6
- renderData: boolean;
7
- };
8
- export class InsightManager {
9
- /** insights is an insight registry */
10
- readonly insights: Map<string, Insight> = new Map();
11
- constructor(
12
- /**
13
- * array of registered insights
14
- */
15
- insights: Insight[]
16
- ) {
17
- insights.forEach((insight) => {
18
- this.register(insight);
19
- });
20
- }
21
-
22
- /**
23
- * registers a new insight and returns the updated insight registry map
24
- */
25
- register(insight: Insight) {
26
- const name = insight.name;
27
- if (this.insights.has(name)) {
28
- throw new InsightAlreadyExists(name);
29
- }
30
- this.insights.set(name, insight);
31
- }
32
- /**
33
- * list of all registered insights
34
- */
35
- listInsights(): string[] {
36
- return [...this.insights.keys()];
37
- }
38
-
39
- /**
40
- * gets a specific insight by its name or undefined if doesn't exist
41
- */
42
- getByName(insightName: string): Insight | undefined {
43
- return this.insights.get(insightName);
44
- }
45
-
46
- /**
47
- * deletes a specific insight by its name if exists
48
- */
49
- delete(insightName: string) {
50
- if (!this.insights.has(insightName)) {
51
- throw new InsightNotFound(insightName);
52
- }
53
- this.insights.delete(insightName);
54
- }
55
-
56
- /**
57
- * execute an array of insights
58
- *
59
- */
60
- async run(insightNames: string[], opts: RunInsightOptions): Promise<InsightResult[]> {
61
- const res: InsightResult[] = [];
62
- await Promise.all(
63
- insightNames.map(async (insightName) => {
64
- const insight = this.getByName(insightName);
65
- if (insight) {
66
- const insightRes: InsightResult = await insight.run();
67
- if (!opts.renderData) {
68
- delete insightRes.renderedData;
69
- }
70
- res.push(insightRes);
71
- }
72
- })
73
- );
74
- return res;
75
- }
76
-
77
- /**
78
- * execute all insights in the registry
79
- *
80
- */
81
- async runAll(opts: RunInsightOptions): Promise<InsightResult[]> {
82
- const allInsightNames = this.listInsights();
83
- return this.run(allInsightNames, opts);
84
- }
85
- }
@@ -1,19 +0,0 @@
1
- import { CLIMain } from '@teambit/cli';
2
- import { GraphBuilder } from '@teambit/graph';
3
-
4
- import getCoreInsights from './core-insights-getter';
5
- import { Insight } from './insight';
6
- import { InsightManager } from './insight-manager';
7
- import InsightsCmd from './insights.cmd';
8
-
9
- export type InsightDeps = [GraphBuilder, CLIMain];
10
-
11
- export async function provide([graphBuilder, cli]: InsightDeps) {
12
- // get all insights from registry
13
- const initialInsights: Insight[] = getCoreInsights(graphBuilder);
14
- // register all insights in cli
15
- // TODO - get user-defined insights as well, and use them when instantiating InsightManager and InsightsCmd
16
- const insightManager = new InsightManager(initialInsights);
17
- const insightsCmd = new InsightsCmd(insightManager);
18
- cli.register(insightsCmd);
19
- }
package/insight.ts DELETED
@@ -1,27 +0,0 @@
1
- export type InsightMetaData = {
2
- name: string;
3
- description: string;
4
- };
5
-
6
- export type InsightResult = {
7
- metaData: InsightMetaData;
8
- message: string;
9
- data: any;
10
- renderedData?: string;
11
- };
12
-
13
- export type RawResult = {
14
- message: string;
15
- data: any;
16
- };
17
-
18
- export interface Insight {
19
- name: string;
20
- description: string;
21
-
22
- /**
23
- * runs a specific insight using _runInsight, gets a RawResult, and uses _formatData to transform the output to InsightResult.
24
- */
25
-
26
- run(...args: any[]): Promise<InsightResult>;
27
- }
@@ -1,7 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const InsightsAspect = Aspect.create({
4
- id: 'teambit.explorer/insights',
5
- dependencies: [],
6
- defaultConfig: {},
7
- });
package/insights.cmd.ts DELETED
@@ -1,57 +0,0 @@
1
- import chalk from 'chalk';
2
- import { Command, CommandOptions } from '@teambit/cli';
3
- import { InsightResult } from './insight';
4
- import { InsightManager, RunInsightOptions } from './insight-manager';
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
- ] as CommandOptions;
15
- insightManager: InsightManager;
16
- constructor(insightManager: InsightManager) {
17
- this.insightManager = insightManager;
18
- }
19
-
20
- async report(names: [string[]], options: { list: boolean }): Promise<string> {
21
- if (options.list) {
22
- const results = await this.json(names, options);
23
- return JSON.stringify(results, null, 2);
24
- }
25
- const results = await this.runInsights(names, { renderData: true });
26
- return template(results);
27
- }
28
-
29
- async json(names: [string[]], { list }: { list: boolean }) {
30
- if (list) {
31
- const results = this.insightManager.listInsights();
32
- return results;
33
- }
34
- return this.runInsights(names, { renderData: false });
35
- }
36
-
37
- private async runInsights([names]: [string[]], opts: RunInsightOptions) {
38
- if (names) {
39
- let results: InsightResult[] = [];
40
- const namesArr = typeof names === 'string' ? [names] : names;
41
- results = await this.insightManager.run(namesArr, opts);
42
- return results;
43
- }
44
- const results = await this.insightManager.runAll(opts);
45
- return results;
46
- }
47
- }
48
-
49
- function template(results: InsightResult[]): string {
50
- const elements = results
51
- .map((result) => {
52
- return `\n${chalk.cyan.bold(result.message)}
53
- ${result.renderedData}`;
54
- })
55
- .join('\n');
56
- return elements;
57
- }
@@ -1,17 +0,0 @@
1
- import { CLIAspect, MainRuntime } from '@teambit/cli';
2
- import { GraphAspect } from '@teambit/graph';
3
-
4
- import { provide } from './insight.provider';
5
- import { InsightsAspect } from './insights.aspect';
6
-
7
- export const InsightsMain = {
8
- runtime: MainRuntime,
9
- name: 'insights',
10
- dependencies: [GraphAspect, CLIAspect],
11
- config: {
12
- silence: false,
13
- },
14
- provider: provide,
15
- };
16
-
17
- InsightsAspect.addRuntime(InsightsMain);
package/tsconfig.json DELETED
@@ -1,34 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
9
- ],
10
- "target": "es2015",
11
- "module": "commonjs",
12
- "jsx": "react",
13
- "declaration": true,
14
- "sourceMap": true,
15
- "skipLibCheck": true,
16
- "moduleResolution": "node",
17
- "esModuleInterop": true,
18
- "outDir": "dist",
19
- "composite": true,
20
- "emitDeclarationOnly": true,
21
- "experimentalDecorators": true,
22
- "emitDecoratorMetadata": true,
23
- "allowSyntheticDefaultImports": true,
24
- "strictPropertyInitialization": false,
25
- "strict": true,
26
- "noImplicitAny": false,
27
- "rootDir": ".",
28
- "preserveConstEnums": true,
29
- "resolveJsonModule": true
30
- },
31
- "exclude": [
32
- "dist"
33
- ]
34
- }
package/types/asset.d.ts DELETED
@@ -1,29 +0,0 @@
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 DELETED
@@ -1,42 +0,0 @@
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
- }