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

fix(scope-rename), rename scope of envs in .bitmap config #7733

Merged
merged 3 commits into from
Aug 3, 2023
Merged
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
33 changes: 30 additions & 3 deletions scopes/component/renaming/renaming.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ComponentAspect, { Component, ComponentID, ComponentMain } from '@teambit
import { DeprecationAspect, DeprecationMain } from '@teambit/deprecation';
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 RefactoringAspect, { MultipleStringsReplacement, RefactoringMain } from '@teambit/refactoring';
import ComponentWriterAspect, { ComponentWriterMain } from '@teambit/component-writer';
Expand Down Expand Up @@ -37,7 +38,8 @@ export class RenamingMain {
private config: ConfigMain,
private componentWriter: ComponentWriterMain,
private compiler: CompilerMain,
private logger: Logger
private logger: Logger,
private envs: EnvsMain
) {}

async rename(sourceIdStr: string, targetName: string, options: RenameOptions): Promise<RenameDependencyNameResult> {
Expand Down Expand Up @@ -119,6 +121,17 @@ make sure this argument is the name only, without the scope-name. to change the
if (!componentsUsingOldScope.length && this.workspace.defaultScope !== oldScope) {
throw new OldScopeNotFound(oldScope);
}
const envs = componentsUsingOldScope.filter((c) => this.envs.isEnv(c));
const compsUsingEnv = {};
await Promise.all(
envs.map(async (env) => {
const components = await this.workspace.getComponentsUsingEnv(env.id.toString(), true);
if (!components.length) return;
const componentIds = components.map((comp) => comp.id);
compsUsingEnv[env.id.toString()] = componentIds;
})
);

// verify they're all new.
const exported = componentsUsingOldScope.filter((comp) => comp.id._legacy.hasScope());
if (exported.length) {
Expand All @@ -137,6 +150,16 @@ make sure this argument is the name only, without the scope-name. to change the
componentsUsingOldScope.forEach((comp) => this.workspace.bitMap.setDefaultScope(comp.id, newScope));
}
await this.workspace.bitMap.write();
await this.workspace.clearCache();

await Promise.all(
envs.map(async (env) => {
const componentIds = compsUsingEnv[env.id.toString()];
if (!componentIds.length) return;
await this.workspace.setEnvToComponents(env.id.changeScope(newScope), componentIds);
})
);

const refactoredIds: ComponentID[] = [];
if (options.refactor) {
const legacyComps = componentsUsingOldScope.map((c) => c.state._consumer);
Expand Down Expand Up @@ -339,6 +362,7 @@ make sure this argument is the name only, without the scope-name. to change the
ComponentWriterAspect,
CompilerAspect,
LoggerAspect,
EnvsAspect,
];
static runtime = MainRuntime;
static async provider([
Expand All @@ -354,6 +378,7 @@ make sure this argument is the name only, without the scope-name. to change the
componentWriter,
compiler,
loggerMain,
envs,
]: [
CLIMain,
Workspace,
Expand All @@ -366,7 +391,8 @@ make sure this argument is the name only, without the scope-name. to change the
ConfigMain,
ComponentWriterMain,
CompilerMain,
LoggerMain
LoggerMain,
EnvsMain
]) {
const logger = loggerMain.createLogger(RenamingAspect.id);
const renaming = new RenamingMain(
Expand All @@ -378,7 +404,8 @@ make sure this argument is the name only, without the scope-name. to change the
config,
componentWriter,
compiler,
logger
logger,
envs
);
cli.register(new RenameCmd(renaming));

Expand Down