@teambit/merging 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,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports["teambit.component/merging-preview"]=o():e["teambit.component/merging-preview"]=o()}(self,(()=>(()=>{"use strict";var e={d:(o,t)=>{for(var r in t)e.o(t,r)&&!e.o(o,r)&&Object.defineProperty(o,r,{enumerable:!0,get:t[r]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},o={};e.r(o),e.d(o,{compositions:()=>t,compositions_metadata:()=>n,overview:()=>r});const t=[],r=[],n={compositions:[]};return o})()));
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/merging",
3
- "version": "1.0.108",
3
+ "version": "1.0.109",
4
4
  "homepage": "https://bit.cloud/teambit/component/merging",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.component",
8
8
  "name": "merging",
9
- "version": "1.0.108"
9
+ "version": "1.0.109"
10
10
  },
11
11
  "dependencies": {
12
12
  "lodash": "4.17.21",
@@ -18,20 +18,20 @@
18
18
  "@teambit/bit-error": "0.0.404",
19
19
  "@teambit/lane-id": "0.0.311",
20
20
  "@teambit/harmony": "0.4.6",
21
- "@teambit/dependency-resolver": "1.0.108",
22
- "@teambit/builder": "1.0.108",
23
- "@teambit/envs": "1.0.108",
24
- "@teambit/logger": "0.0.933",
25
- "@teambit/cli": "0.0.840",
26
- "@teambit/global-config": "0.0.842",
27
- "@teambit/importer": "1.0.108",
28
- "@teambit/workspace": "1.0.108",
29
- "@teambit/checkout": "1.0.108",
30
- "@teambit/component-writer": "1.0.108",
31
- "@teambit/config": "0.0.859",
32
- "@teambit/install": "1.0.108",
33
- "@teambit/remove": "1.0.108",
34
- "@teambit/snapping": "1.0.108"
21
+ "@teambit/dependency-resolver": "1.0.109",
22
+ "@teambit/builder": "1.0.109",
23
+ "@teambit/envs": "1.0.109",
24
+ "@teambit/logger": "0.0.934",
25
+ "@teambit/cli": "0.0.841",
26
+ "@teambit/global-config": "0.0.843",
27
+ "@teambit/importer": "1.0.109",
28
+ "@teambit/workspace": "1.0.109",
29
+ "@teambit/checkout": "1.0.109",
30
+ "@teambit/component-writer": "1.0.109",
31
+ "@teambit/config": "0.0.860",
32
+ "@teambit/install": "1.0.109",
33
+ "@teambit/remove": "1.0.109",
34
+ "@teambit/snapping": "1.0.109"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/lodash": "4.14.165",
@@ -39,7 +39,7 @@
39
39
  "@types/mocha": "9.1.0",
40
40
  "@types/jest": "^29.2.2",
41
41
  "@types/testing-library__jest-dom": "^5.9.5",
42
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
42
+ "@teambit/harmony.envs.core-aspect-env": "0.0.14"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@teambit/legacy": "1.0.624"
@@ -1,126 +0,0 @@
1
- import { DependencyResolverAspect } from '@teambit/dependency-resolver';
2
- import { compact } from 'lodash';
3
- import { MergeStrategyResult, conflictIndicator, GenericConfigOrRemoved } from './config-merger';
4
-
5
- const DEP_RESOLVER_VERSION_INDENTATION = 8;
6
- const CONFLICT_MARKER_INDENTATION = 7;
7
-
8
- export class ConfigMergeResult {
9
- constructor(
10
- readonly compIdStr: string,
11
- private currentLabel: string,
12
- private otherLabel: string,
13
- private results: MergeStrategyResult[]
14
- ) {}
15
- hasConflicts(): boolean {
16
- return this.results.some((result) => result.conflict);
17
- }
18
- generateMergeConflictFile(): string | null {
19
- const resultsWithConflict = this.results.filter((result) => result.conflict);
20
- if (!resultsWithConflict.length) return null;
21
- const allConflicts = compact(resultsWithConflict.map((result) => this.generateConflictStringPerAspect(result)));
22
- const configMergeFormatted = allConflicts.map((c) => this.formatConflict(c));
23
- const conflictStr = `{
24
- ${this.concatenateConflicts(configMergeFormatted)}
25
- }`;
26
- return conflictStr;
27
- }
28
- getSuccessfullyMergedConfig(): Record<string, any> {
29
- const resultsWithMergedConfig = this.results.filter((result) => result.mergedConfig);
30
- return resultsWithMergedConfig.reduce((acc, curr) => {
31
- const currObject = { [curr.id]: curr.mergedConfig };
32
- return { ...acc, ...currObject };
33
- }, {});
34
- }
35
-
36
- getDepsResolverResult(): MergeStrategyResult | undefined {
37
- return this.results.find((result) => result.id === DependencyResolverAspect.id);
38
- }
39
-
40
- private generateConflictStringPerAspect(result: MergeStrategyResult): string | undefined {
41
- if (!result.conflict) return undefined;
42
- if (result.id === DependencyResolverAspect.id) {
43
- return this.depsResolverConfigGenerator(result.conflict);
44
- }
45
- return this.basicConflictGenerator(result.id, result.conflict);
46
- }
47
-
48
- private depsResolverConfigGenerator(conflict: Record<string, any>): string {
49
- const mergedConfigSplit = JSON.stringify({ policy: conflict }, undefined, 2).split('\n');
50
- const conflictLines = mergedConfigSplit.map((line) => {
51
- if (!line.includes(conflictIndicator)) return line;
52
- const [, currentVal, otherVal] = line.split('::');
53
- return `${'<'.repeat(CONFLICT_MARKER_INDENTATION)} ${this.currentLabel}
54
- ${' '.repeat(DEP_RESOLVER_VERSION_INDENTATION)}"version": "${currentVal}",
55
- =======
56
- ${' '.repeat(DEP_RESOLVER_VERSION_INDENTATION)}"version": "${otherVal}",
57
- ${'>'.repeat(CONFLICT_MARKER_INDENTATION)} ${this.otherLabel}`;
58
- });
59
- // replace the first line with line with the id
60
- conflictLines.shift();
61
- conflictLines.unshift(`"${DependencyResolverAspect.id}": {`);
62
- return conflictLines.join('\n');
63
- }
64
-
65
- private basicConflictGenerator(id: string, conflictObj: Record<string, any>): string {
66
- const { currentConfig, otherConfig } = conflictObj;
67
- let conflict: string;
68
- if (currentConfig === '-') {
69
- conflict = `${'<'.repeat(CONFLICT_MARKER_INDENTATION)} ${this.currentLabel}
70
- "${id}": "-"
71
- =======
72
- "${id}": ${JSON.stringify(otherConfig, undefined, 2)}
73
- ${'>'.repeat(CONFLICT_MARKER_INDENTATION)} ${this.otherLabel}`;
74
- } else if (otherConfig === '-') {
75
- conflict = `${'<'.repeat(CONFLICT_MARKER_INDENTATION)} ${this.currentLabel}
76
- "${id}": ${JSON.stringify(currentConfig, undefined, 2)}
77
- =======
78
- "${id}": "-"
79
- ${'>'.repeat(CONFLICT_MARKER_INDENTATION)} ${this.otherLabel}`;
80
- } else {
81
- const formatConfig = (conf: GenericConfigOrRemoved) => {
82
- const confStr = JSON.stringify(conf, undefined, 2);
83
- const confStrSplit = confStr.split('\n');
84
- confStrSplit.shift(); // remove first {
85
- confStrSplit.pop(); // remove last }
86
- return confStrSplit.join('\n');
87
- };
88
- conflict = `"${id}": {
89
- ${'<'.repeat(CONFLICT_MARKER_INDENTATION)} ${this.currentLabel}
90
- ${formatConfig(currentConfig)}
91
- =======
92
- ${formatConfig(otherConfig)}
93
- ${'>'.repeat(CONFLICT_MARKER_INDENTATION)} ${this.otherLabel}
94
- }`;
95
- }
96
-
97
- return conflict;
98
- }
99
-
100
- private formatConflict(conflict: string) {
101
- return (
102
- conflict
103
- .split('\n')
104
- // add 2 spaces before each line
105
- .map((line) => ` ${line}`)
106
- // remove the white spaces before the conflict indicators
107
- .map((line) => line.replace(/ *(<<<<<<<|>>>>>>>|=======)/g, '$1'))
108
- .join('\n')
109
- );
110
- }
111
-
112
- private concatenateConflicts(conflicts: string[]) {
113
- const conflictsWithComma = conflicts.map((conflict, index) => {
114
- if (index === conflicts.length - 1) return conflict; // last element in the array, no need to add a comma
115
- if (conflict.endsWith('}')) return `${conflict},`; // ends normally with a closing brace, add a comma.
116
- // if it doesn't end with a closing brace, it means it ends with a conflict indicator.
117
- // the comma should be added after the last line with a closing brace.
118
- const conflictSplit = conflict.split('\n');
119
- // find the last line with '}' and add a comma after it
120
- const lastLineWithClosingBrace = conflictSplit.lastIndexOf(' }');
121
- conflictSplit[lastLineWithClosingBrace] += ',';
122
- return conflictSplit.join('\n');
123
- });
124
- return conflictsWithComma.join('\n');
125
- }
126
- }