@teambit/renaming 0.0.385 → 0.0.387

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,4 @@
1
+ import { BitError } from '@teambit/bit-error';
2
+ export declare class OldScopeExported extends BitError {
3
+ constructor(idsStr: string[]);
4
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OldScopeExported = void 0;
7
+ function _bitError() {
8
+ const data = require("@teambit/bit-error");
9
+ _bitError = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ class OldScopeExported extends _bitError().BitError {
15
+ constructor(idsStr) {
16
+ super(`unable to rename the scope for the following exported components:\n${idsStr.join(', ')}
17
+ because these components were exported already, other components may use them and they'll break upon rename.
18
+ instead, deprecate the above components (using "bit deprecate"), tag, export and then eject them.
19
+ once they are not in the workspace, you can fork them ("bit fork") with the new scope-name`);
20
+ }
21
+ }
22
+ exports.OldScopeExported = OldScopeExported;
23
+
24
+ //# sourceMappingURL=old-scope-exported.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OldScopeExported","BitError","constructor","idsStr","join"],"sources":["old-scope-exported.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\n\nexport class OldScopeExported extends BitError {\n constructor(idsStr: string[]) {\n super(`unable to rename the scope for the following exported components:\\n${idsStr.join(', ')}\nbecause these components were exported already, other components may use them and they'll break upon rename.\ninstead, deprecate the above components (using \"bit deprecate\"), tag, export and then eject them.\nonce they are not in the workspace, you can fork them (\"bit fork\") with the new scope-name`);\n }\n}\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,gBAAgB,SAASC,oBAAQ,CAAC;EAC7CC,WAAW,CAACC,MAAgB,EAAE;IAC5B,KAAK,CAAE,sEAAqEA,MAAM,CAACC,IAAI,CAAC,IAAI,CAAE;AAClG;AACA;AACA,2FAA2F,CAAC;EAC1F;AACF;AAAC"}
@@ -0,0 +1,4 @@
1
+ import { BitError } from '@teambit/bit-error';
2
+ export declare class OldScopeNotFound extends BitError {
3
+ constructor(oldScope: string);
4
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OldScopeNotFound = void 0;
7
+ function _bitError() {
8
+ const data = require("@teambit/bit-error");
9
+ _bitError = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ class OldScopeNotFound extends _bitError().BitError {
15
+ constructor(oldScope) {
16
+ super(`none of the components is using "${oldScope}". also, the workspace is not configured with "${oldScope}"`);
17
+ }
18
+ }
19
+ exports.OldScopeNotFound = OldScopeNotFound;
20
+
21
+ //# sourceMappingURL=old-scope-not-found.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OldScopeNotFound","BitError","constructor","oldScope"],"sources":["old-scope-not-found.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\n\nexport class OldScopeNotFound extends BitError {\n constructor(oldScope: string) {\n super(`none of the components is using \"${oldScope}\". also, the workspace is not configured with \"${oldScope}\"`);\n }\n}\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,gBAAgB,SAASC,oBAAQ,CAAC;EAC7CC,WAAW,CAACC,QAAgB,EAAE;IAC5B,KAAK,CAAE,oCAAmCA,QAAS,kDAAiDA,QAAS,GAAE,CAAC;EAClH;AACF;AAAC"}
@@ -0,0 +1,4 @@
1
+ import { BitError } from '@teambit/bit-error';
2
+ export declare class OldScopeTagged extends BitError {
3
+ constructor(idsStr: string[]);
4
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OldScopeTagged = void 0;
7
+ function _bitError() {
8
+ const data = require("@teambit/bit-error");
9
+ _bitError = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ class OldScopeTagged extends _bitError().BitError {
15
+ constructor(idsStr) {
16
+ super(`unable to rename the scope for the following tagged components:\n${idsStr.join(', ')}
17
+ because these components were tagged, the objects have the dependencies data of the old-scope.
18
+ to be able to rename the scope, please untag the components first (using "bit reset" command)`);
19
+ }
20
+ }
21
+ exports.OldScopeTagged = OldScopeTagged;
22
+
23
+ //# sourceMappingURL=old-scope-tagged.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OldScopeTagged","BitError","constructor","idsStr","join"],"sources":["old-scope-tagged.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\n\nexport class OldScopeTagged extends BitError {\n constructor(idsStr: string[]) {\n super(`unable to rename the scope for the following tagged components:\\n${idsStr.join(', ')}\nbecause these components were tagged, the objects have the dependencies data of the old-scope.\nto be able to rename the scope, please untag the components first (using \"bit reset\" command)`);\n }\n}\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,cAAc,SAASC,oBAAQ,CAAC;EAC3CC,WAAW,CAACC,MAAgB,EAAE;IAC5B,KAAK,CAAE,oEAAmEA,MAAM,CAACC,IAAI,CAAC,IAAI,CAAE;AAChG;AACA,8FAA8F,CAAC;EAC7F;AACF;AAAC"}
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_renaming@0.0.385/dist/renaming.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_renaming@0.0.385/dist/renaming.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_renaming@0.0.387/dist/renaming.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_renaming@0.0.387/dist/renaming.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -27,7 +27,18 @@ export declare class RenamingMain {
27
27
  renameScope(oldScope: string, newScope: string, options: {
28
28
  refactor?: boolean;
29
29
  }): Promise<RenameScopeResult>;
30
+ /**
31
+ * change the default-scope for new components. optionally (if refactor is true), change the source code to match the
32
+ * new scope-name.
33
+ * keep in mind that this is working for new components only, for tagged/exported it's impossible. See the errors
34
+ * thrown in such cases in this method.
35
+ */
36
+ renameOwner(oldOwner: string, newOwner: string, options: {
37
+ refactor?: boolean;
38
+ }): Promise<RenameScopeResult>;
30
39
  private renameScopeOfAspectIdsInWorkspaceConfig;
40
+ private renameOwnerOfAspectIdsInWorkspaceConfig;
41
+ private renameOwnerInScopeName;
31
42
  private getConfig;
32
43
  static slots: never[];
33
44
  static dependencies: import("@teambit/harmony").Aspect[];
@@ -3,6 +3,8 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
  require("core-js/modules/es.array.iterator.js");
5
5
  require("core-js/modules/es.promise.js");
6
+ require("core-js/modules/es.regexp.exec.js");
7
+ require("core-js/modules/es.string.replace.js");
6
8
  Object.defineProperty(exports, "__esModule", {
7
9
  value: true
8
10
  });
@@ -14,13 +16,6 @@ function _defineProperty2() {
14
16
  };
15
17
  return data;
16
18
  }
17
- function _bitError() {
18
- const data = require("@teambit/bit-error");
19
- _bitError = function () {
20
- return data;
21
- };
22
- return data;
23
- }
24
19
  function _componentIdToPackageName() {
25
20
  const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/bit/component-id-to-package-name"));
26
21
  _componentIdToPackageName = function () {
@@ -133,6 +128,34 @@ function _scopeRename() {
133
128
  };
134
129
  return data;
135
130
  }
131
+ function _oldScopeNotFound() {
132
+ const data = require("./exceptions/old-scope-not-found");
133
+ _oldScopeNotFound = function () {
134
+ return data;
135
+ };
136
+ return data;
137
+ }
138
+ function _oldScopeExported() {
139
+ const data = require("./exceptions/old-scope-exported");
140
+ _oldScopeExported = function () {
141
+ return data;
142
+ };
143
+ return data;
144
+ }
145
+ function _oldScopeTagged() {
146
+ const data = require("./exceptions/old-scope-tagged");
147
+ _oldScopeTagged = function () {
148
+ return data;
149
+ };
150
+ return data;
151
+ }
152
+ function _scopeRenameOwner() {
153
+ const data = require("./scope-rename-owner.cmd");
154
+ _scopeRenameOwner = function () {
155
+ return data;
156
+ };
157
+ return data;
158
+ }
136
159
  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); }
137
160
  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; }
138
161
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -191,23 +214,18 @@ class RenamingMain {
191
214
  const allComponents = await this.workspace.list();
192
215
  const componentsUsingOldScope = allComponents.filter(comp => comp.id.scope === oldScope);
193
216
  if (!componentsUsingOldScope.length && this.workspace.defaultScope !== oldScope) {
194
- throw new (_bitError().BitError)(`none of the components is using "${oldScope}". also, the workspace is not configured with "${oldScope}"`);
217
+ throw new (_oldScopeNotFound().OldScopeNotFound)(oldScope);
195
218
  }
196
219
  // verify they're all new.
197
220
  const exported = componentsUsingOldScope.filter(comp => comp.id._legacy.hasScope());
198
221
  if (exported.length) {
199
- const idsStr = exported.map(comp => comp.id.toString()).join(', ');
200
- throw new (_bitError().BitError)(`unable to rename the scope for the following exported components:\n${idsStr}
201
- because these components were exported already, other components may use them and they'll break upon rename.
202
- instead, deprecate the above components (using "bit deprecate"), tag, export and then eject them.
203
- once they are not in the workspace, you can fork them ("bit fork") with the new scope-name`);
222
+ const idsStr = exported.map(comp => comp.id.toString());
223
+ throw new (_oldScopeExported().OldScopeExported)(idsStr);
204
224
  }
205
225
  const tagged = componentsUsingOldScope.filter(comp => comp.id.hasVersion());
206
226
  if (tagged.length) {
207
- const idsStr = tagged.map(comp => comp.id.toString()).join(', ');
208
- throw new (_bitError().BitError)(`unable to rename the scope for the following tagged components:\n${idsStr}
209
- because these components were tagged, the objects have the dependencies data of the old-scope.
210
- to be able to rename the scope, please untag the components first (using "bit reset" command)`);
227
+ const idsStr = tagged.map(comp => comp.id.toString());
228
+ throw new (_oldScopeTagged().OldScopeTagged)(idsStr);
211
229
  }
212
230
  if (this.workspace.defaultScope === oldScope) {
213
231
  await this.workspace.setDefaultScope(newScope);
@@ -241,6 +259,71 @@ to be able to rename the scope, please untag the components first (using "bit re
241
259
  refactoredIds
242
260
  };
243
261
  }
262
+
263
+ /**
264
+ * change the default-scope for new components. optionally (if refactor is true), change the source code to match the
265
+ * new scope-name.
266
+ * keep in mind that this is working for new components only, for tagged/exported it's impossible. See the errors
267
+ * thrown in such cases in this method.
268
+ */
269
+ async renameOwner(oldOwner, newOwner, options) {
270
+ const allComponents = await this.workspace.list();
271
+ const isScopeUsesOldOwner = scope => scope.startsWith(`${oldOwner}.`);
272
+ const componentsUsingOldScope = allComponents.filter(comp => isScopeUsesOldOwner(comp.id.scope));
273
+ if (!componentsUsingOldScope.length && !isScopeUsesOldOwner(this.workspace.defaultScope)) {
274
+ throw new (_oldScopeNotFound().OldScopeNotFound)(oldOwner);
275
+ }
276
+ // verify they're all new.
277
+ const exported = componentsUsingOldScope.filter(comp => comp.id._legacy.hasScope());
278
+ if (exported.length) {
279
+ const idsStr = exported.map(comp => comp.id.toString());
280
+ throw new (_oldScopeExported().OldScopeExported)(idsStr);
281
+ }
282
+ const tagged = componentsUsingOldScope.filter(comp => comp.id.hasVersion());
283
+ if (tagged.length) {
284
+ const idsStr = tagged.map(comp => comp.id.toString());
285
+ throw new (_oldScopeTagged().OldScopeTagged)(idsStr);
286
+ }
287
+ const oldWorkspaceDefaultScope = this.workspace.defaultScope;
288
+ if (isScopeUsesOldOwner(this.workspace.defaultScope)) {
289
+ const newDefaultScope = this.renameOwnerInScopeName(this.workspace.defaultScope, oldOwner, newOwner);
290
+ await this.workspace.setDefaultScope(newDefaultScope);
291
+ componentsUsingOldScope.forEach(comp => {
292
+ if (comp.id.scope === oldWorkspaceDefaultScope) this.workspace.bitMap.removeDefaultScope(comp.id);
293
+ });
294
+ }
295
+ componentsUsingOldScope.forEach(comp => {
296
+ if (comp.id.scope === oldWorkspaceDefaultScope) return;
297
+ const newCompScope = this.renameOwnerInScopeName(comp.id.scope, oldOwner, newOwner);
298
+ this.workspace.bitMap.setDefaultScope(comp.id, newCompScope);
299
+ });
300
+ await this.workspace.bitMap.write();
301
+ const refactoredIds = [];
302
+ if (options.refactor) {
303
+ const legacyComps = componentsUsingOldScope.map(c => c.state._consumer);
304
+ const packagesToReplace = legacyComps.map(comp => {
305
+ const newScope = this.renameOwnerInScopeName(comp.id.scope, oldOwner, newOwner);
306
+ return {
307
+ oldStr: (0, _componentIdToPackageName().default)(comp),
308
+ newStr: (0, _componentIdToPackageName().default)(_objectSpread(_objectSpread({}, comp), {}, {
309
+ bindingPrefix: (0, _componentConfig().getBindingPrefixByDefaultScope)(newScope),
310
+ id: comp.id,
311
+ defaultScope: newScope
312
+ }))
313
+ };
314
+ });
315
+ const {
316
+ changedComponents
317
+ } = await this.refactoring.replaceMultipleStrings(allComponents, packagesToReplace);
318
+ await this.renameOwnerOfAspectIdsInWorkspaceConfig(componentsUsingOldScope.map(c => c.id), oldOwner, newOwner);
319
+ await Promise.all(changedComponents.map(comp => this.workspace.write(comp)));
320
+ refactoredIds.push(...changedComponents.map(c => c.id));
321
+ }
322
+ return {
323
+ scopeRenamedComponentIds: componentsUsingOldScope.map(comp => comp.id),
324
+ refactoredIds
325
+ };
326
+ }
244
327
  async renameScopeOfAspectIdsInWorkspaceConfig(ids, newScope) {
245
328
  const config = this.config.workspaceConfig;
246
329
  if (!config) throw new Error('unable to get workspace config');
@@ -251,6 +334,20 @@ to be able to rename the scope, please untag the components first (using "bit re
251
334
  });
252
335
  if (hasChanged) await config.write();
253
336
  }
337
+ async renameOwnerOfAspectIdsInWorkspaceConfig(ids, oldOwner, newOwner) {
338
+ const config = this.config.workspaceConfig;
339
+ if (!config) throw new Error('unable to get workspace config');
340
+ let hasChanged = false;
341
+ ids.forEach(id => {
342
+ const newScope = this.renameOwnerInScopeName(id.scope, oldOwner, newOwner);
343
+ const changed = config.renameExtensionInRaw(id.toStringWithoutVersion(), id._legacy.changeScope(newScope).toStringWithoutVersion());
344
+ if (changed) hasChanged = true;
345
+ });
346
+ if (hasChanged) await config.write();
347
+ }
348
+ renameOwnerInScopeName(scopeName, oldOwner, newOwner) {
349
+ return scopeName.replace(`${oldOwner}.`, `${newOwner}.`);
350
+ }
254
351
  async getConfig(comp) {
255
352
  const fromExisting = await this.newComponentHelper.getConfigFromExistingToNewComponent(comp);
256
353
  return _objectSpread(_objectSpread({}, fromExisting), {}, {
@@ -260,11 +357,12 @@ to be able to rename the scope, please untag the components first (using "bit re
260
357
  });
261
358
  }
262
359
  static async provider([cli, workspace, deprecation, newComponentHelper, componentMain, graphql, refactoring, install, config]) {
263
- var _scopeCommand$command;
360
+ var _scopeCommand$command, _scopeCommand$command2;
264
361
  const renaming = new RenamingMain(workspace, install, newComponentHelper, deprecation, refactoring, config);
265
362
  cli.register(new (_rename().RenameCmd)(renaming));
266
363
  const scopeCommand = cli.getCommand('scope');
267
364
  scopeCommand === null || scopeCommand === void 0 ? void 0 : (_scopeCommand$command = scopeCommand.commands) === null || _scopeCommand$command === void 0 ? void 0 : _scopeCommand$command.push(new (_scopeRename().ScopeRenameCmd)(renaming));
365
+ scopeCommand === null || scopeCommand === void 0 ? void 0 : (_scopeCommand$command2 = scopeCommand.commands) === null || _scopeCommand$command2 === void 0 ? void 0 : _scopeCommand$command2.push(new (_scopeRenameOwner().ScopeRenameOwnerCmd)(renaming));
268
366
  graphql.register((0, _renaming3().renamingSchema)(renaming));
269
367
  componentMain.registerShowFragments([new (_renaming2().RenamingFragment)(renaming)]);
270
368
  return renaming;
@@ -1 +1 @@
1
- {"version":3,"names":["RenamingMain","constructor","workspace","install","newComponentHelper","deprecation","refactoring","config","rename","sourceIdStr","targetIdStr","options","sourceId","resolveComponentId","isTagged","hasVersion","sourceComp","get","targetId","getNewComponentId","undefined","scope","getConfig","writeAndAddNewComp","deprecate","bitMap","renameNewComponent","write","refactor","allComponents","list","changedComponents","refactorDependencyName","Promise","all","map","comp","link","getRenamingInfo","component","renameConfig","state","aspects","RenamingAspect","id","renamedFrom","ComponentID","fromObject","renameScope","oldScope","newScope","componentsUsingOldScope","filter","length","defaultScope","BitError","exported","_legacy","hasScope","idsStr","toString","join","tagged","setDefaultScope","forEach","removeDefaultScope","refactoredIds","legacyComps","c","_consumer","packagesToReplace","oldStr","componentIdToPackageName","newStr","bindingPrefix","getBindingPrefixByDefaultScope","replaceMultipleStrings","renameScopeOfAspectIdsInWorkspaceConfig","push","scopeRenamedComponentIds","ids","workspaceConfig","Error","hasChanged","changed","renameExtensionInRaw","toStringWithoutVersion","changeScope","fromExisting","getConfigFromExistingToNewComponent","toObject","provider","cli","componentMain","graphql","renaming","register","RenameCmd","scopeCommand","getCommand","commands","ScopeRenameCmd","renamingSchema","registerShowFragments","RenamingFragment","CLIAspect","WorkspaceAspect","DeprecationAspect","NewComponentHelperAspect","ComponentAspect","GraphqlAspect","RefactoringAspect","InstallAspect","ConfigAspect","MainRuntime","addRuntime"],"sources":["renaming.main.runtime.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\nimport componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';\nimport { ConfigAspect, ConfigMain } from '@teambit/config';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport ComponentAspect, { Component, ComponentID, ComponentMain } from '@teambit/component';\nimport { DeprecationAspect, DeprecationMain } from '@teambit/deprecation';\nimport GraphqlAspect, { GraphqlMain } from '@teambit/graphql';\nimport NewComponentHelperAspect, { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport RefactoringAspect, { MultipleStringsReplacement, RefactoringMain } from '@teambit/refactoring';\nimport { getBindingPrefixByDefaultScope } from '@teambit/legacy/dist/consumer/config/component-config';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { InstallMain, InstallAspect } from '@teambit/install';\nimport { RenameCmd, RenameOptions } from './rename.cmd';\nimport { RenamingAspect } from './renaming.aspect';\nimport { RenamingFragment } from './renaming.fragment';\nimport { renamingSchema } from './renaming.graphql';\nimport { ScopeRenameCmd } from './scope-rename.cmd';\n\nexport class RenamingMain {\n constructor(\n private workspace: Workspace,\n private install: InstallMain,\n private newComponentHelper: NewComponentHelperMain,\n private deprecation: DeprecationMain,\n private refactoring: RefactoringMain,\n private config: ConfigMain\n ) {}\n\n async rename(sourceIdStr: string, targetIdStr: string, options: RenameOptions): Promise<RenameDependencyNameResult> {\n const sourceId = await this.workspace.resolveComponentId(sourceIdStr);\n const isTagged = sourceId.hasVersion();\n const sourceComp = await this.workspace.get(sourceId);\n const targetId = this.newComponentHelper.getNewComponentId(targetIdStr, undefined, options?.scope);\n if (isTagged) {\n const config = await this.getConfig(sourceComp);\n await this.newComponentHelper.writeAndAddNewComp(sourceComp, targetId, options, config);\n await this.deprecation.deprecate(sourceId, targetId);\n } else {\n this.workspace.bitMap.renameNewComponent(sourceId, targetId);\n await this.workspace.bitMap.write();\n }\n if (options.refactor) {\n const allComponents = await this.workspace.list();\n const { changedComponents } = await this.refactoring.refactorDependencyName(allComponents, sourceId, targetId);\n await Promise.all(changedComponents.map((comp) => this.workspace.write(comp)));\n }\n\n await this.install.link();\n\n return {\n sourceId,\n targetId,\n };\n }\n\n getRenamingInfo(component: Component): RenamingInfo | null {\n const renameConfig = component.state.aspects.get(RenamingAspect.id)?.config as RenamingInfo | undefined;\n if (!renameConfig) return null;\n return {\n renamedFrom: ComponentID.fromObject(renameConfig.renamedFrom),\n };\n }\n\n /**\n * change the default-scope for new components. optionally (if refactor is true), change the source code to match the\n * new scope-name.\n * keep in mind that this is working for new components only, for tagged/exported it's impossible. See the errors\n * thrown in such cases in this method.\n */\n async renameScope(oldScope: string, newScope: string, options: { refactor?: boolean }): Promise<RenameScopeResult> {\n const allComponents = await this.workspace.list();\n const componentsUsingOldScope = allComponents.filter((comp) => comp.id.scope === oldScope);\n if (!componentsUsingOldScope.length && this.workspace.defaultScope !== oldScope) {\n throw new BitError(\n `none of the components is using \"${oldScope}\". also, the workspace is not configured with \"${oldScope}\"`\n );\n }\n // verify they're all new.\n const exported = componentsUsingOldScope.filter((comp) => comp.id._legacy.hasScope());\n if (exported.length) {\n const idsStr = exported.map((comp) => comp.id.toString()).join(', ');\n throw new BitError(`unable to rename the scope for the following exported components:\\n${idsStr}\nbecause these components were exported already, other components may use them and they'll break upon rename.\ninstead, deprecate the above components (using \"bit deprecate\"), tag, export and then eject them.\nonce they are not in the workspace, you can fork them (\"bit fork\") with the new scope-name`);\n }\n const tagged = componentsUsingOldScope.filter((comp) => comp.id.hasVersion());\n if (tagged.length) {\n const idsStr = tagged.map((comp) => comp.id.toString()).join(', ');\n throw new BitError(`unable to rename the scope for the following tagged components:\\n${idsStr}\nbecause these components were tagged, the objects have the dependencies data of the old-scope.\nto be able to rename the scope, please untag the components first (using \"bit reset\" command)`);\n }\n if (this.workspace.defaultScope === oldScope) {\n await this.workspace.setDefaultScope(newScope);\n componentsUsingOldScope.forEach((comp) => this.workspace.bitMap.removeDefaultScope(comp.id));\n } else {\n componentsUsingOldScope.forEach((comp) => this.workspace.bitMap.setDefaultScope(comp.id, newScope));\n }\n await this.workspace.bitMap.write();\n const refactoredIds: ComponentID[] = [];\n if (options.refactor) {\n const legacyComps = componentsUsingOldScope.map((c) => c.state._consumer);\n const packagesToReplace: MultipleStringsReplacement = legacyComps.map((comp) => {\n return {\n oldStr: componentIdToPackageName(comp),\n newStr: componentIdToPackageName({\n ...comp,\n bindingPrefix: getBindingPrefixByDefaultScope(newScope),\n id: comp.id,\n defaultScope: newScope,\n }),\n };\n });\n const { changedComponents } = await this.refactoring.replaceMultipleStrings(allComponents, packagesToReplace);\n await this.renameScopeOfAspectIdsInWorkspaceConfig(\n componentsUsingOldScope.map((c) => c.id),\n newScope\n );\n await Promise.all(changedComponents.map((comp) => this.workspace.write(comp)));\n refactoredIds.push(...changedComponents.map((c) => c.id));\n }\n\n return { scopeRenamedComponentIds: componentsUsingOldScope.map((comp) => comp.id), refactoredIds };\n }\n\n private async renameScopeOfAspectIdsInWorkspaceConfig(ids: ComponentID[], newScope: string) {\n const config = this.config.workspaceConfig;\n if (!config) throw new Error('unable to get workspace config');\n let hasChanged = false;\n ids.forEach((id) => {\n const changed = config.renameExtensionInRaw(\n id.toStringWithoutVersion(),\n id._legacy.changeScope(newScope).toStringWithoutVersion()\n );\n if (changed) hasChanged = true;\n });\n if (hasChanged) await config.write();\n }\n\n private async getConfig(comp: Component) {\n const fromExisting = await this.newComponentHelper.getConfigFromExistingToNewComponent(comp);\n return {\n ...fromExisting,\n [RenamingAspect.id]: {\n renamedFrom: comp.id.toObject(),\n },\n };\n }\n\n static slots = [];\n static dependencies = [\n CLIAspect,\n WorkspaceAspect,\n DeprecationAspect,\n NewComponentHelperAspect,\n ComponentAspect,\n GraphqlAspect,\n RefactoringAspect,\n InstallAspect,\n ConfigAspect,\n ];\n static runtime = MainRuntime;\n static async provider([\n cli,\n workspace,\n deprecation,\n newComponentHelper,\n componentMain,\n graphql,\n refactoring,\n install,\n config,\n ]: [\n CLIMain,\n Workspace,\n DeprecationMain,\n NewComponentHelperMain,\n ComponentMain,\n GraphqlMain,\n RefactoringMain,\n InstallMain,\n ConfigMain\n ]) {\n const renaming = new RenamingMain(workspace, install, newComponentHelper, deprecation, refactoring, config);\n cli.register(new RenameCmd(renaming));\n\n const scopeCommand = cli.getCommand('scope');\n scopeCommand?.commands?.push(new ScopeRenameCmd(renaming));\n\n graphql.register(renamingSchema(renaming));\n componentMain.registerShowFragments([new RenamingFragment(renaming)]);\n return renaming;\n }\n}\n\nRenamingAspect.addRuntime(RenamingMain);\n\nexport type RenameDependencyNameResult = { sourceId: ComponentID; targetId: ComponentID };\n\nexport type RenamingInfo = {\n renamedFrom: ComponentID;\n};\n\nexport type RenameScopeResult = { scopeRenamedComponentIds: ComponentID[]; refactoredIds: ComponentID[] };\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;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA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,WAAW,EACXH,OAAO,EACPI,MAAM,CAWP,EAAE;IAAA;IACD,MAAMwF,QAAQ,GAAG,IAAI/F,YAAY,CAACE,SAAS,EAAEC,OAAO,EAAEC,kBAAkB,EAAEC,WAAW,EAAEC,WAAW,EAAEC,MAAM,CAAC;IAC3GqF,GAAG,CAACI,QAAQ,CAAC,KAAIC,mBAAS,EAACF,QAAQ,CAAC,CAAC;IAErC,MAAMG,YAAY,GAAGN,GAAG,CAACO,UAAU,CAAC,OAAO,CAAC;IAC5CD,YAAY,aAAZA,YAAY,gDAAZA,YAAY,CAAEE,QAAQ,0DAAtB,sBAAwBtB,IAAI,CAAC,KAAIuB,6BAAc,EAACN,QAAQ,CAAC,CAAC;IAE1DD,OAAO,CAACE,QAAQ,CAAC,IAAAM,2BAAc,EAACP,QAAQ,CAAC,CAAC;IAC1CF,aAAa,CAACU,qBAAqB,CAAC,CAAC,KAAIC,6BAAgB,EAACT,QAAQ,CAAC,CAAC,CAAC;IACrE,OAAOA,QAAQ;EACjB;AACF;AAAC;AAAA,gCAhLY/F,YAAY,WAoIR,EAAE;AAAA,gCApINA,YAAY,kBAqID,CACpByG,gBAAS,EACTC,oBAAe,EACfC,gCAAiB,EACjBC,6BAAwB,EACxBC,oBAAe,EACfC,kBAAa,EACbC,sBAAiB,EACjBC,wBAAa,EACbC,sBAAY,CACb;AAAA,gCA/IUjH,YAAY,aAgJNkH,kBAAW;AAkC9BvE,0BAAc,CAACwE,UAAU,CAACnH,YAAY,CAAC"}
1
+ {"version":3,"names":["RenamingMain","constructor","workspace","install","newComponentHelper","deprecation","refactoring","config","rename","sourceIdStr","targetIdStr","options","sourceId","resolveComponentId","isTagged","hasVersion","sourceComp","get","targetId","getNewComponentId","undefined","scope","getConfig","writeAndAddNewComp","deprecate","bitMap","renameNewComponent","write","refactor","allComponents","list","changedComponents","refactorDependencyName","Promise","all","map","comp","link","getRenamingInfo","component","renameConfig","state","aspects","RenamingAspect","id","renamedFrom","ComponentID","fromObject","renameScope","oldScope","newScope","componentsUsingOldScope","filter","length","defaultScope","OldScopeNotFound","exported","_legacy","hasScope","idsStr","toString","OldScopeExported","tagged","OldScopeTagged","setDefaultScope","forEach","removeDefaultScope","refactoredIds","legacyComps","c","_consumer","packagesToReplace","oldStr","componentIdToPackageName","newStr","bindingPrefix","getBindingPrefixByDefaultScope","replaceMultipleStrings","renameScopeOfAspectIdsInWorkspaceConfig","push","scopeRenamedComponentIds","renameOwner","oldOwner","newOwner","isScopeUsesOldOwner","startsWith","oldWorkspaceDefaultScope","newDefaultScope","renameOwnerInScopeName","newCompScope","renameOwnerOfAspectIdsInWorkspaceConfig","ids","workspaceConfig","Error","hasChanged","changed","renameExtensionInRaw","toStringWithoutVersion","changeScope","scopeName","replace","fromExisting","getConfigFromExistingToNewComponent","toObject","provider","cli","componentMain","graphql","renaming","register","RenameCmd","scopeCommand","getCommand","commands","ScopeRenameCmd","ScopeRenameOwnerCmd","renamingSchema","registerShowFragments","RenamingFragment","CLIAspect","WorkspaceAspect","DeprecationAspect","NewComponentHelperAspect","ComponentAspect","GraphqlAspect","RefactoringAspect","InstallAspect","ConfigAspect","MainRuntime","addRuntime"],"sources":["renaming.main.runtime.ts"],"sourcesContent":["import componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';\nimport { ConfigAspect, ConfigMain } from '@teambit/config';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport ComponentAspect, { Component, ComponentID, ComponentMain } from '@teambit/component';\nimport { DeprecationAspect, DeprecationMain } from '@teambit/deprecation';\nimport GraphqlAspect, { GraphqlMain } from '@teambit/graphql';\nimport NewComponentHelperAspect, { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport RefactoringAspect, { MultipleStringsReplacement, RefactoringMain } from '@teambit/refactoring';\nimport { getBindingPrefixByDefaultScope } from '@teambit/legacy/dist/consumer/config/component-config';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { InstallMain, InstallAspect } from '@teambit/install';\nimport { RenameCmd, RenameOptions } from './rename.cmd';\nimport { RenamingAspect } from './renaming.aspect';\nimport { RenamingFragment } from './renaming.fragment';\nimport { renamingSchema } from './renaming.graphql';\nimport { ScopeRenameCmd } from './scope-rename.cmd';\nimport { OldScopeNotFound } from './exceptions/old-scope-not-found';\nimport { OldScopeExported } from './exceptions/old-scope-exported';\nimport { OldScopeTagged } from './exceptions/old-scope-tagged';\nimport { ScopeRenameOwnerCmd } from './scope-rename-owner.cmd';\n\nexport class RenamingMain {\n constructor(\n private workspace: Workspace,\n private install: InstallMain,\n private newComponentHelper: NewComponentHelperMain,\n private deprecation: DeprecationMain,\n private refactoring: RefactoringMain,\n private config: ConfigMain\n ) {}\n\n async rename(sourceIdStr: string, targetIdStr: string, options: RenameOptions): Promise<RenameDependencyNameResult> {\n const sourceId = await this.workspace.resolveComponentId(sourceIdStr);\n const isTagged = sourceId.hasVersion();\n const sourceComp = await this.workspace.get(sourceId);\n const targetId = this.newComponentHelper.getNewComponentId(targetIdStr, undefined, options?.scope);\n if (isTagged) {\n const config = await this.getConfig(sourceComp);\n await this.newComponentHelper.writeAndAddNewComp(sourceComp, targetId, options, config);\n await this.deprecation.deprecate(sourceId, targetId);\n } else {\n this.workspace.bitMap.renameNewComponent(sourceId, targetId);\n await this.workspace.bitMap.write();\n }\n if (options.refactor) {\n const allComponents = await this.workspace.list();\n const { changedComponents } = await this.refactoring.refactorDependencyName(allComponents, sourceId, targetId);\n await Promise.all(changedComponents.map((comp) => this.workspace.write(comp)));\n }\n\n await this.install.link();\n\n return {\n sourceId,\n targetId,\n };\n }\n\n getRenamingInfo(component: Component): RenamingInfo | null {\n const renameConfig = component.state.aspects.get(RenamingAspect.id)?.config as RenamingInfo | undefined;\n if (!renameConfig) return null;\n return {\n renamedFrom: ComponentID.fromObject(renameConfig.renamedFrom),\n };\n }\n\n /**\n * change the default-scope for new components. optionally (if refactor is true), change the source code to match the\n * new scope-name.\n * keep in mind that this is working for new components only, for tagged/exported it's impossible. See the errors\n * thrown in such cases in this method.\n */\n async renameScope(oldScope: string, newScope: string, options: { refactor?: boolean }): Promise<RenameScopeResult> {\n const allComponents = await this.workspace.list();\n const componentsUsingOldScope = allComponents.filter((comp) => comp.id.scope === oldScope);\n if (!componentsUsingOldScope.length && this.workspace.defaultScope !== oldScope) {\n throw new OldScopeNotFound(oldScope);\n }\n // verify they're all new.\n const exported = componentsUsingOldScope.filter((comp) => comp.id._legacy.hasScope());\n if (exported.length) {\n const idsStr = exported.map((comp) => comp.id.toString());\n throw new OldScopeExported(idsStr);\n }\n const tagged = componentsUsingOldScope.filter((comp) => comp.id.hasVersion());\n if (tagged.length) {\n const idsStr = tagged.map((comp) => comp.id.toString());\n throw new OldScopeTagged(idsStr);\n }\n if (this.workspace.defaultScope === oldScope) {\n await this.workspace.setDefaultScope(newScope);\n componentsUsingOldScope.forEach((comp) => this.workspace.bitMap.removeDefaultScope(comp.id));\n } else {\n componentsUsingOldScope.forEach((comp) => this.workspace.bitMap.setDefaultScope(comp.id, newScope));\n }\n await this.workspace.bitMap.write();\n const refactoredIds: ComponentID[] = [];\n if (options.refactor) {\n const legacyComps = componentsUsingOldScope.map((c) => c.state._consumer);\n const packagesToReplace: MultipleStringsReplacement = legacyComps.map((comp) => {\n return {\n oldStr: componentIdToPackageName(comp),\n newStr: componentIdToPackageName({\n ...comp,\n bindingPrefix: getBindingPrefixByDefaultScope(newScope),\n id: comp.id,\n defaultScope: newScope,\n }),\n };\n });\n const { changedComponents } = await this.refactoring.replaceMultipleStrings(allComponents, packagesToReplace);\n await this.renameScopeOfAspectIdsInWorkspaceConfig(\n componentsUsingOldScope.map((c) => c.id),\n newScope\n );\n await Promise.all(changedComponents.map((comp) => this.workspace.write(comp)));\n refactoredIds.push(...changedComponents.map((c) => c.id));\n }\n\n return { scopeRenamedComponentIds: componentsUsingOldScope.map((comp) => comp.id), refactoredIds };\n }\n\n /**\n * change the default-scope for new components. optionally (if refactor is true), change the source code to match the\n * new scope-name.\n * keep in mind that this is working for new components only, for tagged/exported it's impossible. See the errors\n * thrown in such cases in this method.\n */\n async renameOwner(oldOwner: string, newOwner: string, options: { refactor?: boolean }): Promise<RenameScopeResult> {\n const allComponents = await this.workspace.list();\n const isScopeUsesOldOwner = (scope: string) => scope.startsWith(`${oldOwner}.`);\n const componentsUsingOldScope = allComponents.filter((comp) => isScopeUsesOldOwner(comp.id.scope));\n if (!componentsUsingOldScope.length && !isScopeUsesOldOwner(this.workspace.defaultScope)) {\n throw new OldScopeNotFound(oldOwner);\n }\n // verify they're all new.\n const exported = componentsUsingOldScope.filter((comp) => comp.id._legacy.hasScope());\n if (exported.length) {\n const idsStr = exported.map((comp) => comp.id.toString());\n throw new OldScopeExported(idsStr);\n }\n const tagged = componentsUsingOldScope.filter((comp) => comp.id.hasVersion());\n if (tagged.length) {\n const idsStr = tagged.map((comp) => comp.id.toString());\n throw new OldScopeTagged(idsStr);\n }\n const oldWorkspaceDefaultScope = this.workspace.defaultScope;\n if (isScopeUsesOldOwner(this.workspace.defaultScope)) {\n const newDefaultScope = this.renameOwnerInScopeName(this.workspace.defaultScope, oldOwner, newOwner);\n await this.workspace.setDefaultScope(newDefaultScope);\n componentsUsingOldScope.forEach((comp) => {\n if (comp.id.scope === oldWorkspaceDefaultScope) this.workspace.bitMap.removeDefaultScope(comp.id);\n });\n }\n componentsUsingOldScope.forEach((comp) => {\n if (comp.id.scope === oldWorkspaceDefaultScope) return;\n const newCompScope = this.renameOwnerInScopeName(comp.id.scope, oldOwner, newOwner);\n this.workspace.bitMap.setDefaultScope(comp.id, newCompScope);\n });\n await this.workspace.bitMap.write();\n const refactoredIds: ComponentID[] = [];\n if (options.refactor) {\n const legacyComps = componentsUsingOldScope.map((c) => c.state._consumer);\n const packagesToReplace: MultipleStringsReplacement = legacyComps.map((comp) => {\n const newScope = this.renameOwnerInScopeName(comp.id.scope, oldOwner, newOwner);\n return {\n oldStr: componentIdToPackageName(comp),\n newStr: componentIdToPackageName({\n ...comp,\n bindingPrefix: getBindingPrefixByDefaultScope(newScope),\n id: comp.id,\n defaultScope: newScope,\n }),\n };\n });\n const { changedComponents } = await this.refactoring.replaceMultipleStrings(allComponents, packagesToReplace);\n await this.renameOwnerOfAspectIdsInWorkspaceConfig(\n componentsUsingOldScope.map((c) => c.id),\n oldOwner,\n newOwner\n );\n await Promise.all(changedComponents.map((comp) => this.workspace.write(comp)));\n refactoredIds.push(...changedComponents.map((c) => c.id));\n }\n\n return { scopeRenamedComponentIds: componentsUsingOldScope.map((comp) => comp.id), refactoredIds };\n }\n\n private async renameScopeOfAspectIdsInWorkspaceConfig(ids: ComponentID[], newScope: string) {\n const config = this.config.workspaceConfig;\n if (!config) throw new Error('unable to get workspace config');\n let hasChanged = false;\n ids.forEach((id) => {\n const changed = config.renameExtensionInRaw(\n id.toStringWithoutVersion(),\n id._legacy.changeScope(newScope).toStringWithoutVersion()\n );\n if (changed) hasChanged = true;\n });\n if (hasChanged) await config.write();\n }\n\n private async renameOwnerOfAspectIdsInWorkspaceConfig(ids: ComponentID[], oldOwner: string, newOwner: string) {\n const config = this.config.workspaceConfig;\n if (!config) throw new Error('unable to get workspace config');\n let hasChanged = false;\n ids.forEach((id) => {\n const newScope = this.renameOwnerInScopeName(id.scope, oldOwner, newOwner);\n const changed = config.renameExtensionInRaw(\n id.toStringWithoutVersion(),\n id._legacy.changeScope(newScope).toStringWithoutVersion()\n );\n if (changed) hasChanged = true;\n });\n if (hasChanged) await config.write();\n }\n\n private renameOwnerInScopeName(scopeName: string, oldOwner: string, newOwner: string): string {\n return scopeName.replace(`${oldOwner}.`, `${newOwner}.`);\n }\n\n private async getConfig(comp: Component) {\n const fromExisting = await this.newComponentHelper.getConfigFromExistingToNewComponent(comp);\n return {\n ...fromExisting,\n [RenamingAspect.id]: {\n renamedFrom: comp.id.toObject(),\n },\n };\n }\n\n static slots = [];\n static dependencies = [\n CLIAspect,\n WorkspaceAspect,\n DeprecationAspect,\n NewComponentHelperAspect,\n ComponentAspect,\n GraphqlAspect,\n RefactoringAspect,\n InstallAspect,\n ConfigAspect,\n ];\n static runtime = MainRuntime;\n static async provider([\n cli,\n workspace,\n deprecation,\n newComponentHelper,\n componentMain,\n graphql,\n refactoring,\n install,\n config,\n ]: [\n CLIMain,\n Workspace,\n DeprecationMain,\n NewComponentHelperMain,\n ComponentMain,\n GraphqlMain,\n RefactoringMain,\n InstallMain,\n ConfigMain\n ]) {\n const renaming = new RenamingMain(workspace, install, newComponentHelper, deprecation, refactoring, config);\n cli.register(new RenameCmd(renaming));\n\n const scopeCommand = cli.getCommand('scope');\n scopeCommand?.commands?.push(new ScopeRenameCmd(renaming));\n scopeCommand?.commands?.push(new ScopeRenameOwnerCmd(renaming));\n\n graphql.register(renamingSchema(renaming));\n componentMain.registerShowFragments([new RenamingFragment(renaming)]);\n return renaming;\n }\n}\n\nRenamingAspect.addRuntime(RenamingMain);\n\nexport type RenameDependencyNameResult = { sourceId: ComponentID; targetId: ComponentID };\n\nexport type RenamingInfo = {\n renamedFrom: ComponentID;\n};\n\nexport type RenameScopeResult = { scopeRenamedComponentIds: ComponentID[]; refactoredIds: ComponentID[] };\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;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;I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AAC;IAC1CF,aAAa,CAACW,qBAAqB,CAAC,CAAC,KAAIC,6BAAgB,EAACV,QAAQ,CAAC,CAAC,CAAC;IACrE,OAAOA,QAAQ;EACjB;AACF;AAAC;AAAA,gCA/PY5G,YAAY,WAkNR,EAAE;AAAA,gCAlNNA,YAAY,kBAmND,CACpBuH,gBAAS,EACTC,oBAAe,EACfC,gCAAiB,EACjBC,6BAAwB,EACxBC,oBAAe,EACfC,kBAAa,EACbC,sBAAiB,EACjBC,wBAAa,EACbC,sBAAY,CACb;AAAA,gCA7NU/H,YAAY,aA8NNgI,kBAAW;AAmC9BrF,0BAAc,CAACsF,UAAU,CAACjI,YAAY,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { Command, CommandOptions } from '@teambit/cli';
2
+ import { RenamingMain } from './renaming.main.runtime';
3
+ export declare class ScopeRenameOwnerCmd implements Command {
4
+ private renaming;
5
+ name: string;
6
+ description: string;
7
+ arguments: {
8
+ name: string;
9
+ description: string;
10
+ }[];
11
+ options: CommandOptions;
12
+ group: string;
13
+ constructor(renaming: RenamingMain);
14
+ report([oldName, newName]: [string, string], { refactor }: {
15
+ refactor?: boolean;
16
+ }): Promise<string>;
17
+ }
@@ -0,0 +1,56 @@
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.ScopeRenameOwnerCmd = void 0;
10
+ function _defineProperty2() {
11
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
+ _defineProperty2 = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _chalk() {
18
+ const data = _interopRequireDefault(require("chalk"));
19
+ _chalk = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ class ScopeRenameOwnerCmd {
25
+ constructor(renaming) {
26
+ this.renaming = renaming;
27
+ (0, _defineProperty2().default)(this, "name", 'rename-owner <current-owner-name> <new-owner-name>');
28
+ (0, _defineProperty2().default)(this, "description", "Renames the owner part of the scope-name for all components with the specified 'current owner name'");
29
+ (0, _defineProperty2().default)(this, "arguments", [{
30
+ name: 'current-owner-name',
31
+ description: 'the owner name to be replaced by another owner name'
32
+ }, {
33
+ name: 'new-owner-name',
34
+ description: 'a new owner name to replace the current owner name'
35
+ }]);
36
+ (0, _defineProperty2().default)(this, "options", [['r', 'refactor', 'update the import statements in all dependent components to the new package name (that contains the new owner name)']]);
37
+ (0, _defineProperty2().default)(this, "group", 'development');
38
+ }
39
+ async report([oldName, newName], {
40
+ refactor
41
+ }) {
42
+ const {
43
+ scopeRenamedComponentIds,
44
+ refactoredIds
45
+ } = await this.renaming.renameOwner(oldName, newName, {
46
+ refactor
47
+ });
48
+ const title = _chalk().default.green(`successfully replaced "${oldName}" owner with "${newName}"`);
49
+ const renamedIdsStr = scopeRenamedComponentIds.length ? `\n${_chalk().default.bold('the following components were affected by this scope-name change:')}\n${scopeRenamedComponentIds.map(c => c.changeScope(newName)).join('\n')}` : '';
50
+ const refactoredStr = refactoredIds.length ? `\n\n${_chalk().default.bold('the following components have been refactored:')}\n${refactoredIds.join('\n')}` : '';
51
+ return `${title}\n${renamedIdsStr}${refactoredStr}`;
52
+ }
53
+ }
54
+ exports.ScopeRenameOwnerCmd = ScopeRenameOwnerCmd;
55
+
56
+ //# sourceMappingURL=scope-rename-owner.cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ScopeRenameOwnerCmd","constructor","renaming","name","description","report","oldName","newName","refactor","scopeRenamedComponentIds","refactoredIds","renameOwner","title","chalk","green","renamedIdsStr","length","bold","map","c","changeScope","join","refactoredStr"],"sources":["scope-rename-owner.cmd.ts"],"sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { RenamingMain } from './renaming.main.runtime';\n\nexport class ScopeRenameOwnerCmd implements Command {\n name = 'rename-owner <current-owner-name> <new-owner-name>';\n description = \"Renames the owner part of the scope-name for all components with the specified 'current owner name'\";\n arguments = [\n { name: 'current-owner-name', description: 'the owner name to be replaced by another owner name' },\n { name: 'new-owner-name', description: 'a new owner name to replace the current owner name' },\n ];\n options = [\n [\n 'r',\n 'refactor',\n 'update the import statements in all dependent components to the new package name (that contains the new owner name)',\n ],\n ] as CommandOptions;\n group = 'development';\n\n constructor(private renaming: RenamingMain) {}\n\n async report([oldName, newName]: [string, string], { refactor }: { refactor?: boolean }) {\n const { scopeRenamedComponentIds, refactoredIds } = await this.renaming.renameOwner(oldName, newName, { refactor });\n const title = chalk.green(`successfully replaced \"${oldName}\" owner with \"${newName}\"`);\n const renamedIdsStr = scopeRenamedComponentIds.length\n ? `\\n${chalk.bold(\n 'the following components were affected by this scope-name change:'\n )}\\n${scopeRenamedComponentIds.map((c) => c.changeScope(newName)).join('\\n')}`\n : '';\n const refactoredStr = refactoredIds.length\n ? `\\n\\n${chalk.bold('the following components have been refactored:')}\\n${refactoredIds.join('\\n')}`\n : '';\n return `${title}\\n${renamedIdsStr}${refactoredStr}`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGO,MAAMA,mBAAmB,CAAoB;EAgBlDC,WAAW,CAASC,QAAsB,EAAE;IAAA,KAAxBA,QAAsB,GAAtBA,QAAsB;IAAA,8CAfnC,oDAAoD;IAAA,qDAC7C,qGAAqG;IAAA,mDACvG,CACV;MAAEC,IAAI,EAAE,oBAAoB;MAAEC,WAAW,EAAE;IAAsD,CAAC,EAClG;MAAED,IAAI,EAAE,gBAAgB;MAAEC,WAAW,EAAE;IAAqD,CAAC,CAC9F;IAAA,iDACS,CACR,CACE,GAAG,EACH,UAAU,EACV,qHAAqH,CACtH,CACF;IAAA,+CACO,aAAa;EAEwB;EAE7C,MAAMC,MAAM,CAAC,CAACC,OAAO,EAAEC,OAAO,CAAmB,EAAE;IAAEC;EAAiC,CAAC,EAAE;IACvF,MAAM;MAAEC,wBAAwB;MAAEC;IAAc,CAAC,GAAG,MAAM,IAAI,CAACR,QAAQ,CAACS,WAAW,CAACL,OAAO,EAAEC,OAAO,EAAE;MAAEC;IAAS,CAAC,CAAC;IACnH,MAAMI,KAAK,GAAGC,gBAAK,CAACC,KAAK,CAAE,0BAAyBR,OAAQ,iBAAgBC,OAAQ,GAAE,CAAC;IACvF,MAAMQ,aAAa,GAAGN,wBAAwB,CAACO,MAAM,GAChD,KAAIH,gBAAK,CAACI,IAAI,CACb,mEAAmE,CACnE,KAAIR,wBAAwB,CAACS,GAAG,CAAEC,CAAC,IAAKA,CAAC,CAACC,WAAW,CAACb,OAAO,CAAC,CAAC,CAACc,IAAI,CAAC,IAAI,CAAE,EAAC,GAC9E,EAAE;IACN,MAAMC,aAAa,GAAGZ,aAAa,CAACM,MAAM,GACrC,OAAMH,gBAAK,CAACI,IAAI,CAAC,gDAAgD,CAAE,KAAIP,aAAa,CAACW,IAAI,CAAC,IAAI,CAAE,EAAC,GAClG,EAAE;IACN,OAAQ,GAAET,KAAM,KAAIG,aAAc,GAAEO,aAAc,EAAC;EACrD;AACF;AAAC"}
@@ -0,0 +1,10 @@
1
+ import { BitError } from '@teambit/bit-error';
2
+
3
+ export class OldScopeExported extends BitError {
4
+ constructor(idsStr: string[]) {
5
+ super(`unable to rename the scope for the following exported components:\n${idsStr.join(', ')}
6
+ because these components were exported already, other components may use them and they'll break upon rename.
7
+ instead, deprecate the above components (using "bit deprecate"), tag, export and then eject them.
8
+ once they are not in the workspace, you can fork them ("bit fork") with the new scope-name`);
9
+ }
10
+ }
@@ -0,0 +1,7 @@
1
+ import { BitError } from '@teambit/bit-error';
2
+
3
+ export class OldScopeNotFound extends BitError {
4
+ constructor(oldScope: string) {
5
+ super(`none of the components is using "${oldScope}". also, the workspace is not configured with "${oldScope}"`);
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ import { BitError } from '@teambit/bit-error';
2
+
3
+ export class OldScopeTagged extends BitError {
4
+ constructor(idsStr: string[]) {
5
+ super(`unable to rename the scope for the following tagged components:\n${idsStr.join(', ')}
6
+ because these components were tagged, the objects have the dependencies data of the old-scope.
7
+ to be able to rename the scope, please untag the components first (using "bit reset" command)`);
8
+ }
9
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/renaming",
3
- "version": "0.0.385",
3
+ "version": "0.0.387",
4
4
  "homepage": "https://bit.dev/teambit/component/renaming",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.component",
8
8
  "name": "renaming",
9
- "version": "0.0.385"
9
+ "version": "0.0.387"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
@@ -14,16 +14,16 @@
14
14
  "core-js": "^3.0.0",
15
15
  "@babel/runtime": "7.20.0",
16
16
  "@teambit/harmony": "0.4.6",
17
- "@teambit/cli": "0.0.660",
18
- "@teambit/component": "0.0.981",
19
- "@teambit/graphql": "0.0.981",
20
- "@teambit/bit-error": "0.0.402",
21
- "@teambit/config": "0.0.673",
22
- "@teambit/deprecation": "0.0.981",
23
- "@teambit/install": "0.0.107",
24
- "@teambit/new-component-helper": "0.0.385",
25
- "@teambit/refactoring": "0.0.278",
26
- "@teambit/workspace": "0.0.981"
17
+ "@teambit/cli": "0.0.661",
18
+ "@teambit/component": "0.0.983",
19
+ "@teambit/graphql": "0.0.983",
20
+ "@teambit/config": "0.0.674",
21
+ "@teambit/deprecation": "0.0.983",
22
+ "@teambit/install": "0.0.109",
23
+ "@teambit/new-component-helper": "0.0.387",
24
+ "@teambit/refactoring": "0.0.280",
25
+ "@teambit/workspace": "0.0.983",
26
+ "@teambit/bit-error": "0.0.402"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/react": "^17.0.8",
@@ -34,7 +34,7 @@
34
34
  "@types/testing-library__jest-dom": "5.9.5"
35
35
  },
36
36
  "peerDependencies": {
37
- "@teambit/legacy": "1.0.441",
37
+ "@teambit/legacy": "1.0.442",
38
38
  "react": "^16.8.0 || ^17.0.0",
39
39
  "react-dom": "^16.8.0 || ^17.0.0"
40
40
  },