@teambit/renaming 0.0.117 → 0.0.118
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/renaming.main.runtime.d.ts +21 -5
- package/dist/renaming.main.runtime.js +149 -4
- package/dist/renaming.main.runtime.js.map +1 -1
- package/dist/scope-rename.cmd.d.ts +13 -0
- package/dist/scope-rename.cmd.js +64 -0
- package/dist/scope-rename.cmd.js.map +1 -0
- package/package-tar/teambit-renaming-0.0.118.tgz +0 -0
- package/package.json +13 -11
- package/{preview-1650598046924.js → preview-1650684349376.js} +2 -2
- package/package-tar/teambit-renaming-0.0.117.tgz +0 -0
|
@@ -4,6 +4,7 @@ import { DeprecationMain } from '@teambit/deprecation';
|
|
|
4
4
|
import { GraphqlMain } from '@teambit/graphql';
|
|
5
5
|
import { NewComponentHelperMain } from '@teambit/new-component-helper';
|
|
6
6
|
import { RefactoringMain } from '@teambit/refactoring';
|
|
7
|
+
import { ConfigMain } from '@teambit/config';
|
|
7
8
|
import { Workspace } from '@teambit/workspace';
|
|
8
9
|
import { RenameOptions } from './rename.cmd';
|
|
9
10
|
export declare class RenamingMain {
|
|
@@ -11,27 +12,42 @@ export declare class RenamingMain {
|
|
|
11
12
|
private newComponentHelper;
|
|
12
13
|
private deprecation;
|
|
13
14
|
private refactoring;
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
private config;
|
|
16
|
+
constructor(workspace: Workspace, newComponentHelper: NewComponentHelperMain, deprecation: DeprecationMain, refactoring: RefactoringMain, config: ConfigMain);
|
|
17
|
+
rename(sourceIdStr: string, targetIdStr: string, options: RenameOptions): Promise<RenameDependencyNameResult>;
|
|
16
18
|
getRenamingInfo(component: Component): RenamingInfo | null;
|
|
19
|
+
/**
|
|
20
|
+
* change the default-scope for new components. optionally (if refactor is true), change the source code to match the
|
|
21
|
+
* new scope-name.
|
|
22
|
+
* keep in mind that this is working for new components only, for tagged/exported it's impossible. See the errors
|
|
23
|
+
* thrown in such cases in this method.
|
|
24
|
+
*/
|
|
25
|
+
renameScope(oldScope: string, newScope: string, options: {
|
|
26
|
+
refactor?: boolean;
|
|
27
|
+
}): Promise<RenameScopeResult>;
|
|
17
28
|
private getConfig;
|
|
18
29
|
static slots: never[];
|
|
19
30
|
static dependencies: import("@teambit/harmony").Aspect[];
|
|
20
31
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
21
|
-
static provider([cli, workspace, deprecation, newComponentHelper, componentMain, graphql, refactoring]: [
|
|
32
|
+
static provider([cli, workspace, deprecation, newComponentHelper, componentMain, graphql, refactoring, config,]: [
|
|
22
33
|
CLIMain,
|
|
23
34
|
Workspace,
|
|
24
35
|
DeprecationMain,
|
|
25
36
|
NewComponentHelperMain,
|
|
26
37
|
ComponentMain,
|
|
27
38
|
GraphqlMain,
|
|
28
|
-
RefactoringMain
|
|
39
|
+
RefactoringMain,
|
|
40
|
+
ConfigMain
|
|
29
41
|
]): Promise<RenamingMain>;
|
|
30
42
|
}
|
|
31
|
-
export declare type
|
|
43
|
+
export declare type RenameDependencyNameResult = {
|
|
32
44
|
sourceId: ComponentID;
|
|
33
45
|
targetId: ComponentID;
|
|
34
46
|
};
|
|
35
47
|
export declare type RenamingInfo = {
|
|
36
48
|
renamedFrom: ComponentID;
|
|
37
49
|
};
|
|
50
|
+
export declare type RenameScopeResult = {
|
|
51
|
+
scopeRenamedComponentIds: ComponentID[];
|
|
52
|
+
refactoredIds: ComponentID[];
|
|
53
|
+
};
|
|
@@ -21,6 +21,36 @@ function _defineProperty2() {
|
|
|
21
21
|
return data;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function _path() {
|
|
25
|
+
const data = _interopRequireDefault(require("path"));
|
|
26
|
+
|
|
27
|
+
_path = function () {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _bitError() {
|
|
35
|
+
const data = require("@teambit/bit-error");
|
|
36
|
+
|
|
37
|
+
_bitError = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _componentIdToPackageName() {
|
|
45
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/bit/component-id-to-package-name"));
|
|
46
|
+
|
|
47
|
+
_componentIdToPackageName = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
|
|
24
54
|
function _cli() {
|
|
25
55
|
const data = require("@teambit/cli");
|
|
26
56
|
|
|
@@ -81,6 +111,26 @@ function _refactoring() {
|
|
|
81
111
|
return data;
|
|
82
112
|
}
|
|
83
113
|
|
|
114
|
+
function _componentConfig() {
|
|
115
|
+
const data = require("@teambit/legacy/dist/consumer/config/component-config");
|
|
116
|
+
|
|
117
|
+
_componentConfig = function () {
|
|
118
|
+
return data;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return data;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function _config() {
|
|
125
|
+
const data = require("@teambit/config");
|
|
126
|
+
|
|
127
|
+
_config = function () {
|
|
128
|
+
return data;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return data;
|
|
132
|
+
}
|
|
133
|
+
|
|
84
134
|
function _workspace() {
|
|
85
135
|
const data = _interopRequireDefault(require("@teambit/workspace"));
|
|
86
136
|
|
|
@@ -131,6 +181,16 @@ function _renaming3() {
|
|
|
131
181
|
return data;
|
|
132
182
|
}
|
|
133
183
|
|
|
184
|
+
function _scopeRename() {
|
|
185
|
+
const data = require("./scope-rename.cmd");
|
|
186
|
+
|
|
187
|
+
_scopeRename = function () {
|
|
188
|
+
return data;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
return data;
|
|
192
|
+
}
|
|
193
|
+
|
|
134
194
|
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); }
|
|
135
195
|
|
|
136
196
|
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; }
|
|
@@ -140,11 +200,12 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
140
200
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
141
201
|
|
|
142
202
|
class RenamingMain {
|
|
143
|
-
constructor(workspace, newComponentHelper, deprecation, refactoring) {
|
|
203
|
+
constructor(workspace, newComponentHelper, deprecation, refactoring, config) {
|
|
144
204
|
this.workspace = workspace;
|
|
145
205
|
this.newComponentHelper = newComponentHelper;
|
|
146
206
|
this.deprecation = deprecation;
|
|
147
207
|
this.refactoring = refactoring;
|
|
208
|
+
this.config = config;
|
|
148
209
|
}
|
|
149
210
|
|
|
150
211
|
async rename(sourceIdStr, targetIdStr, options) {
|
|
@@ -186,6 +247,86 @@ class RenamingMain {
|
|
|
186
247
|
renamedFrom: _component().ComponentID.fromObject(renameConfig.renamedFrom)
|
|
187
248
|
};
|
|
188
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* change the default-scope for new components. optionally (if refactor is true), change the source code to match the
|
|
252
|
+
* new scope-name.
|
|
253
|
+
* keep in mind that this is working for new components only, for tagged/exported it's impossible. See the errors
|
|
254
|
+
* thrown in such cases in this method.
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
async renameScope(oldScope, newScope, options) {
|
|
259
|
+
const allComponents = await this.workspace.list();
|
|
260
|
+
const componentsUsingOldScope = allComponents.filter(comp => comp.id.scope === oldScope);
|
|
261
|
+
|
|
262
|
+
if (!componentsUsingOldScope.length && this.workspace.defaultScope !== oldScope) {
|
|
263
|
+
throw new (_bitError().BitError)(`none of the components is using "${oldScope}". also, the workspace is not configured with "${oldScope}"`);
|
|
264
|
+
} // verify they're all new.
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
const exported = componentsUsingOldScope.filter(comp => comp.id._legacy.hasScope());
|
|
268
|
+
|
|
269
|
+
if (exported.length) {
|
|
270
|
+
const idsStr = exported.map(comp => comp.id.toString()).join(', ');
|
|
271
|
+
throw new (_bitError().BitError)(`unable to rename the scope for the following exported components:\n${idsStr}
|
|
272
|
+
because these components were exported already, other components may use them and they'll break upon rename.
|
|
273
|
+
instead, deprecate the above components (using "bit deprecate"), tag, export and then eject them.
|
|
274
|
+
once they are not in the workspace, you can fork them ("bit fork") with the new scope-name`);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const tagged = componentsUsingOldScope.filter(comp => comp.id.hasVersion());
|
|
278
|
+
|
|
279
|
+
if (tagged.length) {
|
|
280
|
+
const idsStr = tagged.map(comp => comp.id.toString()).join(', ');
|
|
281
|
+
throw new (_bitError().BitError)(`unable to rename the scope for the following tagged components:\n${idsStr}
|
|
282
|
+
because these components were tagged, the objects have the dependencies data of the old-scope.
|
|
283
|
+
to be able to rename the scope, please untag the components first (using "bit untag" command)`);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (this.workspace.defaultScope === oldScope) {
|
|
287
|
+
var _this$config$workspac, _this$config$workspac2;
|
|
288
|
+
|
|
289
|
+
(_this$config$workspac = this.config.workspaceConfig) === null || _this$config$workspac === void 0 ? void 0 : _this$config$workspac.setExtension(_workspace().default.id, {
|
|
290
|
+
defaultScope: newScope
|
|
291
|
+
}, {
|
|
292
|
+
mergeIntoExisting: true,
|
|
293
|
+
ignoreVersion: true
|
|
294
|
+
});
|
|
295
|
+
await ((_this$config$workspac2 = this.config.workspaceConfig) === null || _this$config$workspac2 === void 0 ? void 0 : _this$config$workspac2.write({
|
|
296
|
+
dir: _path().default.dirname(this.config.workspaceConfig.path)
|
|
297
|
+
}));
|
|
298
|
+
componentsUsingOldScope.forEach(comp => this.workspace.bitMap.removeDefaultScope(comp.id));
|
|
299
|
+
} else {
|
|
300
|
+
componentsUsingOldScope.forEach(comp => this.workspace.bitMap.setDefaultScope(comp.id, newScope));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
await this.workspace.bitMap.write();
|
|
304
|
+
const refactoredIds = [];
|
|
305
|
+
|
|
306
|
+
if (options.refactor) {
|
|
307
|
+
const legacyComps = componentsUsingOldScope.map(c => c.state._consumer);
|
|
308
|
+
const packagesToReplace = legacyComps.map(comp => {
|
|
309
|
+
return {
|
|
310
|
+
oldStr: (0, _componentIdToPackageName().default)(comp),
|
|
311
|
+
newStr: (0, _componentIdToPackageName().default)(_objectSpread(_objectSpread({}, comp), {}, {
|
|
312
|
+
bindingPrefix: (0, _componentConfig().getBindingPrefixByDefaultScope)(newScope),
|
|
313
|
+
id: comp.id,
|
|
314
|
+
defaultScope: newScope
|
|
315
|
+
}))
|
|
316
|
+
};
|
|
317
|
+
});
|
|
318
|
+
const {
|
|
319
|
+
changedComponents
|
|
320
|
+
} = await this.refactoring.renameMultiplePackages(allComponents, packagesToReplace);
|
|
321
|
+
await Promise.all(changedComponents.map(comp => this.workspace.write(comp)));
|
|
322
|
+
refactoredIds.push(...changedComponents.map(c => c.id));
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return {
|
|
326
|
+
scopeRenamedComponentIds: componentsUsingOldScope.map(comp => comp.id),
|
|
327
|
+
refactoredIds
|
|
328
|
+
};
|
|
329
|
+
}
|
|
189
330
|
|
|
190
331
|
async getConfig(comp) {
|
|
191
332
|
const fromExisting = await this.newComponentHelper.getConfigFromExistingToNewComponent(comp);
|
|
@@ -196,9 +337,13 @@ class RenamingMain {
|
|
|
196
337
|
});
|
|
197
338
|
}
|
|
198
339
|
|
|
199
|
-
static async provider([cli, workspace, deprecation, newComponentHelper, componentMain, graphql, refactoring]) {
|
|
200
|
-
|
|
340
|
+
static async provider([cli, workspace, deprecation, newComponentHelper, componentMain, graphql, refactoring, config]) {
|
|
341
|
+
var _scopeCommand$command;
|
|
342
|
+
|
|
343
|
+
const renaming = new RenamingMain(workspace, newComponentHelper, deprecation, refactoring, config);
|
|
201
344
|
cli.register(new (_rename().RenameCmd)(renaming));
|
|
345
|
+
const scopeCommand = cli.getCommand('scope');
|
|
346
|
+
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));
|
|
202
347
|
graphql.register((0, _renaming3().renamingSchema)(renaming));
|
|
203
348
|
componentMain.registerShowFragments([new (_renaming2().RenamingFragment)(renaming)]);
|
|
204
349
|
return renaming;
|
|
@@ -208,7 +353,7 @@ class RenamingMain {
|
|
|
208
353
|
|
|
209
354
|
exports.RenamingMain = RenamingMain;
|
|
210
355
|
(0, _defineProperty2().default)(RenamingMain, "slots", []);
|
|
211
|
-
(0, _defineProperty2().default)(RenamingMain, "dependencies", [_cli().CLIAspect, _workspace().default, _deprecation().DeprecationAspect, _newComponentHelper().default, _component().default, _graphql().default, _refactoring().default]);
|
|
356
|
+
(0, _defineProperty2().default)(RenamingMain, "dependencies", [_cli().CLIAspect, _workspace().default, _deprecation().DeprecationAspect, _newComponentHelper().default, _component().default, _graphql().default, _refactoring().default, _config().ConfigAspect]);
|
|
212
357
|
(0, _defineProperty2().default)(RenamingMain, "runtime", _cli().MainRuntime);
|
|
213
358
|
|
|
214
359
|
_renaming().RenamingAspect.addRuntime(RenamingMain);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["renaming.main.runtime.ts"],"names":["RenamingMain","constructor","workspace","newComponentHelper","deprecation","refactoring","rename","sourceIdStr","targetIdStr","options","sourceId","resolveComponentId","isTagged","hasVersion","sourceComp","get","targetId","getNewComponentId","undefined","scope","config","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","fromExisting","getConfigFromExistingToNewComponent","toObject","provider","cli","componentMain","graphql","renaming","register","RenameCmd","registerShowFragments","RenamingFragment","CLIAspect","WorkspaceAspect","DeprecationAspect","NewComponentHelperAspect","ComponentAspect","GraphqlAspect","RefactoringAspect","MainRuntime","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA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1E,CAAD,EAQlB;AACD,UAAMiD,QAAQ,GAAG,IAAItD,YAAJ,CAAiBE,SAAjB,EAA4BC,kBAA5B,EAAgDC,WAAhD,EAA6DC,WAA7D,CAAjB;AACA8C,IAAAA,GAAG,CAACI,QAAJ,CAAa,KAAIC,mBAAJ,EAAcF,QAAd,CAAb;AACAD,IAAAA,OAAO,CAACE,QAAR,CAAiB,iCAAeD,QAAf,CAAjB;AACAF,IAAAA,aAAa,CAACK,qBAAd,CAAoC,CAAC,KAAIC,6BAAJ,EAAqBJ,QAArB,CAAD,CAApC;AACA,WAAOA,QAAP;AACD;;AA9EuB;;;gCAAbtD,Y,WAqDI,E;gCArDJA,Y,kBAsDW,CACpB2D,gBADoB,EAEpBC,oBAFoB,EAGpBC,gCAHoB,EAIpBC,6BAJoB,EAKpBC,oBALoB,EAMpBC,kBANoB,EAOpBC,sBAPoB,C;gCAtDXjE,Y,aA+DMkE,kB;;AAkBnBxB,2BAAeyB,UAAf,CAA0BnE,YAA1B","sourcesContent":["import { 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, { RefactoringMain } from '@teambit/refactoring';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { RenameCmd, RenameOptions } from './rename.cmd';\nimport { RenamingAspect } from './renaming.aspect';\nimport { RenamingFragment } from './renaming.fragment';\nimport { renamingSchema } from './renaming.graphql';\n\nexport class RenamingMain {\n constructor(\n private workspace: Workspace,\n private newComponentHelper: NewComponentHelperMain,\n private deprecation: DeprecationMain,\n private refactoring: RefactoringMain\n ) {}\n\n async rename(sourceIdStr: string, targetIdStr: string, options: RenameOptions): Promise<RenameResult> {\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.workspace.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 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 ];\n static runtime = MainRuntime;\n static async provider([cli, workspace, deprecation, newComponentHelper, componentMain, graphql, refactoring]: [\n CLIMain,\n Workspace,\n DeprecationMain,\n NewComponentHelperMain,\n ComponentMain,\n GraphqlMain,\n RefactoringMain\n ]) {\n const renaming = new RenamingMain(workspace, newComponentHelper, deprecation, refactoring);\n cli.register(new RenameCmd(renaming));\n graphql.register(renamingSchema(renaming));\n componentMain.registerShowFragments([new RenamingFragment(renaming)]);\n return renaming;\n }\n}\n\nRenamingAspect.addRuntime(RenamingMain);\n\nexport type RenameResult = { sourceId: ComponentID; targetId: ComponentID };\n\nexport type RenamingInfo = {\n renamedFrom: ComponentID;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["renaming.main.runtime.ts"],"names":["RenamingMain","constructor","workspace","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","workspaceConfig","setExtension","WorkspaceAspect","mergeIntoExisting","ignoreVersion","dir","path","dirname","forEach","removeDefaultScope","setDefaultScope","refactoredIds","legacyComps","c","_consumer","packagesToReplace","oldStr","newStr","bindingPrefix","renameMultiplePackages","push","scopeRenamedComponentIds","fromExisting","getConfigFromExistingToNewComponent","toObject","provider","cli","componentMain","graphql","renaming","register","RenameCmd","scopeCommand","getCommand","commands","ScopeRenameCmd","registerShowFragments","RenamingFragment","CLIAspect","DeprecationAspect","NewComponentHelperAspect","ComponentAspect","GraphqlAspect","RefactoringAspect","ConfigAspect","MainRuntime","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;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GAAG,CAACI,QAAJ,CAAa,KAAIC,mBAAJ,EAAcF,QAAd,CAAb;AAEA,UAAMG,YAAY,GAAGN,GAAG,CAACO,UAAJ,CAAe,OAAf,CAArB;AACAD,IAAAA,YAAY,SAAZ,IAAAA,YAAY,WAAZ,qCAAAA,YAAY,CAAEE,QAAd,gFAAwBd,IAAxB,CAA6B,KAAIe,6BAAJ,EAAmBN,QAAnB,CAA7B;AAEAD,IAAAA,OAAO,CAACE,QAAR,CAAiB,iCAAeD,QAAf,CAAjB;AACAF,IAAAA,aAAa,CAACS,qBAAd,CAAoC,CAAC,KAAIC,6BAAJ,EAAqBR,QAArB,CAAD,CAApC;AACA,WAAOA,QAAP;AACD;;AA9JuB;;;gCAAb3F,Y,WAsHI,E;gCAtHJA,Y,kBAuHW,CACpBoG,gBADoB,EAEpBpC,oBAFoB,EAGpBqC,gCAHoB,EAIpBC,6BAJoB,EAKpBC,oBALoB,EAMpBC,kBANoB,EAOpBC,sBAPoB,EAQpBC,sBARoB,C;gCAvHX1G,Y,aAiIM2G,kB;;AAgCnBjE,2BAAekE,UAAf,CAA0B5G,YAA1B","sourcesContent":["import path from 'path';\nimport { BitError } from '@teambit/bit-error';\nimport componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';\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 { ConfigAspect, ConfigMain } from '@teambit/config';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\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 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.workspace.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 untag\" command)`);\n }\n if (this.workspace.defaultScope === oldScope) {\n this.config.workspaceConfig?.setExtension(\n WorkspaceAspect.id,\n { defaultScope: newScope },\n { mergeIntoExisting: true, ignoreVersion: true }\n );\n await this.config.workspaceConfig?.write({ dir: path.dirname(this.config.workspaceConfig.path) });\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.renameMultiplePackages(allComponents, packagesToReplace);\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 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 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 config,\n ]: [\n CLIMain,\n Workspace,\n DeprecationMain,\n NewComponentHelperMain,\n ComponentMain,\n GraphqlMain,\n RefactoringMain,\n ConfigMain\n ]) {\n const renaming = new RenamingMain(workspace, 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"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
+
import { RenamingMain } from './renaming.main.runtime';
|
|
3
|
+
export declare class ScopeRenameCmd implements Command {
|
|
4
|
+
private renaming;
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
options: CommandOptions;
|
|
8
|
+
group: string;
|
|
9
|
+
constructor(renaming: RenamingMain);
|
|
10
|
+
report([oldName, newName]: [string, string], { refactor }: {
|
|
11
|
+
refactor?: boolean;
|
|
12
|
+
}): Promise<string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
require("core-js/modules/es.array.iterator.js");
|
|
6
|
+
|
|
7
|
+
require("core-js/modules/es.promise.js");
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "__esModule", {
|
|
10
|
+
value: true
|
|
11
|
+
});
|
|
12
|
+
exports.ScopeRenameCmd = void 0;
|
|
13
|
+
|
|
14
|
+
function _defineProperty2() {
|
|
15
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
+
|
|
17
|
+
_defineProperty2 = function () {
|
|
18
|
+
return data;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function _chalk() {
|
|
25
|
+
const data = _interopRequireDefault(require("chalk"));
|
|
26
|
+
|
|
27
|
+
_chalk = function () {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
class ScopeRenameCmd {
|
|
35
|
+
constructor(renaming) {
|
|
36
|
+
this.renaming = renaming;
|
|
37
|
+
(0, _defineProperty2().default)(this, "name", 'rename <old-name> <new-name>');
|
|
38
|
+
(0, _defineProperty2().default)(this, "description", 'rename a scope for components using the old-name, optionally change the dependencies source-code');
|
|
39
|
+
(0, _defineProperty2().default)(this, "options", [['r', 'refactor', 'change the source code of all components using the original scope-name with the new scope-name']]);
|
|
40
|
+
(0, _defineProperty2().default)(this, "group", 'development');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async report([oldName, newName], {
|
|
44
|
+
refactor
|
|
45
|
+
}) {
|
|
46
|
+
const {
|
|
47
|
+
scopeRenamedComponentIds,
|
|
48
|
+
refactoredIds
|
|
49
|
+
} = await this.renaming.renameScope(oldName, newName, {
|
|
50
|
+
refactor
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const title = _chalk().default.green(`successfully replaced "${oldName}" scope with "${newName}"`);
|
|
54
|
+
|
|
55
|
+
const renamedIdsStr = scopeRenamedComponentIds.length ? `\n${_chalk().default.bold('the following components were affected by this scope-name change:')}\n${scopeRenamedComponentIds.join('\n')}` : '';
|
|
56
|
+
const refactoredStr = refactoredIds.length ? `\n\n${_chalk().default.bold('the following components have been refactored:')}\n${refactoredIds.join('\n')}` : '';
|
|
57
|
+
return `${title}\n${renamedIdsStr}${refactoredStr}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
exports.ScopeRenameCmd = ScopeRenameCmd;
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=scope-rename.cmd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["scope-rename.cmd.ts"],"names":["ScopeRenameCmd","constructor","renaming","report","oldName","newName","refactor","scopeRenamedComponentIds","refactoredIds","renameScope","title","chalk","green","renamedIdsStr","length","bold","join","refactoredStr"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,cAAN,CAAwC;AAQ7CC,EAAAA,WAAW,CAASC,QAAT,EAAiC;AAAA,SAAxBA,QAAwB,GAAxBA,QAAwB;AAAA,kDAPrC,8BAOqC;AAAA,yDAN9B,kGAM8B;AAAA,qDALlC,CACR,CAAC,GAAD,EAAM,UAAN,EAAkB,gGAAlB,CADQ,CAKkC;AAAA,mDAFpC,aAEoC;AAAE;;AAElC,QAANC,MAAM,CAAC,CAACC,OAAD,EAAUC,OAAV,CAAD,EAAuC;AAAEC,IAAAA;AAAF,GAAvC,EAA6E;AACvF,UAAM;AAAEC,MAAAA,wBAAF;AAA4BC,MAAAA;AAA5B,QAA8C,MAAM,KAAKN,QAAL,CAAcO,WAAd,CAA0BL,OAA1B,EAAmCC,OAAnC,EAA4C;AAAEC,MAAAA;AAAF,KAA5C,CAA1D;;AACA,UAAMI,KAAK,GAAGC,iBAAMC,KAAN,CAAa,0BAAyBR,OAAQ,iBAAgBC,OAAQ,GAAtE,CAAd;;AACA,UAAMQ,aAAa,GAAGN,wBAAwB,CAACO,MAAzB,GACjB,KAAIH,iBAAMI,IAAN,CACH,mEADG,CAEH,KAAIR,wBAAwB,CAACS,IAAzB,CAA8B,IAA9B,CAAoC,EAHxB,GAIlB,EAJJ;AAKA,UAAMC,aAAa,GAAGT,aAAa,CAACM,MAAd,GACjB,OAAMH,iBAAMI,IAAN,CAAW,gDAAX,CAA6D,KAAIP,aAAa,CAACQ,IAAd,CAAmB,IAAnB,CAAyB,EAD/E,GAElB,EAFJ;AAGA,WAAQ,GAAEN,KAAM,KAAIG,aAAc,GAAEI,aAAc,EAAlD;AACD;;AAtB4C","sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { RenamingMain } from './renaming.main.runtime';\n\nexport class ScopeRenameCmd implements Command {\n name = 'rename <old-name> <new-name>';\n description = 'rename a scope for components using the old-name, optionally change the dependencies source-code';\n options = [\n ['r', 'refactor', 'change the source code of all components using the original scope-name with the new scope-name'],\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.renameScope(oldName, newName, { refactor });\n const title = chalk.green(`successfully replaced \"${oldName}\" scope 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.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"]}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/renaming",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.118",
|
|
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.
|
|
9
|
+
"version": "0.0.118"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"chalk": "2.4.2",
|
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
"@babel/runtime": "7.12.18",
|
|
15
15
|
"core-js": "^3.0.0",
|
|
16
16
|
"@teambit/harmony": "0.3.3",
|
|
17
|
-
"@teambit/cli": "0.0.
|
|
18
|
-
"@teambit/component": "0.0.
|
|
19
|
-
"@teambit/graphql": "0.0.
|
|
20
|
-
"@teambit/
|
|
21
|
-
"@teambit/
|
|
22
|
-
"@teambit/
|
|
23
|
-
"@teambit/
|
|
17
|
+
"@teambit/cli": "0.0.476",
|
|
18
|
+
"@teambit/component": "0.0.714",
|
|
19
|
+
"@teambit/graphql": "0.0.714",
|
|
20
|
+
"@teambit/bit-error": "0.0.394",
|
|
21
|
+
"@teambit/config": "0.0.489",
|
|
22
|
+
"@teambit/deprecation": "0.0.714",
|
|
23
|
+
"@teambit/new-component-helper": "0.0.118",
|
|
24
|
+
"@teambit/refactoring": "0.0.11",
|
|
25
|
+
"@teambit/workspace": "0.0.714"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"@types/react": "^17.0.8",
|
|
@@ -31,7 +33,7 @@
|
|
|
31
33
|
"@types/node": "12.20.4"
|
|
32
34
|
},
|
|
33
35
|
"peerDependencies": {
|
|
34
|
-
"@teambit/legacy": "1.0.
|
|
36
|
+
"@teambit/legacy": "1.0.256",
|
|
35
37
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
36
38
|
"react": "^16.8.0 || ^17.0.0"
|
|
37
39
|
},
|
|
@@ -59,7 +61,7 @@
|
|
|
59
61
|
"react": "-"
|
|
60
62
|
},
|
|
61
63
|
"peerDependencies": {
|
|
62
|
-
"@teambit/legacy": "1.0.
|
|
64
|
+
"@teambit/legacy": "1.0.256",
|
|
63
65
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
64
66
|
"react": "^16.8.0 || ^17.0.0"
|
|
65
67
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_renaming@0.0.
|
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_renaming@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_renaming@0.0.118/dist/renaming.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_renaming@0.0.118/dist/renaming.docs.mdx')]
|
|
Binary file
|