Skip to content

Commit fc28ddb

Browse files
authored
avoid loading an app that its env was not loaded yet (#9194)
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.
1 parent ed14cf1 commit fc28ddb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

scopes/harmony/application/application.main.runtime.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,14 @@ export class ApplicationMain {
129129
*/
130130
async loadAllAppsAsAspects(poolIds?: ComponentID[]): Promise<ComponentID[]> {
131131
const apps = await this.listAppsComponents(poolIds);
132-
const appIds = apps.map((app) => app.id);
132+
// 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
133+
// 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
134+
// refresh it.
135+
const appsWithEnvLoaded = apps.filter((app) => !app.state.issues.getIssueByName('NonLoadedEnv'));
136+
if (apps.length !== appsWithEnvLoaded.length) {
137+
this.logger.warn(`some apps were not loaded as aspects because their env was not loaded yet`);
138+
}
139+
const appIds = appsWithEnvLoaded.map((app) => app.id);
133140
await this.componentAspect.getHost().loadAspects(appIds.map((id) => id.toString()));
134141
return appIds;
135142
}

0 commit comments

Comments
 (0)