@teambit/component-compare 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.component/component-compare-preview"]=t():e["teambit.component/component-compare-preview"]=t()}(self,(()=>(()=>{"use strict";var e={69198:(e,t,o)=>{var n={id:"teambit.component/component-compare@1.0.109",homepage:"https://bit.cloud/teambit/component/component-compare",exported:!0};function r(){const e=a(o(87363));return r=function(){return e},e}function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Logo=void 0,r.__bit_component=n,a.__bit_component=n;const i=()=>r().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},r().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/bit-icons/compare.svg"}));i.__bit_component=n,t.Logo=i},87363:e=>{e.exports=React}},t={};function o(n){var r=t[n];if(void 0!==r)return r.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,o),a.exports}o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{compositions:()=>d,compositions_metadata:()=>u,overview:()=>l});var e={};o.r(e),o.d(e,{default:()=>s});var t=o(69198);o(87363);const r=MdxJsReact,a=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 n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e},p.apply(this,arguments)}var c={},m="wrapper";function s(e){var t=e.components,o=function(e,t){if(null==e)return{};var o,n,r=function(e,t){if(null==e)return{};var o,n,r={},a=Object.keys(e);for(n=0;n<a.length;n++)o=a[n],t.indexOf(o)>=0||(r[o]=e[o]);return r}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)o=a[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(r[o]=e[o])}return r}(e,i);return(0,r.mdx)(m,p({},c,o,{components:t,mdxType:"MDXLayout"}),(0,r.mdx)(a.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"},(0,r.mdx)("p",null,(0,r.mdx)("a",{parentName:"p",href:"https://bit.cloud/blog/introducing-a-new-feature-component-compare-l4qyxtoo?baseVersion=0.0.5"},"Introducing Component Compare")),(0,r.mdx)("p",null,"Component Compare allows users to compare two component versions. It provides a unified view of all the following differences,"),(0,r.mdx)("ul",null,(0,r.mdx)("li",{parentName:"ul"},"Code: Modifications made to the source code of the component."),(0,r.mdx)("li",{parentName:"ul"},"Composition: Changes made to how the component looks visually."),(0,r.mdx)("li",{parentName:"ul"},"Tests: Changes made to how the component is tested."),(0,r.mdx)("li",{parentName:"ul"},"Dependencies: Changes made to the component's dependency graph."),(0,r.mdx)("li",{parentName:"ul"},"Overview: Changes to the auto-generated documentation for the component."),(0,r.mdx)("li",{parentName:"ul"},"Aspects: Changes made to the extensions for the component."),(0,r.mdx)("li",{parentName:"ul"},"Changelog: Changes exported between the two selected versions"))))}s.isMDXComponent=!0;const d=[t],l=[e],u={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),n})()));
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component-compare@1.0.108/dist/component-compare.compositions.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component-compare@1.0.108/dist/component-compare.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component-compare@1.0.109/dist/component-compare.compositions.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component-compare@1.0.109/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": "1.0.108",
3
+ "version": "1.0.109",
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": "1.0.108"
9
+ "version": "1.0.109"
10
10
  },
11
11
  "dependencies": {
12
12
  "graphql-tag": "2.12.1",
@@ -21,23 +21,23 @@
21
21
  "@teambit/component.ui.component-compare.compare-aspects.compare-aspects": "0.0.145",
22
22
  "@teambit/component.ui.component-compare.component-compare": "0.0.171",
23
23
  "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.506",
24
- "@teambit/component": "1.0.108",
25
- "@teambit/builder": "1.0.108",
26
- "@teambit/cli": "0.0.840",
27
- "@teambit/dependency-resolver": "1.0.108",
28
- "@teambit/graphql": "1.0.108",
29
- "@teambit/logger": "0.0.933",
30
- "@teambit/scope": "1.0.108",
31
- "@teambit/tester": "1.0.108",
32
- "@teambit/workspace": "1.0.108",
33
- "@teambit/ui": "1.0.108"
24
+ "@teambit/component": "1.0.109",
25
+ "@teambit/builder": "1.0.109",
26
+ "@teambit/cli": "0.0.841",
27
+ "@teambit/dependency-resolver": "1.0.109",
28
+ "@teambit/graphql": "1.0.109",
29
+ "@teambit/logger": "0.0.934",
30
+ "@teambit/scope": "1.0.109",
31
+ "@teambit/tester": "1.0.109",
32
+ "@teambit/workspace": "1.0.109",
33
+ "@teambit/ui": "1.0.109"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/lodash.flatten": "4.4.6",
37
37
  "@types/mocha": "9.1.0",
38
38
  "@types/jest": "^29.2.2",
39
39
  "@types/testing-library__jest-dom": "^5.9.5",
40
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
40
+ "@teambit/harmony.envs.core-aspect-env": "0.0.14"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": "^17.0.0 || ^18.0.0",
@@ -1,7 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const ComponentCompareAspect = Aspect.create({
4
- id: 'teambit.component/component-compare',
5
- });
6
-
7
- export default ComponentCompareAspect;
@@ -1,77 +0,0 @@
1
- import gql from 'graphql-tag';
2
- import { ComponentCompareMain, ComponentCompareResult } from './component-compare.main.runtime';
3
-
4
- export function componentCompareSchema(componentCompareMain: ComponentCompareMain) {
5
- return {
6
- typeDefs: gql`
7
- type FileCompareResult {
8
- fileName: String!
9
- baseContent: String!
10
- compareContent: String!
11
- status: String
12
- diffOutput: String
13
- }
14
-
15
- type FieldCompareResult {
16
- fieldName: String!
17
- diffOutput: String
18
- }
19
-
20
- type ComponentCompareResult {
21
- # unique id for graphql - baseId + compareId
22
- id: String!
23
- code(fileName: String): [FileCompareResult!]!
24
- aspects(aspectName: String): [FieldCompareResult!]!
25
- tests(fileName: String): [FileCompareResult!]
26
- }
27
-
28
- extend type ComponentHost {
29
- compareComponent(baseId: String!, compareId: String!): ComponentCompareResult
30
- }
31
- `,
32
- resolvers: {
33
- ComponentHost: {
34
- compareComponent: async (_, { baseId, compareId }: { baseId: string; compareId: string }) => {
35
- return componentCompareMain.compare(baseId, compareId);
36
- },
37
- },
38
- ComponentCompareResult: {
39
- id: (result: ComponentCompareResult) => result.id,
40
- code: (result: ComponentCompareResult, { fileName }: { fileName?: string }) => {
41
- if (fileName) {
42
- return result.code
43
- .filter((codeFile) => codeFile.filePath === fileName)
44
- .map((c) => ({ ...c, fileName: c.filePath, baseContent: c.fromContent, compareContent: c.toContent }));
45
- }
46
-
47
- return result.code.map((c) => ({
48
- ...c,
49
- fileName: c.filePath,
50
- baseContent: c.fromContent,
51
- compareContent: c.toContent,
52
- }));
53
- },
54
- tests: (result: ComponentCompareResult, { fileName }: { fileName?: string }) => {
55
- if (fileName) {
56
- return result.tests
57
- .filter((testFile) => testFile.filePath === fileName)
58
- .map((c) => ({ ...c, fileName: c.filePath, baseContent: c.fromContent, compareContent: c.toContent }));
59
- }
60
-
61
- return result.tests.map((c) => ({
62
- ...c,
63
- fileName: c.filePath,
64
- baseContent: c.fromContent,
65
- compareContent: c.toContent,
66
- }));
67
- },
68
- aspects: (result: ComponentCompareResult, { fieldName }: { fieldName?: string }) => {
69
- if (fieldName) {
70
- return result.fields.filter((field) => field.fieldName === fieldName);
71
- }
72
- return result.fields;
73
- },
74
- },
75
- },
76
- };
77
- }
@@ -1,230 +0,0 @@
1
- import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
2
- import { BitError } from '@teambit/bit-error';
3
- import { WorkspaceAspect, OutsideWorkspaceError, Workspace } from '@teambit/workspace';
4
- import { ComponentID } from '@teambit/component-id';
5
- import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
6
- import hasWildcard from '@teambit/legacy/dist/utils/string/has-wildcard';
7
- import { ScopeMain, ScopeAspect } from '@teambit/scope';
8
- import { GraphqlAspect, GraphqlMain } from '@teambit/graphql';
9
- import BuilderAspect from '@teambit/builder';
10
- import GeneralError from '@teambit/legacy/dist/error/general-error';
11
- import DependencyResolverAspect, {
12
- DependencyList,
13
- DependencyResolverMain,
14
- SerializedDependency,
15
- } from '@teambit/dependency-resolver';
16
- import { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';
17
- import componentsDiff, {
18
- diffBetweenVersionsObjects,
19
- DiffResults,
20
- FieldsDiff,
21
- FileDiff,
22
- } from '@teambit/legacy/dist/consumer/component-ops/components-diff';
23
- import { TesterMain, TesterAspect } from '@teambit/tester';
24
- import ComponentAspect, { Component, ComponentMain } from '@teambit/component';
25
- import { componentCompareSchema } from './component-compare.graphql';
26
- import { ComponentCompareAspect } from './component-compare.aspect';
27
- import { DiffCmd } from './diff-cmd';
28
-
29
- export type ComponentCompareResult = {
30
- id: string;
31
- code: FileDiff[];
32
- fields: FieldsDiff[];
33
- tests: FileDiff[];
34
- };
35
-
36
- type ConfigDiff = {
37
- version?: string;
38
- dependencies?: string[];
39
- aspects?: Record<string, any>;
40
- };
41
-
42
- export class ComponentCompareMain {
43
- constructor(
44
- private componentAspect: ComponentMain,
45
- private scope: ScopeMain,
46
- private logger: Logger,
47
- private tester: TesterMain,
48
- private depResolver: DependencyResolverMain,
49
- private workspace?: Workspace
50
- ) {}
51
-
52
- async compare(baseIdStr: string, compareIdStr: string): Promise<ComponentCompareResult> {
53
- const host = this.componentAspect.getHost();
54
- const [baseCompId, compareCompId] = await host.resolveMultipleComponentIds([baseIdStr, compareIdStr]);
55
- const modelComponent = await this.scope.legacyScope.getModelComponentIfExist(compareCompId);
56
-
57
- if (!modelComponent) {
58
- throw new GeneralError(`component ${compareCompId.toString()} doesn't have any version yet`);
59
- }
60
-
61
- const baseVersion = baseCompId.version as string;
62
- const compareVersion = compareCompId.version as string;
63
-
64
- const repository = this.scope.legacyScope.objects;
65
- const baseVersionObject = await modelComponent.loadVersion(baseVersion, repository);
66
- const compareVersionObject = await modelComponent.loadVersion(compareVersion, repository);
67
-
68
- const diff: DiffResults = await diffBetweenVersionsObjects(
69
- modelComponent,
70
- baseVersionObject,
71
- compareVersionObject,
72
- baseVersion,
73
- compareVersion,
74
- this.scope.legacyScope,
75
- {}
76
- );
77
-
78
- const baseComponent = await host.get(baseCompId);
79
- const compareComponent = await host.get(compareCompId);
80
-
81
- const baseTestFiles =
82
- (baseComponent && (await this.tester.getTestFiles(baseComponent).map((file) => file.relative))) || [];
83
- const compareTestFiles =
84
- (compareComponent && (await this.tester.getTestFiles(compareComponent).map((file) => file.relative))) || [];
85
-
86
- const allTestFiles = [...baseTestFiles, ...compareTestFiles];
87
-
88
- const testFilesDiff = (diff.filesDiff || []).filter(
89
- (fileDiff: FileDiff) => allTestFiles.includes(fileDiff.filePath) && fileDiff.status !== 'UNCHANGED'
90
- );
91
-
92
- const compareResult = {
93
- id: `${baseCompId}-${compareCompId}`,
94
- code: diff.filesDiff || [],
95
- fields: diff.fieldsDiff || [],
96
- tests: testFilesDiff,
97
- };
98
-
99
- return compareResult;
100
- }
101
-
102
- async diffByCLIValues(values: string[], verbose: boolean, table: boolean): Promise<any> {
103
- if (!this.workspace) throw new OutsideWorkspaceError();
104
- const consumer = this.workspace.consumer;
105
- const { bitIds, version, toVersion } = await this.parseValues(values);
106
- if (!bitIds || !bitIds.length) {
107
- throw new BitError('there are no modified components to diff');
108
- }
109
- const diffResults = await componentsDiff(consumer, bitIds, version, toVersion, {
110
- verbose,
111
- formatDepsAsTable: table,
112
- });
113
- await consumer.onDestroy('diff');
114
- return diffResults;
115
- }
116
-
117
- async getConfigForDiffById(id: string): Promise<ConfigDiff> {
118
- const workspace = this.workspace;
119
- if (!workspace) throw new OutsideWorkspaceError();
120
- const componentId = await workspace.resolveComponentId(id);
121
- const component = await workspace.scope.get(componentId, false);
122
- if (!component) throw new Error(`getConfigForDiff: unable to find component ${id} in local scope`);
123
- return this.getConfigForDiffByCompObject(component);
124
- }
125
-
126
- async getConfigForDiffByCompObject(component: Component) {
127
- const depData = await this.depResolver.getDependencies(component);
128
- const serializedToString = (dep: SerializedDependency) => {
129
- const idWithoutVersion = dep.__type === 'package' ? dep.id : dep.id.split('@')[0];
130
- return `${idWithoutVersion}@${dep.version} (${dep.lifecycle}) ${dep.source ? `(${dep.source})` : ''}`;
131
- };
132
- const serializeAndSort = (deps: DependencyList) => {
133
- const serialized = deps.serialize().map(serializedToString);
134
- return serialized.sort();
135
- };
136
- const serializeAspect = (comp: Component) => {
137
- const aspects = comp.state.aspects.withoutEntries([BuilderAspect.id, DependencyResolverAspect.id]);
138
- // return aspects.serialize();
139
- return aspects.toLegacy().sortById().toConfigObject();
140
- };
141
- return {
142
- version: component.id.version,
143
- dependencies: serializeAndSort(depData),
144
- aspects: serializeAspect(component),
145
- };
146
- }
147
-
148
- private async parseValues(
149
- values: string[]
150
- ): Promise<{ bitIds: ComponentID[]; version?: string; toVersion?: string }> {
151
- if (!this.workspace) throw new OutsideWorkspaceError();
152
- // option #1: bit diff
153
- // no arguments
154
- if (!values.length) {
155
- const componentIds = await this.workspace.listTagPendingIds();
156
- return { bitIds: componentIds.map((id) => id) };
157
- }
158
- const firstValue = values[0];
159
- const lastValue = values[values.length - 1];
160
- const oneBeforeLastValue = values[values.length - 2];
161
- const isLastItemVersion = ComponentID.isValidVersion(lastValue);
162
- const isOneBeforeLastItemVersion = ComponentID.isValidVersion(oneBeforeLastValue);
163
- // option #2: bit diff [ids...]
164
- // all arguments are ids
165
- if (!isLastItemVersion) {
166
- return { bitIds: this.getBitIdsForDiff(values) };
167
- }
168
- // option #3: bit diff [id] [version]
169
- // last argument is a version, first argument is id
170
- if (!isOneBeforeLastItemVersion) {
171
- if (values.length !== 2) {
172
- throw new BitError(
173
- `bit diff [id] [version] syntax was used, however, ${values.length} arguments were given instead of 2`
174
- );
175
- }
176
- return { bitIds: this.getBitIdsForDiff([firstValue]), version: lastValue };
177
- }
178
- // option #4: bit diff [id] [version] [to_version]
179
- // last argument and one before the last are versions, first argument is id
180
- if (values.length !== 3) {
181
- throw new BitError(
182
- `bit diff [id] [version] [to_version] syntax was used, however, ${values.length} arguments were given instead of 3`
183
- );
184
- }
185
- return { bitIds: this.getBitIdsForDiff([firstValue]), version: oneBeforeLastValue, toVersion: lastValue };
186
- }
187
-
188
- private getBitIdsForDiff(ids: string[]): ComponentID[] {
189
- if (!this.workspace) throw new OutsideWorkspaceError();
190
- const consumer = this.workspace.consumer;
191
- if (hasWildcard(ids)) {
192
- const componentsList = new ComponentsList(consumer);
193
- return componentsList.listComponentsByIdsWithWildcard(ids);
194
- }
195
- return ids.map((id) => consumer.getParsedId(id));
196
- }
197
-
198
- static slots = [];
199
- static dependencies = [
200
- GraphqlAspect,
201
- ComponentAspect,
202
- ScopeAspect,
203
- LoggerAspect,
204
- CLIAspect,
205
- WorkspaceAspect,
206
- TesterAspect,
207
- DependencyResolverAspect,
208
- ];
209
- static runtime = MainRuntime;
210
- static async provider([graphql, component, scope, loggerMain, cli, workspace, tester, depResolver]: [
211
- GraphqlMain,
212
- ComponentMain,
213
- ScopeMain,
214
- LoggerMain,
215
- CLIMain,
216
- Workspace,
217
- TesterMain,
218
- DependencyResolverMain
219
- ]) {
220
- const logger = loggerMain.createLogger(ComponentCompareAspect.id);
221
- const componentCompareMain = new ComponentCompareMain(component, scope, logger, tester, depResolver, workspace);
222
- cli.register(new DiffCmd(componentCompareMain));
223
- graphql.register(componentCompareSchema(componentCompareMain));
224
- return componentCompareMain;
225
- }
226
- }
227
-
228
- ComponentCompareAspect.addRuntime(ComponentCompareMain);
229
-
230
- export default ComponentCompareMain;
package/diff-cmd.ts DELETED
@@ -1,30 +0,0 @@
1
- import { Command, CommandOptions } from '@teambit/cli';
2
- import { WILDCARD_HELP } from '@teambit/legacy/dist/constants';
3
- import { DiffResults, outputDiffResults } from '@teambit/legacy/dist/consumer/component-ops/components-diff';
4
- import { ComponentCompareMain } from './component-compare.main.runtime';
5
-
6
- export class DiffCmd implements Command {
7
- name = 'diff [values...]';
8
- group = 'development';
9
- description =
10
- "show the diff between the components' current source files and config, and their latest snapshot or tag";
11
- helpUrl = 'docs/components/merging-changes#compare-component-snaps';
12
- extendedDescription = `bit diff => compare all modified components to their model version
13
- bit diff [ids...] => compare the specified components against their modified states
14
- bit diff [id] [version] => compare component's current files and configs to the specified version of the component
15
- bit diff [id] [version] [to_version] => compare component's files and configs between the specified version and the to_version provided
16
- ${WILDCARD_HELP('diff')}`;
17
- alias = '';
18
- options = [
19
- ['v', 'verbose', 'show a more verbose output where possible'],
20
- ['t', 'table', 'show tables instead of plain text for dependencies diff'],
21
- ] as CommandOptions;
22
- loader = true;
23
-
24
- constructor(private componentCompareMain: ComponentCompareMain) {}
25
-
26
- async report([values = []]: [string[]], { verbose = false, table = false }: { verbose?: boolean; table: boolean }) {
27
- const diffResults: DiffResults[] = await this.componentCompareMain.diffByCLIValues(values, verbose, table);
28
- return outputDiffResults(diffResults);
29
- }
30
- }
package/index.ts DELETED
@@ -1,6 +0,0 @@
1
- import { ComponentCompareAspect } from './component-compare.aspect';
2
-
3
- export type { ComponentCompareMain } from './component-compare.main.runtime';
4
- export type { ComponentCompareUI, ComponentCompareNavSlot } from './component-compare.ui.runtime';
5
- export { ComponentCompareAspect };
6
- export default ComponentCompareAspect;