@teambit/insights 0.0.1055 → 0.0.1057

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.
@@ -3,6 +3,7 @@ import { IssuesClasses } from '@teambit/component-issues';
3
3
  import { GraphMain } from '@teambit/graph';
4
4
  import { uniq } from 'lodash';
5
5
  import { Insight, InsightResult, RawResult } from '../insight';
6
+ import { RunInsightOptions } from '../insight-manager';
6
7
 
7
8
  export const INSIGHT_CIRCULAR_DEPS_NAME = 'circular';
8
9
 
@@ -13,7 +14,7 @@ export default class FindCycles implements Insight {
13
14
  constructor(graphBuilder: GraphMain) {
14
15
  this.graphBuilder = graphBuilder;
15
16
  }
16
- private async runInsight(): Promise<RawResult> {
17
+ private async runInsight(opts?: RunInsightOptions): Promise<RawResult> {
17
18
  const graph = await this.graphBuilder.getGraphIds();
18
19
  if (!graph) {
19
20
  return {
@@ -21,7 +22,7 @@ export default class FindCycles implements Insight {
21
22
  data: undefined,
22
23
  };
23
24
  }
24
- const cycles = graph.findCycles();
25
+ const cycles = graph.findCycles(undefined, opts?.includeDeps);
25
26
  if (cycles.length === 1) {
26
27
  return {
27
28
  message: `Found ${cycles.length} cycle.`,
@@ -48,8 +49,8 @@ export default class FindCycles implements Insight {
48
49
  return string;
49
50
  }
50
51
 
51
- async run(): Promise<InsightResult> {
52
- const bareResult = await this.runInsight();
52
+ async run(opts?: RunInsightOptions): Promise<InsightResult> {
53
+ const bareResult = await this.runInsight(opts);
53
54
  const renderedData = this.renderData(bareResult);
54
55
  const result: InsightResult = {
55
56
  metaData: {
@@ -1,6 +1,7 @@
1
1
  import { Component } from '@teambit/component';
2
2
  import { GraphMain } from '@teambit/graph';
3
3
  import { Insight, InsightResult } from '../insight';
4
+ import { RunInsightOptions } from '../insight-manager';
4
5
  export declare const INSIGHT_CIRCULAR_DEPS_NAME = "circular";
5
6
  export default class FindCycles implements Insight {
6
7
  name: string;
@@ -9,6 +10,6 @@ export default class FindCycles implements Insight {
9
10
  constructor(graphBuilder: GraphMain);
10
11
  private runInsight;
11
12
  private renderData;
12
- run(): Promise<InsightResult>;
13
+ run(opts?: RunInsightOptions): Promise<InsightResult>;
13
14
  addAsComponentIssue(components: Component[]): Promise<void>;
14
15
  }
@@ -39,7 +39,7 @@ class FindCycles {
39
39
  (0, _defineProperty2().default)(this, "graphBuilder", void 0);
40
40
  this.graphBuilder = graphBuilder;
41
41
  }
42
- async runInsight() {
42
+ async runInsight(opts) {
43
43
  const graph = await this.graphBuilder.getGraphIds();
44
44
  if (!graph) {
45
45
  return {
@@ -47,7 +47,7 @@ class FindCycles {
47
47
  data: undefined
48
48
  };
49
49
  }
50
- const cycles = graph.findCycles();
50
+ const cycles = graph.findCycles(undefined, opts === null || opts === void 0 ? void 0 : opts.includeDeps);
51
51
  if (cycles.length === 1) {
52
52
  return {
53
53
  message: `Found ${cycles.length} cycle.`,
@@ -70,8 +70,8 @@ class FindCycles {
70
70
  }).join('\n');
71
71
  return string;
72
72
  }
73
- async run() {
74
- const bareResult = await this.runInsight();
73
+ async run(opts) {
74
+ const bareResult = await this.runInsight(opts);
75
75
  const renderedData = this.renderData(bareResult);
76
76
  const result = {
77
77
  metaData: {
@@ -1 +1 @@
1
- {"version":3,"names":["INSIGHT_CIRCULAR_DEPS_NAME","FindCycles","constructor","graphBuilder","runInsight","graph","getGraphIds","message","data","undefined","cycles","findCycles","length","renderData","string","map","cycle","join","run","bareResult","renderedData","result","metaData","name","description","addAsComponentIssue","components","allIds","uniq","flat","componentsWithCircular","filter","component","includes","id","toString","forEach","state","issues","getOrCreate","IssuesClasses","CircularDependencies"],"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';\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(): Promise<RawResult> {\n const graph = await this.graphBuilder.getGraphIds();\n if (!graph) {\n return {\n message: '',\n data: undefined,\n };\n }\n const cycles = graph.findCycles();\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(): Promise<InsightResult> {\n const bareResult = await this.runInsight();\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();\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;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGO,MAAMA,0BAA0B,GAAG,UAAU;AAAC;AAEtC,MAAMC,UAAU,CAAoB;EAIjDC,WAAW,CAACC,YAAuB,EAAE;IAAA,8CAH9BH,0BAA0B;IAAA,qDACnB,kDAAkD;IAAA;IAG9D,IAAI,CAACG,YAAY,GAAGA,YAAY;EAClC;EACA,MAAcC,UAAU,GAAuB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,GAAGY,UAAU,CAACZ,OAAO;IACrC;IACA,OAAOc,MAAM;EACf;EAEA,MAAMI,mBAAmB,CAACC,UAAuB,EAAE;IACjD,MAAML,MAAM,GAAG,MAAM,IAAI,CAACjB,UAAU,EAAE;IACtC,IAAI,CAACiB,MAAM,CAACb,IAAI,CAACI,MAAM,EAAE;MACvB,OAAO,CAAC;IACV;;IACA,MAAMe,MAAM,GAAG,IAAAC,cAAI,EAACP,MAAM,CAACb,IAAI,CAACqB,IAAI,EAAE,CAAC;IACvC,MAAMC,sBAAsB,GAAGJ,UAAU,CAACK,MAAM,CAAEC,SAAS,IAAKL,MAAM,CAACM,QAAQ,CAACD,SAAS,CAACE,EAAE,CAACC,QAAQ,EAAE,CAAC,CAAC;IACzGL,sBAAsB,CAACM,OAAO,CAAEJ,SAAS,IAAK;MAC5CA,SAAS,CAACK,KAAK,CAACC,MAAM,CAACC,WAAW,CAACC,gCAAa,CAACC,oBAAoB,CAAC,CAACjC,IAAI,GAAG,IAAI;IACpF,CAAC,CAAC;EACJ;AACF;AAAC"}
1
+ {"version":3,"names":["INSIGHT_CIRCULAR_DEPS_NAME","FindCycles","constructor","graphBuilder","runInsight","opts","graph","getGraphIds","message","data","undefined","cycles","findCycles","includeDeps","length","renderData","string","map","cycle","join","run","bareResult","renderedData","result","metaData","name","description","addAsComponentIssue","components","allIds","uniq","flat","componentsWithCircular","filter","component","includes","id","toString","forEach","state","issues","getOrCreate","IssuesClasses","CircularDependencies"],"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();\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();\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;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIO,MAAMA,0BAA0B,GAAG,UAAU;AAAC;AAEtC,MAAMC,UAAU,CAAoB;EAIjDC,WAAW,CAACC,YAAuB,EAAE;IAAA,8CAH9BH,0BAA0B;IAAA,qDACnB,kDAAkD;IAAA;IAG9D,IAAI,CAACG,YAAY,GAAGA,YAAY;EAClC;EACA,MAAcC,UAAU,CAACC,IAAwB,EAAsB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AU,CAACb,OAAO;MAC3Bc;IACF,CAAC;IAED,IAAID,UAAU,CAACb,OAAO,EAAE;MACtBe,MAAM,CAACf,OAAO,GAAGa,UAAU,CAACb,OAAO;IACrC;IACA,OAAOe,MAAM;EACf;EAEA,MAAMI,mBAAmB,CAACC,UAAuB,EAAE;IACjD,MAAML,MAAM,GAAG,MAAM,IAAI,CAACnB,UAAU,EAAE;IACtC,IAAI,CAACmB,MAAM,CAACd,IAAI,CAACK,MAAM,EAAE;MACvB,OAAO,CAAC;IACV;;IACA,MAAMe,MAAM,GAAG,IAAAC,cAAI,EAACP,MAAM,CAACd,IAAI,CAACsB,IAAI,EAAE,CAAC;IACvC,MAAMC,sBAAsB,GAAGJ,UAAU,CAACK,MAAM,CAAEC,SAAS,IAAKL,MAAM,CAACM,QAAQ,CAACD,SAAS,CAACE,EAAE,CAACC,QAAQ,EAAE,CAAC,CAAC;IACzGL,sBAAsB,CAACM,OAAO,CAAEJ,SAAS,IAAK;MAC5CA,SAAS,CAACK,KAAK,CAACC,MAAM,CAACC,WAAW,CAACC,gCAAa,CAACC,oBAAoB,CAAC,CAAClC,IAAI,GAAG,IAAI;IACpF,CAAC,CAAC;EACJ;AACF;AAAC"}
@@ -1,6 +1,7 @@
1
1
  import { Insight, InsightResult } from './insight';
2
2
  export declare type RunInsightOptions = {
3
- renderData: boolean;
3
+ renderData?: boolean;
4
+ includeDeps?: boolean;
4
5
  };
5
6
  export declare class InsightManager {
6
7
  /** insights is an insight registry */
@@ -95,7 +95,7 @@ class InsightManager {
95
95
  await (0, _pMapSeries().default)(insightNames, async insightName => {
96
96
  const insight = this.getByName(insightName);
97
97
  if (insight) {
98
- const insightRes = await insight.run();
98
+ const insightRes = await insight.run(opts);
99
99
  if (!opts.renderData) {
100
100
  delete insightRes.renderedData;
101
101
  }
@@ -1 +1 @@
1
- {"version":3,"names":["InsightManager","constructor","insights","Map","forEach","insight","register","name","has","InsightAlreadyExists","set","listInsights","keys","getByName","insightName","get","delete","InsightNotFound","run","insightNames","opts","res","pMapSeries","insightRes","renderData","renderedData","push","runAll","allInsightNames"],"sources":["insight-manager.ts"],"sourcesContent":["import pMapSeries from 'p-map-series';\nimport InsightAlreadyExists from './exceptions/insight-already-exists';\nimport InsightNotFound from './exceptions/insight-not-found';\nimport { Insight, InsightResult } from './insight';\n\nexport type RunInsightOptions = {\n renderData: boolean;\n};\nexport class InsightManager {\n /** insights is an insight registry */\n readonly insights: Map<string, Insight> = new Map();\n constructor(\n /**\n * array of registered insights\n */\n insights: Insight[]\n ) {\n insights.forEach((insight) => {\n this.register(insight);\n });\n }\n\n /**\n * registers a new insight and returns the updated insight registry map\n */\n register(insight: Insight) {\n const name = insight.name;\n if (this.insights.has(name)) {\n throw new InsightAlreadyExists(name);\n }\n this.insights.set(name, insight);\n }\n /**\n * list of all registered insights\n */\n listInsights(): string[] {\n return [...this.insights.keys()];\n }\n\n /**\n * gets a specific insight by its name or undefined if doesn't exist\n */\n getByName(insightName: string): Insight | undefined {\n return this.insights.get(insightName);\n }\n\n /**\n * deletes a specific insight by its name if exists\n */\n delete(insightName: string) {\n if (!this.insights.has(insightName)) {\n throw new InsightNotFound(insightName);\n }\n this.insights.delete(insightName);\n }\n\n /**\n * execute an array of insights\n *\n */\n async run(insightNames: string[], opts: RunInsightOptions): Promise<InsightResult[]> {\n const res: InsightResult[] = [];\n // the reason for not using Promise.all here is that the current both insights building the graph.\n // if it happens at the same time, some props are not populated in one of the instances. it obviously\n // should be fixed in the GraphBuilder class. see \"todo\" there.\n await pMapSeries(insightNames, async (insightName) => {\n const insight = this.getByName(insightName);\n if (insight) {\n const insightRes: InsightResult = await insight.run();\n if (!opts.renderData) {\n delete insightRes.renderedData;\n }\n res.push(insightRes);\n }\n });\n return res;\n }\n\n /**\n * execute all insights in the registry\n *\n */\n async runAll(opts: RunInsightOptions): Promise<InsightResult[]> {\n const allInsightNames = this.listInsights();\n return this.run(allInsightNames, opts);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAA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IAAAC,qBAAU,EAACH,YAAY,EAAE,MAAOL,WAAW,IAAK;MACpD,MAAMT,OAAO,GAAG,IAAI,CAACQ,SAAS,CAACC,WAAW,CAAC;MAC3C,IAAIT,OAAO,EAAE;QACX,MAAMkB,UAAyB,GAAG,MAAMlB,OAAO,CAACa,GAAG,EAAE;QACrD,IAAI,CAACE,IAAI,CAACI,UAAU,EAAE;UACpB,OAAOD,UAAU,CAACE,YAAY;QAChC;QACAJ,GAAG,CAACK,IAAI,CAACH,UAAU,CAAC;MACtB;IACF,CAAC,CAAC;IACF,OAAOF,GAAG;EACZ;;EAEA;AACF;AACA;AACA;EACE,MAAMM,MAAM,CAACP,IAAuB,EAA4B;IAC9D,MAAMQ,eAAe,GAAG,IAAI,CAACjB,YAAY,EAAE;IAC3C,OAAO,IAAI,CAACO,GAAG,CAACU,eAAe,EAAER,IAAI,CAAC;EACxC;AACF;AAAC"}
1
+ {"version":3,"names":["InsightManager","constructor","insights","Map","forEach","insight","register","name","has","InsightAlreadyExists","set","listInsights","keys","getByName","insightName","get","delete","InsightNotFound","run","insightNames","opts","res","pMapSeries","insightRes","renderData","renderedData","push","runAll","allInsightNames"],"sources":["insight-manager.ts"],"sourcesContent":["import pMapSeries from 'p-map-series';\nimport InsightAlreadyExists from './exceptions/insight-already-exists';\nimport InsightNotFound from './exceptions/insight-not-found';\nimport { Insight, InsightResult } from './insight';\n\nexport type RunInsightOptions = {\n renderData?: boolean;\n includeDeps?: boolean;\n};\nexport class InsightManager {\n /** insights is an insight registry */\n readonly insights: Map<string, Insight> = new Map();\n constructor(\n /**\n * array of registered insights\n */\n insights: Insight[]\n ) {\n insights.forEach((insight) => {\n this.register(insight);\n });\n }\n\n /**\n * registers a new insight and returns the updated insight registry map\n */\n register(insight: Insight) {\n const name = insight.name;\n if (this.insights.has(name)) {\n throw new InsightAlreadyExists(name);\n }\n this.insights.set(name, insight);\n }\n /**\n * list of all registered insights\n */\n listInsights(): string[] {\n return [...this.insights.keys()];\n }\n\n /**\n * gets a specific insight by its name or undefined if doesn't exist\n */\n getByName(insightName: string): Insight | undefined {\n return this.insights.get(insightName);\n }\n\n /**\n * deletes a specific insight by its name if exists\n */\n delete(insightName: string) {\n if (!this.insights.has(insightName)) {\n throw new InsightNotFound(insightName);\n }\n this.insights.delete(insightName);\n }\n\n /**\n * execute an array of insights\n *\n */\n async run(insightNames: string[], opts: RunInsightOptions): Promise<InsightResult[]> {\n const res: InsightResult[] = [];\n // the reason for not using Promise.all here is that the current both insights building the graph.\n // if it happens at the same time, some props are not populated in one of the instances. it obviously\n // should be fixed in the GraphBuilder class. see \"todo\" there.\n await pMapSeries(insightNames, async (insightName) => {\n const insight = this.getByName(insightName);\n if (insight) {\n const insightRes: InsightResult = await insight.run(opts);\n if (!opts.renderData) {\n delete insightRes.renderedData;\n }\n res.push(insightRes);\n }\n });\n return res;\n }\n\n /**\n * execute all insights in the registry\n *\n */\n async runAll(opts: RunInsightOptions): Promise<InsightResult[]> {\n const allInsightNames = this.listInsights();\n return this.run(allInsightNames, opts);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAOO,MAAMA,cAAc,CAAC;EAC1B;;EAEAC,WAAW;EACT;AACJ;AACA;EACIC,QAAmB,EACnB;IAAA,kDANwC,IAAIC,GAAG,EAAE;IAOjDD,QAAQ,CAACE,OAAO,CAAEC,OAAO,IAAK;MAC5B,IAAI,CAACC,QAAQ,CAACD,OAAO,CAAC;IACxB,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;EACEC,QAAQ,CAACD,OAAgB,EAAE;IACzB,MAAME,IAAI,GAAGF,OAAO,CAACE,IAAI;IACzB,IAAI,IAAI,CAACL,QAAQ,CAACM,GAAG,CAACD,IAAI,CAAC,EAAE;MAC3B,MAAM,KAAIE,+BAAoB,EAACF,IAAI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CAAC;EACxC;AACF;AAAC"}
package/dist/insight.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Component } from '@teambit/component';
2
+ import { RunInsightOptions } from './insight-manager';
2
3
  export declare type InsightMetaData = {
3
4
  name: string;
4
5
  description: string;
@@ -19,7 +20,7 @@ export interface Insight {
19
20
  /**
20
21
  * runs a specific insight using _runInsight, gets a RawResult, and uses _formatData to transform the output to InsightResult.
21
22
  */
22
- run(...args: any[]): Promise<InsightResult>;
23
+ run(opts?: RunInsightOptions): Promise<InsightResult>;
23
24
  /**
24
25
  * add the results from the insights as a component-issue so then bit-status could show them and bit-tag could block
25
26
  * them.
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["insight.ts"],"sourcesContent":["import { Component } from '@teambit/component';\n\nexport type InsightMetaData = {\n name: string;\n description: string;\n};\n\nexport type InsightResult = {\n metaData: InsightMetaData;\n message: string;\n data: any;\n renderedData?: string;\n};\n\nexport type RawResult = {\n message: string;\n data: any;\n};\n\nexport interface Insight {\n name: string;\n description: string;\n\n /**\n * runs a specific insight using _runInsight, gets a RawResult, and uses _formatData to transform the output to InsightResult.\n */\n run(...args: any[]): Promise<InsightResult>;\n\n /**\n * add the results from the insights as a component-issue so then bit-status could show them and bit-tag could block\n * them.\n */\n addAsComponentIssue?(components: Component[]): Promise<void>;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["insight.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport { RunInsightOptions } from './insight-manager';\n\nexport type InsightMetaData = {\n name: string;\n description: string;\n};\n\nexport type InsightResult = {\n metaData: InsightMetaData;\n message: string;\n data: any;\n renderedData?: string;\n};\n\nexport type RawResult = {\n message: string;\n data: any;\n};\n\nexport interface Insight {\n name: string;\n description: string;\n\n /**\n * runs a specific insight using _runInsight, gets a RawResult, and uses _formatData to transform the output to InsightResult.\n */\n run(opts?: RunInsightOptions): Promise<InsightResult>;\n\n /**\n * add the results from the insights as a component-issue so then bit-status could show them and bit-tag could block\n * them.\n */\n addAsComponentIssue?(components: Component[]): Promise<void>;\n}\n"],"mappings":""}
@@ -11,8 +11,10 @@ export default class InsightsCmd implements Command {
11
11
  constructor(insights: InsightsMain);
12
12
  report([names]: [string[]], options: {
13
13
  list: boolean;
14
+ includeDeps: boolean;
14
15
  }): Promise<string>;
15
- json([names]: [string[]], { list }: {
16
+ json([names]: [string[]], { list, includeDeps }: {
16
17
  list: boolean;
18
+ includeDeps: boolean;
17
19
  }): Promise<string[] | InsightResult[]>;
18
20
  }
@@ -28,7 +28,7 @@ class InsightsCmd {
28
28
  (0, _defineProperty2().default)(this, "description", 'Insights on component graph');
29
29
  (0, _defineProperty2().default)(this, "group", 'development');
30
30
  (0, _defineProperty2().default)(this, "private", true);
31
- (0, _defineProperty2().default)(this, "options", [['l', 'list', 'list all insights'], ['j', 'json', 'return the insights in json format']]);
31
+ (0, _defineProperty2().default)(this, "options", [['l', 'list', 'list all insights'], ['j', 'json', 'return the insights in json format'], ['', 'include-deps', 'include component dependencies that are not in this workspace']]);
32
32
  }
33
33
  async report([names], options) {
34
34
  if (options.list) {
@@ -36,19 +36,22 @@ class InsightsCmd {
36
36
  return JSON.stringify(results, null, 2);
37
37
  }
38
38
  const results = await this.insights.runInsights(names, {
39
- renderData: true
39
+ renderData: true,
40
+ includeDeps: options.includeDeps
40
41
  });
41
42
  return template(results);
42
43
  }
43
44
  async json([names], {
44
- list
45
+ list,
46
+ includeDeps
45
47
  }) {
46
48
  if (list) {
47
49
  const results = this.insights.listInsights();
48
50
  return results;
49
51
  }
50
52
  return this.insights.runInsights(names, {
51
- renderData: false
53
+ renderData: false,
54
+ includeDeps
52
55
  });
53
56
  }
54
57
  }
@@ -1 +1 @@
1
- {"version":3,"names":["InsightsCmd","constructor","insights","report","names","options","list","results","json","JSON","stringify","runInsights","renderData","template","listInsights","elements","map","result","chalk","cyan","bold","message","renderedData","join"],"sources":["insights.cmd.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { Command, CommandOptions } from '@teambit/cli';\nimport { InsightResult } from './insight';\nimport { InsightsMain } from './insights.main.runtime';\n\nexport default class InsightsCmd implements Command {\n name = 'insights [names...]';\n description = 'Insights on component graph';\n group = 'development';\n private = true;\n options = [\n ['l', 'list', 'list all insights'],\n ['j', 'json', 'return the insights in json format'],\n ] as CommandOptions;\n constructor(private insights: InsightsMain) {}\n\n async report([names]: [string[]], options: { list: boolean }): Promise<string> {\n if (options.list) {\n const results = await this.json([names], options);\n return JSON.stringify(results, null, 2);\n }\n const results = await this.insights.runInsights(names, { renderData: true });\n return template(results);\n }\n\n async json([names]: [string[]], { list }: { list: boolean }) {\n if (list) {\n const results = this.insights.listInsights();\n return results;\n }\n return this.insights.runInsights(names, { renderData: false });\n }\n}\n\nfunction template(results: InsightResult[]): string {\n const elements = results\n .map((result) => {\n return `\\n${chalk.cyan.bold(result.message)}\n ${result.renderedData}`;\n })\n .join('\\n');\n return elements;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAKe,MAAMA,WAAW,CAAoB;EASlDC,WAAW,CAASC,QAAsB,EAAE;IAAA,KAAxBA,QAAsB,GAAtBA,QAAsB;IAAA,8CARnC,qBAAqB;IAAA,qDACd,6BAA6B;IAAA,+CACnC,aAAa;IAAA,iDACX,IAAI;IAAA,iDACJ,CACR,CAAC,GAAG,EAAE,MAAM,EAAE,mBAAmB,CAAC,EAClC,CAAC,GAAG,EAAE,MAAM,EAAE,oCAAoC,CAAC,CACpD;EAC4C;EAE7C,MAAMC,MAAM,CAAC,CAACC,KAAK,CAAa,EAAEC,OAA0B,EAAmB;IAC7E,IAAIA,OAAO,CAACC,IAAI,EAAE;MAChB,MAAMC,OAAO,GAAG,MAAM,IAAI,CAACC,IAAI,CAAC,CAACJ,KAAK,CAAC,EAAEC,OAAO,CAAC;MACjD,OAAOI,IAAI,CAACC,SAAS,CAACH,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC;IACA,MAAMA,OAAO,GAAG,MAAM,IAAI,CAACL,QAAQ,CAACS,WAAW,CAACP,KAAK,EAAE;MAAEQ,UAAU,EAAE;IAAK,CAAC,CAAC;IAC5E,OAAOC,QAAQ,CAACN,OAAO,CAAC;EAC1B;EAEA,MAAMC,IAAI,CAAC,CAACJ,KAAK,CAAa,EAAE;IAAEE;EAAwB,CAAC,EAAE;IAC3D,IAAIA,IAAI,EAAE;MACR,MAAMC,OAAO,GAAG,IAAI,CAACL,QAAQ,CAACY,YAAY,EAAE;MAC5C,OAAOP,OAAO;IAChB;IACA,OAAO,IAAI,CAACL,QAAQ,CAACS,WAAW,CAACP,KAAK,EAAE;MAAEQ,UAAU,EAAE;IAAM,CAAC,CAAC;EAChE;AACF;AAAC;AAED,SAASC,QAAQ,CAACN,OAAwB,EAAU;EAClD,MAAMQ,QAAQ,GAAGR,OAAO,CACrBS,GAAG,CAAEC,MAAM,IAAK;IACf,OAAQ,KAAIC,gBAAK,CAACC,IAAI,CAACC,IAAI,CAACH,MAAM,CAACI,OAAO,CAAE;AAClD,IAAIJ,MAAM,CAACK,YAAa,EAAC;EACrB,CAAC,CAAC,CACDC,IAAI,CAAC,IAAI,CAAC;EACb,OAAOR,QAAQ;AACjB"}
1
+ {"version":3,"names":["InsightsCmd","constructor","insights","report","names","options","list","results","json","JSON","stringify","runInsights","renderData","includeDeps","template","listInsights","elements","map","result","chalk","cyan","bold","message","renderedData","join"],"sources":["insights.cmd.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { Command, CommandOptions } from '@teambit/cli';\nimport { InsightResult } from './insight';\nimport { InsightsMain } from './insights.main.runtime';\n\nexport default class InsightsCmd implements Command {\n name = 'insights [names...]';\n description = 'Insights on component graph';\n group = 'development';\n private = true;\n options = [\n ['l', 'list', 'list all insights'],\n ['j', 'json', 'return the insights in json format'],\n ['', 'include-deps', 'include component dependencies that are not in this workspace'],\n ] as CommandOptions;\n constructor(private insights: InsightsMain) {}\n\n async report([names]: [string[]], options: { list: boolean; includeDeps: boolean }): Promise<string> {\n if (options.list) {\n const results = await this.json([names], options);\n return JSON.stringify(results, null, 2);\n }\n const results = await this.insights.runInsights(names, { renderData: true, includeDeps: options.includeDeps });\n return template(results);\n }\n\n async json([names]: [string[]], { list, includeDeps }: { list: boolean; includeDeps: boolean }) {\n if (list) {\n const results = this.insights.listInsights();\n return results;\n }\n return this.insights.runInsights(names, { renderData: false, includeDeps });\n }\n}\n\nfunction template(results: InsightResult[]): string {\n const elements = results\n .map((result) => {\n return `\\n${chalk.cyan.bold(result.message)}\n ${result.renderedData}`;\n })\n .join('\\n');\n return elements;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAKe,MAAMA,WAAW,CAAoB;EAUlDC,WAAW,CAASC,QAAsB,EAAE;IAAA,KAAxBA,QAAsB,GAAtBA,QAAsB;IAAA,8CATnC,qBAAqB;IAAA,qDACd,6BAA6B;IAAA,+CACnC,aAAa;IAAA,iDACX,IAAI;IAAA,iDACJ,CACR,CAAC,GAAG,EAAE,MAAM,EAAE,mBAAmB,CAAC,EAClC,CAAC,GAAG,EAAE,MAAM,EAAE,oCAAoC,CAAC,EACnD,CAAC,EAAE,EAAE,cAAc,EAAE,+DAA+D,CAAC,CACtF;EAC4C;EAE7C,MAAMC,MAAM,CAAC,CAACC,KAAK,CAAa,EAAEC,OAAgD,EAAmB;IACnG,IAAIA,OAAO,CAACC,IAAI,EAAE;MAChB,MAAMC,OAAO,GAAG,MAAM,IAAI,CAACC,IAAI,CAAC,CAACJ,KAAK,CAAC,EAAEC,OAAO,CAAC;MACjD,OAAOI,IAAI,CAACC,SAAS,CAACH,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC;IACA,MAAMA,OAAO,GAAG,MAAM,IAAI,CAACL,QAAQ,CAACS,WAAW,CAACP,KAAK,EAAE;MAAEQ,UAAU,EAAE,IAAI;MAAEC,WAAW,EAAER,OAAO,CAACQ;IAAY,CAAC,CAAC;IAC9G,OAAOC,QAAQ,CAACP,OAAO,CAAC;EAC1B;EAEA,MAAMC,IAAI,CAAC,CAACJ,KAAK,CAAa,EAAE;IAAEE,IAAI;IAAEO;EAAqD,CAAC,EAAE;IAC9F,IAAIP,IAAI,EAAE;MACR,MAAMC,OAAO,GAAG,IAAI,CAACL,QAAQ,CAACa,YAAY,EAAE;MAC5C,OAAOR,OAAO;IAChB;IACA,OAAO,IAAI,CAACL,QAAQ,CAACS,WAAW,CAACP,KAAK,EAAE;MAAEQ,UAAU,EAAE,KAAK;MAAEC;IAAY,CAAC,CAAC;EAC7E;AACF;AAAC;AAED,SAASC,QAAQ,CAACP,OAAwB,EAAU;EAClD,MAAMS,QAAQ,GAAGT,OAAO,CACrBU,GAAG,CAAEC,MAAM,IAAK;IACf,OAAQ,KAAIC,gBAAK,CAACC,IAAI,CAACC,IAAI,CAACH,MAAM,CAACI,OAAO,CAAE;AAClD,IAAIJ,MAAM,CAACK,YAAa,EAAC;EACrB,CAAC,CAAC,CACDC,IAAI,CAAC,IAAI,CAAC;EACb,OAAOR,QAAQ;AACjB"}
@@ -1,5 +1,5 @@
1
1
  ;
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.explorer_insights@0.0.1055/dist/insights.docs.mdx';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.explorer_insights@0.0.1057/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": "0.0.1055",
3
+ "version": "0.0.1057",
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": "0.0.1055"
9
+ "version": "0.0.1057"
10
10
  },
11
11
  "dependencies": {
12
12
  "p-map-series": "2.1.0",
@@ -16,11 +16,11 @@
16
16
  "core-js": "^3.0.0",
17
17
  "@babel/runtime": "7.20.0",
18
18
  "@teambit/harmony": "0.4.6",
19
- "@teambit/graph": "0.0.1055",
20
- "@teambit/component": "0.0.1055",
19
+ "@teambit/graph": "0.0.1057",
20
+ "@teambit/component": "0.0.1057",
21
21
  "@teambit/cli": "0.0.711",
22
22
  "@teambit/component-issues": "0.0.89",
23
- "@teambit/issues": "0.0.363",
23
+ "@teambit/issues": "0.0.365",
24
24
  "@teambit/bit-error": "0.0.402"
25
25
  },
26
26
  "devDependencies": {