From e44458ae8fa164d698a46da61ad11e5aa788f173 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Thu, 19 Jun 2025 16:44:36 +0200 Subject: [PATCH 1/2] fix: loading dependencies from env without env.jsonc --- scopes/workspace/install/install.main.runtime.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/scopes/workspace/install/install.main.runtime.ts b/scopes/workspace/install/install.main.runtime.ts index b76cf2e04cdc..dc715570a9f0 100644 --- a/scopes/workspace/install/install.main.runtime.ts +++ b/scopes/workspace/install/install.main.runtime.ts @@ -325,6 +325,7 @@ export class InstallMain { linkNestedDepsInNM: !this.workspace.isLegacy && !hasRootComponents, }; const { linkedRootDeps } = await this.calculateLinks(linkOpts); + await this.compiler.compileOnWorkspace([], { initiator: CompilationInitiator.Install }); // eslint-disable-next-line prefer-const let { mergedRootPolicy, componentsAndManifests: current } = await this._getComponentsManifestsAndRootPolicy( installer, From 2709b7a22c765f056023c3cfb1aa2cade4e0df27 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Thu, 19 Jun 2025 17:36:46 +0200 Subject: [PATCH 2/2] fix: loading dependencies from env without env.jsonc --- .../compiler/workspace-compiler.ts | 43 +------------------ .../workspace/install/install.main.runtime.ts | 2 +- scopes/workspace/workspace/workspace.ts | 41 ++++++++++++++++++ 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/scopes/compilation/compiler/workspace-compiler.ts b/scopes/compilation/compiler/workspace-compiler.ts index 3d4a14b65735..2f3a5fc187ba 100644 --- a/scopes/compilation/compiler/workspace-compiler.ts +++ b/scopes/compilation/compiler/workspace-compiler.ts @@ -406,7 +406,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); @@ -421,47 +421,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, diff --git a/scopes/workspace/install/install.main.runtime.ts b/scopes/workspace/install/install.main.runtime.ts index dc715570a9f0..e32c643d9514 100644 --- a/scopes/workspace/install/install.main.runtime.ts +++ b/scopes/workspace/install/install.main.runtime.ts @@ -325,7 +325,6 @@ export class InstallMain { linkNestedDepsInNM: !this.workspace.isLegacy && !hasRootComponents, }; const { linkedRootDeps } = await this.calculateLinks(linkOpts); - await this.compiler.compileOnWorkspace([], { initiator: CompilationInitiator.Install }); // eslint-disable-next-line prefer-const let { mergedRootPolicy, componentsAndManifests: current } = await this._getComponentsManifestsAndRootPolicy( installer, @@ -647,6 +646,7 @@ export class InstallMain { linkedRootDeps: Record; } ): 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); diff --git a/scopes/workspace/workspace/workspace.ts b/scopes/workspace/workspace/workspace.ts index 78bc56a860ee..863bbac3c24a 100644 --- a/scopes/workspace/workspace/workspace.ts +++ b/scopes/workspace/workspace/workspace.ts @@ -2412,6 +2412,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))); + } } /**