@teambit/component-compare 0.0.334 → 0.0.336

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,3 +1,5 @@
1
+ import { CLIMain } from '@teambit/cli';
2
+ import { Workspace } from '@teambit/workspace';
1
3
  import { ScopeMain } from '@teambit/scope';
2
4
  import { GraphqlMain } from '@teambit/graphql';
3
5
  import { LoggerMain, Logger } from '@teambit/logger';
@@ -12,11 +14,22 @@ export declare class ComponentCompareMain {
12
14
  private componentAspect;
13
15
  private scope;
14
16
  private logger;
15
- constructor(componentAspect: ComponentMain, scope: ScopeMain, logger: Logger);
17
+ private workspace?;
18
+ constructor(componentAspect: ComponentMain, scope: ScopeMain, logger: Logger, workspace?: Workspace | undefined);
16
19
  compare(baseIdStr: string, compareIdStr: string): Promise<ComponentCompareResult>;
20
+ diffByCLIValues(values: string[], verbose: boolean, table: boolean): Promise<any>;
21
+ private parseValues;
22
+ private getBitIdsForDiff;
17
23
  static slots: never[];
18
24
  static dependencies: import("@teambit/harmony").Aspect[];
19
25
  static runtime: import("@teambit/harmony").RuntimeDefinition;
20
- static provider([graphql, component, scope, loggerMain]: [GraphqlMain, ComponentMain, ScopeMain, LoggerMain]): Promise<ComponentCompareMain>;
26
+ static provider([graphql, component, scope, loggerMain, cli, workspace]: [
27
+ GraphqlMain,
28
+ ComponentMain,
29
+ ScopeMain,
30
+ LoggerMain,
31
+ CLIMain,
32
+ Workspace
33
+ ]): Promise<ComponentCompareMain>;
21
34
  }
22
35
  export default ComponentCompareMain;
@@ -21,6 +21,41 @@ function _cli() {
21
21
  };
22
22
  return data;
23
23
  }
24
+ function _bitError() {
25
+ const data = require("@teambit/bit-error");
26
+ _bitError = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ function _workspace() {
32
+ const data = require("@teambit/workspace");
33
+ _workspace = function () {
34
+ return data;
35
+ };
36
+ return data;
37
+ }
38
+ function _legacyBitId() {
39
+ const data = require("@teambit/legacy-bit-id");
40
+ _legacyBitId = function () {
41
+ return data;
42
+ };
43
+ return data;
44
+ }
45
+ function _componentsList() {
46
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/components-list"));
47
+ _componentsList = function () {
48
+ return data;
49
+ };
50
+ return data;
51
+ }
52
+ function _hasWildcard() {
53
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/string/has-wildcard"));
54
+ _hasWildcard = function () {
55
+ return data;
56
+ };
57
+ return data;
58
+ }
24
59
  function _scope() {
25
60
  const data = require("@teambit/scope");
26
61
  _scope = function () {
@@ -50,7 +85,7 @@ function _logger() {
50
85
  return data;
51
86
  }
52
87
  function _componentsDiff() {
53
- const data = require("@teambit/legacy/dist/consumer/component-ops/components-diff");
88
+ const data = _interopRequireWildcard(require("@teambit/legacy/dist/consumer/component-ops/components-diff"));
54
89
  _componentsDiff = function () {
55
90
  return data;
56
91
  };
@@ -77,14 +112,25 @@ function _componentCompare2() {
77
112
  };
78
113
  return data;
79
114
  }
115
+ function _diffCmd() {
116
+ const data = require("./diff-cmd");
117
+ _diffCmd = function () {
118
+ return data;
119
+ };
120
+ return data;
121
+ }
122
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
123
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
80
124
  class ComponentCompareMain {
81
- constructor(componentAspect, scope, logger) {
125
+ constructor(componentAspect, scope, logger, workspace) {
82
126
  this.componentAspect = componentAspect;
83
127
  this.scope = scope;
84
128
  this.logger = logger;
129
+ this.workspace = workspace;
85
130
  }
86
131
  async compare(baseIdStr, compareIdStr) {
87
132
  const host = this.componentAspect.getHost();
133
+ this.componentAspect.getHost();
88
134
  const [baseCompId, compareCompId] = await host.resolveMultipleComponentIds([baseIdStr, compareIdStr]);
89
135
  const modelComponent = await this.scope.legacyScope.getModelComponentIfExist(compareCompId._legacy);
90
136
  if (!modelComponent) {
@@ -103,16 +149,91 @@ class ComponentCompareMain {
103
149
  };
104
150
  return compareResult;
105
151
  }
106
- static async provider([graphql, component, scope, loggerMain]) {
152
+ async diffByCLIValues(values, verbose, table) {
153
+ if (!this.workspace) throw new (_workspace().OutsideWorkspaceError)();
154
+ const consumer = this.workspace.consumer;
155
+ const {
156
+ bitIds,
157
+ version,
158
+ toVersion
159
+ } = await this.parseValues(values);
160
+ if (!bitIds || !bitIds.length) {
161
+ throw new (_bitError().BitError)('there are no modified components to diff');
162
+ }
163
+ const diffResults = await (0, _componentsDiff().default)(consumer, bitIds, version, toVersion, {
164
+ verbose,
165
+ formatDepsAsTable: table
166
+ });
167
+ await consumer.onDestroy();
168
+ return diffResults;
169
+ }
170
+ async parseValues(values) {
171
+ if (!this.workspace) throw new (_workspace().OutsideWorkspaceError)();
172
+ const consumer = this.workspace.consumer;
173
+ // option #1: bit diff
174
+ // no arguments
175
+ if (!values.length) {
176
+ const componentsList = new (_componentsList().default)(consumer);
177
+ const bitIds = await componentsList.listModifiedComponents();
178
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
179
+ return {
180
+ bitIds
181
+ };
182
+ }
183
+ const firstValue = values[0];
184
+ const lastValue = values[values.length - 1];
185
+ const oneBeforeLastValue = values[values.length - 2];
186
+ const isLastItemVersion = _legacyBitId().BitId.isValidVersion(lastValue);
187
+ const isOneBeforeLastItemVersion = _legacyBitId().BitId.isValidVersion(oneBeforeLastValue);
188
+ // option #2: bit diff [ids...]
189
+ // all arguments are ids
190
+ if (!isLastItemVersion) {
191
+ return {
192
+ bitIds: this.getBitIdsForDiff(values)
193
+ };
194
+ }
195
+ // option #3: bit diff [id] [version]
196
+ // last argument is a version, first argument is id
197
+ if (!isOneBeforeLastItemVersion) {
198
+ if (values.length !== 2) {
199
+ throw new (_bitError().BitError)(`bit diff [id] [version] syntax was used, however, ${values.length} arguments were given instead of 2`);
200
+ }
201
+ return {
202
+ bitIds: this.getBitIdsForDiff([firstValue]),
203
+ version: lastValue
204
+ };
205
+ }
206
+ // option #4: bit diff [id] [version] [to_version]
207
+ // last argument and one before the last are versions, first argument is id
208
+ if (values.length !== 3) {
209
+ throw new (_bitError().BitError)(`bit diff [id] [version] [to_version] syntax was used, however, ${values.length} arguments were given instead of 3`);
210
+ }
211
+ return {
212
+ bitIds: this.getBitIdsForDiff([firstValue]),
213
+ version: oneBeforeLastValue,
214
+ toVersion: lastValue
215
+ };
216
+ }
217
+ getBitIdsForDiff(ids) {
218
+ if (!this.workspace) throw new (_workspace().OutsideWorkspaceError)();
219
+ const consumer = this.workspace.consumer;
220
+ if ((0, _hasWildcard().default)(ids)) {
221
+ const componentsList = new (_componentsList().default)(consumer);
222
+ return componentsList.listComponentsByIdsWithWildcard(ids);
223
+ }
224
+ return ids.map(id => consumer.getParsedId(id));
225
+ }
226
+ static async provider([graphql, component, scope, loggerMain, cli, workspace]) {
107
227
  const logger = loggerMain.createLogger(_componentCompare2().ComponentCompareAspect.id);
108
- const componentCompareMain = new ComponentCompareMain(component, scope, logger);
228
+ const componentCompareMain = new ComponentCompareMain(component, scope, logger, workspace);
229
+ cli.register(new (_diffCmd().DiffCmd)(componentCompareMain));
109
230
  graphql.register((0, _componentCompare().componentCompareSchema)(componentCompareMain));
110
231
  return componentCompareMain;
111
232
  }
112
233
  }
113
234
  exports.ComponentCompareMain = ComponentCompareMain;
114
235
  (0, _defineProperty2().default)(ComponentCompareMain, "slots", []);
115
- (0, _defineProperty2().default)(ComponentCompareMain, "dependencies", [_graphql().GraphqlAspect, _component().default, _scope().ScopeAspect, _logger().LoggerAspect]);
236
+ (0, _defineProperty2().default)(ComponentCompareMain, "dependencies", [_graphql().GraphqlAspect, _component().default, _scope().ScopeAspect, _logger().LoggerAspect, _cli().CLIAspect, _workspace().WorkspaceAspect]);
116
237
  (0, _defineProperty2().default)(ComponentCompareMain, "runtime", _cli().MainRuntime);
117
238
  _componentCompare2().ComponentCompareAspect.addRuntime(ComponentCompareMain);
118
239
  var _default = ComponentCompareMain;
@@ -1 +1 @@
1
- {"version":3,"names":["ComponentCompareMain","constructor","componentAspect","scope","logger","compare","baseIdStr","compareIdStr","host","getHost","baseCompId","compareCompId","resolveMultipleComponentIds","modelComponent","legacyScope","getModelComponentIfExist","_legacy","GeneralError","toString","baseVersion","version","compareVersion","repository","objects","baseVersionObject","loadVersion","compareVersionObject","diff","diffBetweenVersionsObjects","compareResult","id","code","filesDiff","fields","fieldsDiff","provider","graphql","component","loggerMain","createLogger","ComponentCompareAspect","componentCompareMain","register","componentCompareSchema","GraphqlAspect","ComponentAspect","ScopeAspect","LoggerAspect","MainRuntime","addRuntime"],"sources":["component-compare.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\nimport { ScopeMain, ScopeAspect } from '@teambit/scope';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport GeneralError from '@teambit/legacy/dist/error/general-error';\nimport { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';\nimport {\n diffBetweenVersionsObjects,\n DiffResults,\n FieldsDiff,\n FileDiff,\n} from '@teambit/legacy/dist/consumer/component-ops/components-diff';\nimport ComponentAspect, { ComponentMain } from '@teambit/component';\nimport { componentCompareSchema } from './component-compare.graphql';\nimport { ComponentCompareAspect } from './component-compare.aspect';\n\nexport type ComponentCompareResult = {\n id: string;\n code: FileDiff[];\n fields: FieldsDiff[];\n};\n\nexport class ComponentCompareMain {\n constructor(private componentAspect: ComponentMain, private scope: ScopeMain, private logger: Logger) {}\n\n async compare(baseIdStr: string, compareIdStr: string): Promise<ComponentCompareResult> {\n const host = this.componentAspect.getHost();\n const [baseCompId, compareCompId] = await host.resolveMultipleComponentIds([baseIdStr, compareIdStr]);\n const modelComponent = await this.scope.legacyScope.getModelComponentIfExist(compareCompId._legacy);\n\n if (!modelComponent) {\n throw new GeneralError(`component ${compareCompId.toString()} doesn't have any version yet`);\n }\n\n const baseVersion = baseCompId.version as string;\n const compareVersion = compareCompId.version as string;\n\n const repository = this.scope.legacyScope.objects;\n const baseVersionObject = await modelComponent.loadVersion(baseVersion, repository);\n const compareVersionObject = await modelComponent.loadVersion(compareVersion, repository);\n\n const diff: DiffResults = await diffBetweenVersionsObjects(\n modelComponent,\n baseVersionObject,\n compareVersionObject,\n baseVersion,\n compareVersion,\n this.scope.legacyScope,\n {}\n );\n\n const compareResult = {\n id: `${baseCompId}-${compareCompId}`,\n code: diff.filesDiff || [],\n fields: diff.fieldsDiff || [],\n };\n\n return compareResult;\n }\n\n static slots = [];\n static dependencies = [GraphqlAspect, ComponentAspect, ScopeAspect, LoggerAspect];\n static runtime = MainRuntime;\n static async provider([graphql, component, scope, loggerMain]: [GraphqlMain, ComponentMain, ScopeMain, LoggerMain]) {\n const logger = loggerMain.createLogger(ComponentCompareAspect.id);\n const componentCompareMain = new ComponentCompareMain(component, scope, logger);\n graphql.register(componentCompareSchema(componentCompareMain));\n return componentCompareMain;\n }\n}\n\nComponentCompareAspect.addRuntime(ComponentCompareMain);\n\nexport default ComponentCompareMain;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;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ACJ,cAAc,EAAEC,UAAU,CAAC;IAEzF,MAAMK,IAAiB,GAAG,MAAM,IAAAC,4CAA0B,EACxDf,cAAc,EACdW,iBAAiB,EACjBE,oBAAoB,EACpBP,WAAW,EACXE,cAAc,EACd,IAAI,CAAClB,KAAK,CAACW,WAAW,EACtB,CAAC,CAAC,CACH;IAED,MAAMe,aAAa,GAAG;MACpBC,EAAE,EAAG,GAAEpB,UAAW,IAAGC,aAAc,EAAC;MACpCoB,IAAI,EAAEJ,IAAI,CAACK,SAAS,IAAI,EAAE;MAC1BC,MAAM,EAAEN,IAAI,CAACO,UAAU,IAAI;IAC7B,CAAC;IAED,OAAOL,aAAa;EACtB;EAKA,aAAaM,QAAQ,CAAC,CAACC,OAAO,EAAEC,SAAS,EAAElC,KAAK,EAAEmC,UAAU,CAAsD,EAAE;IAClH,MAAMlC,MAAM,GAAGkC,UAAU,CAACC,YAAY,CAACC,2CAAsB,CAACV,EAAE,CAAC;IACjE,MAAMW,oBAAoB,GAAG,IAAIzC,oBAAoB,CAACqC,SAAS,EAAElC,KAAK,EAAEC,MAAM,CAAC;IAC/EgC,OAAO,CAACM,QAAQ,CAAC,IAAAC,0CAAsB,EAACF,oBAAoB,CAAC,CAAC;IAC9D,OAAOA,oBAAoB;EAC7B;AACF;AAAC;AAAA,gCA/CYzC,oBAAoB,WAsChB,EAAE;AAAA,gCAtCNA,oBAAoB,kBAuCT,CAAC4C,wBAAa,EAAEC,oBAAe,EAAEC,oBAAW,EAAEC,sBAAY,CAAC;AAAA,gCAvCtE/C,oBAAoB,aAwCdgD,kBAAW;AAS9BR,2CAAsB,CAACS,UAAU,CAACjD,oBAAoB,CAAC;AAAC,eAEzCA,oBAAoB;AAAA"}
1
+ {"version":3,"names":["ComponentCompareMain","constructor","componentAspect","scope","logger","workspace","compare","baseIdStr","compareIdStr","host","getHost","baseCompId","compareCompId","resolveMultipleComponentIds","modelComponent","legacyScope","getModelComponentIfExist","_legacy","GeneralError","toString","baseVersion","version","compareVersion","repository","objects","baseVersionObject","loadVersion","compareVersionObject","diff","diffBetweenVersionsObjects","compareResult","id","code","filesDiff","fields","fieldsDiff","diffByCLIValues","values","verbose","table","OutsideWorkspaceError","consumer","bitIds","toVersion","parseValues","length","BitError","diffResults","componentsDiff","formatDepsAsTable","onDestroy","componentsList","ComponentsList","listModifiedComponents","firstValue","lastValue","oneBeforeLastValue","isLastItemVersion","BitId","isValidVersion","isOneBeforeLastItemVersion","getBitIdsForDiff","ids","hasWildcard","listComponentsByIdsWithWildcard","map","getParsedId","provider","graphql","component","loggerMain","cli","createLogger","ComponentCompareAspect","componentCompareMain","register","DiffCmd","componentCompareSchema","GraphqlAspect","ComponentAspect","ScopeAspect","LoggerAspect","CLIAspect","WorkspaceAspect","MainRuntime","addRuntime"],"sources":["component-compare.main.runtime.ts"],"sourcesContent":["import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { BitError } from '@teambit/bit-error';\nimport { WorkspaceAspect, OutsideWorkspaceError, Workspace } from '@teambit/workspace';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';\nimport hasWildcard from '@teambit/legacy/dist/utils/string/has-wildcard';\nimport { ScopeMain, ScopeAspect } from '@teambit/scope';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport GeneralError from '@teambit/legacy/dist/error/general-error';\nimport { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';\nimport componentsDiff, {\n diffBetweenVersionsObjects,\n DiffResults,\n FieldsDiff,\n FileDiff,\n} from '@teambit/legacy/dist/consumer/component-ops/components-diff';\nimport ComponentAspect, { ComponentMain } from '@teambit/component';\nimport { componentCompareSchema } from './component-compare.graphql';\nimport { ComponentCompareAspect } from './component-compare.aspect';\nimport { DiffCmd } from './diff-cmd';\n\nexport type ComponentCompareResult = {\n id: string;\n code: FileDiff[];\n fields: FieldsDiff[];\n};\n\nexport class ComponentCompareMain {\n constructor(\n private componentAspect: ComponentMain,\n private scope: ScopeMain,\n private logger: Logger,\n private workspace?: Workspace\n ) {}\n\n async compare(baseIdStr: string, compareIdStr: string): Promise<ComponentCompareResult> {\n const host = this.componentAspect.getHost();\n this.componentAspect.getHost();\n const [baseCompId, compareCompId] = await host.resolveMultipleComponentIds([baseIdStr, compareIdStr]);\n const modelComponent = await this.scope.legacyScope.getModelComponentIfExist(compareCompId._legacy);\n\n if (!modelComponent) {\n throw new GeneralError(`component ${compareCompId.toString()} doesn't have any version yet`);\n }\n\n const baseVersion = baseCompId.version as string;\n const compareVersion = compareCompId.version as string;\n\n const repository = this.scope.legacyScope.objects;\n const baseVersionObject = await modelComponent.loadVersion(baseVersion, repository);\n const compareVersionObject = await modelComponent.loadVersion(compareVersion, repository);\n\n const diff: DiffResults = await diffBetweenVersionsObjects(\n modelComponent,\n baseVersionObject,\n compareVersionObject,\n baseVersion,\n compareVersion,\n this.scope.legacyScope,\n {}\n );\n\n const compareResult = {\n id: `${baseCompId}-${compareCompId}`,\n code: diff.filesDiff || [],\n fields: diff.fieldsDiff || [],\n };\n\n return compareResult;\n }\n\n async diffByCLIValues(values: string[], verbose: boolean, table: boolean): Promise<any> {\n if (!this.workspace) throw new OutsideWorkspaceError();\n const consumer = this.workspace.consumer;\n const { bitIds, version, toVersion } = await this.parseValues(values);\n if (!bitIds || !bitIds.length) {\n throw new BitError('there are no modified components to diff');\n }\n const diffResults = await componentsDiff(consumer, bitIds, version, toVersion, {\n verbose,\n formatDepsAsTable: table,\n });\n await consumer.onDestroy();\n return diffResults;\n }\n\n private async parseValues(values: string[]): Promise<{ bitIds: BitId[]; version?: string; toVersion?: string }> {\n if (!this.workspace) throw new OutsideWorkspaceError();\n const consumer = this.workspace.consumer;\n // option #1: bit diff\n // no arguments\n if (!values.length) {\n const componentsList = new ComponentsList(consumer);\n const bitIds = await componentsList.listModifiedComponents();\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n return { bitIds };\n }\n const firstValue = values[0];\n const lastValue = values[values.length - 1];\n const oneBeforeLastValue = values[values.length - 2];\n const isLastItemVersion = BitId.isValidVersion(lastValue);\n const isOneBeforeLastItemVersion = BitId.isValidVersion(oneBeforeLastValue);\n // option #2: bit diff [ids...]\n // all arguments are ids\n if (!isLastItemVersion) {\n return { bitIds: this.getBitIdsForDiff(values) };\n }\n // option #3: bit diff [id] [version]\n // last argument is a version, first argument is id\n if (!isOneBeforeLastItemVersion) {\n if (values.length !== 2) {\n throw new BitError(\n `bit diff [id] [version] syntax was used, however, ${values.length} arguments were given instead of 2`\n );\n }\n return { bitIds: this.getBitIdsForDiff([firstValue]), version: lastValue };\n }\n // option #4: bit diff [id] [version] [to_version]\n // last argument and one before the last are versions, first argument is id\n if (values.length !== 3) {\n throw new BitError(\n `bit diff [id] [version] [to_version] syntax was used, however, ${values.length} arguments were given instead of 3`\n );\n }\n return { bitIds: this.getBitIdsForDiff([firstValue]), version: oneBeforeLastValue, toVersion: lastValue };\n }\n\n private getBitIdsForDiff(ids: string[]): BitId[] {\n if (!this.workspace) throw new OutsideWorkspaceError();\n const consumer = this.workspace.consumer;\n if (hasWildcard(ids)) {\n const componentsList = new ComponentsList(consumer);\n return componentsList.listComponentsByIdsWithWildcard(ids);\n }\n return ids.map((id) => consumer.getParsedId(id));\n }\n\n static slots = [];\n static dependencies = [GraphqlAspect, ComponentAspect, ScopeAspect, LoggerAspect, CLIAspect, WorkspaceAspect];\n static runtime = MainRuntime;\n static async provider([graphql, component, scope, loggerMain, cli, workspace]: [\n GraphqlMain,\n ComponentMain,\n ScopeMain,\n LoggerMain,\n CLIMain,\n Workspace\n ]) {\n const logger = loggerMain.createLogger(ComponentCompareAspect.id);\n const componentCompareMain = new ComponentCompareMain(component, scope, logger, workspace);\n cli.register(new DiffCmd(componentCompareMain));\n graphql.register(componentCompareSchema(componentCompareMain));\n return componentCompareMain;\n }\n}\n\nComponentCompareAspect.addRuntime(ComponentCompareMain);\n\nexport default ComponentCompareMain;\n"],"mappings":";;;;;;;;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C,MAAM,EAAEC,SAAS,CAAC;IAC1FkE,GAAG,CAACI,QAAQ,CAAC,KAAIC,kBAAO,EAACF,oBAAoB,CAAC,CAAC;IAC/CN,OAAO,CAACO,QAAQ,CAAC,IAAAE,0CAAsB,EAACH,oBAAoB,CAAC,CAAC;IAC9D,OAAOA,oBAAoB;EAC7B;AACF;AAAC;AAAA,gCA/HY1E,oBAAoB,WA8GhB,EAAE;AAAA,gCA9GNA,oBAAoB,kBA+GT,CAAC8E,wBAAa,EAAEC,oBAAe,EAAEC,oBAAW,EAAEC,sBAAY,EAAEC,gBAAS,EAAEC,4BAAe,CAAC;AAAA,gCA/GlGnF,oBAAoB,aAgHdoF,kBAAW;AAiB9BX,2CAAsB,CAACY,UAAU,CAACrF,oBAAoB,CAAC;AAAC,eAEzCA,oBAAoB;AAAA"}
@@ -0,0 +1,18 @@
1
+ import { Command, CommandOptions } from '@teambit/cli';
2
+ import { ComponentCompareMain } from './component-compare.main.runtime';
3
+ export declare class DiffCmd implements Command {
4
+ private componentCompareMain;
5
+ name: string;
6
+ group: string;
7
+ description: string;
8
+ helpUrl: string;
9
+ extendedDescription: string;
10
+ alias: string;
11
+ options: CommandOptions;
12
+ loader: boolean;
13
+ constructor(componentCompareMain: ComponentCompareMain);
14
+ report([values]: [string[]], { verbose, table }: {
15
+ verbose?: boolean;
16
+ table: boolean;
17
+ }): Promise<string>;
18
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ require("core-js/modules/es.array.iterator.js");
5
+ require("core-js/modules/es.promise.js");
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.DiffCmd = void 0;
10
+ function _defineProperty2() {
11
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
+ _defineProperty2 = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _constants() {
18
+ const data = require("@teambit/legacy/dist/constants");
19
+ _constants = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _componentsDiff() {
25
+ const data = require("@teambit/legacy/dist/consumer/component-ops/components-diff");
26
+ _componentsDiff = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ class DiffCmd {
32
+ constructor(componentCompareMain) {
33
+ this.componentCompareMain = componentCompareMain;
34
+ (0, _defineProperty2().default)(this, "name", 'diff [values...]');
35
+ (0, _defineProperty2().default)(this, "group", 'development');
36
+ (0, _defineProperty2().default)(this, "description", "show the diff between the components' source files and config");
37
+ (0, _defineProperty2().default)(this, "helpUrl", 'docs/components/merging-changes#compare-component-snaps');
38
+ (0, _defineProperty2().default)(this, "extendedDescription", `bit diff => compare all modified components to their model version
39
+ bit diff [ids...] => compare the specified components against their modified states
40
+ bit diff [id] [version] => compare the specified version to used or modified files
41
+ bit diff [id] [version] [to_version] => compare the specified version files to to_version files
42
+ ${(0, _constants().WILDCARD_HELP)('diff')}`);
43
+ (0, _defineProperty2().default)(this, "alias", '');
44
+ (0, _defineProperty2().default)(this, "options", [['v', 'verbose', 'show a more verbose output when possible'], ['t', 'table', 'show tables instead of plain text for dependencies diff']]);
45
+ (0, _defineProperty2().default)(this, "loader", true);
46
+ }
47
+ async report([values = []], {
48
+ verbose = false,
49
+ table = false
50
+ }) {
51
+ const diffResults = await this.componentCompareMain.diffByCLIValues(values, verbose, table);
52
+ return (0, _componentsDiff().outputDiffResults)(diffResults);
53
+ }
54
+ }
55
+ exports.DiffCmd = DiffCmd;
56
+
57
+ //# sourceMappingURL=diff-cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DiffCmd","constructor","componentCompareMain","WILDCARD_HELP","report","values","verbose","table","diffResults","diffByCLIValues","outputDiffResults"],"sources":["diff-cmd.ts"],"sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport { WILDCARD_HELP } from '@teambit/legacy/dist/constants';\nimport { DiffResults, outputDiffResults } from '@teambit/legacy/dist/consumer/component-ops/components-diff';\nimport { ComponentCompareMain } from './component-compare.main.runtime';\n\nexport class DiffCmd implements Command {\n name = 'diff [values...]';\n group = 'development';\n description = \"show the diff between the components' source files and config\";\n helpUrl = 'docs/components/merging-changes#compare-component-snaps';\n extendedDescription = `bit diff => compare all modified components to their model version\nbit diff [ids...] => compare the specified components against their modified states\nbit diff [id] [version] => compare the specified version to used or modified files\nbit diff [id] [version] [to_version] => compare the specified version files to to_version files\n${WILDCARD_HELP('diff')}`;\n alias = '';\n options = [\n ['v', 'verbose', 'show a more verbose output when possible'],\n ['t', 'table', 'show tables instead of plain text for dependencies diff'],\n ] as CommandOptions;\n loader = true;\n\n constructor(private componentCompareMain: ComponentCompareMain) {}\n\n async report([values = []]: [string[]], { verbose = false, table = false }: { verbose?: boolean; table: boolean }) {\n const diffResults: DiffResults[] = await this.componentCompareMain.diffByCLIValues(values, verbose, table);\n return outputDiffResults(diffResults);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGO,MAAMA,OAAO,CAAoB;EAiBtCC,WAAW,CAASC,oBAA0C,EAAE;IAAA,KAA5CA,oBAA0C,GAA1CA,oBAA0C;IAAA,8CAhBvD,kBAAkB;IAAA,+CACjB,aAAa;IAAA,qDACP,+DAA+D;IAAA,iDACnE,yDAAyD;IAAA,6DAC5C;AACzB;AACA;AACA;AACA,EAAE,IAAAC,0BAAa,EAAC,MAAM,CAAE,EAAC;IAAA,+CACf,EAAE;IAAA,iDACA,CACR,CAAC,GAAG,EAAE,SAAS,EAAE,0CAA0C,CAAC,EAC5D,CAAC,GAAG,EAAE,OAAO,EAAE,yDAAyD,CAAC,CAC1E;IAAA,gDACQ,IAAI;EAEoD;EAEjE,MAAMC,MAAM,CAAC,CAACC,MAAM,GAAG,EAAE,CAAa,EAAE;IAAEC,OAAO,GAAG,KAAK;IAAEC,KAAK,GAAG;EAA6C,CAAC,EAAE;IACjH,MAAMC,WAA0B,GAAG,MAAM,IAAI,CAACN,oBAAoB,CAACO,eAAe,CAACJ,MAAM,EAAEC,OAAO,EAAEC,KAAK,CAAC;IAC1G,OAAO,IAAAG,mCAAiB,EAACF,WAAW,CAAC;EACvC;AACF;AAAC"}
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component-compare@0.0.334/dist/component-compare.compositions.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component-compare@0.0.334/dist/component-compare.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component-compare@0.0.336/dist/component-compare.compositions.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component-compare@0.0.336/dist/component-compare.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/component-compare",
3
- "version": "0.0.334",
3
+ "version": "0.0.336",
4
4
  "homepage": "https://bit.cloud/teambit/component/component-compare",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.component",
8
8
  "name": "component-compare",
9
- "version": "0.0.334"
9
+ "version": "0.0.336"
10
10
  },
11
11
  "dependencies": {
12
12
  "graphql-tag": "2.12.1",
@@ -14,19 +14,22 @@
14
14
  "core-js": "^3.0.0",
15
15
  "@babel/runtime": "7.20.0",
16
16
  "@teambit/harmony": "0.4.6",
17
+ "@teambit/legacy-bit-id": "0.0.423",
17
18
  "@teambit/component.ui.component-compare.models.component-compare-change-type": "0.0.1",
18
- "@teambit/component.ui.component-compare.models.component-compare-props": "0.0.39",
19
- "@teambit/component": "0.0.1086",
19
+ "@teambit/component.ui.component-compare.models.component-compare-props": "0.0.40",
20
+ "@teambit/component": "0.0.1088",
20
21
  "@teambit/ui-foundation.ui.menu-widget-icon": "0.0.497",
21
- "@teambit/cli": "0.0.730",
22
- "@teambit/graphql": "0.0.1086",
23
- "@teambit/logger": "0.0.823",
24
- "@teambit/scope": "0.0.1086",
25
- "@teambit/component.ui.component-compare.changelog": "0.0.106",
26
- "@teambit/component.ui.component-compare.compare-aspects.compare-aspects": "0.0.81",
27
- "@teambit/component.ui.component-compare.component-compare": "0.0.105",
22
+ "@teambit/bit-error": "0.0.402",
23
+ "@teambit/cli": "0.0.731",
24
+ "@teambit/graphql": "0.0.1088",
25
+ "@teambit/logger": "0.0.824",
26
+ "@teambit/scope": "0.0.1088",
27
+ "@teambit/workspace": "0.0.1088",
28
+ "@teambit/component.ui.component-compare.changelog": "0.0.107",
29
+ "@teambit/component.ui.component-compare.compare-aspects.compare-aspects": "0.0.82",
30
+ "@teambit/component.ui.component-compare.component-compare": "0.0.106",
28
31
  "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.501",
29
- "@teambit/ui": "0.0.1086"
32
+ "@teambit/ui": "0.0.1088"
30
33
  },
31
34
  "devDependencies": {
32
35
  "@types/react": "^17.0.8",
@@ -39,7 +42,7 @@
39
42
  },
40
43
  "peerDependencies": {
41
44
  "react-router-dom": "^6.0.0",
42
- "@teambit/legacy": "1.0.511",
45
+ "@teambit/legacy": "1.0.512",
43
46
  "react": "^16.8.0 || ^17.0.0",
44
47
  "react-dom": "^16.8.0 || ^17.0.0"
45
48
  },