Skip to content
Open
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
43 changes: 1 addition & 42 deletions scopes/compilation/compiler/workspace-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export class WorkspaceCompiler {
componentLoadOptions.loadSeedersAsAspects = false;
}
let components = await this.workspace.getMany(componentIds, componentLoadOptions);
await this.loadExternalEnvs(components);
await this.workspace.loadExternalEnvs(components);
// reload components as we might cleared the cache as part of the loadExternalEnvs
components = await this.workspace.getMany(componentIds, componentLoadOptions);
const grouped = await this.buildGroupsToCompile(components, graph);
Expand All @@ -423,47 +423,6 @@ export class WorkspaceCompiler {
return results.flat();
}

/**
* This will ensue that the envs of the components are loaded before the compilation starts.
* @param components
*/
private async loadExternalEnvs(components: Component[]) {
const componentsIdsStr = components.map((c) => c.id.toString());
const envIdsCompIdsMap = {};
const compsWithWrongEnvId: string[] = [];
await Promise.all(
components.map(async (component) => {
// It's important to use calculate here to get the real id even if it's not loaded
const envId = (await this.envs.calculateEnvId(component)).toString();
// This might be different from the env id above, because the component might be loaded before the env
// in that case we will need to clear the cache of that component
const envIdByGet = this.envs.getEnvId(component);
if (envId !== envIdByGet) {
compsWithWrongEnvId.push(component.id.toString());
}
// If it's part of the components it will be handled later as it's not external
// and might need to be compiled as well
if (componentsIdsStr.includes(envId)) return undefined;
if (!envIdsCompIdsMap[envId]) envIdsCompIdsMap[envId] = [component.id.toString()];
envIdsCompIdsMap[envId].push(component.id.toString());
})
);
const externalEnvsIds = Object.keys(envIdsCompIdsMap);

if (!externalEnvsIds.length) return;
const nonLoadedEnvs = externalEnvsIds.filter((envId) => !this.envs.isEnvRegistered(envId));
await this.workspace.loadAspects(nonLoadedEnvs);
const idsToClearCache: string[] = uniq(
nonLoadedEnvs
.reduce((acc, envId) => {
const compIds = envIdsCompIdsMap[envId];
return [...acc, ...compIds];
}, [] as string[])
.concat(compsWithWrongEnvId)
);
this.workspace.clearComponentsCache(idsToClearCache.map((id) => ComponentID.fromString(id)));
}

private async runCompileComponents(
components: Component[],
options: CompileOptions,
Expand Down
1 change: 1 addition & 0 deletions scopes/workspace/install/install.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ export class InstallMain {
linkedRootDeps: Record<string, string>;
}
): Promise<{ componentsAndManifests: ComponentsAndManifests; mergedRootPolicy: WorkspacePolicy }> {
await this.workspace.loadExternalEnvs(await this.workspace.getMany(this.workspace.listIds()));
const mergedRootPolicy = await this.addConfiguredAspectsToWorkspacePolicy();
await this.addConfiguredGeneratorEnvsToWorkspacePolicy(mergedRootPolicy);
const componentsAndManifests = await this._getComponentsManifests(installer, mergedRootPolicy, options);
Expand Down
41 changes: 41 additions & 0 deletions scopes/workspace/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2505,6 +2505,47 @@ the following envs are used in this workspace: ${uniq(availableEnvs).join(', ')}
});
return componentPolicies;
}

/**
* This will ensue that the envs of the components are loaded before the compilation starts.
* @param components
*/
public async loadExternalEnvs(components: Component[]) {
const componentsIdsStr = components.map((c) => c.id.toString());
const envIdsCompIdsMap = {};
const compsWithWrongEnvId: string[] = [];
await Promise.all(
components.map(async (component) => {
// It's important to use calculate here to get the real id even if it's not loaded
const envId = (await this.envs.calculateEnvId(component)).toString();
// This might be different from the env id above, because the component might be loaded before the env
// in that case we will need to clear the cache of that component
const envIdByGet = this.envs.getEnvId(component);
if (envId !== envIdByGet) {
compsWithWrongEnvId.push(component.id.toString());
}
// If it's part of the components it will be handled later as it's not external
// and might need to be compiled as well
if (componentsIdsStr.includes(envId)) return undefined;
if (!envIdsCompIdsMap[envId]) envIdsCompIdsMap[envId] = [component.id.toString()];
envIdsCompIdsMap[envId].push(component.id.toString());
})
);
const externalEnvsIds = Object.keys(envIdsCompIdsMap);

if (!externalEnvsIds.length) return;
const nonLoadedEnvs = externalEnvsIds.filter((envId) => !this.envs.isEnvRegistered(envId));
await this.loadAspects(nonLoadedEnvs);
const idsToClearCache: string[] = uniq(
nonLoadedEnvs
.reduce((acc, envId) => {
const compIds = envIdsCompIdsMap[envId];
return [...acc, ...compIds];
}, [] as string[])
.concat(compsWithWrongEnvId)
);
this.clearComponentsCache(idsToClearCache.map((id) => ComponentID.fromString(id)));
}
}

/**
Expand Down