Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement(rename), introduce a new flag --delete to delete the old comp instead of deprecating it #8446

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions e2e/harmony/rename.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ describe('bit rename command', function () {
);
});
});
describe('rename with --delete flag', () => {
before(() => {
helper.scopeHelper.getClonedLocalScope(scopeAfterExport);
helper.command.rename('comp1', 'comp2', '--delete');
});
it('should create a new component', () => {
const status = helper.command.statusJson();
expect(status.newComponents).to.have.lengthOf(1);
});
it('should delete the original component', () => {
const showRemove = helper.command.showAspectConfig('comp1', Extensions.remove);
expect(showRemove.config.removed).to.be.true;
});
});
});
describe('rename a new component', () => {
before(() => {
Expand Down
2 changes: 2 additions & 0 deletions scopes/component/renaming/rename.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type RenameOptions = {
refactor?: boolean;
preserve?: boolean;
ast?: boolean;
delete?: boolean;
};

export class RenameCmd implements Command {
Expand Down Expand Up @@ -38,6 +39,7 @@ export class RenameCmd implements Command {
['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
16 changes: 12 additions & 4 deletions scopes/component/renaming/renaming.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import GraphqlAspect, { GraphqlMain } from '@teambit/graphql';
import { CompilerAspect, CompilerMain } from '@teambit/compiler';
import EnvsAspect, { EnvsMain } from '@teambit/envs';
import NewComponentHelperAspect, { NewComponentHelperMain } from '@teambit/new-component-helper';
import RemoveAspect, { RemoveMain } from '@teambit/remove';
import RefactoringAspect, { MultipleStringsReplacement, RefactoringMain } from '@teambit/refactoring';
import ComponentWriterAspect, { ComponentWriterMain } from '@teambit/component-writer';
import { getBindingPrefixByDefaultScope } from '@teambit/legacy/dist/consumer/config/component-config';
Expand Down Expand Up @@ -39,7 +40,8 @@ export class RenamingMain {
private componentWriter: ComponentWriterMain,
private compiler: CompilerMain,
private logger: Logger,
private envs: EnvsMain
private envs: EnvsMain,
private remove: RemoveMain
) {}

async rename(sourceIdStr: string, targetName: string, options: RenameOptions): Promise<RenameDependencyNameResult> {
Expand All @@ -61,7 +63,9 @@ make sure this argument is the name only, without the scope-name. to change the
if (isTagged) {
const config = await this.getConfig(sourceComp);
await this.newComponentHelper.writeAndAddNewComp(sourceComp, targetId, options, config);
await this.deprecation.deprecate(sourceId, targetId);
options.delete
? await this.remove.deleteComps(sourceId.toString())
: await this.deprecation.deprecate(sourceId, targetId);
} else {
this.workspace.bitMap.renameNewComponent(sourceId, targetId);
await this.workspace.bitMap.write(`rename (${sourceIdStr} to ${targetName})`);
Expand Down Expand Up @@ -372,6 +376,7 @@ make sure this argument is the name only, without the scope-name. to change the
CompilerAspect,
LoggerAspect,
EnvsAspect,
RemoveAspect,
];
static runtime = MainRuntime;
static async provider([
Expand All @@ -388,6 +393,7 @@ make sure this argument is the name only, without the scope-name. to change the
compiler,
loggerMain,
envs,
remove,
]: [
CLIMain,
Workspace,
Expand All @@ -401,7 +407,8 @@ make sure this argument is the name only, without the scope-name. to change the
ComponentWriterMain,
CompilerMain,
LoggerMain,
EnvsMain
EnvsMain,
RemoveMain
]) {
const logger = loggerMain.createLogger(RenamingAspect.id);
const renaming = new RenamingMain(
Expand All @@ -414,7 +421,8 @@ make sure this argument is the name only, without the scope-name. to change the
componentWriter,
compiler,
logger,
envs
envs,
remove
);
cli.register(new RenameCmd(renaming));

Expand Down