Skip to content

Commit

Permalink
improvement(scope-rename), support renaming exported components (#8456)
Browse files Browse the repository at this point in the history
Currently, `bit scope rename` supports only new components. For
exported, it suggests users to run `bit rename` one by one, which can be
an hassle.
This PR combines the logic from "rename", "renameScope" and
"renameOwner" to one place "renameMultiple" and allows renaming multiple
components, some can be exported, some can be new.
Previously, some of the actions during the rename were done only on
"rename" or only on "renameScope", now all of them are aligned.
  • Loading branch information
davidfirst authored Jan 26, 2024
1 parent e6b813f commit 0465ce2
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 287 deletions.
34 changes: 34 additions & 0 deletions e2e/harmony/scope-cmd.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,40 @@ describe('bit scope command', function () {
expect(workspaceJsonc).not.to.have.property(`my-scope/comp2`);
});
});
describe('bit scope rename, some components are exported some are new', () => {
before(() => {
helper.scopeHelper.setNewLocalAndRemoteScopes();
helper.fixtures.populateComponents(3);
helper.command.tagWithoutBuild('comp3', '--skip-auto-tag');
helper.command.export();
helper.command.renameScope(helper.scopes.remote, 'my-scope', '--refactor');
});
it('should deprecate the exported one (comp3)', () => {
const showDeprecation = helper.command.showAspectConfig(`${helper.scopes.remote}/comp3`, Extensions.deprecation);
expect(showDeprecation.config.deprecate).to.be.true;
expect(showDeprecation.config).to.have.property('newId');
expect(showDeprecation.config.newId.name).to.equal('comp3');
expect(showDeprecation.config.newId.scope).to.equal('my-scope');
});
it('should rename the new ones', () => {
const list = helper.command.listParsed();
const ids = list.map((c) => c.id);
expect(ids).to.have.members([
'my-scope/comp1',
'my-scope/comp2',
'my-scope/comp3',
`${helper.scopes.remote}/comp3`,
]);
});
it('bit status should not have issues', () => {
helper.command.expectStatusToNotHaveIssues();
});
it('bit status should show 3 new components and one modified (comp3 due to deprecation)', () => {
const status = helper.command.statusJson();
expect(status.newComponents).to.have.lengthOf(3);
expect(status.modifiedComponents).to.have.lengthOf(1);
});
});
describe('bit scope rename-owner', () => {
before(() => {
helper.scopeHelper.setNewLocalAndRemoteScopes();
Expand Down
10 changes: 0 additions & 10 deletions scopes/component/renaming/exceptions/old-scope-exported.ts

This file was deleted.

9 changes: 0 additions & 9 deletions scopes/component/renaming/exceptions/old-scope-tagged.ts

This file was deleted.

9 changes: 9 additions & 0 deletions scopes/component/renaming/exceptions/renaming-tagged.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BitError } from '@teambit/bit-error';

export class RenamingTagged extends BitError {
constructor(idsStr: string[]) {
super(`the following components are tagged/snapped but not exported:\n${idsStr.join(', ')}
renaming them will result in deprecating the current ones and creating new components, which is unnecessary.
please reset the components first (using "bit reset") and then re-run the rename command`);
}
}
10 changes: 5 additions & 5 deletions scopes/component/renaming/rename.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type RenameOptions = {
export class RenameCmd implements Command {
name = 'rename <current-name> <new-name>';
description =
'rename component. if tagged/exported, create a new component and deprecate the original component. otherwise just renames current component';
'rename component. if exported, create a new component and deprecate the original component. otherwise just renames current component';
helpUrl = 'reference/components/renaming-components';
arguments = [
{
Expand All @@ -31,15 +31,15 @@ export class RenameCmd implements Command {
alias = '';
options = [
['s', 'scope <scope-name>', 'define the scope for the newly created component'],
['r', 'refactor', 'update the import/require statements in all dependent components (in the same workspace)'],
['', 'preserve', 'avoid renaming files and variables/classes according to the new component name'],
['', 'ast', 'EXPERIMENTAL. use ast to transform files instead of regex'],
['', 'delete', 'EXPERIMENTAL. instead of deprecating the original component, delete it'],
[
'p',
'path <relative-path>',
'relative path in the workspace to place new component in. by default, the directory of the new component is from your workspace\'s "defaultScope" value',
],
['r', 'refactor', 'update the import/require statements in all dependent components (in the same workspace)'],
['', 'preserve', 'avoid renaming files and variables/classes according to the new component name'],
['', 'ast', 'EXPERIMENTAL. use ast to transform files instead of regex'],
['', 'delete', 'EXPERIMENTAL. instead of deprecating the original component, delete it'],
] as CommandOptions;
loader = true;
remoteOp = true;
Expand Down
Loading

0 comments on commit 0465ce2

Please sign in to comment.