@teambit/snapping 1.0.108 → 1.0.110
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/dist/snapping.main.runtime.js +2 -1
- package/dist/snapping.main.runtime.js.map +1 -1
- package/package.json +29 -25
- 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-1703733956734.js} +0 -0
package/snap-cmd.ts
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { ComponentID } from '@teambit/component-id';
|
|
3
|
-
import ConsumerComponent from '@teambit/legacy/dist/consumer/component/consumer-component';
|
|
4
|
-
import { IssuesClasses } from '@teambit/component-issues';
|
|
5
|
-
import { GlobalConfigMain } from '@teambit/global-config';
|
|
6
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
7
|
-
import {
|
|
8
|
-
NOTHING_TO_SNAP_MSG,
|
|
9
|
-
AUTO_SNAPPED_MSG,
|
|
10
|
-
COMPONENT_PATTERN_HELP,
|
|
11
|
-
CFG_FORCE_LOCAL_BUILD,
|
|
12
|
-
} from '@teambit/legacy/dist/constants';
|
|
13
|
-
import { Logger } from '@teambit/logger';
|
|
14
|
-
import { SnappingMain, SnapResults } from './snapping.main.runtime';
|
|
15
|
-
import { outputIdsIfExists } from './tag-cmd';
|
|
16
|
-
import { BasicTagSnapParams } from './tag-model-component';
|
|
17
|
-
|
|
18
|
-
export class SnapCmd implements Command {
|
|
19
|
-
name = 'snap [component-pattern]';
|
|
20
|
-
description = 'create an immutable and exportable component snapshot (non-release version)';
|
|
21
|
-
extendedDescription: string;
|
|
22
|
-
group = 'development';
|
|
23
|
-
arguments = [
|
|
24
|
-
{
|
|
25
|
-
name: 'component-pattern',
|
|
26
|
-
description: `${COMPONENT_PATTERN_HELP}. By default, only new and modified components are snapped (add --unmodified to snap all components in the workspace).`,
|
|
27
|
-
},
|
|
28
|
-
];
|
|
29
|
-
helpUrl = 'reference/components/snaps';
|
|
30
|
-
alias = '';
|
|
31
|
-
options = [
|
|
32
|
-
['m', 'message <message>', 'snap message describing the latest changes - will appear in component history log'],
|
|
33
|
-
['u', 'unmodified', 'include unmodified components (by default, only new and modified components are snapped)'],
|
|
34
|
-
['', 'unmerged', 'complete a merge process by snapping the unmerged components'],
|
|
35
|
-
['b', 'build', 'locally run the build pipeline (i.e. not via rippleCI) and complete the snap'],
|
|
36
|
-
[
|
|
37
|
-
'',
|
|
38
|
-
'editor [editor]',
|
|
39
|
-
'open an editor to write a snap message per component. optionally specify the editor-name (defaults to vim).',
|
|
40
|
-
],
|
|
41
|
-
['', 'skip-tests', 'skip running component tests during snap process'],
|
|
42
|
-
['', 'skip-auto-snap', 'skip auto snapping dependents'],
|
|
43
|
-
[
|
|
44
|
-
'',
|
|
45
|
-
'disable-snap-pipeline',
|
|
46
|
-
'skip the snap pipeline. this will for instance skip packing and publishing component version for install, and app deployment',
|
|
47
|
-
],
|
|
48
|
-
['', 'force-deploy', 'DEPRECATED. use --ignore-build-error instead'],
|
|
49
|
-
['', 'ignore-build-errors', 'proceed to snap pipeline even when build pipeline fails'],
|
|
50
|
-
['', 'rebuild-deps-graph', 'do not reuse the saved dependencies graph, instead build it from scratch'],
|
|
51
|
-
[
|
|
52
|
-
'i',
|
|
53
|
-
'ignore-issues [issues]',
|
|
54
|
-
`ignore component issues (shown in "bit status" as "issues found"), issues to ignore:
|
|
55
|
-
[${Object.keys(IssuesClasses).join(', ')}]
|
|
56
|
-
to ignore multiple issues, separate them by a comma and wrap with quotes. to ignore all issues, specify "*".`,
|
|
57
|
-
],
|
|
58
|
-
['a', 'all', 'DEPRECATED (not needed anymore, now the default). snap all new and modified components'],
|
|
59
|
-
[
|
|
60
|
-
'',
|
|
61
|
-
'fail-fast',
|
|
62
|
-
'stop pipeline execution on the first failed task (by default a task is skipped only when its dependency failed)',
|
|
63
|
-
],
|
|
64
|
-
[
|
|
65
|
-
'f',
|
|
66
|
-
'force',
|
|
67
|
-
'DEPRECATED (use "--skip-tests" or "--unmodified" instead). force-snap even if tests are failing and even when component has not changed',
|
|
68
|
-
],
|
|
69
|
-
] as CommandOptions;
|
|
70
|
-
loader = true;
|
|
71
|
-
migration = true;
|
|
72
|
-
|
|
73
|
-
constructor(private snapping: SnappingMain, private logger: Logger, private globalConfig: GlobalConfigMain) {}
|
|
74
|
-
|
|
75
|
-
async report(
|
|
76
|
-
[pattern]: string[],
|
|
77
|
-
{
|
|
78
|
-
message = '',
|
|
79
|
-
all = false,
|
|
80
|
-
force = false,
|
|
81
|
-
unmerged = false,
|
|
82
|
-
editor = '',
|
|
83
|
-
ignoreIssues,
|
|
84
|
-
build,
|
|
85
|
-
skipTests = false,
|
|
86
|
-
skipAutoSnap = false,
|
|
87
|
-
disableSnapPipeline = false,
|
|
88
|
-
forceDeploy = false,
|
|
89
|
-
ignoreBuildErrors = false,
|
|
90
|
-
rebuildDepsGraph,
|
|
91
|
-
unmodified = false,
|
|
92
|
-
failFast = false,
|
|
93
|
-
}: {
|
|
94
|
-
all?: boolean;
|
|
95
|
-
force?: boolean;
|
|
96
|
-
unmerged?: boolean;
|
|
97
|
-
editor?: string;
|
|
98
|
-
ignoreIssues?: string;
|
|
99
|
-
skipAutoSnap?: boolean;
|
|
100
|
-
disableSnapPipeline?: boolean;
|
|
101
|
-
forceDeploy?: boolean;
|
|
102
|
-
unmodified?: boolean;
|
|
103
|
-
failFast?: boolean;
|
|
104
|
-
} & BasicTagSnapParams
|
|
105
|
-
) {
|
|
106
|
-
build = (await this.globalConfig.getBool(CFG_FORCE_LOCAL_BUILD)) || Boolean(build);
|
|
107
|
-
const disableTagAndSnapPipelines = disableSnapPipeline;
|
|
108
|
-
if (all) {
|
|
109
|
-
this.logger.consoleWarning(
|
|
110
|
-
`--all is deprecated, please omit it. By default all new and modified components are snapped, to snap all components add --unmodified`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
if (force) {
|
|
114
|
-
this.logger.consoleWarning(
|
|
115
|
-
`--force is deprecated, use either --skip-tests or --ignore-build-errors depending on the use case`
|
|
116
|
-
);
|
|
117
|
-
if (pattern) unmodified = true;
|
|
118
|
-
}
|
|
119
|
-
if (!message && !editor) {
|
|
120
|
-
this.logger.consoleWarning(
|
|
121
|
-
`--message will be mandatory in the next few releases. make sure to add a message with your snap, will be displayed in the version history`
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
if (forceDeploy) {
|
|
125
|
-
this.logger.consoleWarning(`--force-deploy is deprecated, use --ignore-build-errors instead`);
|
|
126
|
-
ignoreBuildErrors = true;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const results = await this.snapping.snap({
|
|
130
|
-
pattern,
|
|
131
|
-
message,
|
|
132
|
-
unmerged,
|
|
133
|
-
editor,
|
|
134
|
-
ignoreIssues,
|
|
135
|
-
build,
|
|
136
|
-
skipTests,
|
|
137
|
-
skipAutoSnap,
|
|
138
|
-
disableTagAndSnapPipelines,
|
|
139
|
-
ignoreBuildErrors,
|
|
140
|
-
rebuildDepsGraph,
|
|
141
|
-
unmodified,
|
|
142
|
-
exitOnFirstFailedTask: failFast,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
if (!results) return chalk.yellow(NOTHING_TO_SNAP_MSG);
|
|
146
|
-
const { snappedComponents, autoSnappedResults, warnings, newComponents, laneName, removedComponents }: SnapResults =
|
|
147
|
-
results;
|
|
148
|
-
const changedComponents = snappedComponents.filter((component) => {
|
|
149
|
-
return (
|
|
150
|
-
!newComponents.searchWithoutVersion(component.id) && !removedComponents?.searchWithoutVersion(component.id)
|
|
151
|
-
);
|
|
152
|
-
});
|
|
153
|
-
const addedComponents = snappedComponents.filter((component) => newComponents.searchWithoutVersion(component.id));
|
|
154
|
-
const autoTaggedCount = autoSnappedResults ? autoSnappedResults.length : 0;
|
|
155
|
-
|
|
156
|
-
const warningsOutput = warnings && warnings.length ? `${chalk.yellow(warnings.join('\n'))}\n\n` : '';
|
|
157
|
-
const snapExplanation = `\n(use "bit export" to push these components to a remote")
|
|
158
|
-
(use "bit reset" to unstage all local versions, or "bit reset --head" to only unstage the latest local snap)`;
|
|
159
|
-
|
|
160
|
-
const compInBold = (id: ComponentID) => {
|
|
161
|
-
const version = id.hasVersion() ? `@${id.version}` : '';
|
|
162
|
-
return `${chalk.bold(id.toStringWithoutVersion())}${version}`;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const outputComponents = (comps: ConsumerComponent[]) => {
|
|
166
|
-
return comps
|
|
167
|
-
.map((component) => {
|
|
168
|
-
let componentOutput = ` > ${compInBold(component.id)}`;
|
|
169
|
-
const autoTag = autoSnappedResults.filter((result) => result.triggeredBy.searchWithoutVersion(component.id));
|
|
170
|
-
if (autoTag.length) {
|
|
171
|
-
const autoTagComp = autoTag.map((a) => compInBold(a.component.id));
|
|
172
|
-
componentOutput += `\n ${AUTO_SNAPPED_MSG} (${autoTagComp.length} total):
|
|
173
|
-
${autoTagComp.join('\n ')}`;
|
|
174
|
-
}
|
|
175
|
-
return componentOutput;
|
|
176
|
-
})
|
|
177
|
-
.join('\n');
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const outputIfExists = (label, explanation, components) => {
|
|
181
|
-
if (!components.length) return '';
|
|
182
|
-
return `\n${chalk.underline(label)}\n(${explanation})\n${outputComponents(components)}\n`;
|
|
183
|
-
};
|
|
184
|
-
const laneStr = laneName ? ` on "${laneName}" lane` : '';
|
|
185
|
-
|
|
186
|
-
return (
|
|
187
|
-
outputIfExists('new components', 'first version for components', addedComponents) +
|
|
188
|
-
outputIfExists('changed components', 'components that got a version bump', changedComponents) +
|
|
189
|
-
outputIdsIfExists('removed components', removedComponents) +
|
|
190
|
-
warningsOutput +
|
|
191
|
-
chalk.green(`\n${snappedComponents.length + autoTaggedCount} component(s) snapped${laneStr}`) +
|
|
192
|
-
snapExplanation
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
}
|
package/snap-distance-cmd.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { BitError } from '@teambit/bit-error';
|
|
2
|
-
import { ScopeMain } from '@teambit/scope';
|
|
3
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
4
|
-
|
|
5
|
-
export class SnapDistanceCmd implements Command {
|
|
6
|
-
name = 'snap-distance <component-id> [source-snap] [target-snap]';
|
|
7
|
-
description = 'show common-snap and distance between two given snaps or between local and remote snaps';
|
|
8
|
-
extendedDescription = `in case source and target snaps are not provided, the command will use the local and remote heads.
|
|
9
|
-
by "head" we mean component-head if on main, or lane-head if on lane.
|
|
10
|
-
if source and target snaps are provided, the command will use them to calculate the distance.`;
|
|
11
|
-
alias = '';
|
|
12
|
-
options = [] as CommandOptions;
|
|
13
|
-
loader = true;
|
|
14
|
-
migration = true;
|
|
15
|
-
private = true;
|
|
16
|
-
|
|
17
|
-
constructor(private scope: ScopeMain) {}
|
|
18
|
-
|
|
19
|
-
async report([id, sourceSnap, targetSnap]: [string, string, string]) {
|
|
20
|
-
const compId = await this.scope.resolveComponentId(id);
|
|
21
|
-
const getSnapDistance = async () => {
|
|
22
|
-
if (!sourceSnap) return this.scope.getSnapDistance(compId, false);
|
|
23
|
-
if (!targetSnap) throw new BitError('either provide both source and target snaps or none');
|
|
24
|
-
return this.scope.getSnapsDistanceBetweenTwoSnaps(compId, sourceSnap, targetSnap, false);
|
|
25
|
-
};
|
|
26
|
-
const snapDistance = await getSnapDistance();
|
|
27
|
-
return JSON.stringify(snapDistance, null, 2);
|
|
28
|
-
}
|
|
29
|
-
}
|
package/snap-from-scope.cmd.ts
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { IssuesClasses } from '@teambit/component-issues';
|
|
3
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
4
|
-
import { BitError } from '@teambit/bit-error';
|
|
5
|
-
import { Logger } from '@teambit/logger';
|
|
6
|
-
import { SnappingMain } from './snapping.main.runtime';
|
|
7
|
-
import { BasicTagSnapParams } from './tag-model-component';
|
|
8
|
-
|
|
9
|
-
export type FileData = { path: string; content: string; delete?: boolean };
|
|
10
|
-
|
|
11
|
-
export type SnapDataPerCompRaw = {
|
|
12
|
-
componentId: string;
|
|
13
|
-
dependencies?: string[];
|
|
14
|
-
aspects?: Record<string, any>;
|
|
15
|
-
message?: string;
|
|
16
|
-
files?: FileData[];
|
|
17
|
-
isNew?: boolean;
|
|
18
|
-
mainFile?: string; // relevant when isNew is true. default to "index.ts".
|
|
19
|
-
newDependencies?: Array<{
|
|
20
|
-
id: string; // component-id or package-name. e.g. "teambit.react/react" or "lodash".
|
|
21
|
-
version?: string; // version of the package. e.g. "2.0.3". for packages, it is mandatory.
|
|
22
|
-
isComponent?: boolean; // default true. if false, it's a package dependency
|
|
23
|
-
type?: 'runtime' | 'dev' | 'peer'; // default "runtime".
|
|
24
|
-
}>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
type SnapFromScopeOptions = {
|
|
28
|
-
push?: boolean;
|
|
29
|
-
lane?: string;
|
|
30
|
-
ignoreIssues?: string;
|
|
31
|
-
disableSnapPipeline?: boolean;
|
|
32
|
-
forceDeploy?: boolean;
|
|
33
|
-
} & BasicTagSnapParams;
|
|
34
|
-
|
|
35
|
-
export class SnapFromScopeCmd implements Command {
|
|
36
|
-
name = '_snap <data>';
|
|
37
|
-
description = 'snap components from a bare-scope';
|
|
38
|
-
extendedDescription = `this command should be running from a new bare scope, it first imports the components it needs and then processes the snap.
|
|
39
|
-
the input data is a stringified JSON of an array of the following object.
|
|
40
|
-
{
|
|
41
|
-
componentId: string; // ids always have scope, so it's safe to parse them from string
|
|
42
|
-
dependencies?: string[]; // dependencies to update their versions, e.g. [teambit/compiler@1.0.0, teambit/tester@1.0.0]
|
|
43
|
-
aspects?: Record<string,any> // e.g. { "teambit.react/react": {}, "teambit.envs/envs": { "env": "teambit.react/react" } }
|
|
44
|
-
message?: string; // tag-message.
|
|
45
|
-
files?: Array<{path: string, content: string}>; // replace content of specified source-files. the content is base64 encoded.
|
|
46
|
-
isNew?: boolean; // if it's new, it'll be generated from the given files. otherwise, it'll be fetched from the scope and updated.
|
|
47
|
-
mainFile?: string; // relevant when isNew is true. default to "index.ts".
|
|
48
|
-
newDependencies?: Array<{ // new dependencies (components and packages) to add.
|
|
49
|
-
id: string; // component-id or package-name. e.g. "teambit.react/react" or "lodash".
|
|
50
|
-
version?: string; // version of the package. e.g. "2.0.3". for packages, it is mandatory.
|
|
51
|
-
isComponent?: boolean; // default true. if false, it's a package dependency
|
|
52
|
-
type?: 'runtime' | 'dev' | 'peer'; // default "runtime".
|
|
53
|
-
}>;
|
|
54
|
-
}
|
|
55
|
-
an example of the final data: '[{"componentId":"ci.remote2/comp-b","message": "first snap"}]'
|
|
56
|
-
`;
|
|
57
|
-
alias = '';
|
|
58
|
-
options = [
|
|
59
|
-
['', 'push', 'export the updated objects to the original scopes once done'],
|
|
60
|
-
['m', 'message <message>', 'log message describing the latest changes'],
|
|
61
|
-
['', 'lane <lane-id>', 'fetch the components from the given lane'],
|
|
62
|
-
['', 'build', 'run the build pipeline'],
|
|
63
|
-
['', 'skip-tests', 'skip running component tests during snap process'],
|
|
64
|
-
['', 'disable-snap-pipeline', 'skip the snap pipeline'],
|
|
65
|
-
['', 'force-deploy', 'DEPRECATED. use --ignore-build-error instead'],
|
|
66
|
-
['', 'ignore-build-errors', 'run the snap pipeline although the build pipeline failed'],
|
|
67
|
-
['', 'rebuild-deps-graph', 'do not reuse the saved dependencies graph, instead build it from scratch'],
|
|
68
|
-
[
|
|
69
|
-
'i',
|
|
70
|
-
'ignore-issues [issues]',
|
|
71
|
-
`ignore component issues (shown in "bit status" as "issues found"), issues to ignore:
|
|
72
|
-
[${Object.keys(IssuesClasses).join(', ')}]
|
|
73
|
-
to ignore multiple issues, separate them by a comma and wrap with quotes. to ignore all issues, specify "*".`,
|
|
74
|
-
],
|
|
75
|
-
['j', 'json', 'output as json format'],
|
|
76
|
-
] as CommandOptions;
|
|
77
|
-
loader = true;
|
|
78
|
-
private = true;
|
|
79
|
-
migration = true;
|
|
80
|
-
|
|
81
|
-
constructor(private snapping: SnappingMain, private logger: Logger) {}
|
|
82
|
-
|
|
83
|
-
async report([data]: [string], options: SnapFromScopeOptions) {
|
|
84
|
-
const results = await this.json([data], options);
|
|
85
|
-
|
|
86
|
-
const { snappedIds, exportedIds } = results;
|
|
87
|
-
|
|
88
|
-
const snappedOutput = `${chalk.bold('snapped components')}\n${snappedIds.join('\n')}`;
|
|
89
|
-
const exportedOutput =
|
|
90
|
-
exportedIds && exportedIds.length ? `\n\n${chalk.bold('exported components')}\n${exportedIds.join('\n')}` : '';
|
|
91
|
-
|
|
92
|
-
return `${snappedOutput}${exportedOutput}`;
|
|
93
|
-
}
|
|
94
|
-
async json(
|
|
95
|
-
[data]: [string],
|
|
96
|
-
{
|
|
97
|
-
push = false,
|
|
98
|
-
message = '',
|
|
99
|
-
lane,
|
|
100
|
-
ignoreIssues,
|
|
101
|
-
build = false,
|
|
102
|
-
skipTests = false,
|
|
103
|
-
disableSnapPipeline = false,
|
|
104
|
-
ignoreBuildErrors = false,
|
|
105
|
-
rebuildDepsGraph,
|
|
106
|
-
forceDeploy = false,
|
|
107
|
-
}: SnapFromScopeOptions
|
|
108
|
-
) {
|
|
109
|
-
const disableTagAndSnapPipelines = disableSnapPipeline;
|
|
110
|
-
if (forceDeploy) {
|
|
111
|
-
ignoreBuildErrors = true;
|
|
112
|
-
}
|
|
113
|
-
if (disableTagAndSnapPipelines && ignoreBuildErrors) {
|
|
114
|
-
throw new BitError('you can use either ignore-build-errors or disable-snap-pipeline, but not both');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const snapDataPerCompRaw = this.parseData(data);
|
|
118
|
-
|
|
119
|
-
const results = await this.snapping.snapFromScope(snapDataPerCompRaw, {
|
|
120
|
-
push,
|
|
121
|
-
message,
|
|
122
|
-
lane,
|
|
123
|
-
ignoreIssues,
|
|
124
|
-
build,
|
|
125
|
-
skipTests,
|
|
126
|
-
disableTagAndSnapPipelines,
|
|
127
|
-
ignoreBuildErrors,
|
|
128
|
-
rebuildDepsGraph,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
return results;
|
|
132
|
-
}
|
|
133
|
-
private parseData(data: string): SnapDataPerCompRaw[] {
|
|
134
|
-
let dataParsed: unknown;
|
|
135
|
-
try {
|
|
136
|
-
dataParsed = JSON.parse(data);
|
|
137
|
-
} catch (err: any) {
|
|
138
|
-
throw new Error(`failed parsing the data entered as JSON. err ${err.message}`);
|
|
139
|
-
}
|
|
140
|
-
if (!Array.isArray(dataParsed)) {
|
|
141
|
-
throw new Error('expect data to be an array');
|
|
142
|
-
}
|
|
143
|
-
dataParsed.forEach((dataItem) => {
|
|
144
|
-
if (!dataItem.componentId) throw new Error('expect data item to have "componentId" prop');
|
|
145
|
-
dataItem.files?.forEach((file) => {
|
|
146
|
-
if (!file.path) throw new Error('expect file to have "path" prop');
|
|
147
|
-
if (file.content) {
|
|
148
|
-
file.content = Buffer.from(file.content, 'base64').toString();
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
return dataParsed;
|
|
154
|
-
}
|
|
155
|
-
}
|