@teambit/remove 1.0.107 → 1.0.108
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/delete-cmd.ts +109 -0
- package/dist/delete-cmd.d.ts +1 -1
- package/dist/delete-cmd.js +2 -3
- package/dist/delete-cmd.js.map +1 -1
- package/dist/recover-cmd.d.ts +1 -1
- package/dist/remove-cmd.d.ts +1 -1
- package/dist/remove-components.d.ts +1 -1
- package/dist/remove-components.js +1 -1
- package/dist/remove-components.js.map +1 -1
- package/dist/remove-template.d.ts +1 -1
- package/dist/remove.main.runtime.d.ts +2 -2
- package/dist/remove.main.runtime.js +8 -15
- package/dist/remove.main.runtime.js.map +1 -1
- package/index.ts +7 -0
- package/package.json +17 -26
- package/recover-cmd.ts +31 -0
- package/remove-cmd.ts +85 -0
- package/remove-components.ts +171 -0
- package/remove-template.ts +73 -0
- package/remove.aspect.ts +5 -0
- package/remove.fragment.ts +26 -0
- package/remove.main.runtime.ts +367 -0
- package/removed-local-objects.ts +17 -0
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
- /package/dist/{preview-1703590665075.js → preview-1703647408454.js} +0 -0
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/remove",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.108",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/component/remove",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.component",
|
|
8
8
|
"name": "remove",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.108"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"chalk": "2.4.2",
|
|
@@ -16,33 +16,27 @@
|
|
|
16
16
|
"p-map-series": "2.1.0",
|
|
17
17
|
"ramda": "0.27.1",
|
|
18
18
|
"lodash": "4.17.21",
|
|
19
|
-
"core-js": "^3.0.0",
|
|
20
|
-
"@babel/runtime": "7.20.0",
|
|
21
19
|
"@teambit/bit-error": "0.0.404",
|
|
22
20
|
"@teambit/component-id": "1.2.0",
|
|
23
21
|
"@teambit/harmony": "0.4.6",
|
|
24
|
-
"@teambit/cli": "0.0.
|
|
25
|
-
"@teambit/workspace": "1.0.
|
|
26
|
-
"@teambit/component": "1.0.
|
|
27
|
-
"@teambit/component-issues": "0.0.
|
|
28
|
-
"@teambit/dependency-resolver": "1.0.
|
|
29
|
-
"@teambit/importer": "1.0.
|
|
30
|
-
"@teambit/issues": "1.0.
|
|
31
|
-
"@teambit/logger": "0.0.
|
|
22
|
+
"@teambit/cli": "0.0.840",
|
|
23
|
+
"@teambit/workspace": "1.0.108",
|
|
24
|
+
"@teambit/component": "1.0.108",
|
|
25
|
+
"@teambit/component-issues": "0.0.138",
|
|
26
|
+
"@teambit/dependency-resolver": "1.0.108",
|
|
27
|
+
"@teambit/importer": "1.0.108",
|
|
28
|
+
"@teambit/issues": "1.0.108",
|
|
29
|
+
"@teambit/logger": "0.0.933"
|
|
32
30
|
},
|
|
33
31
|
"devDependencies": {
|
|
34
32
|
"@types/lodash": "4.14.165",
|
|
35
33
|
"@types/mocha": "9.1.0",
|
|
36
|
-
"@types/
|
|
37
|
-
"@types/
|
|
38
|
-
"@
|
|
39
|
-
"@types/jest": "^26.0.0",
|
|
40
|
-
"@types/testing-library__jest-dom": "5.9.5"
|
|
34
|
+
"@types/jest": "^29.2.2",
|
|
35
|
+
"@types/testing-library__jest-dom": "^5.9.5",
|
|
36
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.13"
|
|
41
37
|
},
|
|
42
38
|
"peerDependencies": {
|
|
43
|
-
"@teambit/legacy": "1.0.624"
|
|
44
|
-
"react": "^16.8.0 || ^17.0.0",
|
|
45
|
-
"react-dom": "^16.8.0 || ^17.0.0"
|
|
39
|
+
"@teambit/legacy": "1.0.624"
|
|
46
40
|
},
|
|
47
41
|
"license": "Apache-2.0",
|
|
48
42
|
"optionalDependencies": {},
|
|
@@ -56,7 +50,7 @@
|
|
|
56
50
|
},
|
|
57
51
|
"private": false,
|
|
58
52
|
"engines": {
|
|
59
|
-
"node": ">=
|
|
53
|
+
"node": ">=16.0.0"
|
|
60
54
|
},
|
|
61
55
|
"repository": {
|
|
62
56
|
"type": "git",
|
|
@@ -65,12 +59,9 @@
|
|
|
65
59
|
"keywords": [
|
|
66
60
|
"bit",
|
|
67
61
|
"bit-aspect",
|
|
62
|
+
"bit-core-aspect",
|
|
68
63
|
"components",
|
|
69
64
|
"collaboration",
|
|
70
|
-
"web"
|
|
71
|
-
"react",
|
|
72
|
-
"react-components",
|
|
73
|
-
"angular",
|
|
74
|
-
"angular-components"
|
|
65
|
+
"web"
|
|
75
66
|
]
|
|
76
67
|
}
|
package/recover-cmd.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { BitError } from '@teambit/bit-error';
|
|
3
|
+
import { Command, CommandOptions } from '@teambit/cli';
|
|
4
|
+
import { RemoveMain } from './remove.main.runtime';
|
|
5
|
+
|
|
6
|
+
export type RecoverOptions = {
|
|
7
|
+
skipDependencyInstallation?: boolean;
|
|
8
|
+
skipWriteConfigFiles?: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export class RecoverCmd implements Command {
|
|
12
|
+
name = 'recover <component-name>';
|
|
13
|
+
description = 'EXPERIMENTAL. recover component(s) soft-deleted from the workspace, or a remote scope';
|
|
14
|
+
group = 'collaborate';
|
|
15
|
+
options = [
|
|
16
|
+
['x', 'skip-dependency-installation', 'do not install packages in case of importing components'],
|
|
17
|
+
['', 'skip-write-config-files', 'do not write config files (such as eslint, tsconfig, prettier, etc...)'],
|
|
18
|
+
] as CommandOptions;
|
|
19
|
+
loader = true;
|
|
20
|
+
migration = true;
|
|
21
|
+
|
|
22
|
+
constructor(private remove: RemoveMain) {}
|
|
23
|
+
|
|
24
|
+
async report([componentName]: [string], options: RecoverOptions) {
|
|
25
|
+
const hasRecovered = await this.remove.recover(componentName, options);
|
|
26
|
+
if (!hasRecovered) {
|
|
27
|
+
throw new BitError(`component ${componentName} was not soft-deleted, nothing to recover`);
|
|
28
|
+
}
|
|
29
|
+
return chalk.green(`successfully recovered ${componentName}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
package/remove-cmd.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import yesno from 'yesno';
|
|
3
|
+
import { Command, CommandOptions } from '@teambit/cli';
|
|
4
|
+
import { Workspace } from '@teambit/workspace';
|
|
5
|
+
import { BitError } from '@teambit/bit-error';
|
|
6
|
+
import { COMPONENT_PATTERN_HELP } from '@teambit/legacy/dist/constants';
|
|
7
|
+
import { RemovedLocalObjects } from './removed-local-objects';
|
|
8
|
+
import { RemoveMain } from './remove.main.runtime';
|
|
9
|
+
import { removeTemplate } from './remove-template';
|
|
10
|
+
|
|
11
|
+
export class RemoveCmd implements Command {
|
|
12
|
+
name = 'remove <component-pattern>';
|
|
13
|
+
description = 'remove component(s) from the local workspace';
|
|
14
|
+
extendedDescription = `to mark components as deleted on the remote scope, use "bit delete".`;
|
|
15
|
+
arguments = [
|
|
16
|
+
{
|
|
17
|
+
name: 'component-pattern',
|
|
18
|
+
description: COMPONENT_PATTERN_HELP,
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
group = 'collaborate';
|
|
22
|
+
helpUrl = 'reference/components/removing-components';
|
|
23
|
+
skipWorkspace = true;
|
|
24
|
+
alias = 'rm';
|
|
25
|
+
options = [
|
|
26
|
+
['t', 'track', 'keep tracking component in .bitmap (default = false), helps transform a tagged-component to new'],
|
|
27
|
+
['', 'keep-files', 'keep component files (just untrack the component)'],
|
|
28
|
+
[
|
|
29
|
+
'f',
|
|
30
|
+
'force',
|
|
31
|
+
'removes the component from the scope, even if used as a dependency. WARNING: you will need to fix the components that depend on this component',
|
|
32
|
+
],
|
|
33
|
+
['s', 'silent', 'skip confirmation'],
|
|
34
|
+
] as CommandOptions;
|
|
35
|
+
loader = true;
|
|
36
|
+
migration = true;
|
|
37
|
+
remoteOp = true;
|
|
38
|
+
|
|
39
|
+
constructor(private remove: RemoveMain, private workspace?: Workspace) {}
|
|
40
|
+
|
|
41
|
+
async report(
|
|
42
|
+
[componentsPattern]: [string],
|
|
43
|
+
{
|
|
44
|
+
force = false,
|
|
45
|
+
track = false,
|
|
46
|
+
silent = false,
|
|
47
|
+
keepFiles = false,
|
|
48
|
+
}: {
|
|
49
|
+
force?: boolean;
|
|
50
|
+
track?: boolean;
|
|
51
|
+
silent?: boolean;
|
|
52
|
+
keepFiles?: boolean;
|
|
53
|
+
}
|
|
54
|
+
) {
|
|
55
|
+
if (!silent) {
|
|
56
|
+
await this.removePrompt(!keepFiles);
|
|
57
|
+
}
|
|
58
|
+
const {
|
|
59
|
+
localResult,
|
|
60
|
+
}: {
|
|
61
|
+
localResult: RemovedLocalObjects;
|
|
62
|
+
} = await this.remove.remove({ componentsPattern, force, track, deleteFiles: !keepFiles });
|
|
63
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
64
|
+
const localMessage = removeTemplate(localResult, false);
|
|
65
|
+
// if (localMessage !== '')
|
|
66
|
+
// localMessage +=
|
|
67
|
+
// '. Note: these components were not deleted from the remote - if you want to delete components run "bit delete"\n';
|
|
68
|
+
return localMessage;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private async removePrompt(deleteFiles?: boolean) {
|
|
72
|
+
this.remove.logger.clearStatusLine();
|
|
73
|
+
const filesDeletionStr = deleteFiles
|
|
74
|
+
? ' and the files will be deleted from the filesystem (can be avoided by entering --keep-files)'
|
|
75
|
+
: '';
|
|
76
|
+
const ok = await yesno({
|
|
77
|
+
question: `this command will remove the component/s only from your local workspace. if your intent is to delete the component/s also from the remote scope, refer to "bit delete".
|
|
78
|
+
the component(s) will be untracked${filesDeletionStr}.
|
|
79
|
+
${chalk.bold('Would you like to proceed? [yes(y)/no(n)]')}`,
|
|
80
|
+
});
|
|
81
|
+
if (!ok) {
|
|
82
|
+
throw new BitError('the operation has been canceled');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import groupArray from 'group-array';
|
|
2
|
+
import partition from 'lodash.partition';
|
|
3
|
+
import R from 'ramda';
|
|
4
|
+
import { Consumer } from '@teambit/legacy/dist/consumer';
|
|
5
|
+
import { ComponentIdList } from '@teambit/component-id';
|
|
6
|
+
import { CENTRAL_BIT_HUB_NAME, CENTRAL_BIT_HUB_URL, LATEST_BIT_VERSION } from '@teambit/legacy/dist/constants';
|
|
7
|
+
import GeneralError from '@teambit/legacy/dist/error/general-error';
|
|
8
|
+
import enrichContextFromGlobal from '@teambit/legacy/dist/hooks/utils/enrich-context-from-global';
|
|
9
|
+
import logger from '@teambit/legacy/dist/logger/logger';
|
|
10
|
+
import { Http } from '@teambit/legacy/dist/scope/network/http';
|
|
11
|
+
import { Remotes } from '@teambit/legacy/dist/remotes';
|
|
12
|
+
import { getScopeRemotes } from '@teambit/legacy/dist/scope/scope-remotes';
|
|
13
|
+
import deleteComponentsFiles from '@teambit/legacy/dist/consumer/component-ops/delete-component-files';
|
|
14
|
+
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
|
|
15
|
+
import Component from '@teambit/legacy/dist/consumer/component/consumer-component';
|
|
16
|
+
import RemovedObjects from '@teambit/legacy/dist/scope/removed-components';
|
|
17
|
+
import * as packageJsonUtils from '@teambit/legacy/dist/consumer/component/package-json-utils';
|
|
18
|
+
import pMapSeries from 'p-map-series';
|
|
19
|
+
import { RemovedLocalObjects } from './removed-local-objects';
|
|
20
|
+
|
|
21
|
+
export type RemoveComponentsResult = { localResult: RemovedLocalObjects; remoteResult: RemovedObjects[] };
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Remove components local and remote
|
|
25
|
+
* splits array of ids into local and remote and removes according to flags
|
|
26
|
+
* @param {string[]} ids - list of remote component ids to delete
|
|
27
|
+
* @param {boolean} force - delete component that are used by other components.
|
|
28
|
+
* @param {boolean} remote - delete component from a remote scope
|
|
29
|
+
* @param {boolean} track - keep tracking local staged components in bitmap.
|
|
30
|
+
* @param {boolean} deleteFiles - delete local added files from fs.
|
|
31
|
+
*/
|
|
32
|
+
export async function removeComponents({
|
|
33
|
+
consumer,
|
|
34
|
+
ids,
|
|
35
|
+
force,
|
|
36
|
+
remote,
|
|
37
|
+
track,
|
|
38
|
+
deleteFiles,
|
|
39
|
+
}: {
|
|
40
|
+
consumer: Consumer | null | undefined; // when remote is false, it's always set
|
|
41
|
+
ids: ComponentIdList;
|
|
42
|
+
force: boolean;
|
|
43
|
+
remote: boolean;
|
|
44
|
+
track: boolean;
|
|
45
|
+
deleteFiles: boolean;
|
|
46
|
+
}): Promise<RemoveComponentsResult> {
|
|
47
|
+
logger.debugAndAddBreadCrumb('removeComponents', `{ids}. force: ${force.toString()}`, { ids: ids.toString() });
|
|
48
|
+
// added this to remove support for remove only one version from a component
|
|
49
|
+
const bitIdsLatest = ComponentIdList.fromArray(
|
|
50
|
+
ids.map((id) => {
|
|
51
|
+
return id.changeVersion(LATEST_BIT_VERSION);
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
const [localIds, remoteIds] = partition(bitIdsLatest, (id) => id.isLocal());
|
|
55
|
+
if (remote && localIds.length) {
|
|
56
|
+
throw new GeneralError(
|
|
57
|
+
`unable to remove the remote components: ${localIds.join(',')} as they don't contain a scope-name`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const remoteResult = remote && !R.isEmpty(remoteIds) ? await removeRemote(consumer, remoteIds, force) : [];
|
|
61
|
+
const localResult = !remote
|
|
62
|
+
? await removeLocal(consumer as Consumer, bitIdsLatest, force, track, deleteFiles)
|
|
63
|
+
: new RemovedLocalObjects();
|
|
64
|
+
|
|
65
|
+
return { localResult, remoteResult };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Remove remote component from ssh server
|
|
70
|
+
* this method groups remote components by remote name and deletes remote components together
|
|
71
|
+
* @param {ComponentIdList} bitIds - list of remote component ids to delete
|
|
72
|
+
* @param {boolean} force - delete component that are used by other components.
|
|
73
|
+
*/
|
|
74
|
+
async function removeRemote(
|
|
75
|
+
consumer: Consumer | null | undefined,
|
|
76
|
+
bitIds: ComponentIdList,
|
|
77
|
+
force: boolean
|
|
78
|
+
): Promise<RemovedObjects[]> {
|
|
79
|
+
const groupedBitsByScope = groupArray(bitIds, 'scope');
|
|
80
|
+
const remotes = consumer ? await getScopeRemotes(consumer.scope) : await Remotes.getGlobalRemotes();
|
|
81
|
+
const shouldGoToCentralHub = remotes.shouldGoToCentralHub(Object.keys(groupedBitsByScope));
|
|
82
|
+
if (shouldGoToCentralHub) {
|
|
83
|
+
const http = await Http.connect(CENTRAL_BIT_HUB_URL, CENTRAL_BIT_HUB_NAME);
|
|
84
|
+
return http.deleteViaCentralHub(
|
|
85
|
+
bitIds.map((id) => id.toString()),
|
|
86
|
+
{ force, idsAreLanes: false }
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
const context = {};
|
|
90
|
+
enrichContextFromGlobal(context);
|
|
91
|
+
const removeP = Object.keys(groupedBitsByScope).map(async (key) => {
|
|
92
|
+
const resolvedRemote = await remotes.resolve(key, consumer?.scope);
|
|
93
|
+
const idsStr = groupedBitsByScope[key].map((id) => id.toStringWithoutVersion());
|
|
94
|
+
return resolvedRemote.deleteMany(idsStr, force, context);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return Promise.all(removeP);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* removeLocal - remove local (imported, new staged components) from modules and bitmap according to flags
|
|
102
|
+
* @param {ComponentIdList} bitIds - list of component ids to delete
|
|
103
|
+
* @param {boolean} force - delete component that are used by other components.
|
|
104
|
+
* @param {boolean} deleteFiles - delete component that are used by other components.
|
|
105
|
+
*/
|
|
106
|
+
async function removeLocal(
|
|
107
|
+
consumer: Consumer,
|
|
108
|
+
bitIds: ComponentIdList,
|
|
109
|
+
force: boolean,
|
|
110
|
+
track: boolean,
|
|
111
|
+
deleteFiles: boolean
|
|
112
|
+
): Promise<RemovedLocalObjects> {
|
|
113
|
+
// local remove in case user wants to delete tagged components
|
|
114
|
+
const modifiedComponents = new ComponentIdList();
|
|
115
|
+
const nonModifiedComponents = new ComponentIdList();
|
|
116
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
117
|
+
if (R.isEmpty(bitIds)) return new RemovedLocalObjects();
|
|
118
|
+
if (!force) {
|
|
119
|
+
await pMapSeries(bitIds, async (id) => {
|
|
120
|
+
try {
|
|
121
|
+
const componentStatus = await consumer.getComponentStatusById(id);
|
|
122
|
+
if (componentStatus.modified) modifiedComponents.push(id);
|
|
123
|
+
else nonModifiedComponents.push(id);
|
|
124
|
+
} catch (err: any) {
|
|
125
|
+
// if a component has an error, such as, missing main file, we do want to allow removing that component
|
|
126
|
+
if (Component.isComponentInvalidByErrorType(err)) {
|
|
127
|
+
nonModifiedComponents.push(id);
|
|
128
|
+
} else {
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const idsToRemove = force ? bitIds : nonModifiedComponents;
|
|
135
|
+
const componentsList = new ComponentsList(consumer);
|
|
136
|
+
const newComponents = (await componentsList.listNewComponents(false)) as ComponentIdList;
|
|
137
|
+
const idsToRemoveFromScope = ComponentIdList.fromArray(
|
|
138
|
+
idsToRemove.filter((id) => !newComponents.hasWithoutVersion(id))
|
|
139
|
+
);
|
|
140
|
+
const idsToCleanFromWorkspace = ComponentIdList.fromArray(
|
|
141
|
+
idsToRemove.filter((id) => newComponents.hasWithoutVersion(id))
|
|
142
|
+
);
|
|
143
|
+
const { components: componentsToRemove, invalidComponents } = await consumer.loadComponents(idsToRemove, false);
|
|
144
|
+
const { removedComponentIds, missingComponents, dependentBits, removedFromLane } = await consumer.scope.removeMany(
|
|
145
|
+
idsToRemoveFromScope,
|
|
146
|
+
force,
|
|
147
|
+
consumer
|
|
148
|
+
);
|
|
149
|
+
// otherwise, components should still be in .bitmap file
|
|
150
|
+
idsToCleanFromWorkspace.push(...removedComponentIds);
|
|
151
|
+
if (idsToCleanFromWorkspace.length) {
|
|
152
|
+
if (deleteFiles) await deleteComponentsFiles(consumer, idsToCleanFromWorkspace);
|
|
153
|
+
if (!track) {
|
|
154
|
+
const invalidComponentsIds = invalidComponents.map((i) => i.id);
|
|
155
|
+
const removedComponents = componentsToRemove.filter((c) => idsToCleanFromWorkspace.hasWithoutVersion(c.id));
|
|
156
|
+
await packageJsonUtils.removeComponentsFromWorkspacesAndDependencies(
|
|
157
|
+
consumer,
|
|
158
|
+
removedComponents,
|
|
159
|
+
invalidComponentsIds
|
|
160
|
+
);
|
|
161
|
+
await consumer.cleanFromBitMap(idsToCleanFromWorkspace);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return new RemovedLocalObjects(
|
|
165
|
+
ComponentIdList.uniqFromArray([...idsToCleanFromWorkspace, ...removedComponentIds]),
|
|
166
|
+
missingComponents,
|
|
167
|
+
modifiedComponents,
|
|
168
|
+
dependentBits,
|
|
169
|
+
removedFromLane
|
|
170
|
+
);
|
|
171
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ComponentID, ComponentIdList } from '@teambit/component-id';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import R from 'ramda';
|
|
4
|
+
|
|
5
|
+
export function removeTemplate(
|
|
6
|
+
{ dependentBits, modifiedComponents = [], removedComponentIds, missingComponents, removedFromLane },
|
|
7
|
+
isRemote
|
|
8
|
+
) {
|
|
9
|
+
const paintMissingComponents = () => {
|
|
10
|
+
if (R.isEmpty(missingComponents)) return '';
|
|
11
|
+
return (
|
|
12
|
+
chalk.red('missing components:') +
|
|
13
|
+
chalk(
|
|
14
|
+
` ${missingComponents.map((id) => {
|
|
15
|
+
if (!(id instanceof ComponentID)) id = ComponentID.fromObject(id); // when the id was received from a remote it's not an instance of ComponentID
|
|
16
|
+
return id.version === 'latest' ? id.toStringWithoutVersion() : id.toString();
|
|
17
|
+
})}\n`
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
const paintRemoved = () => {
|
|
22
|
+
if (R.isEmpty(removedComponentIds) && R.isEmpty(removedFromLane)) return '';
|
|
23
|
+
const compToStr = (comps: ComponentIdList) =>
|
|
24
|
+
chalk(` ${comps.map((id) => (id.version === 'latest' ? id.toStringWithoutVersion() : id.toString()))}\n`);
|
|
25
|
+
const getMsg = (isLane = false) => {
|
|
26
|
+
const removedFrom = isLane ? 'lane' : 'scope';
|
|
27
|
+
const msg = isRemote
|
|
28
|
+
? `successfully removed components from the remote ${removedFrom}:`
|
|
29
|
+
: `successfully removed components from the local ${removedFrom}:`;
|
|
30
|
+
return chalk.green(msg);
|
|
31
|
+
};
|
|
32
|
+
const newLine = '\n';
|
|
33
|
+
const compOutput = R.isEmpty(removedComponentIds) ? '' : getMsg(false) + compToStr(removedComponentIds) + newLine;
|
|
34
|
+
const laneOutput = R.isEmpty(removedFromLane) ? '' : getMsg(true) + compToStr(removedFromLane);
|
|
35
|
+
|
|
36
|
+
return `${compOutput}${laneOutput}`;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const paintUnRemovedComponents = () => {
|
|
40
|
+
if (R.isEmpty(dependentBits)) return '';
|
|
41
|
+
return Object.keys(dependentBits)
|
|
42
|
+
.map((key) => {
|
|
43
|
+
const header = chalk.underline.red(
|
|
44
|
+
`error: unable to delete ${key}, because the following components depend on it:`
|
|
45
|
+
);
|
|
46
|
+
const body = dependentBits[key].join('\n');
|
|
47
|
+
return `${header}\n${body}`;
|
|
48
|
+
})
|
|
49
|
+
.join('\n\n');
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const paintModifiedComponents = () => {
|
|
53
|
+
if (R.isEmpty(modifiedComponents)) return '';
|
|
54
|
+
const modifiedStr = modifiedComponents.map((id: ComponentID) =>
|
|
55
|
+
id.version === 'latest' ? id.toStringWithoutVersion() : id.toString()
|
|
56
|
+
);
|
|
57
|
+
return `${
|
|
58
|
+
chalk.red('error: unable to remove modified components (please use --force to remove modified components)\n') +
|
|
59
|
+
chalk(`- ${modifiedStr}`)
|
|
60
|
+
}`;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
65
|
+
paintUnRemovedComponents(dependentBits) +
|
|
66
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
67
|
+
paintRemoved(removedComponentIds) +
|
|
68
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
69
|
+
paintMissingComponents(missingComponents) +
|
|
70
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
71
|
+
paintModifiedComponents(modifiedComponents)
|
|
72
|
+
);
|
|
73
|
+
}
|
package/remove.aspect.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Component, ShowFragment } from '@teambit/component';
|
|
2
|
+
import { RemoveMain } from './remove.main.runtime';
|
|
3
|
+
|
|
4
|
+
export class RemoveFragment implements ShowFragment {
|
|
5
|
+
constructor(private remove: RemoveMain) {}
|
|
6
|
+
|
|
7
|
+
title = 'removed';
|
|
8
|
+
|
|
9
|
+
async renderRow(component: Component) {
|
|
10
|
+
const isRemoved = this.remove.isRemoved(component);
|
|
11
|
+
return {
|
|
12
|
+
title: this.title,
|
|
13
|
+
// when it's not removed, set as an empty string so then it won't be shown in bit-show
|
|
14
|
+
content: isRemoved ? isRemoved.toString() : '',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async json(component: Component) {
|
|
19
|
+
return {
|
|
20
|
+
title: this.title,
|
|
21
|
+
json: this.remove.getRemoveInfo(component),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
weight = 3;
|
|
26
|
+
}
|