@teambit/merging 1.0.317 → 1.0.319

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,246 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.threeWayMerge = threeWayMerge;
7
+ function _bitError() {
8
+ const data = require("@teambit/bit-error");
9
+ _bitError = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _repositories() {
15
+ const data = require("@teambit/legacy/dist/scope/repositories");
16
+ _repositories = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _utils() {
22
+ const data = require("@teambit/legacy/dist/utils");
23
+ _utils = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _mergeFiles() {
29
+ const data = require("../merge-files");
30
+ _mergeFiles = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _path() {
36
+ const data = require("@teambit/legacy/dist/utils/path");
37
+ _path = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _sources() {
43
+ const data = require("@teambit/legacy/dist/consumer/component/sources");
44
+ _sources = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ function _lodash() {
50
+ const data = require("lodash");
51
+ _lodash = function () {
52
+ return data;
53
+ };
54
+ return data;
55
+ }
56
+ /**
57
+ * to do the actual merge we use git, specifically `merge-file` command, so we try to use the same
58
+ * terminology as git. From the command help:
59
+ * `git merge-file <current-file> <base-file> <other-file>
60
+ * git merge-file incorporates all changes that lead from the <base-file> to <other-file> into
61
+ * <current-file>. The result ordinarily goes into <current-file>.`
62
+ *
63
+ * see checkout-version.getBaseVersion() for a case when a component is modified and then the base-file is not the
64
+ * common file before other-file and current-file.
65
+ * otherwise, Git terminology pretty much reflects what we do here. current-file is the one that is currently written
66
+ * to the filesystem. other-file is the one the user wants to checkout to. base-file is the original file where both:
67
+ * base-file and other-file were originated from.
68
+ */
69
+ async function threeWayMerge({
70
+ scope,
71
+ otherComponent,
72
+ otherLabel,
73
+ currentComponent,
74
+ currentLabel,
75
+ baseComponent
76
+ }) {
77
+ // baseFiles and currentFiles come from the model, therefore their paths include the
78
+ // sharedOriginallyDir. fsFiles come from the Fs, therefore their paths don't include the
79
+ // sharedOriginallyDir.
80
+ // option 1) strip sharedOriginallyDir from baseFiles and currentFiles. the problem is that the
81
+ // sharedDir can be different if the dependencies were changes for example, as a result, it won't
82
+ // be possible to compare between the files as the paths are different.
83
+ // in the previous it was implemented this way and caused a bug, which now has an e2e-test to
84
+ // block it. see https://github.com/teambit/bit/pull/2070 PR.
85
+ // option 2) add sharedOriginallyDir to the fsFiles. we must go with this option.
86
+ // one thing we have to change is the end-of-line, it should be set as LF, same way we do before
87
+ // saving the file as an object.
88
+ const baseFiles = baseComponent.files;
89
+ const otherFiles = otherComponent.files;
90
+ const currentFiles = currentComponent.cloneFilesWithSharedDir();
91
+ currentFiles.forEach(fsFile => {
92
+ fsFile.contents = _utils().eol.lf(fsFile.contents);
93
+ });
94
+ const results = {
95
+ addFiles: [],
96
+ removeFiles: [],
97
+ remainDeletedFiles: [],
98
+ deletedConflictFiles: [],
99
+ modifiedFiles: [],
100
+ unModifiedFiles: [],
101
+ overrideFiles: [],
102
+ updatedFiles: [],
103
+ hasConflicts: false
104
+ };
105
+ const getFileResult = async (fsFile, baseFile, otherFile) => {
106
+ const filePath = (0, _path().pathNormalizeToLinux)(fsFile.relative);
107
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
108
+ const fsFileHash = (0, _utils().sha1)(fsFile.contents);
109
+ if (!otherFile) {
110
+ // if !otherFile && !baseFile, the file was created after the last tag, no need to do any
111
+ // calculation, the file should be added
112
+ if (!baseFile) {
113
+ results.addFiles.push({
114
+ filePath,
115
+ fsFile
116
+ });
117
+ return;
118
+ }
119
+ const baseFileHash = baseFile.file.hash;
120
+ if (fsFileHash === baseFileHash) {
121
+ results.removeFiles.push({
122
+ filePath
123
+ });
124
+ return;
125
+ }
126
+ results.deletedConflictFiles.push({
127
+ filePath
128
+ });
129
+ return;
130
+ }
131
+ const otherFileHash = otherFile.file.hash;
132
+ if (fsFileHash === otherFileHash) {
133
+ // if fs === other, no need to take any action (regardless the base)
134
+ results.unModifiedFiles.push({
135
+ filePath,
136
+ fsFile
137
+ });
138
+ return;
139
+ }
140
+ if (baseFile && fsFileHash === baseFile.file.hash) {
141
+ // the file has no local modification.
142
+ // the file currently in the fs, is not the same as the file we want to write (other).
143
+ // but no need to check whether it has conflicts because we always want to write the other.
144
+ const content = await otherFile.file.load(scope.objects);
145
+ results.updatedFiles.push({
146
+ filePath,
147
+ otherFile,
148
+ content: content.contents
149
+ });
150
+ return;
151
+ }
152
+ // it was changed in both, there is a chance for conflict. (regardless the base)
153
+ fsFile.label = currentLabel;
154
+ // @ts-ignore it's a hack to pass the data, version is not a valid attribute.
155
+ otherFile.label = otherLabel;
156
+ results.modifiedFiles.push({
157
+ filePath,
158
+ fsFile,
159
+ baseFile,
160
+ otherFile,
161
+ output: null,
162
+ conflict: null
163
+ });
164
+ };
165
+ await Promise.all(currentFiles.map(async fsFile => {
166
+ const relativePath = (0, _path().pathNormalizeToLinux)(fsFile.relative);
167
+ const baseFile = baseFiles.find(file => file.relativePath === relativePath);
168
+ const otherFile = otherFiles.find(file => file.relativePath === relativePath);
169
+ await getFileResult(fsFile, baseFile, otherFile);
170
+ }));
171
+ const fsFilesPaths = currentFiles.map(fsFile => (0, _path().pathNormalizeToLinux)(fsFile.relative));
172
+ const baseFilesPaths = baseFiles.map(baseFile => baseFile.relativePath);
173
+ const isOtherSameAsBase = otherFile => {
174
+ const baseFile = baseFiles.find(file => file.relativePath === otherFile.relativePath);
175
+ if (!baseFile) throw new Error('isOtherSameAsBase expect the base to be there');
176
+ return baseFile.file.hash === otherFile.file.hash;
177
+ };
178
+ const deletedFromFs = otherFiles.filter(otherFile => !fsFilesPaths.includes(otherFile.relativePath) && baseFilesPaths.includes(otherFile.relativePath) && isOtherSameAsBase(otherFile));
179
+ const deletedAndModified = otherFiles.filter(otherFile => !fsFilesPaths.includes(otherFile.relativePath) && baseFilesPaths.includes(otherFile.relativePath) && !isOtherSameAsBase(otherFile));
180
+ const addedOnOther = otherFiles.filter(otherFile => !fsFilesPaths.includes(otherFile.relativePath) && !baseFilesPaths.includes(otherFile.relativePath));
181
+ deletedFromFs.forEach(file => results.remainDeletedFiles.push({
182
+ filePath: file.relativePath
183
+ }));
184
+ deletedAndModified.forEach(file => results.deletedConflictFiles.push({
185
+ filePath: file.relativePath
186
+ }));
187
+ await Promise.all(addedOnOther.map(async file => {
188
+ const fsFile = await _sources().SourceFile.loadFromSourceFileModel(file, scope.objects);
189
+ results.addFiles.push({
190
+ filePath: file.relativePath,
191
+ fsFile
192
+ });
193
+ }));
194
+ await Promise.all(deletedAndModified.map(async file => {
195
+ const fsFile = await _sources().SourceFile.loadFromSourceFileModel(file, scope.objects);
196
+ results.deletedConflictFiles.push({
197
+ filePath: file.relativePath,
198
+ fsFile
199
+ });
200
+ }));
201
+ if ((0, _lodash().isEmpty)(results.modifiedFiles)) return results;
202
+ const conflictResults = await getMergeResults(scope, results.modifiedFiles);
203
+ conflictResults.forEach(conflictResult => {
204
+ const modifiedFile = results.modifiedFiles.find(file => file.filePath === conflictResult.filePath);
205
+ if (!modifiedFile) throw new (_bitError().BitError)(`unable to find ${conflictResult.filePath} in modified files array`);
206
+ modifiedFile.output = conflictResult.output;
207
+ modifiedFile.conflict = conflictResult.conflict;
208
+ modifiedFile.isBinaryConflict = conflictResult.isBinaryConflict;
209
+ if (conflictResult.conflict || conflictResult.isBinaryConflict) results.hasConflicts = true;
210
+ });
211
+ return results;
212
+ }
213
+ async function getMergeResults(scope, modifiedFiles) {
214
+ const tmp = new (_repositories().Tmp)(scope);
215
+ const conflictResultsP = modifiedFiles.map(async modifiedFile => {
216
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
217
+ const fsFilePathP = tmp.save(modifiedFile.fsFile.contents);
218
+ const writeFile = async file => {
219
+ const content = await file.file.load(scope.objects);
220
+ // @ts-ignore
221
+ return tmp.save(content.contents.toString());
222
+ };
223
+ const baseFilePathP = modifiedFile.baseFile ? writeFile(modifiedFile.baseFile) : tmp.save('');
224
+ const otherFilePathP = writeFile(modifiedFile.otherFile);
225
+ const [fsFilePath, baseFilePath, otherFilePath] = await Promise.all([fsFilePathP, baseFilePathP, otherFilePathP]);
226
+ const mergeFilesParams = {
227
+ filePath: modifiedFile.filePath,
228
+ currentFile: {
229
+ label: modifiedFile.fsFile.label,
230
+ path: fsFilePath
231
+ },
232
+ baseFile: {
233
+ path: baseFilePath
234
+ },
235
+ otherFile: {
236
+ // @ts-ignore
237
+ label: modifiedFile.otherFile.label,
238
+ path: otherFilePath
239
+ }
240
+ };
241
+ return (0, _mergeFiles().mergeFiles)(mergeFilesParams);
242
+ });
243
+ return Promise.all(conflictResultsP);
244
+ }
245
+
246
+ //# sourceMappingURL=three-way-merge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_bitError","data","require","_repositories","_utils","_mergeFiles","_path","_sources","_lodash","threeWayMerge","scope","otherComponent","otherLabel","currentComponent","currentLabel","baseComponent","baseFiles","files","otherFiles","currentFiles","cloneFilesWithSharedDir","forEach","fsFile","contents","eol","lf","results","addFiles","removeFiles","remainDeletedFiles","deletedConflictFiles","modifiedFiles","unModifiedFiles","overrideFiles","updatedFiles","hasConflicts","getFileResult","baseFile","otherFile","filePath","pathNormalizeToLinux","relative","fsFileHash","sha1","push","baseFileHash","file","hash","otherFileHash","content","load","objects","label","output","conflict","Promise","all","map","relativePath","find","fsFilesPaths","baseFilesPaths","isOtherSameAsBase","Error","deletedFromFs","filter","includes","deletedAndModified","addedOnOther","SourceFile","loadFromSourceFileModel","isEmpty","conflictResults","getMergeResults","conflictResult","modifiedFile","BitError","isBinaryConflict","tmp","Tmp","conflictResultsP","fsFilePathP","save","writeFile","toString","baseFilePathP","otherFilePathP","fsFilePath","baseFilePath","otherFilePath","mergeFilesParams","currentFile","path","mergeFiles"],"sources":["three-way-merge.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\nimport { Source, Version } from '@teambit/legacy/dist/scope/models';\nimport { SourceFileModel } from '@teambit/legacy/dist/scope/models/version';\nimport { Tmp } from '@teambit/legacy/dist/scope/repositories';\nimport { eol, sha1 } from '@teambit/legacy/dist/utils';\nimport { mergeFiles, MergeFileParams, MergeFileResult } from '../merge-files';\nimport { PathLinux, pathNormalizeToLinux, PathOsBased } from '@teambit/legacy/dist/utils/path';\nimport Component from '@teambit/legacy/dist/consumer/component';\nimport { SourceFile } from '@teambit/legacy/dist/consumer/component/sources';\nimport { Scope } from '@teambit/legacy/dist/scope';\nimport { isEmpty } from 'lodash';\n\nexport type MergeResultsThreeWay = {\n addFiles: Array<{\n filePath: PathLinux;\n fsFile: SourceFile;\n }>;\n removeFiles: Array<{\n filePath: PathLinux;\n }>;\n remainDeletedFiles: Array<{\n filePath: PathLinux;\n }>;\n deletedConflictFiles: Array<{\n filePath: PathLinux;\n fsFile?: SourceFile;\n }>;\n modifiedFiles: Array<{\n filePath: PathLinux;\n fsFile: SourceFile;\n baseFile?: SourceFileModel;\n otherFile: SourceFileModel;\n output: string | null | undefined;\n conflict: string | null | undefined;\n isBinaryConflict?: boolean;\n }>;\n unModifiedFiles: Array<{\n filePath: PathLinux;\n fsFile: SourceFile;\n }>;\n overrideFiles: Array<{\n filePath: PathLinux;\n fsFile: SourceFile;\n }>;\n updatedFiles: Array<{\n filePath: PathLinux;\n otherFile: SourceFileModel;\n content: Buffer;\n }>;\n hasConflicts: boolean;\n};\n\n/**\n * to do the actual merge we use git, specifically `merge-file` command, so we try to use the same\n * terminology as git. From the command help:\n * `git merge-file <current-file> <base-file> <other-file>\n * git merge-file incorporates all changes that lead from the <base-file> to <other-file> into\n * <current-file>. The result ordinarily goes into <current-file>.`\n *\n * see checkout-version.getBaseVersion() for a case when a component is modified and then the base-file is not the\n * common file before other-file and current-file.\n * otherwise, Git terminology pretty much reflects what we do here. current-file is the one that is currently written\n * to the filesystem. other-file is the one the user wants to checkout to. base-file is the original file where both:\n * base-file and other-file were originated from.\n */\nexport async function threeWayMerge({\n scope,\n otherComponent,\n otherLabel,\n currentComponent,\n currentLabel,\n baseComponent,\n}: {\n scope: Scope;\n otherComponent: Version;\n otherLabel: string;\n currentComponent: Component;\n currentLabel: string;\n baseComponent: Version;\n}): Promise<MergeResultsThreeWay> {\n // baseFiles and currentFiles come from the model, therefore their paths include the\n // sharedOriginallyDir. fsFiles come from the Fs, therefore their paths don't include the\n // sharedOriginallyDir.\n // option 1) strip sharedOriginallyDir from baseFiles and currentFiles. the problem is that the\n // sharedDir can be different if the dependencies were changes for example, as a result, it won't\n // be possible to compare between the files as the paths are different.\n // in the previous it was implemented this way and caused a bug, which now has an e2e-test to\n // block it. see https://github.com/teambit/bit/pull/2070 PR.\n // option 2) add sharedOriginallyDir to the fsFiles. we must go with this option.\n // one thing we have to change is the end-of-line, it should be set as LF, same way we do before\n // saving the file as an object.\n const baseFiles: SourceFileModel[] = baseComponent.files;\n const otherFiles: SourceFileModel[] = otherComponent.files;\n const currentFiles: SourceFile[] = currentComponent.cloneFilesWithSharedDir();\n currentFiles.forEach((fsFile) => {\n fsFile.contents = eol.lf(fsFile.contents) as Buffer;\n });\n const results: MergeResultsThreeWay = {\n addFiles: [],\n removeFiles: [],\n remainDeletedFiles: [],\n deletedConflictFiles: [],\n modifiedFiles: [],\n unModifiedFiles: [],\n overrideFiles: [],\n updatedFiles: [],\n hasConflicts: false,\n };\n const getFileResult = async (fsFile: SourceFile, baseFile?: SourceFileModel, otherFile?: SourceFileModel) => {\n const filePath: PathLinux = pathNormalizeToLinux(fsFile.relative);\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const fsFileHash = sha1(fsFile.contents);\n if (!otherFile) {\n // if !otherFile && !baseFile, the file was created after the last tag, no need to do any\n // calculation, the file should be added\n if (!baseFile) {\n results.addFiles.push({ filePath, fsFile });\n return;\n }\n const baseFileHash = baseFile.file.hash;\n if (fsFileHash === baseFileHash) {\n results.removeFiles.push({ filePath });\n return;\n }\n results.deletedConflictFiles.push({ filePath });\n return;\n }\n const otherFileHash = otherFile.file.hash;\n if (fsFileHash === otherFileHash) {\n // if fs === other, no need to take any action (regardless the base)\n results.unModifiedFiles.push({ filePath, fsFile });\n return;\n }\n if (baseFile && fsFileHash === baseFile.file.hash) {\n // the file has no local modification.\n // the file currently in the fs, is not the same as the file we want to write (other).\n // but no need to check whether it has conflicts because we always want to write the other.\n const content = (await otherFile.file.load(scope.objects)) as Source;\n results.updatedFiles.push({ filePath, otherFile, content: content.contents });\n return;\n }\n // it was changed in both, there is a chance for conflict. (regardless the base)\n fsFile.label = currentLabel;\n // @ts-ignore it's a hack to pass the data, version is not a valid attribute.\n otherFile.label = otherLabel;\n results.modifiedFiles.push({ filePath, fsFile, baseFile, otherFile, output: null, conflict: null });\n };\n\n await Promise.all(\n currentFiles.map(async (fsFile) => {\n const relativePath = pathNormalizeToLinux(fsFile.relative);\n const baseFile = baseFiles.find((file) => file.relativePath === relativePath);\n const otherFile = otherFiles.find((file) => file.relativePath === relativePath);\n await getFileResult(fsFile, baseFile, otherFile);\n })\n );\n const fsFilesPaths = currentFiles.map((fsFile) => pathNormalizeToLinux(fsFile.relative));\n const baseFilesPaths = baseFiles.map((baseFile) => baseFile.relativePath);\n const isOtherSameAsBase = (otherFile: SourceFileModel) => {\n const baseFile = baseFiles.find((file) => file.relativePath === otherFile.relativePath);\n if (!baseFile) throw new Error('isOtherSameAsBase expect the base to be there');\n return baseFile.file.hash === otherFile.file.hash;\n };\n const deletedFromFs = otherFiles.filter(\n (otherFile) =>\n !fsFilesPaths.includes(otherFile.relativePath) &&\n baseFilesPaths.includes(otherFile.relativePath) &&\n isOtherSameAsBase(otherFile)\n );\n const deletedAndModified = otherFiles.filter(\n (otherFile) =>\n !fsFilesPaths.includes(otherFile.relativePath) &&\n baseFilesPaths.includes(otherFile.relativePath) &&\n !isOtherSameAsBase(otherFile)\n );\n const addedOnOther = otherFiles.filter(\n (otherFile) => !fsFilesPaths.includes(otherFile.relativePath) && !baseFilesPaths.includes(otherFile.relativePath)\n );\n deletedFromFs.forEach((file) => results.remainDeletedFiles.push({ filePath: file.relativePath }));\n deletedAndModified.forEach((file) => results.deletedConflictFiles.push({ filePath: file.relativePath }));\n\n await Promise.all(\n addedOnOther.map(async (file) => {\n const fsFile = await SourceFile.loadFromSourceFileModel(file, scope.objects);\n results.addFiles.push({ filePath: file.relativePath, fsFile });\n })\n );\n await Promise.all(\n deletedAndModified.map(async (file) => {\n const fsFile = await SourceFile.loadFromSourceFileModel(file, scope.objects);\n results.deletedConflictFiles.push({ filePath: file.relativePath, fsFile });\n })\n );\n if (isEmpty(results.modifiedFiles)) return results;\n\n const conflictResults = await getMergeResults(scope, results.modifiedFiles);\n conflictResults.forEach((conflictResult: MergeFileResult) => {\n const modifiedFile = results.modifiedFiles.find((file) => file.filePath === conflictResult.filePath);\n if (!modifiedFile) throw new BitError(`unable to find ${conflictResult.filePath} in modified files array`);\n modifiedFile.output = conflictResult.output;\n modifiedFile.conflict = conflictResult.conflict;\n modifiedFile.isBinaryConflict = conflictResult.isBinaryConflict;\n if (conflictResult.conflict || conflictResult.isBinaryConflict) results.hasConflicts = true;\n });\n\n return results;\n}\n\nasync function getMergeResults(\n scope: Scope,\n modifiedFiles: MergeResultsThreeWay['modifiedFiles']\n): Promise<MergeFileResult[]> {\n const tmp = new Tmp(scope);\n const conflictResultsP = modifiedFiles.map(async (modifiedFile) => {\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const fsFilePathP = tmp.save(modifiedFile.fsFile.contents);\n const writeFile = async (file: SourceFileModel): Promise<PathOsBased> => {\n const content = await file.file.load(scope.objects);\n // @ts-ignore\n return tmp.save(content.contents.toString());\n };\n const baseFilePathP = modifiedFile.baseFile ? writeFile(modifiedFile.baseFile) : tmp.save('');\n const otherFilePathP = writeFile(modifiedFile.otherFile);\n const [fsFilePath, baseFilePath, otherFilePath] = await Promise.all([fsFilePathP, baseFilePathP, otherFilePathP]);\n const mergeFilesParams: MergeFileParams = {\n filePath: modifiedFile.filePath,\n currentFile: {\n label: modifiedFile.fsFile.label,\n path: fsFilePath,\n },\n baseFile: {\n path: baseFilePath,\n },\n otherFile: {\n // @ts-ignore\n label: modifiedFile.otherFile.label,\n path: otherFilePath,\n },\n };\n return mergeFiles(mergeFilesParams);\n });\n return Promise.all(conflictResultsP);\n}\n"],"mappings":";;;;;;AAAA,SAAAA,UAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,SAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,cAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,aAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,OAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,MAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,YAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,MAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,KAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAM,SAAA;EAAA,MAAAN,IAAA,GAAAC,OAAA;EAAAK,QAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAO,QAAA;EAAA,MAAAP,IAAA,GAAAC,OAAA;EAAAM,OAAA,YAAAA,CAAA;IAA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AO2B,GAAG,CAACI,IAAI,CAACjC,OAAO,CAAC1B,QAAQ,CAAC6D,QAAQ,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,MAAMC,aAAa,GAAGV,YAAY,CAACtC,QAAQ,GAAG8C,SAAS,CAACR,YAAY,CAACtC,QAAQ,CAAC,GAAGyC,GAAG,CAACI,IAAI,CAAC,EAAE,CAAC;IAC7F,MAAMI,cAAc,GAAGH,SAAS,CAACR,YAAY,CAACrC,SAAS,CAAC;IACxD,MAAM,CAACiD,UAAU,EAAEC,YAAY,EAAEC,aAAa,CAAC,GAAG,MAAMlC,OAAO,CAACC,GAAG,CAAC,CAACyB,WAAW,EAAEI,aAAa,EAAEC,cAAc,CAAC,CAAC;IACjH,MAAMI,gBAAiC,GAAG;MACxCnD,QAAQ,EAAEoC,YAAY,CAACpC,QAAQ;MAC/BoD,WAAW,EAAE;QACXvC,KAAK,EAAEuB,YAAY,CAACrD,MAAM,CAAC8B,KAAK;QAChCwC,IAAI,EAAEL;MACR,CAAC;MACDlD,QAAQ,EAAE;QACRuD,IAAI,EAAEJ;MACR,CAAC;MACDlD,SAAS,EAAE;QACT;QACAc,KAAK,EAAEuB,YAAY,CAACrC,SAAS,CAACc,KAAK;QACnCwC,IAAI,EAAEH;MACR;IACF,CAAC;IACD,OAAO,IAAAI,wBAAU,EAACH,gBAAgB,CAAC;EACrC,CAAC,CAAC;EACF,OAAOnC,OAAO,CAACC,GAAG,CAACwB,gBAAgB,CAAC;AACtC","ignoreList":[]}
@@ -1,7 +1,6 @@
1
1
  import { CLIMain } from '@teambit/cli';
2
2
  import { Workspace } from '@teambit/workspace';
3
3
  import { Consumer } from '@teambit/legacy/dist/consumer';
4
- import { MergeStrategy, FileStatus } from '@teambit/legacy/dist/consumer/versions-ops/merge-version';
5
4
  import { SnappingMain } from '@teambit/snapping';
6
5
  import { ComponentID, ComponentIdList } from '@teambit/component-id';
7
6
  import { LaneId } from '@teambit/lane-id';
@@ -15,7 +14,6 @@ import ConsumerComponent from '@teambit/legacy/dist/consumer/component/consumer-
15
14
  import { ImporterMain } from '@teambit/importer';
16
15
  import { Logger, LoggerMain } from '@teambit/logger';
17
16
  import { GlobalConfigMain } from '@teambit/global-config';
18
- import { MergeResultsThreeWay } from '@teambit/legacy/dist/consumer/versions-ops/merge-version/three-way-merge';
19
17
  import { ApplyVersionWithComps, CheckoutMain, ComponentStatusBase } from '@teambit/checkout';
20
18
  import { ConfigMergerMain, ConfigMergeResult, WorkspaceConfigUpdateResult } from '@teambit/config-merger';
21
19
  import { SnapsDistance } from '@teambit/legacy/dist/scope/component-ops/snaps-distance';
@@ -23,6 +21,7 @@ import { DependencyResolverMain } from '@teambit/dependency-resolver';
23
21
  import { InstallMain } from '@teambit/install';
24
22
  import { ScopeMain } from '@teambit/scope';
25
23
  import { MergeStatusProviderOptions } from './merge-status-provider';
24
+ import { MergeStrategy, FileStatus, MergeResultsThreeWay } from './merge-version';
26
25
  type ResolveUnrelatedData = {
27
26
  strategy: MergeStrategy;
28
27
  headOnCurrentLane: Ref;
@@ -94,7 +93,7 @@ export declare class MergingMain {
94
93
  private configMerger;
95
94
  private depResolver;
96
95
  constructor(workspace: Workspace, scope: ScopeMain, install: InstallMain, snapping: SnappingMain, checkout: CheckoutMain, logger: Logger, componentWriter: ComponentWriterMain, importer: ImporterMain, config: ConfigMain, remove: RemoveMain, configMerger: ConfigMergerMain, depResolver: DependencyResolverMain);
97
- merge(ids: string[], mergeStrategy: MergeStrategy, abort: boolean, resolve: boolean, noSnap: boolean, message: string, build: boolean, skipDependencyInstallation: boolean): Promise<ApplyVersionResults>;
96
+ merge(pattern: string, mergeStrategy: MergeStrategy, abort: boolean, resolve: boolean, noSnap: boolean, message: string, build: boolean, skipDependencyInstallation: boolean): Promise<ApplyVersionResults>;
98
97
  /**
99
98
  * when user is on main, it merges the remote main components into local.
100
99
  * when user is on a lane, it merges the remote lane components into the local lane.
@@ -25,13 +25,6 @@ function _componentsList() {
25
25
  };
26
26
  return data;
27
27
  }
28
- function _mergeVersion() {
29
- const data = require("@teambit/legacy/dist/consumer/versions-ops/merge-version");
30
- _mergeVersion = function () {
31
- return data;
32
- };
33
- return data;
34
- }
35
28
  function _snapping() {
36
29
  const data = require("@teambit/snapping");
37
30
  _snapping = function () {
@@ -39,13 +32,6 @@ function _snapping() {
39
32
  };
40
33
  return data;
41
34
  }
42
- function _hasWildcard() {
43
- const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/string/has-wildcard"));
44
- _hasWildcard = function () {
45
- return data;
46
- };
47
- return data;
48
- }
49
35
  function _pMapSeries() {
50
36
  const data = _interopRequireDefault(require("p-map-series"));
51
37
  _pMapSeries = function () {
@@ -207,6 +193,13 @@ function _mergeStatusProvider() {
207
193
  };
208
194
  return data;
209
195
  }
196
+ function _mergeVersion() {
197
+ const data = require("./merge-version");
198
+ _mergeVersion = function () {
199
+ return data;
200
+ };
201
+ return data;
202
+ }
210
203
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
211
204
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
212
205
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -230,16 +223,16 @@ class MergingMain {
230
223
  this.configMerger = configMerger;
231
224
  this.depResolver = depResolver;
232
225
  }
233
- async merge(ids, mergeStrategy, abort, resolve, noSnap, message, build, skipDependencyInstallation) {
226
+ async merge(pattern, mergeStrategy, abort, resolve, noSnap, message, build, skipDependencyInstallation) {
234
227
  if (!this.workspace) throw new (_workspace().OutsideWorkspaceError)();
235
228
  const consumer = this.workspace.consumer;
236
229
  let mergeResults;
237
230
  if (resolve) {
238
- mergeResults = await this.resolveMerge(ids, message, build);
231
+ mergeResults = await this.resolveMerge(pattern, message, build);
239
232
  } else if (abort) {
240
- mergeResults = await this.abortMerge(ids);
233
+ mergeResults = await this.abortMerge(pattern);
241
234
  } else {
242
- const bitIds = await this.getComponentsToMerge(consumer, ids);
235
+ const bitIds = await this.getComponentsToMerge(consumer, pattern);
243
236
  mergeResults = await this.mergeComponentsFromRemote(consumer, bitIds, mergeStrategy, noSnap, message, build, skipDependencyInstallation);
244
237
  }
245
238
  await consumer.onDestroy('merge');
@@ -583,9 +576,9 @@ class MergingMain {
583
576
  legacyCompToWrite: legacyComponent
584
577
  };
585
578
  }
586
- async abortMerge(values) {
579
+ async abortMerge(pattern) {
587
580
  const consumer = this.workspace.consumer;
588
- const ids = await this.getIdsForUnmerged(values);
581
+ const ids = await this.getIdsForUnmerged(pattern);
589
582
  const results = await this.checkout.checkout({
590
583
  ids,
591
584
  reset: true
@@ -596,8 +589,8 @@ class MergingMain {
596
589
  abortedComponents: results.components
597
590
  };
598
591
  }
599
- async resolveMerge(values, snapMessage, build) {
600
- const ids = await this.getIdsForUnmerged(values);
592
+ async resolveMerge(pattern, snapMessage, build) {
593
+ const ids = await this.getIdsForUnmerged(pattern);
601
594
  // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
602
595
  const {
603
596
  snappedComponents
@@ -661,9 +654,9 @@ class MergingMain {
661
654
  unmodified: true
662
655
  });
663
656
  }
664
- async getIdsForUnmerged(idsStr) {
665
- if (idsStr && idsStr.length) {
666
- const componentIds = await this.workspace.resolveMultipleComponentIds(idsStr);
657
+ async getIdsForUnmerged(pattern) {
658
+ if (pattern) {
659
+ const componentIds = await this.workspace.idsByPattern(pattern);
667
660
  componentIds.forEach(id => {
668
661
  const entry = this.workspace.consumer.scope.objects.unmergedComponents.getEntry(id);
669
662
  if (!entry) {
@@ -676,16 +669,13 @@ class MergingMain {
676
669
  if (!unresolvedComponents.length) throw new (_bitError().BitError)(`all components are resolved already, nothing to do`);
677
670
  return unresolvedComponents.map(u => _componentId().ComponentID.fromObject(u.id));
678
671
  }
679
- async getComponentsToMerge(consumer, ids) {
680
- const componentsList = new (_componentsList().default)(consumer);
681
- if (!ids.length) {
682
- const mergePending = await componentsList.listMergePendingComponents();
683
- return mergePending.map(c => c.id);
672
+ async getComponentsToMerge(consumer, pattern) {
673
+ if (pattern) {
674
+ return this.workspace.idsByPattern(pattern);
684
675
  }
685
- if ((0, _hasWildcard().default)(ids)) {
686
- return componentsList.listComponentsByIdsWithWildcard(ids);
687
- }
688
- return ids.map(id => consumer.getParsedId(id));
676
+ const componentsList = new (_componentsList().default)(consumer);
677
+ const mergePending = await componentsList.listMergePendingComponents();
678
+ return mergePending.map(c => c.id);
689
679
  }
690
680
  static async provider([cli, workspace, scope, snapping, checkout, install, loggerMain, compWriter, importer, config, remove, globalConfig, configMerger, depResolver]) {
691
681
  const logger = loggerMain.createLogger(_merging().MergingAspect.id);