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

perf, imporove bootstrap performance by making it unnecessary to add apps to workspace.jsonc #8965

Merged
merged 2 commits into from
Jun 21, 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
2 changes: 1 addition & 1 deletion scopes/component/status/mini-status-cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ this command only checks source code changes, it doesn't check for config/aspect
return `${modifiedOutput}\n\n${newOutput}${compWithIssuesOutput}`;
}

async json([pattern]: [string], opts: MiniStatusOpts) {
async json([pattern]: [string], opts: MiniStatusOpts): Promise<Record<string, any>> {
const { modified, newComps, compWithIssues } = await this.status.statusMini(pattern, opts);
return {
modified: modified.map((m) => m.toStringWithoutVersion()),
Expand Down
1 change: 1 addition & 0 deletions scopes/harmony/application/app.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class AppListCmd implements Command {
constructor(private applicationAspect: ApplicationMain) {}

async report(args: [string], { json }: { json: boolean }) {
await this.applicationAspect.loadAllAppsAsAspects();
const appComponents = this.applicationAspect.mapApps();
if (json) return JSON.stringify(appComponents, null, 2);
if (!appComponents.length) return chalk.yellow('no apps found');
Expand Down
17 changes: 17 additions & 0 deletions scopes/harmony/application/application.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,18 @@ export class ApplicationMain {
return this.appSlot.toArray();
}

/**
* instead of adding apps to workspace.jsonc, this method gets all apps components and load them as aspects so then
* they could register to the apps slots and be available to list/run etc.
*/
async loadAllAppsAsAspects() {
const apps = await this.listAppsComponents();
await this.componentAspect.getHost().loadAspects(apps.map((a) => a.id.toString()));
}

/**
* list apps by a component id.
* make sure to call `this.loadAllAppsAsAspects` before calling this method in case the app is not listed in workspace.jsonc
*/
listAppsById(id?: ComponentID): Application[] | undefined {
if (!id) return undefined;
Expand All @@ -122,6 +132,7 @@ export class ApplicationMain {

/**
* get an application by a component id.
* make sure to call `this.loadAllAppsAsAspects` before calling this method in case the app is not listed in workspace.jsonc
*/
async getAppById(id: ComponentID) {
const apps = await this.listAppsById(id);
Expand Down Expand Up @@ -232,6 +243,7 @@ export class ApplicationMain {

/**
* get an app.
* make sure to call `this.loadAllAppsAsAspects` before calling this method in case the app is not listed in workspace.jsonc
*/
getApp(appName: string, id?: ComponentID): Application | undefined {
const apps = id ? this.listAppsById(id) : this.listApps();
Expand Down Expand Up @@ -279,6 +291,7 @@ export class ApplicationMain {

/**
* get app to throw.
* make sure to call `this.loadAllAppsAsAspects` before calling this method in case the app is not listed in workspace.jsonc
*/
getAppOrThrow(appName: string): Application {
const app = this.getAppByNameOrId(appName);
Expand All @@ -305,6 +318,10 @@ export class ApplicationMain {
return this;
}

/**
* run an app.
* make sure to call `this.loadAllAppsAsAspects` before calling this method in case the app is not listed in workspace.jsonc
*/
async runApp(
appName: string,
options?: ServeAppOptions
Expand Down
1 change: 1 addition & 0 deletions scopes/harmony/application/run.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class RunCmd implements Command {
) {}

async wait([appName]: [string], { dev, watch, ssr, port: exactPort }: RunOptions) {
await this.application.loadAllAppsAsAspects();
// remove wds logs until refactoring webpack to a worker through the Worker aspect.
this.logger.off();
const { port, errors, isOldApi } = await this.application.runApp(appName, {
Expand Down