@teambit/insights 1.0.108 → 1.0.109

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 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.explorer/insights-preview"]=t():e["teambit.explorer/insights-preview"]=t()}(self,(()=>(()=>{"use strict";var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{compositions:()=>d,compositions_metadata:()=>u,overview:()=>l});var o={};e.r(o),e.d(o,{default:()=>s}),React;const r=MdxJsReact,n=TeambitMdxUiMdxScopeContext;var i=["components"];function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},p.apply(this,arguments)}var a={},c="wrapper";function s(e){var t=e.components,o=function(e,t){if(null==e)return{};var o,r,n=function(e,t){if(null==e)return{};var o,r,n={},i=Object.keys(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||(n[o]=e[o]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(n[o]=e[o])}return n}(e,i);return(0,r.mdx)(c,p({},a,o,{components:t,mdxType:"MDXLayout"}),(0,r.mdx)(n.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"},(0,r.mdx)("p",null,"Reveals circular and outdated dependencies.")))}s.isMDXComponent=!0;const d=[],l=[o],u={compositions:[]};return t})()));
@@ -1,5 +1,5 @@
1
1
  ;
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.explorer_insights@1.0.108/dist/insights.docs.mdx';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.explorer_insights@1.0.109/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.108",
3
+ "version": "1.0.109",
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.108"
9
+ "version": "1.0.109"
10
10
  },
11
11
  "dependencies": {
12
12
  "p-map-series": "2.1.0",
@@ -16,11 +16,11 @@
16
16
  "@teambit/component-id": "1.2.0",
17
17
  "@teambit/harmony": "0.4.6",
18
18
  "@teambit/bit-error": "0.0.404",
19
- "@teambit/graph": "1.0.108",
20
- "@teambit/component": "1.0.108",
21
- "@teambit/cli": "0.0.840",
19
+ "@teambit/graph": "1.0.109",
20
+ "@teambit/component": "1.0.109",
21
+ "@teambit/cli": "0.0.841",
22
22
  "@teambit/component-issues": "0.0.138",
23
- "@teambit/issues": "1.0.108"
23
+ "@teambit/issues": "1.0.109"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/semver": "7.3.4",
@@ -28,7 +28,7 @@
28
28
  "@types/mocha": "9.1.0",
29
29
  "@types/jest": "^29.2.2",
30
30
  "@types/testing-library__jest-dom": "^5.9.5",
31
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
31
+ "@teambit/harmony.envs.core-aspect-env": "0.0.14"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": "^17.0.0 || ^18.0.0",
@@ -1,9 +0,0 @@
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
- }
package/index.ts DELETED
@@ -1,5 +0,0 @@
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';
@@ -1,90 +0,0 @@
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 DELETED
@@ -1,35 +0,0 @@
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
- }
@@ -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,44 +0,0 @@
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
- }
@@ -1,63 +0,0 @@
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);