@teambit/snapping 1.0.108 → 1.0.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/__bit_junit.xml +9 -0
- package/artifacts/preview/teambit_component_snapping-preview.js +1 -0
- package/package.json +21 -21
- package/components-have-issues.ts +0 -39
- package/flattened-edges.ts +0 -189
- package/generate-comp-from-scope.ts +0 -124
- package/index.ts +0 -8
- package/reset-cmd.ts +0 -70
- package/snap-cmd.ts +0 -195
- package/snap-distance-cmd.ts +0 -29
- package/snap-from-scope.cmd.ts +0 -155
- package/snapping.aspect.ts +0 -5
- package/snapping.main.runtime.ts +0 -1331
- package/snapping.spec.ts +0 -52
- package/tag-cmd.ts +0 -360
- package/tag-from-scope.cmd.ts +0 -258
- package/tag-model-component.ts +0 -641
- /package/dist/{preview-1703647408454.js → preview-1703698405864.js} +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<testsuites>
|
|
3
|
+
<testsuite name="teambit.component/snapping@1.0.109" timestamp="2023-12-27T17:56:28.158Z" tests="2" failures="0" errors="0" skipped="1">
|
|
4
|
+
<testcase classname="snapping.spec.js" name="tag should throw an ComponentsHaveIssues error" time="0.162"/>
|
|
5
|
+
<testcase classname="snapping.spec.js" name="should not throw an error if the config was set to ignore MissingPackagesDependenciesOnFs error">
|
|
6
|
+
<skipped/>
|
|
7
|
+
</testcase>
|
|
8
|
+
</testsuite>
|
|
9
|
+
</testsuites>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports["teambit.component/snapping-preview"]=o():e["teambit.component/snapping-preview"]=o()}(self,(()=>(()=>{"use strict";var e={d:(o,t)=>{for(var n in t)e.o(t,n)&&!e.o(o,n)&&Object.defineProperty(o,n,{enumerable:!0,get:t[n]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},o={};e.r(o),e.d(o,{compositions:()=>t,compositions_metadata:()=>r,overview:()=>n});const t=[],n=[],r={compositions:[]};return o})()));
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/snapping",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.109",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/component/snapping",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.component",
|
|
8
8
|
"name": "snapping",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.109"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"chalk": "2.4.2",
|
|
@@ -23,22 +23,22 @@
|
|
|
23
23
|
"@teambit/harmony": "0.4.6",
|
|
24
24
|
"@teambit/component-version": "1.0.3",
|
|
25
25
|
"@teambit/lane-id": "0.0.311",
|
|
26
|
-
"@teambit/issues": "1.0.
|
|
27
|
-
"@teambit/graph": "1.0.
|
|
28
|
-
"@teambit/logger": "0.0.
|
|
29
|
-
"@teambit/scope": "1.0.
|
|
30
|
-
"@teambit/component": "1.0.
|
|
31
|
-
"@teambit/dependencies": "1.0.
|
|
32
|
-
"@teambit/dependency-resolver": "1.0.
|
|
33
|
-
"@teambit/cli": "0.0.
|
|
26
|
+
"@teambit/issues": "1.0.109",
|
|
27
|
+
"@teambit/graph": "1.0.109",
|
|
28
|
+
"@teambit/logger": "0.0.934",
|
|
29
|
+
"@teambit/scope": "1.0.109",
|
|
30
|
+
"@teambit/component": "1.0.109",
|
|
31
|
+
"@teambit/dependencies": "1.0.109",
|
|
32
|
+
"@teambit/dependency-resolver": "1.0.109",
|
|
33
|
+
"@teambit/cli": "0.0.841",
|
|
34
34
|
"@teambit/component-issues": "0.0.138",
|
|
35
|
-
"@teambit/global-config": "0.0.
|
|
36
|
-
"@teambit/builder": "1.0.
|
|
37
|
-
"@teambit/export": "1.0.
|
|
38
|
-
"@teambit/importer": "1.0.
|
|
39
|
-
"@teambit/insights": "1.0.
|
|
40
|
-
"@teambit/workspace": "1.0.
|
|
41
|
-
"@teambit/workspace.modules.node-modules-linker": "0.0.
|
|
35
|
+
"@teambit/global-config": "0.0.843",
|
|
36
|
+
"@teambit/builder": "1.0.109",
|
|
37
|
+
"@teambit/export": "1.0.109",
|
|
38
|
+
"@teambit/importer": "1.0.109",
|
|
39
|
+
"@teambit/insights": "1.0.109",
|
|
40
|
+
"@teambit/workspace": "1.0.109",
|
|
41
|
+
"@teambit/workspace.modules.node-modules-linker": "0.0.159"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/lodash": "4.14.165",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"@types/mocha": "9.1.0",
|
|
51
51
|
"@types/jest": "^29.2.2",
|
|
52
52
|
"@types/testing-library__jest-dom": "^5.9.5",
|
|
53
|
-
"@teambit/harmony.envs.core-aspect-env": "0.0.
|
|
54
|
-
"@teambit/compiler": "1.0.
|
|
55
|
-
"@teambit/component.testing.mock-components": "0.0.
|
|
56
|
-
"@teambit/harmony.testing.load-aspect": "0.0.
|
|
53
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.14",
|
|
54
|
+
"@teambit/compiler": "1.0.109",
|
|
55
|
+
"@teambit/component.testing.mock-components": "0.0.181",
|
|
56
|
+
"@teambit/harmony.testing.load-aspect": "0.0.180",
|
|
57
57
|
"@teambit/workspace.testing.mock-workspace": "0.0.18"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { BitError } from '@teambit/bit-error';
|
|
2
|
-
import IssuesAspect from '@teambit/issues';
|
|
3
|
-
import { formatIssues } from '@teambit/legacy/dist/cli/templates/component-issues-template';
|
|
4
|
-
import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import { uniq } from 'lodash';
|
|
7
|
-
|
|
8
|
-
export class ComponentsHaveIssues extends BitError {
|
|
9
|
-
constructor(components: ConsumerComponent[]) {
|
|
10
|
-
components.forEach((component) => {
|
|
11
|
-
component.issues = component.issues.filterNonTagBlocking();
|
|
12
|
-
});
|
|
13
|
-
const allIssueNames = uniq(components.map((comp) => comp.issues.getAllIssueNames()).flat());
|
|
14
|
-
const issuesColored = componentIssuesTemplate(components);
|
|
15
|
-
super(`error: issues found with the following components
|
|
16
|
-
${issuesColored}
|
|
17
|
-
|
|
18
|
-
to get the list of component-issues names and suggestions how to resolve them, run "bit component-issues".
|
|
19
|
-
|
|
20
|
-
while highly not recommended, it's possible to ignore issues in two ways:
|
|
21
|
-
1) temporarily ignore for this tag/snap command by entering "--ignore-issues" flag, e.g. \`bit tag --ignore-issues "${allIssueNames.join(
|
|
22
|
-
', '
|
|
23
|
-
)}" \`
|
|
24
|
-
2) ignore the issue completely by configuring it in the workspace.jsonc file. e.g:
|
|
25
|
-
"${IssuesAspect.id}": {
|
|
26
|
-
"ignoreIssues": [${allIssueNames.map((issue) => `"${issue}"`).join(', ')}]
|
|
27
|
-
}
|
|
28
|
-
`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function componentIssuesTemplate(components: ConsumerComponent[]) {
|
|
33
|
-
function format(component: ConsumerComponent) {
|
|
34
|
-
return `${chalk.underline(chalk.cyan(component.id.toString()))}\n${formatIssues(component)}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const result = `\n${components.map(format).join('\n')}`;
|
|
38
|
-
return result;
|
|
39
|
-
}
|
package/flattened-edges.ts
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { Graph, Node, Edge } from '@teambit/graph.cleargraph';
|
|
2
|
-
import { DepEdgeType } from '@teambit/graph';
|
|
3
|
-
import { ScopeMain } from '@teambit/scope';
|
|
4
|
-
import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
|
|
5
|
-
import { Lane } from '@teambit/legacy/dist/scope/models';
|
|
6
|
-
import { ComponentID, ComponentIdList } from '@teambit/component-id';
|
|
7
|
-
import { DepEdge } from '@teambit/legacy/dist/scope/models/version';
|
|
8
|
-
import { Logger } from '@teambit/logger';
|
|
9
|
-
import { pMapPool } from '@teambit/legacy/dist/utils/promise-with-concurrent';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* the goal of this class is to determine the graph dependencies of a given set of components with minimal effort.
|
|
13
|
-
* it takes advantage of the fact that we save the dependency graph in the `Version` object and tries to reuse it.
|
|
14
|
-
*
|
|
15
|
-
* to optimize it as much as possible, we do it in 4 steps. each step we check whether the graph has missing ids,
|
|
16
|
-
* and if so, continue to the next step.
|
|
17
|
-
*
|
|
18
|
-
* * * First step * * *
|
|
19
|
-
* we have two groups in this graph.
|
|
20
|
-
* 1. components that are now versioned (this.consumerComponents). they have the new version (which is not in the scope yet).
|
|
21
|
-
* 2. component that are not part of the current snap/tag.
|
|
22
|
-
* it's not possible that this group has new components that never been into the scope, otherwise the tag/snap is failing.
|
|
23
|
-
* so we know we can always find the version-object of these components in the scope or import them.
|
|
24
|
-
*
|
|
25
|
-
* given the above. we can simply get the first level of dependencies of the first group.
|
|
26
|
-
* start the graph by adding them all as nodes and edges.
|
|
27
|
-
*
|
|
28
|
-
* this dependencies array may contain components from the first group. we can filter them out. (we don't care about
|
|
29
|
-
* them, they're part of the graph already)
|
|
30
|
-
* we're left with the dependencies that are part of the second group. there are the `missingFromGraph`.
|
|
31
|
-
*
|
|
32
|
-
* * * Second step * * *
|
|
33
|
-
* instead of import these components, we can more efficiently get their previous version from the scope.
|
|
34
|
-
* it must be already in the scope because these are the components we load in the first place.
|
|
35
|
-
* chances are that 99% of the dependencies of the current components objects are identical to the previous version.
|
|
36
|
-
* by adding the flattenedEdges of the previous versions we can probably finish the graph without importing a single
|
|
37
|
-
* component. It's ok that this graph of previous versions has ids that are not relevant to this graph. for example, if
|
|
38
|
-
* we now tag bar@0.0.2, this graph will have bar@0.0.1 although it's not relevant. it's ok, because finally we don't
|
|
39
|
-
* use this graph as a whole. we only pick a component and get its sub-graph, so all irrelevant ids are ignored.
|
|
40
|
-
*
|
|
41
|
-
* * * Third step * * *
|
|
42
|
-
* in case the graph above wasn't enough. we can import the missing components and get their flattenedEdges.
|
|
43
|
-
* all components that were snapped/tagged since around 0.0.8000 have the flattenedEdges saved in the version.
|
|
44
|
-
* older components don't have them and that's why the last step is needed.
|
|
45
|
-
*
|
|
46
|
-
* * * Fourth step * * *
|
|
47
|
-
* this is the worst scenario. we have some old dependencies without flattenedEdges, we have to import them with
|
|
48
|
-
* all their flattened dependencies.
|
|
49
|
-
* once we have all these objects we can iterate them and add them to the graph.
|
|
50
|
-
*/
|
|
51
|
-
export class FlattenedEdgesGetter {
|
|
52
|
-
private graph = new Graph<ComponentID, DepEdgeType>();
|
|
53
|
-
private missingFromGraph: ComponentID[] = [];
|
|
54
|
-
constructor(
|
|
55
|
-
private scope: ScopeMain,
|
|
56
|
-
private consumerComponents: ConsumerComponent[],
|
|
57
|
-
private logger: Logger,
|
|
58
|
-
private lane?: Lane
|
|
59
|
-
) {}
|
|
60
|
-
|
|
61
|
-
async buildGraph() {
|
|
62
|
-
this.logger.debug('FlattenedEdgesGetter, start');
|
|
63
|
-
this.buildTheFirstLevel();
|
|
64
|
-
this.populateMissingFromGraph();
|
|
65
|
-
if (!this.missingFromGraph.length) {
|
|
66
|
-
return this.graph;
|
|
67
|
-
}
|
|
68
|
-
this.logger.debug(
|
|
69
|
-
`FlattenedEdgesGetter, total ${this.missingFromGraph.length} components missing from graph, trying to find them in previous versions`
|
|
70
|
-
);
|
|
71
|
-
await this.addPreviousGraphs();
|
|
72
|
-
if (!this.missingFromGraph.length) {
|
|
73
|
-
this.logger.debug(`FlattenedEdgesGetter, all missing ids were found in previous versions`);
|
|
74
|
-
return this.graph;
|
|
75
|
-
}
|
|
76
|
-
this.logger.debug(
|
|
77
|
-
`FlattenedEdgesGetter, total ${this.missingFromGraph.length} components missing from graph, trying to import them and load their flattenedEdges`
|
|
78
|
-
);
|
|
79
|
-
await this.importMissingAndAddToGraph();
|
|
80
|
-
if (!this.missingFromGraph.length) {
|
|
81
|
-
this.logger.debug(`FlattenedEdgesGetter, successfully found flattened edges for all components without graph`);
|
|
82
|
-
return this.graph;
|
|
83
|
-
}
|
|
84
|
-
this.logger.debug(
|
|
85
|
-
`FlattenedEdgesGetter, total ${this.missingFromGraph.length} components without graph and their version-objects has no flattened edges, no choice but to import all their flattened deps`
|
|
86
|
-
);
|
|
87
|
-
await this.addComponentsWithMissingFlattenedEdges();
|
|
88
|
-
return this.graph;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private async importMissingAndAddToGraph() {
|
|
92
|
-
const idsWithoutGraphList = ComponentIdList.fromArray(this.missingFromGraph);
|
|
93
|
-
await this.scope.legacyScope.scopeImporter.importWithoutDeps(idsWithoutGraphList, {
|
|
94
|
-
cache: true,
|
|
95
|
-
lane: this.lane,
|
|
96
|
-
});
|
|
97
|
-
const componentsAndVersions = await this.scope.legacyScope.getComponentsAndVersions(idsWithoutGraphList);
|
|
98
|
-
const missingEdges: ComponentID[] = [];
|
|
99
|
-
await Promise.all(
|
|
100
|
-
componentsAndVersions.map(async ({ component, version, versionStr }) => {
|
|
101
|
-
const flattenedEdges = await version.getFlattenedEdges(this.scope.legacyScope.objects);
|
|
102
|
-
if (!flattenedEdges.length && version.flattenedDependencies.length) {
|
|
103
|
-
missingEdges.push(component.toComponentId().changeVersion(versionStr));
|
|
104
|
-
}
|
|
105
|
-
this.addFlattenedEdgesToGraph(flattenedEdges);
|
|
106
|
-
})
|
|
107
|
-
);
|
|
108
|
-
this.missingFromGraph = missingEdges;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private async addPreviousGraphs() {
|
|
112
|
-
const flattenedDeps: ComponentID[][] = [];
|
|
113
|
-
await pMapPool(
|
|
114
|
-
this.consumerComponents,
|
|
115
|
-
async (comp) => {
|
|
116
|
-
const previousVersion = comp.previouslyUsedVersion;
|
|
117
|
-
if (!previousVersion) return;
|
|
118
|
-
const modelComponent =
|
|
119
|
-
comp.modelComponent || (await this.scope.legacyScope.getModelComponent(comp.id.changeVersion(undefined)));
|
|
120
|
-
const version = await modelComponent.loadVersion(previousVersion, this.scope.legacyScope.objects, true);
|
|
121
|
-
const flattenedEdges = await version.getFlattenedEdges(this.scope.legacyScope.objects);
|
|
122
|
-
if (flattenedEdges.length) flattenedDeps.push(version.flattenedDependencies);
|
|
123
|
-
this.addFlattenedEdgesToGraph(flattenedEdges);
|
|
124
|
-
},
|
|
125
|
-
{ concurrency: 50 }
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
const flattenedDepsUniq = ComponentIdList.uniqFromArray(flattenedDeps.flat());
|
|
129
|
-
this.missingFromGraph = this.missingFromGraph.filter((id) => !flattenedDepsUniq.has(id));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private async addComponentsWithMissingFlattenedEdges() {
|
|
133
|
-
const missingEdges = this.missingFromGraph;
|
|
134
|
-
this.logger.warn(`FlattenedEdgesGetter, found ${missingEdges.length} components with missing flattened edges:
|
|
135
|
-
${missingEdges.map((e) => e.toString()).join('\n')}`);
|
|
136
|
-
const missingEdgesList = ComponentIdList.fromArray(missingEdges);
|
|
137
|
-
const results = await this.scope.legacyScope.scopeImporter.importMany({
|
|
138
|
-
ids: missingEdgesList,
|
|
139
|
-
cache: true,
|
|
140
|
-
lane: this.lane,
|
|
141
|
-
preferDependencyGraph: false, // we know it does not have a dependency graph
|
|
142
|
-
});
|
|
143
|
-
const allFlattened = results.map((result) => result.version.flattenedDependencies);
|
|
144
|
-
allFlattened.push(missingEdgesList);
|
|
145
|
-
const allFlattenedUniq = ComponentIdList.uniqFromArray(allFlattened.flat());
|
|
146
|
-
const componentsAndVersions = await this.scope.legacyScope.getComponentsAndVersions(
|
|
147
|
-
ComponentIdList.fromArray(allFlattenedUniq)
|
|
148
|
-
);
|
|
149
|
-
componentsAndVersions.forEach(({ component, version, versionStr }) => {
|
|
150
|
-
const compId = component.toComponentId().changeVersion(versionStr);
|
|
151
|
-
this.graph.setNode(new Node(compId.toString(), compId));
|
|
152
|
-
this.addEdges(compId, version.dependencies, 'prod');
|
|
153
|
-
this.addEdges(compId, version.devDependencies, 'dev');
|
|
154
|
-
this.addEdges(compId, version.extensionDependencies, 'ext');
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
private addFlattenedEdgesToGraph(flattenedEdges: DepEdge[]) {
|
|
159
|
-
flattenedEdges.forEach(({ source, target, type }) => {
|
|
160
|
-
this.graph.setNode(new Node(source.toString(), source));
|
|
161
|
-
this.graph.setNode(new Node(target.toString(), target));
|
|
162
|
-
this.graph.setEdge(new Edge(source.toString(), target.toString(), type));
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private populateMissingFromGraph() {
|
|
167
|
-
const allIds = this.graph.nodes.map((node) => node.attr);
|
|
168
|
-
const currentlySnappedIds = ComponentIdList.fromArray(this.consumerComponents.map((comp) => comp.id));
|
|
169
|
-
const filteredIds = allIds.filter((id) => !currentlySnappedIds.has(id));
|
|
170
|
-
this.missingFromGraph = filteredIds;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
private buildTheFirstLevel() {
|
|
174
|
-
this.consumerComponents.forEach((comp) => {
|
|
175
|
-
const id = comp.id;
|
|
176
|
-
this.graph.setNode(new Node(id.toString(), id));
|
|
177
|
-
this.addEdges(comp.id, comp.dependencies, 'prod');
|
|
178
|
-
this.addEdges(comp.id, comp.devDependencies, 'dev');
|
|
179
|
-
this.addEdges(comp.id, comp.extensionDependencies, 'ext');
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
private addEdges(compId: ComponentID, dependencies: ConsumerComponent['dependencies'], label: DepEdgeType) {
|
|
184
|
-
dependencies.get().forEach((dep) => {
|
|
185
|
-
this.graph.setNode(new Node(dep.id.toString(), dep.id));
|
|
186
|
-
this.graph.setEdge(new Edge(compId.toString(), dep.id.toString(), label));
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { ComponentID } from '@teambit/component-id';
|
|
2
|
-
import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
|
|
3
|
-
import { Dependency } from '@teambit/legacy/dist/consumer/component/dependencies';
|
|
4
|
-
import { SourceFile } from '@teambit/legacy/dist/consumer/component/sources';
|
|
5
|
-
import { ScopeMain } from '@teambit/scope';
|
|
6
|
-
import ComponentOverrides from '@teambit/legacy/dist/consumer/config/component-overrides';
|
|
7
|
-
import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config';
|
|
8
|
-
import { Component } from '@teambit/component';
|
|
9
|
-
import { CURRENT_SCHEMA } from '@teambit/legacy/dist/consumer/component/component-schema';
|
|
10
|
-
import { DependenciesMain } from '@teambit/dependencies';
|
|
11
|
-
import DependencyResolverAspect, { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
12
|
-
import { FileData } from './snap-from-scope.cmd';
|
|
13
|
-
import { SnapDataParsed } from './snapping.main.runtime';
|
|
14
|
-
|
|
15
|
-
export type CompData = {
|
|
16
|
-
componentId: ComponentID;
|
|
17
|
-
dependencies: ComponentID[];
|
|
18
|
-
aspects: Record<string, any> | undefined;
|
|
19
|
-
message: string | undefined;
|
|
20
|
-
files: FileData[] | undefined;
|
|
21
|
-
mainFile?: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* normally new components are created from a workspace. the files are in the filesystem and the ConsumerComponent
|
|
26
|
-
* object is created from the files.
|
|
27
|
-
* here, we need to create the ConsumerComponent object "on the fly". we don't have workspace, only scope. the files
|
|
28
|
-
* are in-memory (we got them from snap-from-scope command).
|
|
29
|
-
* the way how it is done is by creating a minimal ConsumerComponent object, then convert `Version` object from it,
|
|
30
|
-
* write the version and files into the scope as objects, so then it's possible to load Component object using the
|
|
31
|
-
* ConsumerComponent.
|
|
32
|
-
*/
|
|
33
|
-
export async function generateCompFromScope(scope: ScopeMain, compData: CompData): Promise<Component> {
|
|
34
|
-
if (!compData.files) throw new Error('generateComp: files are missing');
|
|
35
|
-
const files = compData.files.map((file) => {
|
|
36
|
-
return new SourceFile({ base: '.', path: file.path, contents: Buffer.from(file.content), test: false });
|
|
37
|
-
});
|
|
38
|
-
const id = compData.componentId;
|
|
39
|
-
const extensions = ExtensionDataList.fromConfigObject(compData.aspects || {});
|
|
40
|
-
|
|
41
|
-
const consumerComponent = new ConsumerComponent({
|
|
42
|
-
mainFile: compData.mainFile || 'index.ts',
|
|
43
|
-
name: compData.componentId.fullName,
|
|
44
|
-
scope: compData.componentId.scope,
|
|
45
|
-
files,
|
|
46
|
-
schema: CURRENT_SCHEMA,
|
|
47
|
-
overrides: await ComponentOverrides.loadNewFromScope(id, files, extensions),
|
|
48
|
-
defaultScope: compData.componentId.scope,
|
|
49
|
-
extensions,
|
|
50
|
-
// the dummy data here are not important. this Version object will be discarded later.
|
|
51
|
-
log: {
|
|
52
|
-
message: compData.message || '',
|
|
53
|
-
date: Date.now().toString(),
|
|
54
|
-
username: '',
|
|
55
|
-
email: '',
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
const { version, files: filesBitObject } = await scope.legacyScope.sources.consumerComponentToVersion(
|
|
59
|
-
consumerComponent
|
|
60
|
-
);
|
|
61
|
-
const modelComponent = scope.legacyScope.sources.findOrAddComponent(consumerComponent);
|
|
62
|
-
consumerComponent.version = version.hash().toString();
|
|
63
|
-
await scope.legacyScope.objects.writeObjectsToTheFS([version, modelComponent, ...filesBitObject.map((f) => f.file)]);
|
|
64
|
-
const component = await scope.getManyByLegacy([consumerComponent]);
|
|
65
|
-
|
|
66
|
-
return component[0];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export async function addDeps(
|
|
70
|
-
component: Component,
|
|
71
|
-
snapData: SnapDataParsed,
|
|
72
|
-
scope: ScopeMain,
|
|
73
|
-
deps: DependenciesMain,
|
|
74
|
-
depsResolver: DependencyResolverMain
|
|
75
|
-
) {
|
|
76
|
-
const newDeps = snapData.newDependencies || [];
|
|
77
|
-
const compIdsData = newDeps.filter((dep) => dep.isComponent);
|
|
78
|
-
const compIdsDataParsed = compIdsData.map((data) => ({
|
|
79
|
-
...data,
|
|
80
|
-
id: ComponentID.fromString(data.id),
|
|
81
|
-
}));
|
|
82
|
-
const compIds = compIdsDataParsed.map((dep) => (dep.version ? dep.id.changeVersion(dep.version) : dep.id));
|
|
83
|
-
const comps = await scope.getMany(compIds);
|
|
84
|
-
const toDependency = (depId: ComponentID) => {
|
|
85
|
-
const comp = comps.find((c) => c.id.isEqualWithoutVersion(depId));
|
|
86
|
-
if (!comp) throw new Error(`unable to find the specified dependency ${depId.toString()} in the scope`);
|
|
87
|
-
const pkgName = depsResolver.getPackageName(comp);
|
|
88
|
-
return new Dependency(comp.id, [], pkgName);
|
|
89
|
-
};
|
|
90
|
-
const compDeps = compIdsDataParsed.filter((c) => c.type === 'runtime').map((dep) => toDependency(dep.id));
|
|
91
|
-
const compDevDeps = compIdsDataParsed.filter((c) => c.type === 'dev').map((dep) => toDependency(dep.id));
|
|
92
|
-
const packageDeps = newDeps.filter((dep) => !dep.isComponent);
|
|
93
|
-
const toPackageObj = (pkgs: Array<{ id: string; version?: string }>) => {
|
|
94
|
-
return pkgs.reduce((acc, curr) => {
|
|
95
|
-
if (!curr.version) throw new Error(`please specify a version for the package dependency: "${curr.id}"`);
|
|
96
|
-
acc[curr.id] = curr.version;
|
|
97
|
-
return acc;
|
|
98
|
-
}, {});
|
|
99
|
-
};
|
|
100
|
-
const dependenciesData = {
|
|
101
|
-
allDependencies: {
|
|
102
|
-
dependencies: compDeps,
|
|
103
|
-
devDependencies: compDevDeps,
|
|
104
|
-
},
|
|
105
|
-
allPackagesDependencies: {
|
|
106
|
-
packageDependencies: toPackageObj(packageDeps.filter((dep) => dep.type === 'runtime')),
|
|
107
|
-
devPackageDependencies: toPackageObj(packageDeps.filter((dep) => dep.type === 'dev')),
|
|
108
|
-
peerPackageDependencies: toPackageObj(packageDeps.filter((dep) => dep.type === 'peer')),
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const consumerComponent = component.state._consumer as ConsumerComponent;
|
|
113
|
-
// add the dependencies to the legacy ConsumerComponent object
|
|
114
|
-
// it takes care of both: given dependencies (from the cli) and the overrides, which are coming from the env.
|
|
115
|
-
await deps.loadDependenciesFromScope(consumerComponent, dependenciesData);
|
|
116
|
-
|
|
117
|
-
// add the dependencies data to the dependency-resolver aspect
|
|
118
|
-
const dependenciesListSerialized = (await depsResolver.extractDepsFromLegacy(component)).serialize();
|
|
119
|
-
const extId = DependencyResolverAspect.id;
|
|
120
|
-
const data = { dependencies: dependenciesListSerialized };
|
|
121
|
-
const existingExtension = component.config.extensions.findExtension(extId);
|
|
122
|
-
if (!existingExtension) throw new Error('unable to find DependencyResolver extension');
|
|
123
|
-
Object.assign(existingExtension.data, data);
|
|
124
|
-
}
|
package/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { SnappingAspect } from './snapping.aspect';
|
|
2
|
-
|
|
3
|
-
export type { BitCloudUser } from './tag-model-component';
|
|
4
|
-
export { getBitCloudUsername, getBitCloudUser, getBasicLog } from './tag-model-component';
|
|
5
|
-
export type { SnappingMain, TagResults, SnapResults } from './snapping.main.runtime';
|
|
6
|
-
export default SnappingAspect;
|
|
7
|
-
export { SnappingAspect };
|
|
8
|
-
export type { onTagIdTransformer } from './tag-model-component';
|
package/reset-cmd.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { BitError } from '@teambit/bit-error';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
4
|
-
import { BASE_DOCS_DOMAIN, COMPONENT_PATTERN_HELP } from '@teambit/legacy/dist/constants';
|
|
5
|
-
import { SnappingMain } from './snapping.main.runtime';
|
|
6
|
-
|
|
7
|
-
export default class ResetCmd implements Command {
|
|
8
|
-
name = 'reset [component-pattern]';
|
|
9
|
-
description = 'revert tagged or snapped versions for component(s)';
|
|
10
|
-
arguments = [
|
|
11
|
-
{
|
|
12
|
-
name: 'component-pattern',
|
|
13
|
-
description: COMPONENT_PATTERN_HELP,
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
name: 'component-version',
|
|
17
|
-
description: 'the version to untag (semver for tags. hash for snaps)',
|
|
18
|
-
},
|
|
19
|
-
];
|
|
20
|
-
group = 'development';
|
|
21
|
-
extendedDescription = `${BASE_DOCS_DOMAIN}components/tags#undoing-a-tag`;
|
|
22
|
-
alias = '';
|
|
23
|
-
options = [
|
|
24
|
-
['a', 'all', 'revert all unexported tags/snaps for all components'],
|
|
25
|
-
['', 'head', 'revert the head tag/snap only (by default, all local tags/snaps are reverted)'],
|
|
26
|
-
['', 'soft', 'revert only soft-tags (components tagged with --soft flag)'],
|
|
27
|
-
[
|
|
28
|
-
'f',
|
|
29
|
-
'force',
|
|
30
|
-
"revert the tag even if it's used as a dependency. WARNING: components that depend on this tag will be corrupted",
|
|
31
|
-
],
|
|
32
|
-
['', 'never-exported', 'reset only components that were never exported'],
|
|
33
|
-
] as CommandOptions;
|
|
34
|
-
loader = true;
|
|
35
|
-
migration = true;
|
|
36
|
-
|
|
37
|
-
constructor(private snapping: SnappingMain) {}
|
|
38
|
-
|
|
39
|
-
async report(
|
|
40
|
-
[pattern]: [string],
|
|
41
|
-
{
|
|
42
|
-
all = false,
|
|
43
|
-
head = false,
|
|
44
|
-
force = false,
|
|
45
|
-
soft = false,
|
|
46
|
-
neverExported = false,
|
|
47
|
-
}: { all?: boolean; head?: boolean; force?: boolean; soft?: boolean; neverExported?: boolean }
|
|
48
|
-
) {
|
|
49
|
-
if (neverExported) {
|
|
50
|
-
const compIds = await this.snapping.resetNeverExported();
|
|
51
|
-
return chalk.green(`successfully reset the following never-exported components:\n${compIds.join('\n')}`);
|
|
52
|
-
}
|
|
53
|
-
if (!pattern && !all) {
|
|
54
|
-
throw new BitError('please specify a component-pattern or use --all flag');
|
|
55
|
-
}
|
|
56
|
-
if (pattern && all) {
|
|
57
|
-
throw new BitError('please specify either a component-pattern or --all flag, not both');
|
|
58
|
-
}
|
|
59
|
-
if (soft && head) {
|
|
60
|
-
throw new BitError('please specify either --soft or --head flag, not both');
|
|
61
|
-
}
|
|
62
|
-
const { results, isSoftUntag } = await this.snapping.reset(pattern, head, force, soft);
|
|
63
|
-
const titleSuffix = isSoftUntag ? 'soft-untagged (are not candidates for tagging any more)' : 'untagged';
|
|
64
|
-
const title = chalk.green(`${results.length} component(s) were ${titleSuffix}:\n`);
|
|
65
|
-
const components = results.map((result) => {
|
|
66
|
-
return `${chalk.cyan(result.id.toStringWithoutVersion())}. version(s): ${result.versions.join(', ')}`;
|
|
67
|
-
});
|
|
68
|
-
return title + components.join('\n');
|
|
69
|
-
}
|
|
70
|
-
}
|