@teambit/merging 1.0.1242 → 1.0.1244
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.
- package/dist/merge-dependencies.d.ts +42 -4
- package/dist/merge-dependencies.js +132 -6
- package/dist/merge-dependencies.js.map +1 -1
- package/dist/merge-dependencies.spec.js +214 -3
- package/dist/merge-dependencies.spec.js.map +1 -1
- package/dist/merge-status-provider.d.ts +10 -0
- package/dist/merge-status-provider.js +142 -9
- package/dist/merge-status-provider.js.map +1 -1
- package/package.json +18 -14
- /package/dist/{preview-1792591009402.js → preview-1792610244914.js} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { MergeStrategy } from '@teambit/component.modules.merge-helper';
|
|
2
2
|
import type { ComponentIdList } from '@teambit/component-id';
|
|
3
|
+
import type { ImportedPackages } from '@teambit/dependencies';
|
|
3
4
|
import type { ExtensionDataList } from '@teambit/legacy.extension-data';
|
|
4
5
|
import { Dependencies } from '@teambit/legacy.consumer-component';
|
|
5
6
|
declare const COMPONENT_DEPS_FIELDS: readonly ['dependencies', 'devDependencies', 'peerDependencies'];
|
|
@@ -23,6 +24,14 @@ export type DependenciesSnapshot = {
|
|
|
23
24
|
export declare function getDependenciesOfVersion(version: DependenciesSnapshot & {
|
|
24
25
|
extensions: ExtensionDataList;
|
|
25
26
|
}): DependenciesSnapshot;
|
|
27
|
+
/**
|
|
28
|
+
* the packages imported by the files of a merge, see detectImportedPackages().
|
|
29
|
+
*/
|
|
30
|
+
export type ImportsOfMerge = {
|
|
31
|
+
merged: ImportedPackages;
|
|
32
|
+
sides: Set<string>;
|
|
33
|
+
isOfPolicy?: (name: string) => boolean;
|
|
34
|
+
};
|
|
26
35
|
/**
|
|
27
36
|
* 3-way merge of the resolved dependencies of a component: base (the common snap), current (the target lane) and
|
|
28
37
|
* other (the merged lane/main).
|
|
@@ -30,9 +39,15 @@ export declare function getDependenciesOfVersion(version: DependenciesSnapshot &
|
|
|
30
39
|
* a workspace merge gets the dependencies of the merged component by re-detecting them from the merged files. a bare
|
|
31
40
|
* scope has no node_modules to resolve imports against, so it merges the dependencies that each side resolved when it
|
|
32
41
|
* was snapped instead: a dependency added or removed on one side, or whose version or type (runtime/dev/peer) changed
|
|
33
|
-
* on one side, is taken from that side.
|
|
34
|
-
*
|
|
35
|
-
*
|
|
42
|
+
* on one side, is taken from that side.
|
|
43
|
+
*
|
|
44
|
+
* when `imports` is given, the dependencies that come from imports follow the merged files, same as the detection: a
|
|
45
|
+
* dependency that no merged file imports is removed, one that a merged file imports is kept (taken from the side that
|
|
46
|
+
* has it when the 3-way merge removed it), and it's a runtime or dev dependency according to the files that import it.
|
|
47
|
+
* the version is still the one of the 3-way merge. a dependency that no side imports (e.g. one added by a policy) keeps
|
|
48
|
+
* the 3-way result. without `imports`, it's close to the detection, not identical. e.g. when one side removed an
|
|
49
|
+
* import of a dependency from one file and the other side added an import of it to another file, the dependency is
|
|
50
|
+
* removed, although the merged files still import it.
|
|
36
51
|
*
|
|
37
52
|
* each dependency is keyed by its name, and its field (runtime/dev/peer) is part of what is compared, so a dependency
|
|
38
53
|
* that moved between fields on one side is taken from that side, and it's never added to two fields.
|
|
@@ -44,5 +59,28 @@ export declare function getDependenciesOfVersion(version: DependenciesSnapshot &
|
|
|
44
59
|
* anyway (see MergingMain.setLaneVersionsOfDeps), so its version is not compared. otherwise, the lane snap of it would
|
|
45
60
|
* look like a change on the lane, and a removal of it on the other side would be lost.
|
|
46
61
|
*/
|
|
47
|
-
export declare function mergeDependencies(base: DependenciesSnapshot, current: DependenciesSnapshot, other: DependenciesSnapshot, mergeStrategy?: MergeStrategy, laneComponentIds?: ComponentIdList): DependenciesSnapshot;
|
|
62
|
+
export declare function mergeDependencies(base: DependenciesSnapshot, current: DependenciesSnapshot, other: DependenciesSnapshot, mergeStrategy?: MergeStrategy, laneComponentIds?: ComponentIdList, imports?: ImportsOfMerge): DependenciesSnapshot;
|
|
63
|
+
/**
|
|
64
|
+
* the dependencies of one side of a merge, and the packages that its dependencies policy ignores ("-") or forces (adds
|
|
65
|
+
* even when no file imports them, e.g. the own peers of an env).
|
|
66
|
+
*/
|
|
67
|
+
export type SideOfMerge = {
|
|
68
|
+
dependencies: DependenciesSnapshot;
|
|
69
|
+
ignoredPackages: Set<string>;
|
|
70
|
+
forcedPackages: Set<string>;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* packages that the merged files import, that the merged policy doesn't ignore, and that no side has as a dependency,
|
|
74
|
+
* because the sides that import them ignored them. (e.g. one side imports a package while it's ignored, and the other
|
|
75
|
+
* side removes the "-"). a workspace adds such a package with the version installed in node_modules, a bare scope has
|
|
76
|
+
* no version for it. a types package of it (e.g. @types/foo) is not a version of it.
|
|
77
|
+
*/
|
|
78
|
+
export declare function getImportedPackagesWithoutVersion(base: SideOfMerge, current: SideOfMerge, other: SideOfMerge, importedByMergedFiles: Iterable<string>): string[];
|
|
79
|
+
/**
|
|
80
|
+
* the imports of a merge, with the packages that the merged policy ignores ("-") or forces. these keep the 3-way
|
|
81
|
+
* result, which follows the policy of each side, the imports don't change them. e.g. when one side adds a "-" for a
|
|
82
|
+
* package that the files import, the 3-way merge removes it, and the imports don't restore it. and an env keeps its
|
|
83
|
+
* own peers when no file imports them anymore.
|
|
84
|
+
*/
|
|
85
|
+
export declare function withPolicyOfMerge(imports: ImportsOfMerge, base: SideOfMerge, current: SideOfMerge, other: SideOfMerge): ImportsOfMerge;
|
|
48
86
|
export {};
|
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getDependenciesOfVersion = getDependenciesOfVersion;
|
|
7
|
+
exports.getImportedPackagesWithoutVersion = getImportedPackagesWithoutVersion;
|
|
7
8
|
exports.mergeDependencies = mergeDependencies;
|
|
9
|
+
exports.withPolicyOfMerge = withPolicyOfMerge;
|
|
8
10
|
function _lodash() {
|
|
9
11
|
const data = require("lodash");
|
|
10
12
|
_lodash = function () {
|
|
@@ -56,6 +58,10 @@ function getDependenciesOfVersion(version) {
|
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
/**
|
|
62
|
+
* the packages imported by the files of a merge, see detectImportedPackages().
|
|
63
|
+
*/
|
|
64
|
+
|
|
59
65
|
/**
|
|
60
66
|
* 3-way merge of the resolved dependencies of a component: base (the common snap), current (the target lane) and
|
|
61
67
|
* other (the merged lane/main).
|
|
@@ -63,9 +69,15 @@ function getDependenciesOfVersion(version) {
|
|
|
63
69
|
* a workspace merge gets the dependencies of the merged component by re-detecting them from the merged files. a bare
|
|
64
70
|
* scope has no node_modules to resolve imports against, so it merges the dependencies that each side resolved when it
|
|
65
71
|
* was snapped instead: a dependency added or removed on one side, or whose version or type (runtime/dev/peer) changed
|
|
66
|
-
* on one side, is taken from that side.
|
|
67
|
-
*
|
|
68
|
-
*
|
|
72
|
+
* on one side, is taken from that side.
|
|
73
|
+
*
|
|
74
|
+
* when `imports` is given, the dependencies that come from imports follow the merged files, same as the detection: a
|
|
75
|
+
* dependency that no merged file imports is removed, one that a merged file imports is kept (taken from the side that
|
|
76
|
+
* has it when the 3-way merge removed it), and it's a runtime or dev dependency according to the files that import it.
|
|
77
|
+
* the version is still the one of the 3-way merge. a dependency that no side imports (e.g. one added by a policy) keeps
|
|
78
|
+
* the 3-way result. without `imports`, it's close to the detection, not identical. e.g. when one side removed an
|
|
79
|
+
* import of a dependency from one file and the other side added an import of it to another file, the dependency is
|
|
80
|
+
* removed, although the merged files still import it.
|
|
69
81
|
*
|
|
70
82
|
* each dependency is keyed by its name, and its field (runtime/dev/peer) is part of what is compared, so a dependency
|
|
71
83
|
* that moved between fields on one side is taken from that side, and it's never added to two fields.
|
|
@@ -77,20 +89,31 @@ function getDependenciesOfVersion(version) {
|
|
|
77
89
|
* anyway (see MergingMain.setLaneVersionsOfDeps), so its version is not compared. otherwise, the lane snap of it would
|
|
78
90
|
* look like a change on the lane, and a removal of it on the other side would be lost.
|
|
79
91
|
*/
|
|
80
|
-
function mergeDependencies(base, current, other, mergeStrategy, laneComponentIds) {
|
|
92
|
+
function mergeDependencies(base, current, other, mergeStrategy, laneComponentIds, imports) {
|
|
81
93
|
const componentDeps = snapshot => new Map(COMPONENT_DEPS_FIELDS.flatMap(field => snapshot[field].get().map(dep => [dep.id.toStringWithoutVersion(), {
|
|
82
94
|
field,
|
|
83
95
|
value: dep
|
|
84
96
|
}])));
|
|
97
|
+
const applyImportsIfNeeded = (entries, sides, nameOf, fields) => imports ? applyImports(entries, sides, nameOf, fields, imports) : entries;
|
|
85
98
|
// all the persisted data is compared (e.g. the import paths and the version range), not only the id, so a change of
|
|
86
99
|
// any of them on one side is not lost. (no methods are called, a loaded component has the dependencies as plain objects)
|
|
87
100
|
const isSameDep = (a, b) => (laneComponentIds?.hasWithoutVersion(a.id) ? a.id.isEqualWithoutVersion(b.id) : a.id.isEqual(b.id)) && a.packageName === b.packageName && a.versionRange === b.versionRange && (0, _lodash().isEqual)(a.relativePaths, b.relativePaths);
|
|
88
|
-
const
|
|
101
|
+
const [baseCompDeps, currentCompDeps, otherCompDeps] = [base, current, other].map(componentDeps);
|
|
102
|
+
const mergedCompDeps = applyImportsIfNeeded(mergeEntries(baseCompDeps, currentCompDeps, otherCompDeps, mergeStrategy, isSameDep), [otherCompDeps, currentCompDeps, baseCompDeps], (_key, dep) => dep.packageName, {
|
|
103
|
+
runtime: 'dependencies',
|
|
104
|
+
dev: 'devDependencies',
|
|
105
|
+
peer: 'peerDependencies'
|
|
106
|
+
});
|
|
89
107
|
const packageDeps = snapshot => new Map(PACKAGE_DEPS_FIELDS.flatMap(field => Object.entries(snapshot[field] || {}).map(([name, version]) => [name, {
|
|
90
108
|
field,
|
|
91
109
|
value: version
|
|
92
110
|
}])));
|
|
93
|
-
const
|
|
111
|
+
const [basePkgDeps, currentPkgDeps, otherPkgDeps] = [base, current, other].map(packageDeps);
|
|
112
|
+
const mergedPkgDeps = applyImportsIfNeeded(mergeEntries(basePkgDeps, currentPkgDeps, otherPkgDeps, mergeStrategy, (a, b) => a === b), [otherPkgDeps, currentPkgDeps, basePkgDeps], key => key, {
|
|
113
|
+
runtime: 'packageDependencies',
|
|
114
|
+
dev: 'devPackageDependencies',
|
|
115
|
+
peer: 'peerPackageDependencies'
|
|
116
|
+
});
|
|
94
117
|
const compDepsOf = field => new (_legacy().Dependencies)(mergedCompDeps.filter(entry => entry.field === field).map(({
|
|
95
118
|
value
|
|
96
119
|
}) => cloneDependency(value)));
|
|
@@ -107,6 +130,109 @@ function mergeDependencies(base, current, other, mergeStrategy, laneComponentIds
|
|
|
107
130
|
peerPackageDependencies: pkgDepsOf('peerPackageDependencies')
|
|
108
131
|
};
|
|
109
132
|
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* the dependencies of one side of a merge, and the packages that its dependencies policy ignores ("-") or forces (adds
|
|
136
|
+
* even when no file imports them, e.g. the own peers of an env).
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* packages that the merged files import, that the merged policy doesn't ignore, and that no side has as a dependency,
|
|
141
|
+
* because the sides that import them ignored them. (e.g. one side imports a package while it's ignored, and the other
|
|
142
|
+
* side removes the "-"). a workspace adds such a package with the version installed in node_modules, a bare scope has
|
|
143
|
+
* no version for it. a types package of it (e.g. @types/foo) is not a version of it.
|
|
144
|
+
*/
|
|
145
|
+
function getImportedPackagesWithoutVersion(base, current, other, importedByMergedFiles) {
|
|
146
|
+
const sides = [base, current, other];
|
|
147
|
+
const dependencyNames = new Set(sides.flatMap(({
|
|
148
|
+
dependencies
|
|
149
|
+
}) => namesOfDependencies(dependencies)));
|
|
150
|
+
return [...importedByMergedFiles].filter(name => !dependencyNames.has(name) && sides.some(side => side.ignoredPackages.has(name)) && !isSetOnMerge(base, current, other, side => side.ignoredPackages.has(name)));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* the imports of a merge, with the packages that the merged policy ignores ("-") or forces. these keep the 3-way
|
|
155
|
+
* result, which follows the policy of each side, the imports don't change them. e.g. when one side adds a "-" for a
|
|
156
|
+
* package that the files import, the 3-way merge removes it, and the imports don't restore it. and an env keeps its
|
|
157
|
+
* own peers when no file imports them anymore.
|
|
158
|
+
*/
|
|
159
|
+
function withPolicyOfMerge(imports, base, current, other) {
|
|
160
|
+
const isOfPolicy = name => isSetOnMerge(base, current, other, side => side.ignoredPackages.has(name)) || isSetOnMerge(base, current, other, side => side.forcedPackages.has(name));
|
|
161
|
+
return _objectSpread(_objectSpread({}, imports), {}, {
|
|
162
|
+
isOfPolicy
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* whether the merged policy sets something for a package (e.g. ignores it), by a 3-way merge of whether the policy of
|
|
168
|
+
* each side sets it.
|
|
169
|
+
*/
|
|
170
|
+
function isSetOnMerge(base, current, other, isSet) {
|
|
171
|
+
const [onBase, onCurrent, onOther] = [base, current, other].map(isSet);
|
|
172
|
+
return Boolean(mergeValue(onBase, onCurrent, onOther, undefined, (a, b) => a === b));
|
|
173
|
+
}
|
|
174
|
+
function namesOfDependencies(dependencies) {
|
|
175
|
+
const componentDeps = COMPONENT_DEPS_FIELDS.flatMap(field => dependencies[field].get());
|
|
176
|
+
const packageNames = PACKAGE_DEPS_FIELDS.flatMap(field => Object.keys(dependencies[field] || {}));
|
|
177
|
+
return [...(0, _lodash().compact)(componentDeps.map(dep => dep.packageName)), ...packageNames];
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* make the dependencies that come from imports follow the merged files, see mergeDependencies().
|
|
181
|
+
* `sides` are the entries of other, current and base, in this order of preference, to take a dependency from when the
|
|
182
|
+
* 3-way merge removed it.
|
|
183
|
+
*/
|
|
184
|
+
function applyImports(entries, sides, nameOf, fields, imports) {
|
|
185
|
+
// a types package (e.g. @types/foo) follows the package it types, see AutoDetectDeps._addTypesPackagesForTypeScript
|
|
186
|
+
const importedName = name => typedPackageName(name) || name;
|
|
187
|
+
const isFromImports = name => imports.merged.has(importedName(name)) || imports.sides.has(importedName(name));
|
|
188
|
+
const isOfPolicy = name => Boolean(imports.isOfPolicy?.(name));
|
|
189
|
+
const withFieldOfImports = (entry, name) => {
|
|
190
|
+
const importedAs = imports.merged.get(name);
|
|
191
|
+
// a peer is set by a policy or by the dependency itself, not by the files that import it
|
|
192
|
+
if (!importedAs || entry.field === fields.peer) return entry;
|
|
193
|
+
return _objectSpread(_objectSpread({}, entry), {}, {
|
|
194
|
+
field: fields[importedAs]
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
const result = [];
|
|
198
|
+
const names = new Set();
|
|
199
|
+
entries.forEach(entry => {
|
|
200
|
+
const name = nameOf(entry.key, entry.value);
|
|
201
|
+
if (!name || isOfPolicy(name)) {
|
|
202
|
+
result.push(entry);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (isFromImports(name) && !imports.merged.has(importedName(name))) return; // no merged file imports it
|
|
206
|
+
names.add(name);
|
|
207
|
+
result.push(withFieldOfImports(entry, name));
|
|
208
|
+
});
|
|
209
|
+
const sidesByName = sides.map(side => new Map([...side].map(([key, entry]) => [nameOf(key, entry.value), _objectSpread({
|
|
210
|
+
key
|
|
211
|
+
}, entry)])));
|
|
212
|
+
const importedNames = [...imports.merged.keys()].flatMap(name => [name, toTypesPackageName(name)]);
|
|
213
|
+
importedNames.forEach(name => {
|
|
214
|
+
if (names.has(name) || isOfPolicy(name)) return;
|
|
215
|
+
// when no side has it, it's e.g. a core aspect, or a package that a policy ignores
|
|
216
|
+
const fromSide = sidesByName.map(side => side.get(name)).find(Boolean);
|
|
217
|
+
if (!fromSide) return;
|
|
218
|
+
names.add(name);
|
|
219
|
+
result.push(withFieldOfImports(fromSide, name));
|
|
220
|
+
});
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* e.g. "@types/foo" => "foo", "@types/scope__foo" => "@scope/foo". undefined when it's not a types package.
|
|
226
|
+
*/
|
|
227
|
+
function typedPackageName(name) {
|
|
228
|
+
if (!name.startsWith('@types/')) return undefined;
|
|
229
|
+
const typed = name.slice('@types/'.length);
|
|
230
|
+
return typed.includes('__') ? `@${typed.replace('__', '/')}` : typed;
|
|
231
|
+
}
|
|
232
|
+
function toTypesPackageName(name) {
|
|
233
|
+
return `@types/${name.replace(/^@([^/]+)\//, '$1__')}`;
|
|
234
|
+
}
|
|
235
|
+
|
|
110
236
|
/**
|
|
111
237
|
* 3-way merge of the entries of each key. an entry is unchanged between two sides when it's in the same field with an
|
|
112
238
|
* equal value. returns the merged entries that exist (not removed).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_lodash","data","require","_legacy","_objects","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","COMPONENT_DEPS_FIELDS","PACKAGE_DEPS_FIELDS","getDependenciesOfVersion","version","withPackageNames","deps","Dependencies","ModelComponent","addDepsInfoFromDepsResolver","extensions","dependencies","devDependencies","peerDependencies","packageDependencies","devPackageDependencies","peerPackageDependencies","mergeDependencies","base","current","other","mergeStrategy","laneComponentIds","componentDeps","snapshot","Map","flatMap","field","get","map","dep","id","toStringWithoutVersion","isSameDep","a","b","hasWithoutVersion","isEqualWithoutVersion","isEqual","packageName","versionRange","relativePaths","mergedCompDeps","mergeEntries","packageDeps","entries","name","mergedPkgDeps","compDepsOf","entry","cloneDependency","pkgDepsOf","fromEntries","key","isEqualValue","union","merged","mergeValue","equal","undefined","clone","Dependency","getClone"],"sources":["merge-dependencies.ts"],"sourcesContent":["import type { MergeStrategy } from '@teambit/component.modules.merge-helper';\nimport { isEqual, union } from 'lodash';\nimport type { ComponentIdList } from '@teambit/component-id';\nimport type { ExtensionDataList } from '@teambit/legacy.extension-data';\nimport { Dependencies, Dependency } from '@teambit/legacy.consumer-component';\nimport { ModelComponent } from '@teambit/objects';\n\nconst COMPONENT_DEPS_FIELDS = ['dependencies', 'devDependencies', 'peerDependencies'] as const;\nconst PACKAGE_DEPS_FIELDS = ['packageDependencies', 'devPackageDependencies', 'peerPackageDependencies'] as const;\n\ntype ComponentDepsField = (typeof COMPONENT_DEPS_FIELDS)[number];\ntype PackageDepsField = (typeof PACKAGE_DEPS_FIELDS)[number];\n\n/**\n * the dependency fields shared by a Version object and a ConsumerComponent.\n */\nexport type DependenciesSnapshot = { [field in ComponentDepsField]: Dependencies } & {\n [field in PackageDepsField]: Record<string, string>;\n};\n\n/**\n * the dependencies of a Version, with the package names of the component dependencies, same as a component loaded from\n * the scope has them (see ModelComponent.toConsumerComponent). without them, a dependency of a Version and the same\n * dependency of a loaded component are not equal.\n * returns copies, so they can be changed (e.g. set to a component that is snapped) without changing the Version.\n */\nexport function getDependenciesOfVersion(\n version: DependenciesSnapshot & { extensions: ExtensionDataList }\n): DependenciesSnapshot {\n const withPackageNames = (deps: Dependencies) =>\n new Dependencies(ModelComponent.addDepsInfoFromDepsResolver(deps, version.extensions));\n return {\n dependencies: withPackageNames(version.dependencies),\n devDependencies: withPackageNames(version.devDependencies),\n peerDependencies: withPackageNames(version.peerDependencies),\n packageDependencies: { ...version.packageDependencies },\n devPackageDependencies: { ...version.devPackageDependencies },\n peerPackageDependencies: { ...version.peerPackageDependencies },\n };\n}\n\n/**\n * 3-way merge of the resolved dependencies of a component: base (the common snap), current (the target lane) and\n * other (the merged lane/main).\n *\n * a workspace merge gets the dependencies of the merged component by re-detecting them from the merged files. a bare\n * scope has no node_modules to resolve imports against, so it merges the dependencies that each side resolved when it\n * was snapped instead: a dependency added or removed on one side, or whose version or type (runtime/dev/peer) changed\n * on one side, is taken from that side. it's close to what the detection finds, not identical. e.g. when one side\n * removed an import of a dependency from one file and the other side added an import of it to another file, the\n * dependency is removed, although the merged files still import it.\n *\n * each dependency is keyed by its name, and its field (runtime/dev/peer) is part of what is compared, so a dependency\n * that moved between fields on one side is taken from that side, and it's never added to two fields.\n * when both sides changed the same dependency differently, \"theirs\" takes other, any other strategy keeps current\n * (in \"manual\", such a version conflict is reported by the config-merger, which stops the merge before the snap).\n * the returned component dependencies are copies, so they can be changed without changing the inputs.\n *\n * `laneComponentIds` are the components of the current lane. a dependency on one of them gets the lane's version\n * anyway (see MergingMain.setLaneVersionsOfDeps), so its version is not compared. otherwise, the lane snap of it would\n * look like a change on the lane, and a removal of it on the other side would be lost.\n */\nexport function mergeDependencies(\n base: DependenciesSnapshot,\n current: DependenciesSnapshot,\n other: DependenciesSnapshot,\n mergeStrategy?: MergeStrategy,\n laneComponentIds?: ComponentIdList\n): DependenciesSnapshot {\n const componentDeps = (snapshot: DependenciesSnapshot) =>\n new Map(\n COMPONENT_DEPS_FIELDS.flatMap((field) =>\n snapshot[field].get().map((dep) => [dep.id.toStringWithoutVersion(), { field, value: dep }] as const)\n )\n );\n // all the persisted data is compared (e.g. the import paths and the version range), not only the id, so a change of\n // any of them on one side is not lost. (no methods are called, a loaded component has the dependencies as plain objects)\n const isSameDep = (a: Dependency, b: Dependency) =>\n (laneComponentIds?.hasWithoutVersion(a.id) ? a.id.isEqualWithoutVersion(b.id) : a.id.isEqual(b.id)) &&\n a.packageName === b.packageName &&\n a.versionRange === b.versionRange &&\n isEqual(a.relativePaths, b.relativePaths);\n const mergedCompDeps = mergeEntries(\n componentDeps(base),\n componentDeps(current),\n componentDeps(other),\n mergeStrategy,\n isSameDep\n );\n const packageDeps = (snapshot: DependenciesSnapshot) =>\n new Map(\n PACKAGE_DEPS_FIELDS.flatMap((field) =>\n Object.entries(snapshot[field] || {}).map(([name, version]) => [name, { field, value: version }] as const)\n )\n );\n const mergedPkgDeps = mergeEntries(\n packageDeps(base),\n packageDeps(current),\n packageDeps(other),\n mergeStrategy,\n (a, b) => a === b\n );\n const compDepsOf = (field: ComponentDepsField) =>\n new Dependencies(\n mergedCompDeps.filter((entry) => entry.field === field).map(({ value }) => cloneDependency(value))\n );\n const pkgDepsOf = (field: PackageDepsField) =>\n Object.fromEntries(mergedPkgDeps.filter((entry) => entry.field === field).map(({ key, value }) => [key, value]));\n return {\n dependencies: compDepsOf('dependencies'),\n devDependencies: compDepsOf('devDependencies'),\n peerDependencies: compDepsOf('peerDependencies'),\n packageDependencies: pkgDepsOf('packageDependencies'),\n devPackageDependencies: pkgDepsOf('devPackageDependencies'),\n peerPackageDependencies: pkgDepsOf('peerPackageDependencies'),\n };\n}\n\ntype FieldEntry<Field, Value> = { field: Field; value: Value };\n\n/**\n * 3-way merge of the entries of each key. an entry is unchanged between two sides when it's in the same field with an\n * equal value. returns the merged entries that exist (not removed).\n */\nfunction mergeEntries<Field, Value>(\n base: Map<string, FieldEntry<Field, Value>>,\n current: Map<string, FieldEntry<Field, Value>>,\n other: Map<string, FieldEntry<Field, Value>>,\n mergeStrategy: MergeStrategy | undefined,\n isEqualValue: (a: Value, b: Value) => boolean\n): Array<FieldEntry<Field, Value> & { key: string }> {\n return union([...current.keys()], [...other.keys()]).flatMap((key) => {\n const merged = mergeValue(\n base.get(key),\n current.get(key),\n other.get(key),\n mergeStrategy,\n (a, b) => a.field === b.field && isEqualValue(a.value, b.value)\n );\n return merged ? [{ key, ...merged }] : [];\n });\n}\n\n/**\n * returns undefined when the merged result is \"absent\" (removed or never existed).\n */\nfunction mergeValue<T>(\n base: T | undefined,\n current: T | undefined,\n other: T | undefined,\n mergeStrategy: MergeStrategy | undefined,\n isEqualValue: (a: T, b: T) => boolean\n): T | undefined {\n const equal = (a?: T, b?: T) => (a === undefined || b === undefined ? a === b : isEqualValue(a, b));\n if (equal(current, other)) return current;\n if (equal(base, current)) return other; // changed (or removed) on other only\n if (equal(base, other)) return current; // changed (or removed) on current only\n return mergeStrategy === 'theirs' ? other : current;\n}\n\nfunction cloneDependency(dep: Dependency): Dependency {\n const clone = Dependency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AAGwE;IAAG,GAAKG,MAAM,EAAG,GAAG,EAAE;EAC3C,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA,SAASC,UAAUA,CACjBvC,IAAmB,EACnBC,OAAsB,EACtBC,KAAoB,EACpBC,aAAwC,EACxCiC,YAAqC,EACtB;EACf,MAAMI,KAAK,GAAGA,CAACxB,CAAK,EAAEC,CAAK,KAAMD,CAAC,KAAKyB,SAAS,IAAIxB,CAAC,KAAKwB,SAAS,GAAGzB,CAAC,KAAKC,CAAC,GAAGmB,YAAY,CAACpB,CAAC,EAAEC,CAAC,CAAE;EACnG,IAAIuB,KAAK,CAACvC,OAAO,EAAEC,KAAK,CAAC,EAAE,OAAOD,OAAO;EACzC,IAAIuC,KAAK,CAACxC,IAAI,EAAEC,OAAO,CAAC,EAAE,OAAOC,KAAK,CAAC,CAAC;EACxC,IAAIsC,KAAK,CAACxC,IAAI,EAAEE,KAAK,CAAC,EAAE,OAAOD,OAAO,CAAC,CAAC;EACxC,OAAOE,aAAa,KAAK,QAAQ,GAAGD,KAAK,GAAGD,OAAO;AACrD;AAEA,SAAS+B,eAAeA,CAACpB,GAAe,EAAc;EACpD,MAAM8B,KAAK,GAAGC,oBAAU,CAACC,QAAQ,CAAChC,GAAG,CAAC;EACtC,OAAO,KAAI+B,oBAAU,EAACD,KAAK,CAAC7B,EAAE,EAAE6B,KAAK,CAACnB,aAAa,EAAEmB,KAAK,CAACrB,WAAW,EAAEqB,KAAK,CAACpB,YAAY,CAAC;AAC7F","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_lodash","data","require","_legacy","_objects","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","COMPONENT_DEPS_FIELDS","PACKAGE_DEPS_FIELDS","getDependenciesOfVersion","version","withPackageNames","deps","Dependencies","ModelComponent","addDepsInfoFromDepsResolver","extensions","dependencies","devDependencies","peerDependencies","packageDependencies","devPackageDependencies","peerPackageDependencies","mergeDependencies","base","current","other","mergeStrategy","laneComponentIds","imports","componentDeps","snapshot","Map","flatMap","field","get","map","dep","id","toStringWithoutVersion","applyImportsIfNeeded","entries","sides","nameOf","fields","applyImports","isSameDep","a","b","hasWithoutVersion","isEqualWithoutVersion","isEqual","packageName","versionRange","relativePaths","baseCompDeps","currentCompDeps","otherCompDeps","mergedCompDeps","mergeEntries","_key","runtime","dev","peer","packageDeps","name","basePkgDeps","currentPkgDeps","otherPkgDeps","mergedPkgDeps","key","compDepsOf","entry","cloneDependency","pkgDepsOf","fromEntries","getImportedPackagesWithoutVersion","importedByMergedFiles","dependencyNames","Set","namesOfDependencies","has","some","side","ignoredPackages","isSetOnMerge","withPolicyOfMerge","isOfPolicy","forcedPackages","isSet","onBase","onCurrent","onOther","Boolean","mergeValue","undefined","packageNames","compact","importedName","typedPackageName","isFromImports","merged","withFieldOfImports","importedAs","result","names","add","sidesByName","importedNames","toTypesPackageName","fromSide","find","startsWith","typed","slice","includes","replace","isEqualValue","union","equal","clone","Dependency","getClone"],"sources":["merge-dependencies.ts"],"sourcesContent":["import type { MergeStrategy } from '@teambit/component.modules.merge-helper';\nimport { compact, isEqual, union } from 'lodash';\nimport type { ComponentIdList } from '@teambit/component-id';\nimport type { ImportedPackages } from '@teambit/dependencies';\nimport type { ExtensionDataList } from '@teambit/legacy.extension-data';\nimport { Dependencies, Dependency } from '@teambit/legacy.consumer-component';\nimport { ModelComponent } from '@teambit/objects';\n\nconst COMPONENT_DEPS_FIELDS = ['dependencies', 'devDependencies', 'peerDependencies'] as const;\nconst PACKAGE_DEPS_FIELDS = ['packageDependencies', 'devPackageDependencies', 'peerPackageDependencies'] as const;\n\ntype ComponentDepsField = (typeof COMPONENT_DEPS_FIELDS)[number];\ntype PackageDepsField = (typeof PACKAGE_DEPS_FIELDS)[number];\n\n/**\n * the dependency fields shared by a Version object and a ConsumerComponent.\n */\nexport type DependenciesSnapshot = { [field in ComponentDepsField]: Dependencies } & {\n [field in PackageDepsField]: Record<string, string>;\n};\n\n/**\n * the dependencies of a Version, with the package names of the component dependencies, same as a component loaded from\n * the scope has them (see ModelComponent.toConsumerComponent). without them, a dependency of a Version and the same\n * dependency of a loaded component are not equal.\n * returns copies, so they can be changed (e.g. set to a component that is snapped) without changing the Version.\n */\nexport function getDependenciesOfVersion(\n version: DependenciesSnapshot & { extensions: ExtensionDataList }\n): DependenciesSnapshot {\n const withPackageNames = (deps: Dependencies) =>\n new Dependencies(ModelComponent.addDepsInfoFromDepsResolver(deps, version.extensions));\n return {\n dependencies: withPackageNames(version.dependencies),\n devDependencies: withPackageNames(version.devDependencies),\n peerDependencies: withPackageNames(version.peerDependencies),\n packageDependencies: { ...version.packageDependencies },\n devPackageDependencies: { ...version.devPackageDependencies },\n peerPackageDependencies: { ...version.peerPackageDependencies },\n };\n}\n\n/**\n * the packages imported by the files of a merge, see detectImportedPackages().\n */\nexport type ImportsOfMerge = {\n merged: ImportedPackages; // imported by the merged files\n sides: Set<string>; // imported by the files of base, current or other\n isOfPolicy?: (name: string) => boolean; // whether the merged policy decides on the package, see withPolicyOfMerge()\n};\n\n/**\n * 3-way merge of the resolved dependencies of a component: base (the common snap), current (the target lane) and\n * other (the merged lane/main).\n *\n * a workspace merge gets the dependencies of the merged component by re-detecting them from the merged files. a bare\n * scope has no node_modules to resolve imports against, so it merges the dependencies that each side resolved when it\n * was snapped instead: a dependency added or removed on one side, or whose version or type (runtime/dev/peer) changed\n * on one side, is taken from that side.\n *\n * when `imports` is given, the dependencies that come from imports follow the merged files, same as the detection: a\n * dependency that no merged file imports is removed, one that a merged file imports is kept (taken from the side that\n * has it when the 3-way merge removed it), and it's a runtime or dev dependency according to the files that import it.\n * the version is still the one of the 3-way merge. a dependency that no side imports (e.g. one added by a policy) keeps\n * the 3-way result. without `imports`, it's close to the detection, not identical. e.g. when one side removed an\n * import of a dependency from one file and the other side added an import of it to another file, the dependency is\n * removed, although the merged files still import it.\n *\n * each dependency is keyed by its name, and its field (runtime/dev/peer) is part of what is compared, so a dependency\n * that moved between fields on one side is taken from that side, and it's never added to two fields.\n * when both sides changed the same dependency differently, \"theirs\" takes other, any other strategy keeps current\n * (in \"manual\", such a version conflict is reported by the config-merger, which stops the merge before the snap).\n * the returned component dependencies are copies, so they can be changed without changing the inputs.\n *\n * `laneComponentIds` are the components of the current lane. a dependency on one of them gets the lane's version\n * anyway (see MergingMain.setLaneVersionsOfDeps), so its version is not compared. otherwise, the lane snap of it would\n * look like a change on the lane, and a removal of it on the other side would be lost.\n */\nexport function mergeDependencies(\n base: DependenciesSnapshot,\n current: DependenciesSnapshot,\n other: DependenciesSnapshot,\n mergeStrategy?: MergeStrategy,\n laneComponentIds?: ComponentIdList,\n imports?: ImportsOfMerge\n): DependenciesSnapshot {\n const componentDeps = (snapshot: DependenciesSnapshot) =>\n new Map(\n COMPONENT_DEPS_FIELDS.flatMap((field) =>\n snapshot[field].get().map((dep) => [dep.id.toStringWithoutVersion(), { field, value: dep }] as const)\n )\n );\n const applyImportsIfNeeded = <Field extends string, Value>(\n entries: Array<MergedEntry<Field, Value>>,\n sides: Array<Map<string, FieldEntry<Field, Value>>>,\n nameOf: (key: string, value: Value) => string | undefined,\n fields: DepTypeFields<Field>\n ) => (imports ? applyImports(entries, sides, nameOf, fields, imports) : entries);\n // all the persisted data is compared (e.g. the import paths and the version range), not only the id, so a change of\n // any of them on one side is not lost. (no methods are called, a loaded component has the dependencies as plain objects)\n const isSameDep = (a: Dependency, b: Dependency) =>\n (laneComponentIds?.hasWithoutVersion(a.id) ? a.id.isEqualWithoutVersion(b.id) : a.id.isEqual(b.id)) &&\n a.packageName === b.packageName &&\n a.versionRange === b.versionRange &&\n isEqual(a.relativePaths, b.relativePaths);\n const [baseCompDeps, currentCompDeps, otherCompDeps] = [base, current, other].map(componentDeps);\n const mergedCompDeps = applyImportsIfNeeded(\n mergeEntries(baseCompDeps, currentCompDeps, otherCompDeps, mergeStrategy, isSameDep),\n [otherCompDeps, currentCompDeps, baseCompDeps],\n (_key, dep) => dep.packageName,\n { runtime: 'dependencies', dev: 'devDependencies', peer: 'peerDependencies' }\n );\n const packageDeps = (snapshot: DependenciesSnapshot) =>\n new Map(\n PACKAGE_DEPS_FIELDS.flatMap((field) =>\n Object.entries(snapshot[field] || {}).map(([name, version]) => [name, { field, value: version }] as const)\n )\n );\n const [basePkgDeps, currentPkgDeps, otherPkgDeps] = [base, current, other].map(packageDeps);\n const mergedPkgDeps = applyImportsIfNeeded(\n mergeEntries(basePkgDeps, currentPkgDeps, otherPkgDeps, mergeStrategy, (a, b) => a === b),\n [otherPkgDeps, currentPkgDeps, basePkgDeps],\n (key) => key,\n { runtime: 'packageDependencies', dev: 'devPackageDependencies', peer: 'peerPackageDependencies' }\n );\n const compDepsOf = (field: ComponentDepsField) =>\n new Dependencies(\n mergedCompDeps.filter((entry) => entry.field === field).map(({ value }) => cloneDependency(value))\n );\n const pkgDepsOf = (field: PackageDepsField) =>\n Object.fromEntries(mergedPkgDeps.filter((entry) => entry.field === field).map(({ key, value }) => [key, value]));\n return {\n dependencies: compDepsOf('dependencies'),\n devDependencies: compDepsOf('devDependencies'),\n peerDependencies: compDepsOf('peerDependencies'),\n packageDependencies: pkgDepsOf('packageDependencies'),\n devPackageDependencies: pkgDepsOf('devPackageDependencies'),\n peerPackageDependencies: pkgDepsOf('peerPackageDependencies'),\n };\n}\n\n/**\n * the dependencies of one side of a merge, and the packages that its dependencies policy ignores (\"-\") or forces (adds\n * even when no file imports them, e.g. the own peers of an env).\n */\nexport type SideOfMerge = {\n dependencies: DependenciesSnapshot;\n ignoredPackages: Set<string>;\n forcedPackages: Set<string>;\n};\n\n/**\n * packages that the merged files import, that the merged policy doesn't ignore, and that no side has as a dependency,\n * because the sides that import them ignored them. (e.g. one side imports a package while it's ignored, and the other\n * side removes the \"-\"). a workspace adds such a package with the version installed in node_modules, a bare scope has\n * no version for it. a types package of it (e.g. @types/foo) is not a version of it.\n */\nexport function getImportedPackagesWithoutVersion(\n base: SideOfMerge,\n current: SideOfMerge,\n other: SideOfMerge,\n importedByMergedFiles: Iterable<string>\n): string[] {\n const sides = [base, current, other];\n const dependencyNames = new Set(sides.flatMap(({ dependencies }) => namesOfDependencies(dependencies)));\n return [...importedByMergedFiles].filter(\n (name) =>\n !dependencyNames.has(name) &&\n sides.some((side) => side.ignoredPackages.has(name)) &&\n !isSetOnMerge(base, current, other, (side) => side.ignoredPackages.has(name))\n );\n}\n\n/**\n * the imports of a merge, with the packages that the merged policy ignores (\"-\") or forces. these keep the 3-way\n * result, which follows the policy of each side, the imports don't change them. e.g. when one side adds a \"-\" for a\n * package that the files import, the 3-way merge removes it, and the imports don't restore it. and an env keeps its\n * own peers when no file imports them anymore.\n */\nexport function withPolicyOfMerge(\n imports: ImportsOfMerge,\n base: SideOfMerge,\n current: SideOfMerge,\n other: SideOfMerge\n): ImportsOfMerge {\n const isOfPolicy = (name: string) =>\n isSetOnMerge(base, current, other, (side) => side.ignoredPackages.has(name)) ||\n isSetOnMerge(base, current, other, (side) => side.forcedPackages.has(name));\n return { ...imports, isOfPolicy };\n}\n\n/**\n * whether the merged policy sets something for a package (e.g. ignores it), by a 3-way merge of whether the policy of\n * each side sets it.\n */\nfunction isSetOnMerge(\n base: SideOfMerge,\n current: SideOfMerge,\n other: SideOfMerge,\n isSet: (side: SideOfMerge) => boolean\n): boolean {\n const [onBase, onCurrent, onOther] = [base, current, other].map(isSet);\n return Boolean(mergeValue(onBase, onCurrent, onOther, undefined, (a, b) => a === b));\n}\n\nfunction namesOfDependencies(dependencies: DependenciesSnapshot): string[] {\n const componentDeps = COMPONENT_DEPS_FIELDS.flatMap((field) => dependencies[field].get());\n const packageNames = PACKAGE_DEPS_FIELDS.flatMap((field) => Object.keys(dependencies[field] || {}));\n return [...compact(componentDeps.map((dep) => dep.packageName)), ...packageNames];\n}\n\ntype FieldEntry<Field, Value> = { field: Field; value: Value };\ntype MergedEntry<Field, Value> = FieldEntry<Field, Value> & { key: string };\ntype DepTypeFields<Field> = { runtime: Field; dev: Field; peer: Field };\n\n/**\n * make the dependencies that come from imports follow the merged files, see mergeDependencies().\n * `sides` are the entries of other, current and base, in this order of preference, to take a dependency from when the\n * 3-way merge removed it.\n */\nfunction applyImports<Field extends string, Value>(\n entries: Array<MergedEntry<Field, Value>>,\n sides: Array<Map<string, FieldEntry<Field, Value>>>,\n nameOf: (key: string, value: Value) => string | undefined,\n fields: DepTypeFields<Field>,\n imports: ImportsOfMerge\n): Array<MergedEntry<Field, Value>> {\n // a types package (e.g. @types/foo) follows the package it types, see AutoDetectDeps._addTypesPackagesForTypeScript\n const importedName = (name: string) => typedPackageName(name) || name;\n const isFromImports = (name: string) =>\n imports.merged.has(importedName(name)) || imports.sides.has(importedName(name));\n const isOfPolicy = (name: string) => Boolean(imports.isOfPolicy?.(name));\n const withFieldOfImports = (entry: MergedEntry<Field, Value>, name: string): MergedEntry<Field, Value> => {\n const importedAs = imports.merged.get(name);\n // a peer is set by a policy or by the dependency itself, not by the files that import it\n if (!importedAs || entry.field === fields.peer) return entry;\n return { ...entry, field: fields[importedAs] };\n };\n const result: Array<MergedEntry<Field, Value>> = [];\n const names = new Set<string>();\n entries.forEach((entry) => {\n const name = nameOf(entry.key, entry.value);\n if (!name || isOfPolicy(name)) {\n result.push(entry);\n return;\n }\n if (isFromImports(name) && !imports.merged.has(importedName(name))) return; // no merged file imports it\n names.add(name);\n result.push(withFieldOfImports(entry, name));\n });\n const sidesByName = sides.map(\n (side) => new Map([...side].map(([key, entry]) => [nameOf(key, entry.value), { key, ...entry }]))\n );\n const importedNames = [...imports.merged.keys()].flatMap((name) => [name, toTypesPackageName(name)]);\n importedNames.forEach((name) => {\n if (names.has(name) || isOfPolicy(name)) return;\n // when no side has it, it's e.g. a core aspect, or a package that a policy ignores\n const fromSide = sidesByName.map((side) => side.get(name)).find(Boolean);\n if (!fromSide) return;\n names.add(name);\n result.push(withFieldOfImports(fromSide, name));\n });\n return result;\n}\n\n/**\n * e.g. \"@types/foo\" => \"foo\", \"@types/scope__foo\" => \"@scope/foo\". undefined when it's not a types package.\n */\nfunction typedPackageName(name: string): string | undefined {\n if (!name.startsWith('@types/')) return undefined;\n const typed = name.slice('@types/'.length);\n return typed.includes('__') ? `@${typed.replace('__', '/')}` : typed;\n}\n\nfunction toTypesPackageName(name: string): string {\n return `@types/${name.replace(/^@([^/]+)\\//, '$1__')}`;\n}\n\n/**\n * 3-way merge of the entries of each key. an entry is unchanged between two sides when it's in the same field with an\n * equal value. returns the merged entries that exist (not removed).\n */\nfunction mergeEntries<Field, Value>(\n base: Map<string, FieldEntry<Field, Value>>,\n current: Map<string, FieldEntry<Field, Value>>,\n other: Map<string, FieldEntry<Field, Value>>,\n mergeStrategy: MergeStrategy | undefined,\n isEqualValue: (a: Value, b: Value) => boolean\n): Array<MergedEntry<Field, Value>> {\n return union([...current.keys()], [...other.keys()]).flatMap((key) => {\n const merged = mergeValue(\n base.get(key),\n current.get(key),\n other.get(key),\n mergeStrategy,\n (a, b) => a.field === b.field && isEqualValue(a.value, b.value)\n );\n return merged ? [{ key, ...merged }] : [];\n });\n}\n\n/**\n * returns undefined when the merged result is \"absent\" (removed or never existed).\n */\nfunction mergeValue<T>(\n base: T | undefined,\n current: T | undefined,\n other: T | undefined,\n mergeStrategy: MergeStrategy | undefined,\n isEqualValue: (a: T, b: T) => boolean\n): T | undefined {\n const equal = (a?: T, b?: T) => (a === undefined || b === undefined ? a === b : isEqualValue(a, b));\n if (equal(current, other)) return current;\n if (equal(base, current)) return other; // changed (or removed) on other only\n if (equal(base, other)) return current; // changed (or removed) on current only\n return mergeStrategy === 'theirs' ? other : current;\n}\n\nfunction cloneDependency(dep: Dependency): Dependency {\n const clone = Dependency.getClone(dep);\n return new Dependency(clone.id, clone.relativePaths, clone.packageName, clone.versionRange);\n}\n"],"mappings":";;;;;;;;;AACA,SAA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,CAAC,GAAGqE,YAAY,CAACtE,CAAC,EAAEC,CAAC,CAAE;EACnG,IAAIuE,KAAK,CAAC9F,OAAO,EAAEC,KAAK,CAAC,EAAE,OAAOD,OAAO;EACzC,IAAI8F,KAAK,CAAC/F,IAAI,EAAEC,OAAO,CAAC,EAAE,OAAOC,KAAK,CAAC,CAAC;EACxC,IAAI6F,KAAK,CAAC/F,IAAI,EAAEE,KAAK,CAAC,EAAE,OAAOD,OAAO,CAAC,CAAC;EACxC,OAAOE,aAAa,KAAK,QAAQ,GAAGD,KAAK,GAAGD,OAAO;AACrD;AAEA,SAASgD,eAAeA,CAACpC,GAAe,EAAc;EACpD,MAAMmF,KAAK,GAAGC,oBAAU,CAACC,QAAQ,CAACrF,GAAG,CAAC;EACtC,OAAO,KAAIoF,oBAAU,EAACD,KAAK,CAAClF,EAAE,EAAEkF,KAAK,CAAClE,aAAa,EAAEkE,KAAK,CAACpE,WAAW,EAAEoE,KAAK,CAACnE,YAAY,CAAC;AAC7F","ignoreList":[]}
|
|
@@ -49,19 +49,30 @@ const toDeps = (ids = []) => asLoaded(ids.map(id => {
|
|
|
49
49
|
function snapshot({
|
|
50
50
|
comps,
|
|
51
51
|
devComps,
|
|
52
|
+
peerComps,
|
|
52
53
|
pkgs,
|
|
53
|
-
devPkgs
|
|
54
|
+
devPkgs,
|
|
55
|
+
peerPkgs
|
|
54
56
|
}) {
|
|
55
57
|
return {
|
|
56
58
|
dependencies: toDeps(comps),
|
|
57
59
|
devDependencies: toDeps(devComps),
|
|
58
|
-
peerDependencies: toDeps(),
|
|
60
|
+
peerDependencies: toDeps(peerComps),
|
|
59
61
|
packageDependencies: pkgs || {},
|
|
60
62
|
devPackageDependencies: devPkgs || {},
|
|
61
|
-
peerPackageDependencies: {}
|
|
63
|
+
peerPackageDependencies: peerPkgs || {}
|
|
62
64
|
};
|
|
63
65
|
}
|
|
66
|
+
const importsOf = (merged, sides) => ({
|
|
67
|
+
merged: new Map(Object.entries(merged)),
|
|
68
|
+
sides: new Set(sides)
|
|
69
|
+
});
|
|
64
70
|
const idsOf = deps => deps.get().map(dep => dep.id.toString());
|
|
71
|
+
const side = (input, ignoredPackages = [], forcedPackages = []) => ({
|
|
72
|
+
dependencies: snapshot(input),
|
|
73
|
+
ignoredPackages: new Set(ignoredPackages),
|
|
74
|
+
forcedPackages: new Set(forcedPackages)
|
|
75
|
+
});
|
|
65
76
|
describe('mergeDependencies', () => {
|
|
66
77
|
describe('packages', () => {
|
|
67
78
|
const base = snapshot({
|
|
@@ -294,6 +305,206 @@ describe('mergeDependencies', () => {
|
|
|
294
305
|
(0, _chai().expect)(idsOf((0, _mergeDependencies().mergeDependencies)(base, current, other, 'manual').dependencies)).to.deep.equal([]);
|
|
295
306
|
});
|
|
296
307
|
});
|
|
308
|
+
describe('with the imports of the merged files', () => {
|
|
309
|
+
describe('a package that one side stopped importing and the other side imports from another file', () => {
|
|
310
|
+
// the lane removed the only import of lodash, main kept it and imports it from another file as well
|
|
311
|
+
const base = snapshot({
|
|
312
|
+
pkgs: {
|
|
313
|
+
lodash: '4.17.20'
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
const current = snapshot({});
|
|
317
|
+
const other = snapshot({
|
|
318
|
+
pkgs: {
|
|
319
|
+
lodash: '4.17.21'
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
const imports = importsOf({
|
|
323
|
+
lodash: 'runtime'
|
|
324
|
+
}, ['lodash']);
|
|
325
|
+
it('should be removed without the imports, as it was removed on current only', () => {
|
|
326
|
+
(0, _chai().expect)((0, _mergeDependencies().mergeDependencies)(base, current, other, 'manual').packageDependencies).to.deep.equal({});
|
|
327
|
+
});
|
|
328
|
+
it('should be kept, taken from other, when the merged files import it', () => {
|
|
329
|
+
const merged = (0, _mergeDependencies().mergeDependencies)(base, current, other, 'manual', undefined, imports);
|
|
330
|
+
(0, _chai().expect)(merged.packageDependencies).to.deep.equal({
|
|
331
|
+
lodash: '4.17.21'
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
describe('a package that each side stopped importing from a different file', () => {
|
|
336
|
+
// both sides still import it, but not the merged files
|
|
337
|
+
const base = snapshot({
|
|
338
|
+
pkgs: {
|
|
339
|
+
lodash: '4.17.20'
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
const merged = (0, _mergeDependencies().mergeDependencies)(base, base, base, 'manual', undefined, importsOf({}, ['lodash']));
|
|
343
|
+
it('should be removed', () => {
|
|
344
|
+
(0, _chai().expect)(merged.packageDependencies).to.deep.equal({});
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
describe('a component dependency that the merged files import from dev files only', () => {
|
|
348
|
+
const base = snapshot({
|
|
349
|
+
comps: ['my-scope/b@0.0.1']
|
|
350
|
+
});
|
|
351
|
+
const merged = (0, _mergeDependencies().mergeDependencies)(base, base, base, 'manual', undefined, importsOf({
|
|
352
|
+
'@my-scope/b': 'dev'
|
|
353
|
+
}, []));
|
|
354
|
+
it('should be a dev dependency', () => {
|
|
355
|
+
(0, _chai().expect)(idsOf(merged.dependencies)).to.deep.equal([]);
|
|
356
|
+
(0, _chai().expect)(idsOf(merged.devDependencies)).to.deep.equal(['my-scope/b@0.0.1']);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
describe('a component dependency that the merged files import, and only base has', () => {
|
|
360
|
+
const base = snapshot({
|
|
361
|
+
comps: ['my-scope/b@0.0.1']
|
|
362
|
+
});
|
|
363
|
+
const current = snapshot({});
|
|
364
|
+
const merged = (0, _mergeDependencies().mergeDependencies)(base, current, current, 'manual', undefined, importsOf({
|
|
365
|
+
'@my-scope/b': 'runtime'
|
|
366
|
+
}, []));
|
|
367
|
+
it('should be taken from base', () => {
|
|
368
|
+
(0, _chai().expect)(idsOf(merged.dependencies)).to.deep.equal(['my-scope/b@0.0.1']);
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
describe('a peer package that the merged files import', () => {
|
|
372
|
+
const base = snapshot({
|
|
373
|
+
peerPkgs: {
|
|
374
|
+
react: '^18.0.0'
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
const merged = (0, _mergeDependencies().mergeDependencies)(base, base, base, 'manual', undefined, importsOf({
|
|
378
|
+
react: 'runtime'
|
|
379
|
+
}, ['react']));
|
|
380
|
+
it('should stay a peer', () => {
|
|
381
|
+
(0, _chai().expect)(merged.peerPackageDependencies).to.deep.equal({
|
|
382
|
+
react: '^18.0.0'
|
|
383
|
+
});
|
|
384
|
+
(0, _chai().expect)(merged.packageDependencies).to.deep.equal({});
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
describe('a package that no side imports', () => {
|
|
388
|
+
// e.g. added by a policy
|
|
389
|
+
const base = snapshot({
|
|
390
|
+
pkgs: {
|
|
391
|
+
'core-js': '3.0.0'
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
const merged = (0, _mergeDependencies().mergeDependencies)(base, base, base, 'manual', undefined, importsOf({}, []));
|
|
395
|
+
it('should keep the 3-way result', () => {
|
|
396
|
+
(0, _chai().expect)(merged.packageDependencies).to.deep.equal({
|
|
397
|
+
'core-js': '3.0.0'
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
describe('a types package', () => {
|
|
402
|
+
const base = snapshot({
|
|
403
|
+
pkgs: {
|
|
404
|
+
'@scope/foo': '1.0.0'
|
|
405
|
+
},
|
|
406
|
+
devPkgs: {
|
|
407
|
+
'@types/scope__foo': '1.0.0'
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
const current = snapshot({});
|
|
411
|
+
it('should be removed with the package it types', () => {
|
|
412
|
+
const merged = (0, _mergeDependencies().mergeDependencies)(base, base, base, 'manual', undefined, importsOf({}, ['@scope/foo']));
|
|
413
|
+
(0, _chai().expect)(merged.devPackageDependencies).to.deep.equal({});
|
|
414
|
+
});
|
|
415
|
+
it('should be kept with the package it types', () => {
|
|
416
|
+
const imports = importsOf({
|
|
417
|
+
'@scope/foo': 'runtime'
|
|
418
|
+
}, ['@scope/foo']);
|
|
419
|
+
const merged = (0, _mergeDependencies().mergeDependencies)(base, current, base, 'manual', undefined, imports);
|
|
420
|
+
(0, _chai().expect)(merged.packageDependencies).to.deep.equal({
|
|
421
|
+
'@scope/foo': '1.0.0'
|
|
422
|
+
});
|
|
423
|
+
(0, _chai().expect)(merged.devPackageDependencies).to.deep.equal({
|
|
424
|
+
'@types/scope__foo': '1.0.0'
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
describe('getImportedPackagesWithoutVersion', () => {
|
|
431
|
+
it('should return a package that a side ignored and the merge does not, when no side has it', () => {
|
|
432
|
+
// the lane imports lodash while it's ignored, main removes the "-"
|
|
433
|
+
const result = (0, _mergeDependencies().getImportedPackagesWithoutVersion)(side({}, ['lodash']), side({}, ['lodash']), side({}), ['lodash']);
|
|
434
|
+
(0, _chai().expect)(result).to.deep.equal(['lodash']);
|
|
435
|
+
});
|
|
436
|
+
it('should not return a package that the merge still ignores', () => {
|
|
437
|
+
const ignoring = side({}, ['lodash']);
|
|
438
|
+
(0, _chai().expect)((0, _mergeDependencies().getImportedPackagesWithoutVersion)(ignoring, ignoring, ignoring, ['lodash'])).to.deep.equal([]);
|
|
439
|
+
});
|
|
440
|
+
it('should not return a package that a side has as a dependency', () => {
|
|
441
|
+
const result = (0, _mergeDependencies().getImportedPackagesWithoutVersion)(side({}, ['lodash']), side({}, ['lodash']), side({
|
|
442
|
+
pkgs: {
|
|
443
|
+
lodash: '4.17.21'
|
|
444
|
+
}
|
|
445
|
+
}), ['lodash']);
|
|
446
|
+
(0, _chai().expect)(result).to.deep.equal([]);
|
|
447
|
+
});
|
|
448
|
+
it('should return a package that a side ignored and the merge does not, when a side has its types package only', () => {
|
|
449
|
+
const result = (0, _mergeDependencies().getImportedPackagesWithoutVersion)(side({}, ['lodash']), side({
|
|
450
|
+
devPkgs: {
|
|
451
|
+
'@types/lodash': '4.17.0'
|
|
452
|
+
}
|
|
453
|
+
}, ['lodash']), side({}), ['lodash']);
|
|
454
|
+
(0, _chai().expect)(result).to.deep.equal(['lodash']);
|
|
455
|
+
});
|
|
456
|
+
it('should not return a package that no side ignored', () => {
|
|
457
|
+
// e.g. a core aspect, which is never a dependency
|
|
458
|
+
(0, _chai().expect)((0, _mergeDependencies().getImportedPackagesWithoutVersion)(side({}), side({}), side({}), ['@scope/core'])).to.deep.equal([]);
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
describe('withPolicyOfMerge', () => {
|
|
462
|
+
const mergeWithImports = (base, current, other, imports) => (0, _mergeDependencies().mergeDependencies)(base.dependencies, current.dependencies, other.dependencies, 'manual', undefined, (0, _mergeDependencies().withPolicyOfMerge)(imports, base, current, other));
|
|
463
|
+
it('should let the 3-way merge remove a package that other started to ignore, although the files import it', () => {
|
|
464
|
+
const base = side({
|
|
465
|
+
pkgs: {
|
|
466
|
+
lodash: '4.17.21'
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
const merged = mergeWithImports(base, base, side({}, ['lodash']), importsOf({
|
|
470
|
+
lodash: 'runtime'
|
|
471
|
+
}, ['lodash']));
|
|
472
|
+
(0, _chai().expect)(merged.packageDependencies).to.deep.equal({});
|
|
473
|
+
});
|
|
474
|
+
it('should keep a package that the policy forces, when the merged files stop importing it', () => {
|
|
475
|
+
// e.g. an own peer of an env, which is a runtime dependency of the env
|
|
476
|
+
const env = side({
|
|
477
|
+
pkgs: {
|
|
478
|
+
react: '^18.0.0'
|
|
479
|
+
}
|
|
480
|
+
}, [], ['react']);
|
|
481
|
+
const merged = mergeWithImports(env, env, env, importsOf({}, ['react']));
|
|
482
|
+
(0, _chai().expect)(merged.packageDependencies).to.deep.equal({
|
|
483
|
+
react: '^18.0.0'
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
it('should let the 3-way merge remove a types package that other started to ignore, although the files import it', () => {
|
|
487
|
+
const base = side({
|
|
488
|
+
pkgs: {
|
|
489
|
+
react: '18.0.0'
|
|
490
|
+
},
|
|
491
|
+
devPkgs: {
|
|
492
|
+
'@types/react': '18.0.0'
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
const other = side({
|
|
496
|
+
pkgs: {
|
|
497
|
+
react: '18.0.0'
|
|
498
|
+
}
|
|
499
|
+
}, ['@types/react']);
|
|
500
|
+
const merged = mergeWithImports(base, base, other, importsOf({
|
|
501
|
+
react: 'runtime'
|
|
502
|
+
}, ['react']));
|
|
503
|
+
(0, _chai().expect)(merged.devPackageDependencies).to.deep.equal({});
|
|
504
|
+
(0, _chai().expect)(merged.packageDependencies).to.deep.equal({
|
|
505
|
+
react: '18.0.0'
|
|
506
|
+
});
|
|
507
|
+
});
|
|
297
508
|
});
|
|
298
509
|
|
|
299
510
|
//# sourceMappingURL=merge-dependencies.spec.js.map
|