@teambit/merging 0.0.251 → 0.0.253

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,11 @@
1
+ import { MergeStrategyResult } from './config-merger';
2
+ export declare class ConfigMergeResult {
3
+ readonly compIdStr: string;
4
+ private results;
5
+ constructor(compIdStr: string, results: MergeStrategyResult[]);
6
+ hasConflicts(): boolean;
7
+ generateMergeConflictFile(): string | null;
8
+ getSuccessfullyMergedConfig(): Record<string, any>;
9
+ private formatConflict;
10
+ private concatenateConflicts;
11
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ require("core-js/modules/es.regexp.exec.js");
5
+ require("core-js/modules/es.string.replace.js");
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.ConfigMergeResult = 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 _lodash() {
18
+ const data = require("lodash");
19
+ _lodash = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
25
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
26
+ class ConfigMergeResult {
27
+ constructor(compIdStr, results) {
28
+ this.compIdStr = compIdStr;
29
+ this.results = results;
30
+ }
31
+ hasConflicts() {
32
+ return this.results.some(result => result.conflict);
33
+ }
34
+ generateMergeConflictFile() {
35
+ const resultsWithConflict = this.results.filter(result => result.conflict);
36
+ if (!resultsWithConflict.length) return null;
37
+ const configMergeAspects = (0, _lodash().compact)(resultsWithConflict.map(result => result.conflict));
38
+ const configMergeFormatted = configMergeAspects.map(c => this.formatConflict(c));
39
+ const conflictStr = `{
40
+ ${this.concatenateConflicts(configMergeFormatted)}
41
+ }
42
+ `;
43
+ return conflictStr;
44
+ }
45
+ getSuccessfullyMergedConfig() {
46
+ const resultsWithMergedConfig = this.results.filter(result => result.mergedConfig);
47
+ return resultsWithMergedConfig.reduce((acc, curr) => {
48
+ const currObject = {
49
+ [curr.id]: curr.mergedConfig
50
+ };
51
+ return _objectSpread(_objectSpread({}, acc), currObject);
52
+ }, {});
53
+ }
54
+ formatConflict(conflict) {
55
+ return conflict.split('\n')
56
+ // add 2 spaces before each line
57
+ .map(line => ` ${line}`)
58
+ // remove the white spaces before the conflict indicators
59
+ .map(line => line.replace(/ *(<<<<<<<|>>>>>>>|=======)/g, '$1')).join('\n');
60
+ }
61
+ concatenateConflicts(conflicts) {
62
+ const conflictsWithComma = conflicts.map((conflict, index) => {
63
+ if (index === conflicts.length - 1) return conflict; // last element in the array, no need to add a comma
64
+ if (conflict.endsWith('}')) return `${conflict},`; // ends normally with a closing brace, add a comma.
65
+ // if it doesn't end with a closing brace, it means it ends with a conflict indicator.
66
+ // the comma should be added after the last line with a closing brace.
67
+ const conflictSplit = conflict.split('\n');
68
+ // find the last line with '}' and add a comma after it
69
+ const lastLineWithClosingBrace = conflictSplit.lastIndexOf(' }');
70
+ conflictSplit[lastLineWithClosingBrace] += ',';
71
+ return conflictSplit.join('\n');
72
+ });
73
+ return conflictsWithComma.join('\n');
74
+ }
75
+ }
76
+ exports.ConfigMergeResult = ConfigMergeResult;
77
+
78
+ //# sourceMappingURL=config-merge-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ConfigMergeResult","constructor","compIdStr","results","hasConflicts","some","result","conflict","generateMergeConflictFile","resultsWithConflict","filter","length","configMergeAspects","compact","map","configMergeFormatted","c","formatConflict","conflictStr","concatenateConflicts","getSuccessfullyMergedConfig","resultsWithMergedConfig","mergedConfig","reduce","acc","curr","currObject","id","split","line","replace","join","conflicts","conflictsWithComma","index","endsWith","conflictSplit","lastLineWithClosingBrace","lastIndexOf"],"sources":["config-merge-result.ts"],"sourcesContent":["import { compact } from 'lodash';\nimport { MergeStrategyResult } from './config-merger';\n\nexport class ConfigMergeResult {\n constructor(readonly compIdStr: string, private results: MergeStrategyResult[]) {}\n hasConflicts(): boolean {\n return this.results.some((result) => result.conflict);\n }\n generateMergeConflictFile(): string | null {\n const resultsWithConflict = this.results.filter((result) => result.conflict);\n if (!resultsWithConflict.length) return null;\n const configMergeAspects = compact(resultsWithConflict.map((result) => result.conflict));\n const configMergeFormatted = configMergeAspects.map((c) => this.formatConflict(c));\n const conflictStr = `{\n${this.concatenateConflicts(configMergeFormatted)}\n}\n`;\n return conflictStr;\n }\n getSuccessfullyMergedConfig(): Record<string, any> {\n const resultsWithMergedConfig = this.results.filter((result) => result.mergedConfig);\n return resultsWithMergedConfig.reduce((acc, curr) => {\n const currObject = { [curr.id]: curr.mergedConfig };\n return { ...acc, ...currObject };\n }, {});\n }\n\n private formatConflict(conflict: string) {\n return (\n conflict\n .split('\\n')\n // add 2 spaces before each line\n .map((line) => ` ${line}`)\n // remove the white spaces before the conflict indicators\n .map((line) => line.replace(/ *(<<<<<<<|>>>>>>>|=======)/g, '$1'))\n .join('\\n')\n );\n }\n\n private concatenateConflicts(conflicts: string[]) {\n const conflictsWithComma = conflicts.map((conflict, index) => {\n if (index === conflicts.length - 1) return conflict; // last element in the array, no need to add a comma\n if (conflict.endsWith('}')) return `${conflict},`; // ends normally with a closing brace, add a comma.\n // if it doesn't end with a closing brace, it means it ends with a conflict indicator.\n // the comma should be added after the last line with a closing brace.\n const conflictSplit = conflict.split('\\n');\n // find the last line with '}' and add a comma after it\n const lastLineWithClosingBrace = conflictSplit.lastIndexOf(' }');\n conflictSplit[lastLineWithClosingBrace] += ',';\n return conflictSplit.join('\\n');\n });\n return conflictsWithComma.join('\\n');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAiC;AAAA;AAG1B,MAAMA,iBAAiB,CAAC;EAC7BC,WAAW,CAAUC,SAAiB,EAAUC,OAA8B,EAAE;IAAA,KAA3DD,SAAiB,GAAjBA,SAAiB;IAAA,KAAUC,OAA8B,GAA9BA,OAA8B;EAAG;EACjFC,YAAY,GAAY;IACtB,OAAO,IAAI,CAACD,OAAO,CAACE,IAAI,CAAEC,MAAM,IAAKA,MAAM,CAACC,QAAQ,CAAC;EACvD;EACAC,yBAAyB,GAAkB;IACzC,MAAMC,mBAAmB,GAAG,IAAI,CAACN,OAAO,CAACO,MAAM,CAAEJ,MAAM,IAAKA,MAAM,CAACC,QAAQ,CAAC;IAC5E,IAAI,CAACE,mBAAmB,CAACE,MAAM,EAAE,OAAO,IAAI;IAC5C,MAAMC,kBAAkB,GAAG,IAAAC,iBAAO,EAACJ,mBAAmB,CAACK,GAAG,CAAER,MAAM,IAAKA,MAAM,CAACC,QAAQ,CAAC,CAAC;IACxF,MAAMQ,oBAAoB,GAAGH,kBAAkB,CAACE,GAAG,CAAEE,CAAC,IAAK,IAAI,CAACC,cAAc,CAACD,CAAC,CAAC,CAAC;IAClF,MAAME,WAAW,GAAI;AACzB,EAAE,IAAI,CAACC,oBAAoB,CAACJ,oBAAoB,CAAE;AAClD;AACA,CAAC;IACG,OAAOG,WAAW;EACpB;EACAE,2BAA2B,GAAwB;IACjD,MAAMC,uBAAuB,GAAG,IAAI,CAAClB,OAAO,CAACO,MAAM,CAAEJ,MAAM,IAAKA,MAAM,CAAC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
2
+
3
+ require("core-js/modules/es.regexp.exec.js");
4
+ function _chai() {
5
+ const data = require("chai");
6
+ _chai = function () {
7
+ return data;
8
+ };
9
+ return data;
10
+ }
11
+ function _configMergeResult() {
12
+ const data = require("./config-merge-result");
13
+ _configMergeResult = function () {
14
+ return data;
15
+ };
16
+ return data;
17
+ }
18
+ describe('ConfigMergeResult', function () {
19
+ describe('generateMergeConflictFile()', () => {
20
+ it('should generate a merge conflict file', () => {
21
+ const mergeStrategyResult1 = {
22
+ id: 'teambit.component/renaming',
23
+ conflict: '<<<<<<< 8e589ef07ce6e9f4e7b7dce5c409c269adfc76d5 (teambit.hello/world)\n' + '=======\n' + '"teambit.component/renaming": {\n' + ' "renamedFrom": {\n' + ' "scope": "teambit.design",\n' + ' "name": "ui/panels/tabs",\n' + ' "version": "1.0.17"\n' + ' }\n' + '}\n' + '>>>>>>> 93ba7ce641ab443b18243d93f2725604640c2090 (main)'
24
+ };
25
+ const mergeStrategyResult2 = {
26
+ id: 'teambit.envs/envs',
27
+ conflict: '"teambit.envs/envs": {\n' + '<<<<<<< 8e589ef07ce6e9f4e7b7dce5c409c269adfc76d5 (teambit.hello/world)\n' + ' "env": "teambit.community/envs/community-react@2.1.8"\n' + '=======\n' + ' "env": "teambit.design/envs/react@2.0.9"\n' + '>>>>>>> 93ba7ce641ab443b18243d93f2725604640c2090 (main)\n' + '}'
28
+ };
29
+ const configMergeResult = new (_configMergeResult().ConfigMergeResult)('compIdStr', [mergeStrategyResult1, mergeStrategyResult2]);
30
+ const generatedFile = configMergeResult.generateMergeConflictFile();
31
+ (0, _chai().expect)(generatedFile).to.not.be.null;
32
+ if (!generatedFile) throw new Error('generatedFile is null');
33
+ const generatedFileSplit = generatedFile.split('\n');
34
+ (0, _chai().expect)(generatedFileSplit[9]).to.equal(' },');
35
+ });
36
+ });
37
+ });
38
+
39
+ //# sourceMappingURL=config-merge-result.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["describe","it","mergeStrategyResult1","id","conflict","mergeStrategyResult2","configMergeResult","ConfigMergeResult","generatedFile","generateMergeConflictFile","expect","to","not","be","null","Error","generatedFileSplit","split","equal"],"sources":["config-merge-result.spec.ts"],"sourcesContent":["import { expect } from 'chai';\nimport { ConfigMergeResult } from './config-merge-result';\n\ndescribe('ConfigMergeResult', function () {\n describe('generateMergeConflictFile()', () => {\n it('should generate a merge conflict file', () => {\n const mergeStrategyResult1 = {\n id: 'teambit.component/renaming',\n conflict:\n '<<<<<<< 8e589ef07ce6e9f4e7b7dce5c409c269adfc76d5 (teambit.hello/world)\\n' +\n '=======\\n' +\n '\"teambit.component/renaming\": {\\n' +\n ' \"renamedFrom\": {\\n' +\n ' \"scope\": \"teambit.design\",\\n' +\n ' \"name\": \"ui/panels/tabs\",\\n' +\n ' \"version\": \"1.0.17\"\\n' +\n ' }\\n' +\n '}\\n' +\n '>>>>>>> 93ba7ce641ab443b18243d93f2725604640c2090 (main)',\n };\n const mergeStrategyResult2 = {\n id: 'teambit.envs/envs',\n conflict:\n '\"teambit.envs/envs\": {\\n' +\n '<<<<<<< 8e589ef07ce6e9f4e7b7dce5c409c269adfc76d5 (teambit.hello/world)\\n' +\n ' \"env\": \"teambit.community/envs/community-react@2.1.8\"\\n' +\n '=======\\n' +\n ' \"env\": \"teambit.design/envs/react@2.0.9\"\\n' +\n '>>>>>>> 93ba7ce641ab443b18243d93f2725604640c2090 (main)\\n' +\n '}',\n };\n const configMergeResult = new ConfigMergeResult('compIdStr', [mergeStrategyResult1, mergeStrategyResult2]);\n const generatedFile = configMergeResult.generateMergeConflictFile();\n expect(generatedFile).to.not.be.null;\n if (!generatedFile) throw new Error('generatedFile is null');\n const generatedFileSplit = generatedFile.split('\\n');\n expect(generatedFileSplit[9]).to.equal(' },');\n });\n });\n});\n"],"mappings":";;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEAA,QAAQ,CAAC,mBAAmB,EAAE,YAAY;EACxCA,QAAQ,CAAC,6BAA6B,EAAE,MAAM;IAC5CC,EAAE,CAAC,uCAAuC,EAAE,MAAM;MAChD,MAAMC,oBAAoB,GAAG;QAC3BC,EAAE,EAAE,4BAA4B;QAChCC,QAAQ,EACN,0EAA0E,GAC1E,WAAW,GACX,mCAAmC,GACnC,sBAAsB,GACtB,kCAAkC,GAClC,iCAAiC,GACjC,2BAA2B,GAC3B,OAAO,GACP,KAAK,GACL;MACJ,CAAC;MACD,MAAMC,oBAAoB,GAAG;QAC3BF,EAAE,EAAE,mBAAmB;QACvBC,QAAQ,EACN,0BAA0B,GAC1B,0EAA0E,GAC1E,2DAA2D,GAC3D,WAAW,GACX,8CAA8C,GAC9C,2DAA2D,GAC3D;MACJ,CAAC;MACD,MAAME,iBAAiB,GAAG,KAAIC,sCAAiB,EAAC,WAAW,EAAE,CAACL,oBAAoB,EAAEG,oBAAoB,CAAC,CAAC;MAC1G,MAAMG,aAAa,GAAGF,iBAAiB,CAACG,yBAAyB,EAAE;MACnE,IAAAC,cAAM,EAACF,aAAa,CAAC,CAACG,EAAE,CAACC,GAAG,CAACC,EAAE,CAACC,IAAI;MACpC,IAAI,CAACN,aAAa,EAAE,MAAM,IAAIO,KAAK,CAAC,uBAAuB,CAAC;MAC5D,MAAMC,kBAAkB,GAAGR,aAAa,CAACS,KAAK,CAAC,IAAI,CAAC;MACpD,IAAAP,cAAM,EAACM,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAACL,EAAE,CAACO,KAAK,CAAC,MAAM,CAAC;IAChD,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { ComponentID } from '@teambit/component-id';
2
+ import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';
3
+ import { ConfigMergeResult } from './config-merge-result';
4
+ declare type GenericConfigOrRemoved = Record<string, any> | '-';
5
+ export declare type MergeStrategyResult = {
6
+ id: string;
7
+ mergedConfig?: GenericConfigOrRemoved;
8
+ conflict?: string;
9
+ };
10
+ /**
11
+ * perform 3-way merge of component configuration (aspects).
12
+ * normally this is needed when merging one lane into another. the component may have different aspects config in each lane.
13
+ * the baseAspects are the aspects of the component in the diversion point (the common ancestor of the two lanes).
14
+ * the currentAspects are the aspects of the component in the current lane.
15
+ * the otherAspects are the aspects of the component in the other lane. this is the lane we merge into the current lane.
16
+ *
17
+ * the basic merging strategy is a simple comparison between the aspect-configs, if they're different, we have a conflict.
18
+ * we have two special cases:
19
+ *
20
+ * 1. dependency-resolver: we do a deeper check for the policy, we compare each dependency separately. also, we take
21
+ * into account not only the config, but also the data. this is needed because some dependencies are automatically
22
+ * added by Bit (from the import statements in the code) and they're not in the config. the final config has the deps
23
+ * from both sources, the config and the data. The way we know to differentiate between them is by the "force" prop.
24
+ * the config has always force: true.
25
+ *
26
+ * 2. envs: if we don't treat it specially, the user will need to make the change not only in the envs aspect, but also
27
+ * in the deps-resolver (because the env is added as a devDependency) and also in the aspect itself (because
28
+ * teambit.envs/env has only the id and not the version). to make it simpler, we ignore the envs in the deps-resolver
29
+ * we ignore the individual aspect that is the env itself. we only show teambit.envs/env and we put the env id and
30
+ * version. later, when the component is loaded, we split the id and the version and put them in the correct places.
31
+ * see workspace.componentExtension / adjustEnvsOnConfigMerge for more details.
32
+ */
33
+ export declare class ConfigMerger {
34
+ private compIdStr;
35
+ private workspaceIds;
36
+ private currentAspects;
37
+ private baseAspects;
38
+ private otherAspects;
39
+ private currentLabel;
40
+ private otherLabel;
41
+ private currentEnv;
42
+ private otherEnv;
43
+ private baseEnv?;
44
+ private handledExtIds;
45
+ constructor(compIdStr: string, workspaceIds: ComponentID[], currentAspects: ExtensionDataList, baseAspects: ExtensionDataList, otherAspects: ExtensionDataList, currentLabel: string, otherLabel: string);
46
+ merge(): ConfigMergeResult;
47
+ private populateEnvs;
48
+ private envStrategy;
49
+ private areConfigsEqual;
50
+ private mergePerStrategy;
51
+ private basicConfigMerge;
52
+ private basicConflictGenerator;
53
+ private depResolverStrategy;
54
+ private isIdInWorkspace;
55
+ private isEnv;
56
+ private getConfig;
57
+ }
58
+ export {};