@teambit/importer 0.0.0-002d6dcabfb575e2f1d90b69be43c7de9cc94c70
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/dependents-getter.d.ts +15 -0
- package/dist/dependents-getter.js +208 -0
- package/dist/dependents-getter.js.map +1 -0
- package/dist/esm.mjs +7 -0
- package/dist/fetch-cmd.d.ts +20 -0
- package/dist/fetch-cmd.js +84 -0
- package/dist/fetch-cmd.js.map +1 -0
- package/dist/import-components.d.ts +155 -0
- package/dist/import-components.js +704 -0
- package/dist/import-components.js.map +1 -0
- package/dist/import.cmd.d.ts +57 -0
- package/dist/import.cmd.js +273 -0
- package/dist/import.cmd.js.map +1 -0
- package/dist/importer.aspect.d.ts +2 -0
- package/dist/importer.aspect.js +18 -0
- package/dist/importer.aspect.js.map +1 -0
- package/dist/importer.composition.d.ts +1 -0
- package/dist/importer.composition.js +29 -0
- package/dist/importer.composition.js.map +1 -0
- package/dist/importer.docs.mdx +4 -0
- package/dist/importer.main.runtime.d.ts +90 -0
- package/dist/importer.main.runtime.js +537 -0
- package/dist/importer.main.runtime.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/preview-1760020086363.js +7 -0
- package/esm.mjs +7 -0
- package/importer.composition.tsx +7 -0
- package/importer.docs.mdx +4 -0
- package/package.json +87 -0
- package/types/asset.d.ts +41 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentID } from '@teambit/component-id';
|
|
2
|
+
import type { GraphMain } from '@teambit/graph';
|
|
3
|
+
import type { Logger } from '@teambit/logger';
|
|
4
|
+
import type { Workspace } from '@teambit/workspace';
|
|
5
|
+
import type { ImportOptions } from './import-components';
|
|
6
|
+
export declare class DependentsGetter {
|
|
7
|
+
private logger;
|
|
8
|
+
private workspace;
|
|
9
|
+
private graph;
|
|
10
|
+
private options;
|
|
11
|
+
constructor(logger: Logger, workspace: Workspace, graph: GraphMain, options: ImportOptions);
|
|
12
|
+
getDependents(targetCompIds: ComponentID[]): Promise<ComponentID[]>;
|
|
13
|
+
private promptDependents;
|
|
14
|
+
private promptLevelByLevel;
|
|
15
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DependentsGetter = void 0;
|
|
7
|
+
function _yesno() {
|
|
8
|
+
const data = _interopRequireDefault(require("yesno"));
|
|
9
|
+
_yesno = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _enquirer() {
|
|
15
|
+
const data = require("enquirer");
|
|
16
|
+
_enquirer = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _lodash() {
|
|
22
|
+
const data = require("lodash");
|
|
23
|
+
_lodash = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _chalk() {
|
|
29
|
+
const data = _interopRequireDefault(require("chalk"));
|
|
30
|
+
_chalk = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _componentId() {
|
|
36
|
+
const data = require("@teambit/component-id");
|
|
37
|
+
_componentId = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
function _bitError() {
|
|
43
|
+
const data = require("@teambit/bit-error");
|
|
44
|
+
_bitError = function () {
|
|
45
|
+
return data;
|
|
46
|
+
};
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
50
|
+
// @ts-ignore AutoComplete is actually there, the d.ts is probably outdated
|
|
51
|
+
|
|
52
|
+
const SHOW_ALL_PATHS_LIMIT = 10;
|
|
53
|
+
const SCROLL_LIMIT = 20;
|
|
54
|
+
class DependentsGetter {
|
|
55
|
+
constructor(logger, workspace, graph, options) {
|
|
56
|
+
this.logger = logger;
|
|
57
|
+
this.workspace = workspace;
|
|
58
|
+
this.graph = graph;
|
|
59
|
+
this.options = options;
|
|
60
|
+
}
|
|
61
|
+
async getDependents(targetCompIds) {
|
|
62
|
+
this.logger.setStatusLine('finding dependents');
|
|
63
|
+
const {
|
|
64
|
+
silent,
|
|
65
|
+
dependentsAll
|
|
66
|
+
} = this.options;
|
|
67
|
+
const graph = await this.graph.getGraphIds();
|
|
68
|
+
const sourceIds = this.workspace.listIds();
|
|
69
|
+
const getIdsForThrough = () => {
|
|
70
|
+
if (!this.options.dependentsVia) return undefined;
|
|
71
|
+
return this.options.dependentsVia.split(',').map(idStr => idStr.trim()).map(id => _componentId().ComponentID.fromString(id));
|
|
72
|
+
};
|
|
73
|
+
const allPaths = graph.findAllPathsFromSourcesToTargets(sourceIds, targetCompIds, getIdsForThrough());
|
|
74
|
+
const selectedPaths = silent || dependentsAll ? allPaths : await this.promptDependents(allPaths);
|
|
75
|
+
const uniqAsStrings = (0, _lodash().uniq)(selectedPaths.flat());
|
|
76
|
+
const ids = [];
|
|
77
|
+
const idsToFilterOut = _componentId().ComponentIdList.fromArray([...sourceIds, ...targetCompIds]);
|
|
78
|
+
uniqAsStrings.forEach(idStr => {
|
|
79
|
+
const id = _componentId().ComponentID.fromString(idStr);
|
|
80
|
+
if (idsToFilterOut.hasWithoutVersion(id)) return;
|
|
81
|
+
const sameIds = uniqAsStrings.filter(idString => idString.startsWith(`${id.toStringWithoutVersion()}@`));
|
|
82
|
+
const idToImport = sameIds.length === 1 ? id : id.changeVersion(undefined);
|
|
83
|
+
ids.push(idToImport);
|
|
84
|
+
idsToFilterOut.push(idToImport);
|
|
85
|
+
});
|
|
86
|
+
const idsStr = ids.map(id => id.toString());
|
|
87
|
+
this.logger.debug(`found ${ids.length} component for --dependents flag`, idsStr);
|
|
88
|
+
if (!this.options.silent) {
|
|
89
|
+
this.logger.clearStatusLine();
|
|
90
|
+
const question = idsStr.length ? `found the following ${ids.length} components for --dependents flag:\n${idsStr.join('\n')}` : 'unable to find dependents for the given component (probably the workspace components using it directly)';
|
|
91
|
+
const ok = await (0, _yesno().default)({
|
|
92
|
+
question: `${question}\nWould you like to continue with the import? [yes(y)/no(n)]`
|
|
93
|
+
});
|
|
94
|
+
if (!ok) {
|
|
95
|
+
throw new (_bitError().BitError)('import was aborted');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return ids;
|
|
99
|
+
}
|
|
100
|
+
async promptDependents(allPaths) {
|
|
101
|
+
if (!allPaths.length) return [];
|
|
102
|
+
this.logger.clearStatusLine();
|
|
103
|
+
const totalToShow = SHOW_ALL_PATHS_LIMIT;
|
|
104
|
+
if (allPaths.length > totalToShow) {
|
|
105
|
+
return this.promptLevelByLevel(allPaths);
|
|
106
|
+
}
|
|
107
|
+
const firstItems = allPaths.slice(0, totalToShow);
|
|
108
|
+
const choices = firstItems.map(path => {
|
|
109
|
+
const name = path.join(' -> ');
|
|
110
|
+
return {
|
|
111
|
+
name,
|
|
112
|
+
value: path
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
const tooManyPathsMsg = allPaths.length > totalToShow ? `${_chalk().default.yellow(`\nfound ${allPaths.length} paths, showing the shortest ${totalToShow}. if the desired path is not shown, use the --dependents-via flag`)}` : '';
|
|
116
|
+
const result = await (0, _enquirer().prompt)({
|
|
117
|
+
choices,
|
|
118
|
+
footer: '\nEnter to start importing. Ctrl+C to cancel.',
|
|
119
|
+
indicator: (state, choice) => ` ${choice.enabled ? '●' : '○'}`,
|
|
120
|
+
message: 'Choose which path to include ' + `(Press ${_chalk().default.cyan('<space>')} to select, ` + `${_chalk().default.cyan('<a>')} to toggle all, ` + `${_chalk().default.cyan('<i>')} to invert selection)${tooManyPathsMsg}`,
|
|
121
|
+
name: 'selectDependents',
|
|
122
|
+
pointer: '❯',
|
|
123
|
+
styles: {
|
|
124
|
+
dark: _chalk().default.white,
|
|
125
|
+
em: _chalk().default.bgBlack.whiteBright,
|
|
126
|
+
success: _chalk().default.white
|
|
127
|
+
},
|
|
128
|
+
type: 'multiselect',
|
|
129
|
+
validate(value) {
|
|
130
|
+
if (value.length === 0) {
|
|
131
|
+
return 'You must choose at least one path.';
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
},
|
|
135
|
+
j() {
|
|
136
|
+
return this.down();
|
|
137
|
+
},
|
|
138
|
+
k() {
|
|
139
|
+
return this.up();
|
|
140
|
+
},
|
|
141
|
+
result(names) {
|
|
142
|
+
// This is needed in order to have the values of the choices in the answer object.
|
|
143
|
+
// Otherwise, only the names of the selected choices would've been included.
|
|
144
|
+
return this.map(names);
|
|
145
|
+
},
|
|
146
|
+
cancel() {
|
|
147
|
+
// By default, canceling the prompt via Ctrl+c throws an empty string.
|
|
148
|
+
// The custom cancel function prevents that behavior.
|
|
149
|
+
// Otherwise, Bit CLI would print an error and confuse users.
|
|
150
|
+
// See related issue: https://github.com/enquirer/enquirer/issues/225
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return Object.values(result.selectDependents);
|
|
154
|
+
}
|
|
155
|
+
async promptLevelByLevel(allPaths) {
|
|
156
|
+
if (allPaths.length < SHOW_ALL_PATHS_LIMIT) {
|
|
157
|
+
throw new Error(`expected to have at least ${SHOW_ALL_PATHS_LIMIT} paths`);
|
|
158
|
+
}
|
|
159
|
+
const finalPath = [];
|
|
160
|
+
this.logger.console(`found ${allPaths.length} available paths from the workspace components to the target components.
|
|
161
|
+
the following prompts will guide you to choose the desired path to import.`);
|
|
162
|
+
const getPrompt = (choices, level, totalPaths) => {
|
|
163
|
+
return new (_enquirer().AutoComplete)({
|
|
164
|
+
name: 'comp',
|
|
165
|
+
message: `Choose which component to include`,
|
|
166
|
+
limit: SCROLL_LIMIT,
|
|
167
|
+
footer() {
|
|
168
|
+
return choices.length >= SCROLL_LIMIT ? _chalk().default.dim('(Scroll up and down to reveal more choices)') : '';
|
|
169
|
+
},
|
|
170
|
+
header() {
|
|
171
|
+
if (level === 1) return '';
|
|
172
|
+
return `total ${totalPaths} paths left (out of ${allPaths.length})`;
|
|
173
|
+
},
|
|
174
|
+
cancel() {
|
|
175
|
+
// By default, canceling the prompt via Ctrl+c throws an empty string.
|
|
176
|
+
// The custom cancel function prevents that behavior.
|
|
177
|
+
// Otherwise, Bit CLI would print an error and confuse users.
|
|
178
|
+
// See related issue: https://github.com/enquirer/enquirer/issues/225
|
|
179
|
+
},
|
|
180
|
+
choices
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
const getLevel = (level, withinPaths) => {
|
|
184
|
+
return (0, _lodash().compact)((0, _lodash().uniq)(withinPaths.map(path => path[level]))).sort();
|
|
185
|
+
};
|
|
186
|
+
const processLevel = async (level, paths, previousLevel) => {
|
|
187
|
+
const pathsWithinThisLevel = previousLevel ? paths.filter(path => path[level] === previousLevel) : paths;
|
|
188
|
+
const nextLevel = getLevel(level + 1, pathsWithinThisLevel);
|
|
189
|
+
if (!nextLevel.length) {
|
|
190
|
+
return finalPath;
|
|
191
|
+
}
|
|
192
|
+
if (nextLevel.length === 1) {
|
|
193
|
+
finalPath.push(nextLevel[0]);
|
|
194
|
+
this.logger.consoleSuccess(`${nextLevel[0]} (auto-selected)`);
|
|
195
|
+
return processLevel(level + 1, pathsWithinThisLevel, nextLevel[0]);
|
|
196
|
+
}
|
|
197
|
+
const promptNextLevel = getPrompt(nextLevel, level + 1, pathsWithinThisLevel.length);
|
|
198
|
+
const resultNextLevel = await promptNextLevel.run();
|
|
199
|
+
finalPath.push(resultNextLevel);
|
|
200
|
+
return processLevel(level + 1, pathsWithinThisLevel, resultNextLevel);
|
|
201
|
+
};
|
|
202
|
+
const result = await processLevel(0, allPaths);
|
|
203
|
+
return [result];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.DependentsGetter = DependentsGetter;
|
|
207
|
+
|
|
208
|
+
//# sourceMappingURL=dependents-getter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_yesno","data","_interopRequireDefault","require","_enquirer","_lodash","_chalk","_componentId","_bitError","e","__esModule","default","SHOW_ALL_PATHS_LIMIT","SCROLL_LIMIT","DependentsGetter","constructor","logger","workspace","graph","options","getDependents","targetCompIds","setStatusLine","silent","dependentsAll","getGraphIds","sourceIds","listIds","getIdsForThrough","dependentsVia","undefined","split","map","idStr","trim","id","ComponentID","fromString","allPaths","findAllPathsFromSourcesToTargets","selectedPaths","promptDependents","uniqAsStrings","uniq","flat","ids","idsToFilterOut","ComponentIdList","fromArray","forEach","hasWithoutVersion","sameIds","filter","idString","startsWith","toStringWithoutVersion","idToImport","length","changeVersion","push","idsStr","toString","debug","clearStatusLine","question","join","ok","yesno","BitError","totalToShow","promptLevelByLevel","firstItems","slice","choices","path","name","value","tooManyPathsMsg","chalk","yellow","result","prompt","footer","indicator","state","choice","enabled","message","cyan","pointer","styles","dark","white","em","bgBlack","whiteBright","success","type","validate","j","down","k","up","names","cancel","Object","values","selectDependents","Error","finalPath","console","getPrompt","level","totalPaths","AutoComplete","limit","dim","header","getLevel","withinPaths","compact","sort","processLevel","paths","previousLevel","pathsWithinThisLevel","nextLevel","consoleSuccess","promptNextLevel","resultNextLevel","run","exports"],"sources":["dependents-getter.ts"],"sourcesContent":["import yesno from 'yesno';\n// @ts-ignore AutoComplete is actually there, the d.ts is probably outdated\nimport { prompt, AutoComplete } from 'enquirer';\nimport { compact, uniq } from 'lodash';\nimport chalk from 'chalk';\nimport { ComponentID, ComponentIdList } from '@teambit/component-id';\nimport type { GraphMain } from '@teambit/graph';\nimport type { Logger } from '@teambit/logger';\nimport type { Workspace } from '@teambit/workspace';\nimport { BitError } from '@teambit/bit-error';\nimport type { ImportOptions } from './import-components';\n\nconst SHOW_ALL_PATHS_LIMIT = 10;\nconst SCROLL_LIMIT = 20;\n\nexport class DependentsGetter {\n constructor(\n private logger: Logger,\n private workspace: Workspace,\n private graph: GraphMain,\n private options: ImportOptions\n ) {}\n\n async getDependents(targetCompIds: ComponentID[]): Promise<ComponentID[]> {\n this.logger.setStatusLine('finding dependents');\n const { silent, dependentsAll } = this.options;\n const graph = await this.graph.getGraphIds();\n const sourceIds = this.workspace.listIds();\n const getIdsForThrough = () => {\n if (!this.options.dependentsVia) return undefined;\n return this.options.dependentsVia\n .split(',')\n .map((idStr) => idStr.trim())\n .map((id) => ComponentID.fromString(id));\n };\n const allPaths = graph.findAllPathsFromSourcesToTargets(sourceIds, targetCompIds, getIdsForThrough());\n const selectedPaths = silent || dependentsAll ? allPaths : await this.promptDependents(allPaths);\n const uniqAsStrings = uniq(selectedPaths.flat());\n\n const ids: ComponentID[] = [];\n const idsToFilterOut = ComponentIdList.fromArray([...sourceIds, ...targetCompIds]);\n uniqAsStrings.forEach((idStr) => {\n const id = ComponentID.fromString(idStr);\n if (idsToFilterOut.hasWithoutVersion(id)) return;\n const sameIds = uniqAsStrings.filter((idString) => idString.startsWith(`${id.toStringWithoutVersion()}@`));\n const idToImport = sameIds.length === 1 ? id : id.changeVersion(undefined);\n ids.push(idToImport);\n idsToFilterOut.push(idToImport);\n });\n\n const idsStr = ids.map((id) => id.toString());\n\n this.logger.debug(`found ${ids.length} component for --dependents flag`, idsStr);\n if (!this.options.silent) {\n this.logger.clearStatusLine();\n const question = idsStr.length\n ? `found the following ${ids.length} components for --dependents flag:\\n${idsStr.join('\\n')}`\n : 'unable to find dependents for the given component (probably the workspace components using it directly)';\n const ok = await yesno({\n question: `${question}\\nWould you like to continue with the import? [yes(y)/no(n)]`,\n });\n if (!ok) {\n throw new BitError('import was aborted');\n }\n }\n\n return ids;\n }\n\n private async promptDependents(allPaths: string[][]): Promise<string[][]> {\n if (!allPaths.length) return [];\n this.logger.clearStatusLine();\n\n const totalToShow = SHOW_ALL_PATHS_LIMIT;\n if (allPaths.length > totalToShow) {\n return this.promptLevelByLevel(allPaths);\n }\n const firstItems = allPaths.slice(0, totalToShow);\n const choices = firstItems.map((path) => {\n const name = path.join(' -> ');\n return { name, value: path };\n });\n const tooManyPathsMsg =\n allPaths.length > totalToShow\n ? `${chalk.yellow(\n `\\nfound ${allPaths.length} paths, showing the shortest ${totalToShow}. if the desired path is not shown, use the --dependents-via flag`\n )}`\n : '';\n const result = await prompt<{ selectDependents: Record<string, string[]> }>({\n choices,\n footer: '\\nEnter to start importing. Ctrl+C to cancel.',\n indicator: (state: any, choice: any) => ` ${choice.enabled ? '●' : '○'}`,\n message:\n 'Choose which path to include ' +\n `(Press ${chalk.cyan('<space>')} to select, ` +\n `${chalk.cyan('<a>')} to toggle all, ` +\n `${chalk.cyan('<i>')} to invert selection)${tooManyPathsMsg}`,\n name: 'selectDependents',\n pointer: '❯',\n styles: {\n dark: chalk.white,\n em: chalk.bgBlack.whiteBright,\n success: chalk.white,\n },\n type: 'multiselect',\n validate(value: string[]) {\n if (value.length === 0) {\n return 'You must choose at least one path.';\n }\n return true;\n },\n j() {\n return this.down();\n },\n k() {\n return this.up();\n },\n result(names: string[]) {\n // This is needed in order to have the values of the choices in the answer object.\n // Otherwise, only the names of the selected choices would've been included.\n return this.map(names);\n },\n cancel() {\n // By default, canceling the prompt via Ctrl+c throws an empty string.\n // The custom cancel function prevents that behavior.\n // Otherwise, Bit CLI would print an error and confuse users.\n // See related issue: https://github.com/enquirer/enquirer/issues/225\n },\n } as any);\n\n return Object.values(result.selectDependents);\n }\n\n private async promptLevelByLevel(allPaths: string[][]): Promise<string[][]> {\n if (allPaths.length < SHOW_ALL_PATHS_LIMIT) {\n throw new Error(`expected to have at least ${SHOW_ALL_PATHS_LIMIT} paths`);\n }\n const finalPath: string[] = [];\n this.logger\n .console(`found ${allPaths.length} available paths from the workspace components to the target components.\nthe following prompts will guide you to choose the desired path to import.`);\n\n const getPrompt = (choices: string[], level: number, totalPaths: number) => {\n return new AutoComplete({\n name: 'comp',\n message: `Choose which component to include`,\n limit: SCROLL_LIMIT,\n footer() {\n return choices.length >= SCROLL_LIMIT ? chalk.dim('(Scroll up and down to reveal more choices)') : '';\n },\n header() {\n if (level === 1) return '';\n return `total ${totalPaths} paths left (out of ${allPaths.length})`;\n },\n cancel() {\n // By default, canceling the prompt via Ctrl+c throws an empty string.\n // The custom cancel function prevents that behavior.\n // Otherwise, Bit CLI would print an error and confuse users.\n // See related issue: https://github.com/enquirer/enquirer/issues/225\n },\n choices,\n });\n };\n\n const getLevel = (level: number, withinPaths: string[][]): string[] => {\n return compact(uniq(withinPaths.map((path) => path[level]))).sort();\n };\n\n const processLevel = async (level: number, paths: string[][], previousLevel?: string): Promise<string[]> => {\n const pathsWithinThisLevel = previousLevel ? paths.filter((path) => path[level] === previousLevel) : paths;\n const nextLevel = getLevel(level + 1, pathsWithinThisLevel);\n if (!nextLevel.length) {\n return finalPath;\n }\n if (nextLevel.length === 1) {\n finalPath.push(nextLevel[0]);\n this.logger.consoleSuccess(`${nextLevel[0]} (auto-selected)`);\n return processLevel(level + 1, pathsWithinThisLevel, nextLevel[0]);\n }\n const promptNextLevel = getPrompt(nextLevel, level + 1, pathsWithinThisLevel.length);\n const resultNextLevel = await promptNextLevel.run();\n finalPath.push(resultNextLevel);\n return processLevel(level + 1, pathsWithinThisLevel, resultNextLevel);\n };\n\n const result = await processLevel(0, allPaths);\n\n return [result];\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,G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AQ,CAAC;IAE9C,OAAO,CAAC0C,MAAM,CAAC;EACjB;AACF;AAACmD,OAAA,CAAArH,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
package/dist/esm.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
+
import type { ImporterMain } from './importer.main.runtime';
|
|
3
|
+
export declare class FetchCmd implements Command {
|
|
4
|
+
private importer;
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
extendedDescription: string;
|
|
8
|
+
group: string;
|
|
9
|
+
alias: string;
|
|
10
|
+
private: boolean;
|
|
11
|
+
options: CommandOptions;
|
|
12
|
+
loader: boolean;
|
|
13
|
+
constructor(importer: ImporterMain);
|
|
14
|
+
report([ids]: [string[]], { lanes, components, fromOriginalScope, allHistory, }: {
|
|
15
|
+
lanes?: boolean;
|
|
16
|
+
components?: boolean;
|
|
17
|
+
fromOriginalScope?: boolean;
|
|
18
|
+
allHistory?: boolean;
|
|
19
|
+
}): Promise<string>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FetchCmd = void 0;
|
|
7
|
+
function _chalk() {
|
|
8
|
+
const data = _interopRequireDefault(require("chalk"));
|
|
9
|
+
_chalk = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _componentModules() {
|
|
15
|
+
const data = require("@teambit/component.modules.merge-helper");
|
|
16
|
+
_componentModules = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
23
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
24
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
25
|
+
class FetchCmd {
|
|
26
|
+
constructor(importer) {
|
|
27
|
+
this.importer = importer;
|
|
28
|
+
_defineProperty(this, "name", 'fetch [ids...]');
|
|
29
|
+
_defineProperty(this, "description", `fetch remote objects and store locally`);
|
|
30
|
+
_defineProperty(this, "extendedDescription", `for lanes, use "/" as a separator between the remote and the lane name, e.g. teambit.ui/fix-button`);
|
|
31
|
+
_defineProperty(this, "group", 'collaborate');
|
|
32
|
+
_defineProperty(this, "alias", '');
|
|
33
|
+
_defineProperty(this, "private", true);
|
|
34
|
+
_defineProperty(this, "options", [['l', 'lanes', 'fetch component objects from lanes. note, it does not save the remote lanes objects locally, only the refs'], ['c', 'components', 'fetch components'], ['', 'all-history', 'for each component, fetch all its versions. by default, only the latest version is fetched'], ['j', 'json', 'return the output as JSON'], ['', 'from-original-scopes', 'fetch indirect dependencies from their original scope as opposed to from their dependents']]);
|
|
35
|
+
_defineProperty(this, "loader", true);
|
|
36
|
+
}
|
|
37
|
+
async report([ids = []], {
|
|
38
|
+
lanes = false,
|
|
39
|
+
components = false,
|
|
40
|
+
fromOriginalScope = false,
|
|
41
|
+
allHistory = false
|
|
42
|
+
}) {
|
|
43
|
+
const {
|
|
44
|
+
importedIds,
|
|
45
|
+
importDetails
|
|
46
|
+
} = await this.importer.fetch(ids, lanes, components, fromOriginalScope, allHistory);
|
|
47
|
+
if (!importedIds.length) {
|
|
48
|
+
return _chalk().default.yellow('nothing to import');
|
|
49
|
+
}
|
|
50
|
+
const title = `successfully fetched ${importedIds.length} component(s)`;
|
|
51
|
+
if (!importDetails) {
|
|
52
|
+
// in case it fetches from a scope, when a workspace is not available.
|
|
53
|
+
const comps = importedIds.map(id => _chalk().default.cyan(id.toString()));
|
|
54
|
+
return [_chalk().default.green(title)].concat(comps).join('\n');
|
|
55
|
+
}
|
|
56
|
+
const componentDependencies = importedIds.map(id => {
|
|
57
|
+
const details = importDetails.find(c => c.id === id.toStringWithoutVersion());
|
|
58
|
+
if (!details) throw new Error(`missing details for component ${id.toString()}`);
|
|
59
|
+
return formatPlainComponentItemWithVersions(id, details);
|
|
60
|
+
});
|
|
61
|
+
const componentDependenciesOutput = [_chalk().default.green(title)].concat(componentDependencies).join('\n');
|
|
62
|
+
return componentDependenciesOutput;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.FetchCmd = FetchCmd;
|
|
66
|
+
function formatPlainComponentItemWithVersions(bitId, importDetails) {
|
|
67
|
+
const status = importDetails.status;
|
|
68
|
+
const id = bitId.toStringWithoutVersion();
|
|
69
|
+
const versions = importDetails.versions.length ? `new versions: ${importDetails.versions.join(', ')}` : '';
|
|
70
|
+
const usedVersion = status === 'added' ? `, currently used version ${bitId.version}` : '';
|
|
71
|
+
const getConflictMessage = () => {
|
|
72
|
+
if (!importDetails.filesStatus) return '';
|
|
73
|
+
const conflictedFiles = Object.keys(importDetails.filesStatus) // $FlowFixMe file is set
|
|
74
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
75
|
+
.filter(file => importDetails.filesStatus[file] === _componentModules().FileStatus.manual);
|
|
76
|
+
if (!conflictedFiles.length) return '';
|
|
77
|
+
return `(the following files were saved with conflicts ${conflictedFiles.map(file => _chalk().default.bold(file)).join(', ')}) `;
|
|
78
|
+
};
|
|
79
|
+
const deprecated = importDetails.deprecated ? _chalk().default.yellow('deprecated') : '';
|
|
80
|
+
const missingDeps = importDetails.missingDeps.length ? _chalk().default.red(`missing dependencies: ${importDetails.missingDeps.map(d => d.toString()).join(', ')}`) : '';
|
|
81
|
+
return `- ${_chalk().default.green(status)} ${_chalk().default.cyan(id)} ${versions}${usedVersion} ${getConflictMessage()}${deprecated} ${missingDeps}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=fetch-cmd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_chalk","data","_interopRequireDefault","require","_componentModules","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","FetchCmd","constructor","importer","report","ids","lanes","components","fromOriginalScope","allHistory","importedIds","importDetails","fetch","length","chalk","yellow","title","comps","map","id","cyan","toString","green","concat","join","componentDependencies","details","find","c","toStringWithoutVersion","Error","formatPlainComponentItemWithVersions","componentDependenciesOutput","exports","bitId","status","versions","usedVersion","version","getConflictMessage","filesStatus","conflictedFiles","keys","filter","file","FileStatus","manual","bold","deprecated","missingDeps","red","d"],"sources":["fetch-cmd.ts"],"sourcesContent":["import chalk from 'chalk';\nimport type { Command, CommandOptions } from '@teambit/cli';\nimport type { ComponentID } from '@teambit/component-id';\nimport { FileStatus } from '@teambit/component.modules.merge-helper';\nimport type { ImporterMain } from './importer.main.runtime';\nimport type { ImportDetails, ImportStatus } from './import-components';\n\nexport class FetchCmd implements Command {\n name = 'fetch [ids...]';\n description = `fetch remote objects and store locally`;\n extendedDescription = `for lanes, use \"/\" as a separator between the remote and the lane name, e.g. teambit.ui/fix-button`;\n group = 'collaborate';\n alias = '';\n private = true;\n options = [\n [\n 'l',\n 'lanes',\n 'fetch component objects from lanes. note, it does not save the remote lanes objects locally, only the refs',\n ],\n ['c', 'components', 'fetch components'],\n ['', 'all-history', 'for each component, fetch all its versions. by default, only the latest version is fetched'],\n ['j', 'json', 'return the output as JSON'],\n [\n '',\n 'from-original-scopes',\n 'fetch indirect dependencies from their original scope as opposed to from their dependents',\n ],\n ] as CommandOptions;\n loader = true;\n\n constructor(private importer: ImporterMain) {}\n\n async report(\n [ids = []]: [string[]],\n {\n lanes = false,\n components = false,\n fromOriginalScope = false,\n allHistory = false,\n }: {\n lanes?: boolean;\n components?: boolean;\n fromOriginalScope?: boolean;\n allHistory?: boolean;\n }\n ) {\n const { importedIds, importDetails } = await this.importer.fetch(\n ids,\n lanes,\n components,\n fromOriginalScope,\n allHistory\n );\n\n if (!importedIds.length) {\n return chalk.yellow('nothing to import');\n }\n const title = `successfully fetched ${importedIds.length} component(s)`;\n if (!importDetails) {\n // in case it fetches from a scope, when a workspace is not available.\n const comps = importedIds.map((id) => chalk.cyan(id.toString()));\n return [chalk.green(title)].concat(comps).join('\\n');\n }\n\n const componentDependencies = importedIds.map((id) => {\n const details = importDetails.find((c) => c.id === id.toStringWithoutVersion());\n if (!details) throw new Error(`missing details for component ${id.toString()}`);\n return formatPlainComponentItemWithVersions(id, details);\n });\n const componentDependenciesOutput = [chalk.green(title)].concat(componentDependencies).join('\\n');\n\n return componentDependenciesOutput;\n }\n}\n\nfunction formatPlainComponentItemWithVersions(bitId: ComponentID, importDetails: ImportDetails) {\n const status: ImportStatus = importDetails.status;\n const id = bitId.toStringWithoutVersion();\n const versions = importDetails.versions.length ? `new versions: ${importDetails.versions.join(', ')}` : '';\n const usedVersion = status === 'added' ? `, currently used version ${bitId.version}` : '';\n const getConflictMessage = () => {\n if (!importDetails.filesStatus) return '';\n const conflictedFiles = Object.keys(importDetails.filesStatus) // $FlowFixMe file is set\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n .filter((file) => importDetails.filesStatus[file] === FileStatus.manual);\n if (!conflictedFiles.length) return '';\n return `(the following files were saved with conflicts ${conflictedFiles\n .map((file) => chalk.bold(file))\n .join(', ')}) `;\n };\n const deprecated = importDetails.deprecated ? chalk.yellow('deprecated') : '';\n const missingDeps = importDetails.missingDeps.length\n ? chalk.red(`missing dependencies: ${importDetails.missingDeps.map((d) => d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ACzC,MAAMC,eAAe,GAAGtD,MAAM,CAACuD,IAAI,CAAC/B,aAAa,CAAC6B,WAAW,CAAC,CAAC;IAC7D;IAAA,CACCG,MAAM,CAAEC,IAAI,IAAKjC,aAAa,CAAC6B,WAAW,CAACI,IAAI,CAAC,KAAKC,8BAAU,CAACC,MAAM,CAAC;IAC1E,IAAI,CAACL,eAAe,CAAC5B,MAAM,EAAE,OAAO,EAAE;IACtC,OAAO,kDAAkD4B,eAAe,CACrEvB,GAAG,CAAE0B,IAAI,IAAK9B,gBAAK,CAACiC,IAAI,CAACH,IAAI,CAAC,CAAC,CAC/BpB,IAAI,CAAC,IAAI,CAAC,IAAI;EACnB,CAAC;EACD,MAAMwB,UAAU,GAAGrC,aAAa,CAACqC,UAAU,GAAGlC,gBAAK,CAACC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE;EAC7E,MAAMkC,WAAW,GAAGtC,aAAa,CAACsC,WAAW,CAACpC,MAAM,GAChDC,gBAAK,CAACoC,GAAG,CAAC,yBAAyBvC,aAAa,CAACsC,WAAW,CAAC/B,GAAG,CAAEiC,CAAC,IAAKA,CAAC,CAAC9B,QAAQ,CAAC,CAAC,CAAC,CAACG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GACnG,EAAE;EACN,OAAO,KAAKV,gBAAK,CAACQ,KAAK,CAACa,MAAM,CAAC,IAAIrB,gBAAK,CAACM,IAAI,CAC3CD,EACF,CAAC,IAAIiB,QAAQ,GAAGC,WAAW,IAAIE,kBAAkB,CAAC,CAAC,GAAGS,UAAU,IAAIC,WAAW,EAAE;AACnF","ignoreList":[]}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { LaneId } from '@teambit/lane-id';
|
|
2
|
+
import { ComponentID, ComponentIdList } from '@teambit/component-id';
|
|
3
|
+
import type { Consumer } from '@teambit/legacy.consumer';
|
|
4
|
+
import type { Lane } from '@teambit/objects';
|
|
5
|
+
import type { ConsumerComponent as Component } from '@teambit/legacy.consumer-component';
|
|
6
|
+
import type { MergeStrategy, MergeResultsThreeWay, FilesStatus } from '@teambit/component.modules.merge-helper';
|
|
7
|
+
import type { VersionDependencies, Scope } from '@teambit/legacy.scope';
|
|
8
|
+
import type { GraphMain } from '@teambit/graph';
|
|
9
|
+
import type { Workspace } from '@teambit/workspace';
|
|
10
|
+
import type { ComponentWriterMain, ComponentWriterResults } from '@teambit/component-writer';
|
|
11
|
+
import type { EnvsMain } from '@teambit/envs';
|
|
12
|
+
import type { WorkspaceConfigUpdateResult } from '@teambit/config-merger';
|
|
13
|
+
import type { Logger } from '@teambit/logger';
|
|
14
|
+
import type { ListerMain } from '@teambit/lister';
|
|
15
|
+
export type ImportOptions = {
|
|
16
|
+
ids: string[];
|
|
17
|
+
verbose?: boolean;
|
|
18
|
+
merge?: boolean;
|
|
19
|
+
mergeStrategy?: MergeStrategy;
|
|
20
|
+
filterEnvs?: string[];
|
|
21
|
+
writeToPath?: string;
|
|
22
|
+
writeConfig?: boolean;
|
|
23
|
+
override?: boolean;
|
|
24
|
+
installNpmPackages: boolean;
|
|
25
|
+
writeConfigFiles: boolean;
|
|
26
|
+
objectsOnly?: boolean;
|
|
27
|
+
importDependenciesDirectly?: boolean;
|
|
28
|
+
importHeadDependenciesDirectly?: boolean;
|
|
29
|
+
importDependents?: boolean;
|
|
30
|
+
dependentsVia?: string;
|
|
31
|
+
dependentsAll?: boolean;
|
|
32
|
+
silent?: boolean;
|
|
33
|
+
fromOriginalScope?: boolean;
|
|
34
|
+
saveInLane?: boolean;
|
|
35
|
+
lanes?: {
|
|
36
|
+
laneId: LaneId;
|
|
37
|
+
remoteLane?: Lane;
|
|
38
|
+
};
|
|
39
|
+
allHistory?: boolean;
|
|
40
|
+
fetchDeps?: boolean;
|
|
41
|
+
trackOnly?: boolean;
|
|
42
|
+
includeDeprecated?: boolean;
|
|
43
|
+
isLaneFromRemote?: boolean;
|
|
44
|
+
writeDeps?: 'package.json' | 'workspace.jsonc';
|
|
45
|
+
laneOnly?: boolean;
|
|
46
|
+
};
|
|
47
|
+
type ComponentMergeStatus = {
|
|
48
|
+
component: Component;
|
|
49
|
+
mergeResults: MergeResultsThreeWay | null | undefined;
|
|
50
|
+
};
|
|
51
|
+
type ImportedVersions = {
|
|
52
|
+
[id: string]: string[];
|
|
53
|
+
};
|
|
54
|
+
export type ImportStatus = 'added' | 'updated' | 'up to date';
|
|
55
|
+
export type ImportDetails = {
|
|
56
|
+
id: string;
|
|
57
|
+
versions: string[];
|
|
58
|
+
latestVersion: string | null;
|
|
59
|
+
status: ImportStatus;
|
|
60
|
+
filesStatus: FilesStatus | null | undefined;
|
|
61
|
+
missingDeps: ComponentID[];
|
|
62
|
+
deprecated: boolean;
|
|
63
|
+
removed?: boolean;
|
|
64
|
+
};
|
|
65
|
+
export type ImportResult = {
|
|
66
|
+
importedIds: ComponentID[];
|
|
67
|
+
importedDeps: ComponentID[];
|
|
68
|
+
writtenComponents?: Component[];
|
|
69
|
+
importDetails: ImportDetails[];
|
|
70
|
+
cancellationMessage?: string;
|
|
71
|
+
installationError?: Error;
|
|
72
|
+
compilationError?: Error;
|
|
73
|
+
workspaceConfigUpdateResult?: WorkspaceConfigUpdateResult;
|
|
74
|
+
missingIds?: string[];
|
|
75
|
+
lane?: Lane;
|
|
76
|
+
};
|
|
77
|
+
export default class ImportComponents {
|
|
78
|
+
private workspace;
|
|
79
|
+
private graph;
|
|
80
|
+
private componentWriter;
|
|
81
|
+
private envs;
|
|
82
|
+
private logger;
|
|
83
|
+
private lister;
|
|
84
|
+
options: ImportOptions;
|
|
85
|
+
consumer: Consumer;
|
|
86
|
+
scope: Scope;
|
|
87
|
+
mergeStatus: {
|
|
88
|
+
[id: string]: FilesStatus;
|
|
89
|
+
};
|
|
90
|
+
private remoteLane;
|
|
91
|
+
private divergeData;
|
|
92
|
+
constructor(workspace: Workspace, graph: GraphMain, componentWriter: ComponentWriterMain, envs: EnvsMain, logger: Logger, lister: ListerMain, options: ImportOptions);
|
|
93
|
+
importComponents(): Promise<ImportResult>;
|
|
94
|
+
importObjectsOnLane(): Promise<ImportResult>;
|
|
95
|
+
private returnCompleteResults;
|
|
96
|
+
importSpecificComponents(): Promise<ImportResult>;
|
|
97
|
+
private mergeAndSaveLaneObject;
|
|
98
|
+
private _filterComponentsByFilters;
|
|
99
|
+
private _fetchDivergeData;
|
|
100
|
+
_throwForDivergedHistory(): void;
|
|
101
|
+
private throwForComponentsFromAnotherLane;
|
|
102
|
+
private _importComponentsObjects;
|
|
103
|
+
/**
|
|
104
|
+
* consider the following use cases:
|
|
105
|
+
* 1) no ids were provided. it should import all the lanes components objects AND main components objects
|
|
106
|
+
* (otherwise, if main components are not imported and are missing, then bit-status complains about it)
|
|
107
|
+
* 2) ids are provided with wildcards. by default, imports from both lane and main (lane versions preferred).
|
|
108
|
+
* if --lane-only flag is specified, import only components that exist on the lane.
|
|
109
|
+
* 3) ids are provided without wildcards. here, the user knows exactly what's needed and it's ok to get the ids from
|
|
110
|
+
* main if not found on the lane.
|
|
111
|
+
*/
|
|
112
|
+
private getBitIdsForLanes;
|
|
113
|
+
private getIdFromStr;
|
|
114
|
+
private getBitIdsForNonLanes;
|
|
115
|
+
private getBitIds;
|
|
116
|
+
private getFlattenedDepsUnique;
|
|
117
|
+
private uniqWithoutVersions;
|
|
118
|
+
private removeMultipleVersionsKeepLatest;
|
|
119
|
+
importAccordingToBitMap(): Promise<ImportResult>;
|
|
120
|
+
private getIdsToImportFromBitmap;
|
|
121
|
+
_getCurrentVersions(ids: ComponentIdList): Promise<ImportedVersions>;
|
|
122
|
+
/**
|
|
123
|
+
* get import details, includes the diff between the versions array before import and after import
|
|
124
|
+
*/
|
|
125
|
+
_getImportDetails(currentVersions: ImportedVersions, components: VersionDependencies[]): Promise<ImportDetails[]>;
|
|
126
|
+
_throwForPotentialIssues(ids: ComponentIdList): Promise<void>;
|
|
127
|
+
_throwForModifiedOrNewComponents(ids: ComponentIdList): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Model Component id() calculation uses id.toString() for the hash.
|
|
130
|
+
* If an imported component has scopereadonly name equals to a local name, both will have the exact same
|
|
131
|
+
* hash and they'll override each other.
|
|
132
|
+
*/
|
|
133
|
+
_throwForDifferentComponentWithSameName(ids: ComponentIdList): void;
|
|
134
|
+
_getMergeStatus(component: Component): Promise<ComponentMergeStatus>;
|
|
135
|
+
/**
|
|
136
|
+
* 1) when there are conflicts and the strategy is "ours", don't write the imported component to
|
|
137
|
+
* the filesystem, only update bitmap.
|
|
138
|
+
*
|
|
139
|
+
* 2) when there are conflicts and the strategy is "theirs", override the local changes by the
|
|
140
|
+
* imported component. (similar to --override)
|
|
141
|
+
*
|
|
142
|
+
* 3) when there is no conflict or there are conflicts and the strategy is manual, write the files
|
|
143
|
+
* according to the merge result. (done by applyModifiedVersion())
|
|
144
|
+
*/
|
|
145
|
+
_updateComponentFilesPerMergeStrategy(componentMergeStatus: ComponentMergeStatus): FilesStatus | null | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* update the component files if they are modified and there is a merge strategy.
|
|
148
|
+
* returns only the components that need to be written to the filesystem
|
|
149
|
+
*/
|
|
150
|
+
updateAllComponentsAccordingToMergeStrategy(components: Component[]): Promise<Component[]>;
|
|
151
|
+
_shouldSaveLaneData(): boolean;
|
|
152
|
+
_saveLaneDataIfNeeded(components: Component[]): Promise<void>;
|
|
153
|
+
_writeToFileSystem(components: Component[]): Promise<ComponentWriterResults>;
|
|
154
|
+
}
|
|
155
|
+
export {};
|