Skip to content

Commit

Permalink
avoid loading an app that its env was not loaded yet (#9194)
Browse files Browse the repository at this point in the history
This PR fixes an issue of app data not being saved after running "create
component" and then "snap" from the extension. The reason it happened is
complex. It involves node.js caching package.json info and an API call
of "getCompsMetadata" that was executed during the "create component"
call.
Because "getCompsMetadata" gets app-data, it tries to load the apps as
plugins, which makes node access its package.json. At this stage, the
package.json didn't have the "type: module" yet, so node.js assumes this
is a CJS file.
Later, bit re-write the package.json with the data from the env, which
includes "type: module", but it's too late. Node.js already cached the
package.json and refuses to see the change.

This fix block the access to the app files unless the env is fully
loaded, which then we assume the package.json is correct.
  • Loading branch information
davidfirst authored Sep 14, 2024
1 parent ed14cf1 commit fc28ddb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scopes/harmony/application/application.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,14 @@ export class ApplicationMain {
*/
async loadAllAppsAsAspects(poolIds?: ComponentID[]): Promise<ComponentID[]> {
const apps = await this.listAppsComponents(poolIds);
const appIds = apps.map((app) => app.id);
// do not load apps that their env was not loaded yet. their package-json may not be up to date. e.g. it could be
// cjs, when the env needs it as esm. once it is loaded, node.js saved the package.json in the cache with no way to
// refresh it.
const appsWithEnvLoaded = apps.filter((app) => !app.state.issues.getIssueByName('NonLoadedEnv'));
if (apps.length !== appsWithEnvLoaded.length) {
this.logger.warn(`some apps were not loaded as aspects because their env was not loaded yet`);
}
const appIds = appsWithEnvLoaded.map((app) => app.id);
await this.componentAspect.getHost().loadAspects(appIds.map((id) => id.toString()));
return appIds;
}
Expand Down

0 comments on commit fc28ddb

Please sign in to comment.