@teambit/remove 0.0.132 → 0.0.134

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.
@@ -0,0 +1,24 @@
1
+ import { Consumer } from '@teambit/legacy/dist/consumer';
2
+ import BitIds from '@teambit/legacy/dist/bit-id/bit-ids';
3
+ import RemovedLocalObjects from '@teambit/legacy/dist/scope/removed-local-objects';
4
+ /**
5
+ * Remove components local and remote
6
+ * splits array of ids into local and remote and removes according to flags
7
+ * @param {string[]} ids - list of remote component ids to delete
8
+ * @param {boolean} force - delete component that are used by other components.
9
+ * @param {boolean} remote - delete component from a remote scope
10
+ * @param {boolean} track - keep tracking local staged components in bitmap.
11
+ * @param {boolean} deleteFiles - delete local added files from fs.
12
+ */
13
+ export declare function removeComponents({ consumer, ids, force, remote, track, deleteFiles, fromLane, }: {
14
+ consumer: Consumer | null | undefined;
15
+ ids: BitIds;
16
+ force: boolean;
17
+ remote: boolean;
18
+ track: boolean;
19
+ deleteFiles: boolean;
20
+ fromLane: boolean;
21
+ }): Promise<{
22
+ localResult: RemovedLocalObjects;
23
+ remoteResult: Record<string, any>[];
24
+ }>;
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ require("core-js/modules/es.array.iterator.js");
5
+ require("core-js/modules/es.promise.js");
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.removeComponents = removeComponents;
10
+ function _groupArray() {
11
+ const data = _interopRequireDefault(require("group-array"));
12
+ _groupArray = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _lodash() {
18
+ const data = _interopRequireDefault(require("lodash.partition"));
19
+ _lodash = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _ramda() {
25
+ const data = _interopRequireDefault(require("ramda"));
26
+ _ramda = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ function _bitIds() {
32
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/bit-id/bit-ids"));
33
+ _bitIds = function () {
34
+ return data;
35
+ };
36
+ return data;
37
+ }
38
+ function _constants() {
39
+ const data = require("@teambit/legacy/dist/constants");
40
+ _constants = function () {
41
+ return data;
42
+ };
43
+ return data;
44
+ }
45
+ function _generalError() {
46
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/error/general-error"));
47
+ _generalError = function () {
48
+ return data;
49
+ };
50
+ return data;
51
+ }
52
+ function _enrichContextFromGlobal() {
53
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/hooks/utils/enrich-context-from-global"));
54
+ _enrichContextFromGlobal = function () {
55
+ return data;
56
+ };
57
+ return data;
58
+ }
59
+ function _logger() {
60
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/logger/logger"));
61
+ _logger = function () {
62
+ return data;
63
+ };
64
+ return data;
65
+ }
66
+ function _remotes() {
67
+ const data = require("@teambit/legacy/dist/remotes");
68
+ _remotes = function () {
69
+ return data;
70
+ };
71
+ return data;
72
+ }
73
+ function _removedLocalObjects() {
74
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/scope/removed-local-objects"));
75
+ _removedLocalObjects = function () {
76
+ return data;
77
+ };
78
+ return data;
79
+ }
80
+ function _scopeRemotes() {
81
+ const data = require("@teambit/legacy/dist/scope/scope-remotes");
82
+ _scopeRemotes = function () {
83
+ return data;
84
+ };
85
+ return data;
86
+ }
87
+ function _deleteComponentFiles() {
88
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component-ops/delete-component-files"));
89
+ _deleteComponentFiles = function () {
90
+ return data;
91
+ };
92
+ return data;
93
+ }
94
+ function _componentsList() {
95
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/components-list"));
96
+ _componentsList = function () {
97
+ return data;
98
+ };
99
+ return data;
100
+ }
101
+ function _consumerComponent() {
102
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/consumer-component"));
103
+ _consumerComponent = function () {
104
+ return data;
105
+ };
106
+ return data;
107
+ }
108
+ function packageJsonUtils() {
109
+ const data = _interopRequireWildcard(require("@teambit/legacy/dist/consumer/component/package-json-utils"));
110
+ packageJsonUtils = function () {
111
+ return data;
112
+ };
113
+ return data;
114
+ }
115
+ function _pMapSeries() {
116
+ const data = _interopRequireDefault(require("p-map-series"));
117
+ _pMapSeries = function () {
118
+ return data;
119
+ };
120
+ return data;
121
+ }
122
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
123
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
124
+ /**
125
+ * Remove components local and remote
126
+ * splits array of ids into local and remote and removes according to flags
127
+ * @param {string[]} ids - list of remote component ids to delete
128
+ * @param {boolean} force - delete component that are used by other components.
129
+ * @param {boolean} remote - delete component from a remote scope
130
+ * @param {boolean} track - keep tracking local staged components in bitmap.
131
+ * @param {boolean} deleteFiles - delete local added files from fs.
132
+ */
133
+ async function removeComponents({
134
+ consumer,
135
+ ids,
136
+ force,
137
+ remote,
138
+ track,
139
+ deleteFiles,
140
+ fromLane
141
+ }) {
142
+ _logger().default.debugAndAddBreadCrumb('removeComponents', `{ids}. force: ${force.toString()}`, {
143
+ ids: ids.toString()
144
+ });
145
+ // added this to remove support for remove only one version from a component
146
+ const bitIdsLatest = _bitIds().default.fromArray(ids.map(id => {
147
+ return id.changeVersion(_constants().LATEST_BIT_VERSION);
148
+ }));
149
+ const [localIds, remoteIds] = (0, _lodash().default)(bitIdsLatest, id => id.isLocal());
150
+ if (remote && localIds.length) {
151
+ throw new (_generalError().default)(`unable to remove the remote components: ${localIds.join(',')} as they don't contain a scope-name`);
152
+ }
153
+ const remoteResult = remote && !_ramda().default.isEmpty(remoteIds) ? await removeRemote(consumer, remoteIds, force) : [];
154
+ const localResult = !remote ? await removeLocal(consumer, bitIdsLatest, force, track, deleteFiles, fromLane) : new (_removedLocalObjects().default)();
155
+ return {
156
+ localResult,
157
+ remoteResult
158
+ };
159
+ }
160
+
161
+ /**
162
+ * Remove remote component from ssh server
163
+ * this method groups remote components by remote name and deletes remote components together
164
+ * @param {BitIds} bitIds - list of remote component ids to delete
165
+ * @param {boolean} force - delete component that are used by other components.
166
+ */
167
+ async function removeRemote(consumer, bitIds, force) {
168
+ const groupedBitsByScope = (0, _groupArray().default)(bitIds, 'scope');
169
+ const remotes = consumer ? await (0, _scopeRemotes().getScopeRemotes)(consumer.scope) : await _remotes().Remotes.getGlobalRemotes();
170
+ const context = {};
171
+ (0, _enrichContextFromGlobal().default)(context);
172
+ const removeP = Object.keys(groupedBitsByScope).map(async key => {
173
+ const resolvedRemote = await remotes.resolve(key, consumer === null || consumer === void 0 ? void 0 : consumer.scope);
174
+ const idsStr = groupedBitsByScope[key].map(id => id.toStringWithoutVersion());
175
+ return resolvedRemote.deleteMany(idsStr, force, context);
176
+ });
177
+ return Promise.all(removeP);
178
+ }
179
+
180
+ /**
181
+ * removeLocal - remove local (imported, new staged components) from modules and bitmap according to flags
182
+ * @param {BitIds} bitIds - list of component ids to delete
183
+ * @param {boolean} force - delete component that are used by other components.
184
+ * @param {boolean} deleteFiles - delete component that are used by other components.
185
+ */
186
+ async function removeLocal(consumer, bitIds, force, track, deleteFiles, fromLane) {
187
+ // local remove in case user wants to delete tagged components
188
+ const modifiedComponents = new (_bitIds().default)();
189
+ const nonModifiedComponents = new (_bitIds().default)(); // $FlowFixMe
190
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
191
+ if (_ramda().default.isEmpty(bitIds)) return new (_removedLocalObjects().default)();
192
+ if (!force) {
193
+ await (0, _pMapSeries().default)(bitIds, async id => {
194
+ try {
195
+ const componentStatus = await consumer.getComponentStatusById(id);
196
+ if (componentStatus.modified) modifiedComponents.push(id);else nonModifiedComponents.push(id);
197
+ } catch (err) {
198
+ // if a component has an error, such as, missing main file, we do want to allow removing that component
199
+ if (_consumerComponent().default.isComponentInvalidByErrorType(err)) {
200
+ nonModifiedComponents.push(id);
201
+ } else {
202
+ throw err;
203
+ }
204
+ }
205
+ });
206
+ }
207
+ const idsToRemove = force ? bitIds : nonModifiedComponents;
208
+ const componentsList = new (_componentsList().default)(consumer);
209
+ const newComponents = await componentsList.listNewComponents(false);
210
+ const idsToRemoveFromScope = _bitIds().default.fromArray(idsToRemove.filter(id => !newComponents.hasWithoutScopeAndVersion(id)));
211
+ const idsToCleanFromWorkspace = _bitIds().default.fromArray(idsToRemove.filter(id => newComponents.hasWithoutScopeAndVersion(id)));
212
+ const {
213
+ components: componentsToRemove,
214
+ invalidComponents
215
+ } = await consumer.loadComponents(idsToRemove, false);
216
+ const {
217
+ removedComponentIds,
218
+ missingComponents,
219
+ dependentBits,
220
+ removedFromLane
221
+ } = await consumer.scope.removeMany(idsToRemoveFromScope, force, consumer, fromLane);
222
+ // otherwise, components should still be in .bitmap file
223
+ idsToCleanFromWorkspace.push(...removedComponentIds);
224
+ if (idsToCleanFromWorkspace.length) {
225
+ if (deleteFiles) await (0, _deleteComponentFiles().default)(consumer, idsToCleanFromWorkspace);
226
+ if (!track) {
227
+ const invalidComponentsIds = invalidComponents.map(i => i.id);
228
+ const removedComponents = componentsToRemove.filter(c => idsToCleanFromWorkspace.hasWithoutVersion(c.id));
229
+ await packageJsonUtils().removeComponentsFromWorkspacesAndDependencies(consumer, removedComponents, invalidComponentsIds);
230
+ await consumer.cleanFromBitMap(idsToCleanFromWorkspace);
231
+ }
232
+ }
233
+ if (removedFromLane.length) {
234
+ await consumer.cleanOrRevertFromBitMapWhenOnLane(removedFromLane);
235
+ }
236
+ return new (_removedLocalObjects().default)(_bitIds().default.uniqFromArray([...idsToCleanFromWorkspace, ...removedComponentIds]), missingComponents, modifiedComponents, dependentBits, removedFromLane);
237
+ }
238
+
239
+ //# sourceMappingURL=remove-components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["removeComponents","consumer","ids","force","remote","track","deleteFiles","fromLane","logger","debugAndAddBreadCrumb","toString","bitIdsLatest","BitIds","fromArray","map","id","changeVersion","LATEST_BIT_VERSION","localIds","remoteIds","partition","isLocal","length","GeneralError","join","remoteResult","R","isEmpty","removeRemote","localResult","removeLocal","RemovedLocalObjects","bitIds","groupedBitsByScope","groupArray","remotes","getScopeRemotes","scope","Remotes","getGlobalRemotes","context","enrichContextFromGlobal","removeP","Object","keys","key","resolvedRemote","resolve","idsStr","toStringWithoutVersion","deleteMany","Promise","all","modifiedComponents","nonModifiedComponents","pMapSeries","componentStatus","getComponentStatusById","modified","push","err","Component","isComponentInvalidByErrorType","idsToRemove","componentsList","ComponentsList","newComponents","listNewComponents","idsToRemoveFromScope","filter","hasWithoutScopeAndVersion","idsToCleanFromWorkspace","components","componentsToRemove","invalidComponents","loadComponents","removedComponentIds","missingComponents","dependentBits","removedFromLane","removeMany","deleteComponentsFiles","invalidComponentsIds","i","removedComponents","c","hasWithoutVersion","packageJsonUtils","removeComponentsFromWorkspacesAndDependencies","cleanFromBitMap","cleanOrRevertFromBitMapWhenOnLane","uniqFromArray"],"sources":["remove-components.ts"],"sourcesContent":["import groupArray from 'group-array';\nimport partition from 'lodash.partition';\nimport R from 'ramda';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport BitIds from '@teambit/legacy/dist/bit-id/bit-ids';\nimport { LATEST_BIT_VERSION } from '@teambit/legacy/dist/constants';\nimport GeneralError from '@teambit/legacy/dist/error/general-error';\nimport enrichContextFromGlobal from '@teambit/legacy/dist/hooks/utils/enrich-context-from-global';\nimport logger from '@teambit/legacy/dist/logger/logger';\nimport { Remotes } from '@teambit/legacy/dist/remotes';\nimport RemovedLocalObjects from '@teambit/legacy/dist/scope/removed-local-objects';\nimport { getScopeRemotes } from '@teambit/legacy/dist/scope/scope-remotes';\nimport deleteComponentsFiles from '@teambit/legacy/dist/consumer/component-ops/delete-component-files';\nimport ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';\nimport Component from '@teambit/legacy/dist/consumer/component/consumer-component';\nimport * as packageJsonUtils from '@teambit/legacy/dist/consumer/component/package-json-utils';\nimport pMapSeries from 'p-map-series';\n\n/**\n * Remove components local and remote\n * splits array of ids into local and remote and removes according to flags\n * @param {string[]} ids - list of remote component ids to delete\n * @param {boolean} force - delete component that are used by other components.\n * @param {boolean} remote - delete component from a remote scope\n * @param {boolean} track - keep tracking local staged components in bitmap.\n * @param {boolean} deleteFiles - delete local added files from fs.\n */\nexport async function removeComponents({\n consumer,\n ids,\n force,\n remote,\n track,\n deleteFiles,\n fromLane,\n}: {\n consumer: Consumer | null | undefined; // when remote is false, it's always set\n ids: BitIds;\n force: boolean;\n remote: boolean;\n track: boolean;\n deleteFiles: boolean;\n fromLane: boolean;\n}): Promise<{ localResult: RemovedLocalObjects; remoteResult: Record<string, any>[] }> {\n logger.debugAndAddBreadCrumb('removeComponents', `{ids}. force: ${force.toString()}`, { ids: ids.toString() });\n // added this to remove support for remove only one version from a component\n const bitIdsLatest = BitIds.fromArray(\n ids.map((id) => {\n return id.changeVersion(LATEST_BIT_VERSION);\n })\n );\n const [localIds, remoteIds] = partition(bitIdsLatest, (id) => id.isLocal());\n if (remote && localIds.length) {\n throw new GeneralError(\n `unable to remove the remote components: ${localIds.join(',')} as they don't contain a scope-name`\n );\n }\n const remoteResult = remote && !R.isEmpty(remoteIds) ? await removeRemote(consumer, remoteIds, force) : [];\n const localResult = !remote\n ? await removeLocal(consumer as Consumer, bitIdsLatest, force, track, deleteFiles, fromLane)\n : new RemovedLocalObjects();\n\n return { localResult, remoteResult };\n}\n\n/**\n * Remove remote component from ssh server\n * this method groups remote components by remote name and deletes remote components together\n * @param {BitIds} bitIds - list of remote component ids to delete\n * @param {boolean} force - delete component that are used by other components.\n */\nasync function removeRemote(consumer: Consumer | null | undefined, bitIds: BitIds, force: boolean) {\n const groupedBitsByScope = groupArray(bitIds, 'scope');\n const remotes = consumer ? await getScopeRemotes(consumer.scope) : await Remotes.getGlobalRemotes();\n const context = {};\n enrichContextFromGlobal(context);\n const removeP = Object.keys(groupedBitsByScope).map(async (key) => {\n const resolvedRemote = await remotes.resolve(key, consumer?.scope);\n const idsStr = groupedBitsByScope[key].map((id) => id.toStringWithoutVersion());\n return resolvedRemote.deleteMany(idsStr, force, context);\n });\n\n return Promise.all(removeP);\n}\n\n/**\n * removeLocal - remove local (imported, new staged components) from modules and bitmap according to flags\n * @param {BitIds} bitIds - list of component ids to delete\n * @param {boolean} force - delete component that are used by other components.\n * @param {boolean} deleteFiles - delete component that are used by other components.\n */\nasync function removeLocal(\n consumer: Consumer,\n bitIds: BitIds,\n force: boolean,\n track: boolean,\n deleteFiles: boolean,\n fromLane: boolean\n): Promise<RemovedLocalObjects> {\n // local remove in case user wants to delete tagged components\n const modifiedComponents = new BitIds();\n const nonModifiedComponents = new BitIds(); // $FlowFixMe\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n if (R.isEmpty(bitIds)) return new RemovedLocalObjects();\n if (!force) {\n await pMapSeries(bitIds, async (id) => {\n try {\n const componentStatus = await consumer.getComponentStatusById(id);\n if (componentStatus.modified) modifiedComponents.push(id);\n else nonModifiedComponents.push(id);\n } catch (err: any) {\n // if a component has an error, such as, missing main file, we do want to allow removing that component\n if (Component.isComponentInvalidByErrorType(err)) {\n nonModifiedComponents.push(id);\n } else {\n throw err;\n }\n }\n });\n }\n const idsToRemove = force ? bitIds : nonModifiedComponents;\n const componentsList = new ComponentsList(consumer);\n const newComponents = (await componentsList.listNewComponents(false)) as BitIds;\n const idsToRemoveFromScope = BitIds.fromArray(\n idsToRemove.filter((id) => !newComponents.hasWithoutScopeAndVersion(id))\n );\n const idsToCleanFromWorkspace = BitIds.fromArray(\n idsToRemove.filter((id) => newComponents.hasWithoutScopeAndVersion(id))\n );\n const { components: componentsToRemove, invalidComponents } = await consumer.loadComponents(idsToRemove, false);\n const { removedComponentIds, missingComponents, dependentBits, removedFromLane } = await consumer.scope.removeMany(\n idsToRemoveFromScope,\n force,\n consumer,\n fromLane\n );\n // otherwise, components should still be in .bitmap file\n idsToCleanFromWorkspace.push(...removedComponentIds);\n if (idsToCleanFromWorkspace.length) {\n if (deleteFiles) await deleteComponentsFiles(consumer, idsToCleanFromWorkspace);\n if (!track) {\n const invalidComponentsIds = invalidComponents.map((i) => i.id);\n const removedComponents = componentsToRemove.filter((c) => idsToCleanFromWorkspace.hasWithoutVersion(c.id));\n await packageJsonUtils.removeComponentsFromWorkspacesAndDependencies(\n consumer,\n removedComponents,\n invalidComponentsIds\n );\n await consumer.cleanFromBitMap(idsToCleanFromWorkspace);\n }\n }\n if (removedFromLane.length) {\n await consumer.cleanOrRevertFromBitMapWhenOnLane(removedFromLane);\n }\n return new RemovedLocalObjects(\n BitIds.uniqFromArray([...idsToCleanFromWorkspace, ...removedComponentIds]),\n missingComponents,\n modifiedComponents,\n dependentBits,\n removedFromLane\n );\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAA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ACyF,iCAAiC,CAACX,eAAe,CAAC;EACnE;EACA,OAAO,KAAIhD,8BAAmB,EAC5BnB,iBAAM,CAAC+E,aAAa,CAAC,CAAC,GAAGpB,uBAAuB,EAAE,GAAGK,mBAAmB,CAAC,CAAC,EAC1EC,iBAAiB,EACjBxB,kBAAkB,EAClByB,aAAa,EACbC,eAAe,CAChB;AACH"}
@@ -49,13 +49,6 @@ function _bitId() {
49
49
  };
50
50
  return data;
51
51
  }
52
- function _removeComponents() {
53
- const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component-ops/remove-components"));
54
- _removeComponents = function () {
55
- return data;
56
- };
57
- return data;
58
- }
59
52
  function _exceptions() {
60
53
  const data = require("@teambit/legacy/dist/consumer/exceptions");
61
54
  _exceptions = function () {
@@ -112,6 +105,13 @@ function _removeCmd() {
112
105
  };
113
106
  return data;
114
107
  }
108
+ function _removeComponents() {
109
+ const data = require("./remove-components");
110
+ _removeComponents = function () {
111
+ return data;
112
+ };
113
+ return data;
114
+ }
115
115
  function _remove() {
116
116
  const data = require("./remove.aspect");
117
117
  _remove = function () {
@@ -145,7 +145,7 @@ class RemoveMain {
145
145
  const bitIds = remote ? await this.getRemoteBitIdsToRemove(componentsPattern) : await this.getLocalBitIdsToRemove(componentsPattern);
146
146
  this.logger.setStatusLine(BEFORE_REMOVE); // again because the loader might changed when talking to the remote
147
147
  const consumer = (_this$workspace = this.workspace) === null || _this$workspace === void 0 ? void 0 : _this$workspace.consumer;
148
- const removeResults = await (0, _removeComponents().default)({
148
+ const removeResults = await (0, _removeComponents().removeComponents)({
149
149
  consumer,
150
150
  ids: _bitId().BitIds.fromArray(bitIds),
151
151
  force,
@@ -1 +1 @@
1
- {"version":3,"names":["BEFORE_REMOVE","RemoveMain","constructor","workspace","logger","remove","componentsPattern","force","remote","track","deleteFiles","fromLane","setStatusLine","bitIds","getRemoteBitIdsToRemove","getLocalBitIdsToRemove","consumer","removeResults","removeComponents","ids","BitIds","fromArray","onDestroy","softRemove","ConsumerNotFound","componentIds","idsByPattern","components","getMany","newComps","filter","c","id","hasVersion","length","BitError","map","toString","join","removeComponentsFromNodeModules","state","_consumer","compId","bitMap","addComponentConfig","RemoveAspect","removed","write","_legacy","deleteComponentsFiles","getRemoveInfo","component","data","config","extensions","findExtension","isRemoved","getRemovedStaged","stagedConfig","scope","getStagedConfig","getAll","compConfig","hasWildcard","getRemoteBitIdsByWildcards","BitId","parse","provider","cli","loggerMain","componentAspect","createLogger","removeMain","registerShowFragments","RemoveFragment","register","RemoveCmd","WorkspaceAspect","CLIAspect","LoggerAspect","ComponentAspect","MainRuntime","addRuntime"],"sources":["remove.main.runtime.ts"],"sourcesContent":["import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { BitIds } from '@teambit/legacy/dist/bit-id';\nimport removeComponents from '@teambit/legacy/dist/consumer/component-ops/remove-components';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport hasWildcard from '@teambit/legacy/dist/utils/string/has-wildcard';\nimport { getRemoteBitIdsByWildcards } from '@teambit/legacy/dist/api/consumer/lib/list-scope';\nimport { ComponentID } from '@teambit/component-id';\nimport { BitError } from '@teambit/bit-error';\nimport deleteComponentsFiles from '@teambit/legacy/dist/consumer/component-ops/delete-component-files';\nimport ComponentAspect, { Component, ComponentMain } from '@teambit/component';\nimport { removeComponentsFromNodeModules } from '@teambit/legacy/dist/consumer/component/package-json-utils';\nimport { RemoveCmd } from './remove-cmd';\nimport { RemoveAspect } from './remove.aspect';\nimport { RemoveFragment } from './remove.fragment';\n\nconst BEFORE_REMOVE = 'removing components';\n\nexport type RemoveInfo = {\n removed: boolean;\n};\n\nexport class RemoveMain {\n constructor(private workspace: Workspace, private logger: Logger) {}\n\n async remove({\n componentsPattern,\n force,\n remote,\n track,\n deleteFiles,\n fromLane,\n }: {\n componentsPattern: string;\n force: boolean;\n remote: boolean;\n track: boolean;\n deleteFiles: boolean;\n fromLane: boolean;\n }): Promise<any> {\n this.logger.setStatusLine(BEFORE_REMOVE);\n const bitIds = remote\n ? await this.getRemoteBitIdsToRemove(componentsPattern)\n : await this.getLocalBitIdsToRemove(componentsPattern);\n this.logger.setStatusLine(BEFORE_REMOVE); // again because the loader might changed when talking to the remote\n const consumer = this.workspace?.consumer;\n const removeResults = await removeComponents({\n consumer,\n ids: BitIds.fromArray(bitIds),\n force,\n remote,\n track,\n deleteFiles,\n fromLane,\n });\n if (consumer) await consumer.onDestroy();\n return removeResults;\n }\n\n async softRemove(componentsPattern: string): Promise<ComponentID[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n const componentIds = await this.workspace.idsByPattern(componentsPattern);\n const components = await this.workspace.getMany(componentIds);\n const newComps = components.filter((c) => !c.id.hasVersion());\n if (newComps.length) {\n throw new BitError(\n `unable to soft-remove the following new component(s), please remove them without --soft\\n${newComps\n .map((c) => c.id.toString())\n .join('\\n')}`\n );\n }\n await removeComponentsFromNodeModules(\n this.workspace.consumer,\n components.map((c) => c.state._consumer)\n );\n // don't use `this.workspace.addSpecificComponentConfig`, if the component has component.json it will be deleted\n // during this removal along with the entire component dir.\n componentIds.map((compId) =>\n this.workspace.bitMap.addComponentConfig(compId, RemoveAspect.id, {\n removed: true,\n })\n );\n await this.workspace.bitMap.write();\n const bitIds = BitIds.fromArray(componentIds.map((id) => id._legacy));\n await deleteComponentsFiles(this.workspace.consumer, bitIds);\n\n return componentIds;\n }\n\n getRemoveInfo(component: Component): RemoveInfo {\n const data = component.config.extensions.findExtension(RemoveAspect.id)?.config as RemoveInfo | undefined;\n return {\n removed: data?.removed || false,\n };\n }\n\n isRemoved(component: Component): boolean {\n return this.getRemoveInfo(component).removed;\n }\n\n /**\n * get components that were soft-removed and tagged/snapped but not exported yet.\n */\n async getRemovedStaged(): Promise<ComponentID[]> {\n const stagedConfig = await this.workspace.scope.getStagedConfig();\n return stagedConfig\n .getAll()\n .filter((compConfig) => compConfig.config?.[RemoveAspect.id]?.removed)\n .map((compConfig) => compConfig.id);\n }\n\n private async getLocalBitIdsToRemove(componentsPattern: string): Promise<BitId[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n const componentIds = await this.workspace.idsByPattern(componentsPattern);\n return componentIds.map((id) => id._legacy);\n }\n\n private async getRemoteBitIdsToRemove(componentsPattern: string): Promise<BitId[]> {\n if (hasWildcard(componentsPattern)) {\n return getRemoteBitIdsByWildcards(componentsPattern);\n }\n return [BitId.parse(componentsPattern, true)];\n }\n\n static slots = [];\n static dependencies = [WorkspaceAspect, CLIAspect, LoggerAspect, ComponentAspect];\n static runtime = MainRuntime;\n\n static async provider([workspace, cli, loggerMain, componentAspect]: [\n Workspace,\n CLIMain,\n LoggerMain,\n ComponentMain\n ]) {\n const logger = loggerMain.createLogger(RemoveAspect.id);\n const removeMain = new RemoveMain(workspace, logger);\n componentAspect.registerShowFragments([new RemoveFragment(removeMain)]);\n cli.register(new RemoveCmd(removeMain));\n return new RemoveMain(workspace, logger);\n }\n}\n\nRemoveAspect.addRuntime(RemoveMain);\n\nexport default RemoveMain;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;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AAEC,UAAU,EAAEC,eAAe,CAKjE,EAAE;IACD,MAAMlE,MAAM,GAAGiE,UAAU,CAACE,YAAY,CAAC1B,sBAAY,CAACb,EAAE,CAAC;IACvD,MAAMwC,UAAU,GAAG,IAAIvE,UAAU,CAACE,SAAS,EAAEC,MAAM,CAAC;IACpDkE,eAAe,CAACG,qBAAqB,CAAC,CAAC,KAAIC,yBAAc,EAACF,UAAU,CAAC,CAAC,CAAC;IACvEJ,GAAG,CAACO,QAAQ,CAAC,KAAIC,sBAAS,EAACJ,UAAU,CAAC,CAAC;IACvC,OAAO,IAAIvE,UAAU,CAACE,SAAS,EAAEC,MAAM,CAAC;EAC1C;AACF;AAAC;AAAA,gCAtHYH,UAAU,WAsGN,EAAE;AAAA,gCAtGNA,UAAU,kBAuGC,CAAC4E,oBAAe,EAAEC,gBAAS,EAAEC,sBAAY,EAAEC,oBAAe,CAAC;AAAA,gCAvGtE/E,UAAU,aAwGJgF,kBAAW;AAgB9BpC,sBAAY,CAACqC,UAAU,CAACjF,UAAU,CAAC;AAAC,eAErBA,UAAU;AAAA"}
1
+ {"version":3,"names":["BEFORE_REMOVE","RemoveMain","constructor","workspace","logger","remove","componentsPattern","force","remote","track","deleteFiles","fromLane","setStatusLine","bitIds","getRemoteBitIdsToRemove","getLocalBitIdsToRemove","consumer","removeResults","removeComponents","ids","BitIds","fromArray","onDestroy","softRemove","ConsumerNotFound","componentIds","idsByPattern","components","getMany","newComps","filter","c","id","hasVersion","length","BitError","map","toString","join","removeComponentsFromNodeModules","state","_consumer","compId","bitMap","addComponentConfig","RemoveAspect","removed","write","_legacy","deleteComponentsFiles","getRemoveInfo","component","data","config","extensions","findExtension","isRemoved","getRemovedStaged","stagedConfig","scope","getStagedConfig","getAll","compConfig","hasWildcard","getRemoteBitIdsByWildcards","BitId","parse","provider","cli","loggerMain","componentAspect","createLogger","removeMain","registerShowFragments","RemoveFragment","register","RemoveCmd","WorkspaceAspect","CLIAspect","LoggerAspect","ComponentAspect","MainRuntime","addRuntime"],"sources":["remove.main.runtime.ts"],"sourcesContent":["import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { BitIds } from '@teambit/legacy/dist/bit-id';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport hasWildcard from '@teambit/legacy/dist/utils/string/has-wildcard';\nimport { getRemoteBitIdsByWildcards } from '@teambit/legacy/dist/api/consumer/lib/list-scope';\nimport { ComponentID } from '@teambit/component-id';\nimport { BitError } from '@teambit/bit-error';\nimport deleteComponentsFiles from '@teambit/legacy/dist/consumer/component-ops/delete-component-files';\nimport ComponentAspect, { Component, ComponentMain } from '@teambit/component';\nimport { removeComponentsFromNodeModules } from '@teambit/legacy/dist/consumer/component/package-json-utils';\nimport { RemoveCmd } from './remove-cmd';\nimport { removeComponents } from './remove-components';\nimport { RemoveAspect } from './remove.aspect';\nimport { RemoveFragment } from './remove.fragment';\n\nconst BEFORE_REMOVE = 'removing components';\n\nexport type RemoveInfo = {\n removed: boolean;\n};\n\nexport class RemoveMain {\n constructor(private workspace: Workspace, private logger: Logger) {}\n\n async remove({\n componentsPattern,\n force,\n remote,\n track,\n deleteFiles,\n fromLane,\n }: {\n componentsPattern: string;\n force: boolean;\n remote: boolean;\n track: boolean;\n deleteFiles: boolean;\n fromLane: boolean;\n }): Promise<any> {\n this.logger.setStatusLine(BEFORE_REMOVE);\n const bitIds = remote\n ? await this.getRemoteBitIdsToRemove(componentsPattern)\n : await this.getLocalBitIdsToRemove(componentsPattern);\n this.logger.setStatusLine(BEFORE_REMOVE); // again because the loader might changed when talking to the remote\n const consumer = this.workspace?.consumer;\n const removeResults = await removeComponents({\n consumer,\n ids: BitIds.fromArray(bitIds),\n force,\n remote,\n track,\n deleteFiles,\n fromLane,\n });\n if (consumer) await consumer.onDestroy();\n return removeResults;\n }\n\n async softRemove(componentsPattern: string): Promise<ComponentID[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n const componentIds = await this.workspace.idsByPattern(componentsPattern);\n const components = await this.workspace.getMany(componentIds);\n const newComps = components.filter((c) => !c.id.hasVersion());\n if (newComps.length) {\n throw new BitError(\n `unable to soft-remove the following new component(s), please remove them without --soft\\n${newComps\n .map((c) => c.id.toString())\n .join('\\n')}`\n );\n }\n await removeComponentsFromNodeModules(\n this.workspace.consumer,\n components.map((c) => c.state._consumer)\n );\n // don't use `this.workspace.addSpecificComponentConfig`, if the component has component.json it will be deleted\n // during this removal along with the entire component dir.\n componentIds.map((compId) =>\n this.workspace.bitMap.addComponentConfig(compId, RemoveAspect.id, {\n removed: true,\n })\n );\n await this.workspace.bitMap.write();\n const bitIds = BitIds.fromArray(componentIds.map((id) => id._legacy));\n await deleteComponentsFiles(this.workspace.consumer, bitIds);\n\n return componentIds;\n }\n\n getRemoveInfo(component: Component): RemoveInfo {\n const data = component.config.extensions.findExtension(RemoveAspect.id)?.config as RemoveInfo | undefined;\n return {\n removed: data?.removed || false,\n };\n }\n\n isRemoved(component: Component): boolean {\n return this.getRemoveInfo(component).removed;\n }\n\n /**\n * get components that were soft-removed and tagged/snapped but not exported yet.\n */\n async getRemovedStaged(): Promise<ComponentID[]> {\n const stagedConfig = await this.workspace.scope.getStagedConfig();\n return stagedConfig\n .getAll()\n .filter((compConfig) => compConfig.config?.[RemoveAspect.id]?.removed)\n .map((compConfig) => compConfig.id);\n }\n\n private async getLocalBitIdsToRemove(componentsPattern: string): Promise<BitId[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n const componentIds = await this.workspace.idsByPattern(componentsPattern);\n return componentIds.map((id) => id._legacy);\n }\n\n private async getRemoteBitIdsToRemove(componentsPattern: string): Promise<BitId[]> {\n if (hasWildcard(componentsPattern)) {\n return getRemoteBitIdsByWildcards(componentsPattern);\n }\n return [BitId.parse(componentsPattern, true)];\n }\n\n static slots = [];\n static dependencies = [WorkspaceAspect, CLIAspect, LoggerAspect, ComponentAspect];\n static runtime = MainRuntime;\n\n static async provider([workspace, cli, loggerMain, componentAspect]: [\n Workspace,\n CLIMain,\n LoggerMain,\n ComponentMain\n ]) {\n const logger = loggerMain.createLogger(RemoveAspect.id);\n const removeMain = new RemoveMain(workspace, logger);\n componentAspect.registerShowFragments([new RemoveFragment(removeMain)]);\n cli.register(new RemoveCmd(removeMain));\n return new RemoveMain(workspace, logger);\n }\n}\n\nRemoveAspect.addRuntime(RemoveMain);\n\nexport default RemoveMain;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA,MAAMA,aAAa,GAAG,qBAAqB;AAMpC,MAAMC,UAAU,CAAC;EACtBC,WAAW,CAASC,SAAoB,EAAUC,MAAc,EAAE;IAAA,KAA9CD,SAAoB,GAApBA,SAAoB;IAAA,KAAUC,MAAc,GAAdA,MAAc;EAAG;EAEnE,MAAMC,MAAM,CAAC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,MAAM,CAAC;EAC1C;AACF;AAAC;AAAA,gCAtHYH,UAAU,WAsGN,EAAE;AAAA,gCAtGNA,UAAU,kBAuGC,CAAC4E,oBAAe,EAAEC,gBAAS,EAAEC,sBAAY,EAAEC,oBAAe,CAAC;AAAA,gCAvGtE/E,UAAU,aAwGJgF,kBAAW;AAgB9BpC,sBAAY,CAACqC,UAAU,CAACjF,UAAU,CAAC;AAAC,eAErBA,UAAU;AAAA"}
package/package.json CHANGED
@@ -1,26 +1,30 @@
1
1
  {
2
2
  "name": "@teambit/remove",
3
- "version": "0.0.132",
3
+ "version": "0.0.134",
4
4
  "homepage": "https://bit.dev/teambit/component/remove",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.component",
8
8
  "name": "remove",
9
- "version": "0.0.132"
9
+ "version": "0.0.134"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
13
13
  "yn": "2.0.0",
14
+ "group-array": "1.0.0",
15
+ "lodash.partition": "4.6.0",
16
+ "p-map-series": "2.1.0",
17
+ "ramda": "0.27.1",
14
18
  "core-js": "^3.0.0",
15
19
  "@babel/runtime": "7.20.0",
16
20
  "@teambit/harmony": "0.4.6",
17
21
  "@teambit/bit-error": "0.0.402",
18
- "@teambit/cli": "0.0.640",
19
- "@teambit/component": "0.0.955",
22
+ "@teambit/cli": "0.0.641",
23
+ "@teambit/component": "0.0.957",
20
24
  "@teambit/component-id": "0.0.425",
21
25
  "@teambit/legacy-bit-id": "0.0.421",
22
- "@teambit/logger": "0.0.733",
23
- "@teambit/workspace": "0.0.955"
26
+ "@teambit/logger": "0.0.734",
27
+ "@teambit/workspace": "0.0.957"
24
28
  },
25
29
  "devDependencies": {
26
30
  "@types/mocha": "9.1.0",
@@ -31,7 +35,7 @@
31
35
  "@types/testing-library__jest-dom": "5.9.5"
32
36
  },
33
37
  "peerDependencies": {
34
- "@teambit/legacy": "1.0.422",
38
+ "@teambit/legacy": "1.0.423",
35
39
  "react": "^16.8.0 || ^17.0.0",
36
40
  "react-dom": "^16.8.0 || ^17.0.0"
37
41
  },