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(bit-aspect-update): indicate in the output when components are up to date #6566

Merged
merged 2 commits into from
Oct 19, 2022
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
5 changes: 5 additions & 0 deletions e2e/harmony/aspect.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ describe('aspect', function () {
expect(show).to.have.string(`${helper.scopes.remote}/[email protected]`);
expect(show).not.to.have.string(`${helper.scopes.remote}/[email protected]`);
});
it('running the same command again, should not show a message that no component is using this aspect', () => {
const secondRun = helper.command.updateAspect(`${helper.scopes.remote}/my-aspect`);
expect(secondRun).to.have.string('are already up to date');
expect(secondRun).to.not.have.string('unable to find any component');
});
it('bit tag should save only the updated aspect and not the old one', () => {
helper.command.importComponent('my-aspect'); // otherwise, the tag will try to get it as a package
helper.command.tagAllComponents();
Expand Down
13 changes: 10 additions & 3 deletions scopes/harmony/aspect/aspect.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,16 @@ export class UpdateAspectCmd implements Command {
constructor(private aspect: AspectMain) {}

async report([aspectId, pattern]: [string, string]) {
const results = await this.aspect.updateAspectsToComponents(aspectId, pattern);
if (!results.length) return chalk.yellow(`unable to find any component that use ${chalk.bold(aspectId)}`);
return chalk.green(`the following component(s) have been successfully updated:\n${results.join('\n')}`);
const { updated, alreadyUpToDate } = await this.aspect.updateAspectsToComponents(aspectId, pattern);
if (updated.length) {
return chalk.green(`the following component(s) have been successfully updated:\n${updated.join('\n')}`);
}
if (alreadyUpToDate.length) {
return chalk.green(
`all ${alreadyUpToDate.length} component(s) that use this aspect are already up to date. nothing to update`
);
}
return chalk.yellow(`unable to find any component that use ${chalk.bold(aspectId)}`);
}
}

Expand Down
14 changes: 11 additions & 3 deletions scopes/harmony/aspect/aspect.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ export class AspectMain {
};
}

async updateAspectsToComponents(aspectId: string, pattern?: string): Promise<ComponentID[]> {
async updateAspectsToComponents(
aspectId: string,
pattern?: string
): Promise<{ updated: ComponentID[]; alreadyUpToDate: ComponentID[] }> {
let aspectCompId = await this.workspace.resolveComponentId(aspectId);
if (!aspectCompId.hasVersion()) {
try {
Expand All @@ -159,11 +162,16 @@ export class AspectMain {
}
const allCompIds = pattern ? await this.workspace.idsByPattern(pattern) : await this.workspace.listIds();
const allComps = await this.workspace.getMany(allCompIds);
const alreadyUpToDate: ComponentID[] = [];
const updatedComponentIds = await Promise.all(
allComps.map(async (comp) => {
const aspect = comp.state.aspects.get(aspectCompId.toStringWithoutVersion());
if (!aspect) return undefined;
if (aspect.id.version === aspectCompId.version) return undefined; // nothing to update
if (aspect.id.version === aspectCompId.version) {
// nothing to update
alreadyUpToDate.push(comp.id);
return undefined;
}
// don't mark with minus if not exist in .bitmap. it's not needed. when the component is loaded, the
// merge-operation of the aspects removes duplicate aspect-id with different versions.
await this.workspace.removeSpecificComponentConfig(comp.id, aspect.id.toString(), false);
Expand All @@ -172,7 +180,7 @@ export class AspectMain {
})
);
await this.workspace.bitMap.write();
return compact(updatedComponentIds);
return { updated: compact(updatedComponentIds), alreadyUpToDate };
}

/**
Expand Down