Skip to content
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
18 changes: 14 additions & 4 deletions scopes/dependencies/dependency-resolver/dependency-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export type GetComponentManifestsOptions = {
excludeExtensionsDependencies?: boolean;
} & Pick<
PackageManagerInstallOptions,
'dedupe' | 'dependencyFilterFn' | 'copyPeerToRuntimeOnComponents' | 'copyPeerToRuntimeOnRoot' | 'installPeersFromEnvs'
| 'dedupe'
| 'dependencyFilterFn'
| 'copyPeerToRuntimeOnComponents'
| 'copyPeerToRuntimeOnRoot'
| 'installPeersFromEnvs'
| 'resolveEnvPeersFromRoot'
>;

export type PreInstallSubscriber = (installer: DependencyInstaller, installArgs: InstallArgs) => Promise<void>;
Expand Down Expand Up @@ -127,7 +132,7 @@ export class DependencyInstaller {
if (!finalRootDir) {
throw new RootDirNotDefined();
}
const manifests = await this.getComponentManifests({
const { manifests } = await this.getComponentManifests({
...packageManagerOptions,
componentDirectoryMap,
rootPolicy,
Expand Down Expand Up @@ -301,12 +306,16 @@ export class DependencyInstaller {
copyPeerToRuntimeOnComponents,
copyPeerToRuntimeOnRoot,
installPeersFromEnvs,
resolveEnvPeersFromRoot,
resolveVersionsFromDependenciesOnly,
referenceLocalPackages,
includeAllEnvPeers,
hasRootComponents,
excludeExtensionsDependencies,
}: GetComponentManifestsOptions) {
}: GetComponentManifestsOptions): Promise<{
manifests: Record<string, ProjectManifest>;
peerOverrides: Record<string, string>;
}> {
const options: CreateFromComponentsOptions = {
filterComponentsFromManifests: true,
createManifestForComponentsWithoutDependencies: true,
Expand Down Expand Up @@ -341,9 +350,10 @@ export class DependencyInstaller {
manifests[rootDir] = workspaceManifest.toJson({
copyPeerToRuntime: copyPeerToRuntimeOnRoot,
installPeersFromEnvs,
resolveEnvPeersFromRoot,
Comment on lines 350 to +353
});
}
return manifests;
return { manifests, peerOverrides: workspaceManifest.peerOverrides };
}

private async cleanCompsNodeModules(componentDirectoryMap: ComponentMap<string>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,25 @@ export interface DependencyResolverWorkspaceConfig {
*/
autoInstallPeers?: boolean;

/**
* When true (default), env peer dependencies defined in env.jsonc are resolved once and merged
* into the workspace root manifest as regular dependencies, instead of being injected into each
* component's manifest individually. Conflicts between envs are resolved by picking the version
* that satisfies the most envs, with a warning logged for any conflicts.
* Set to false to revert to the legacy per-component env peer injection behavior.
*/
resolveEnvPeersFromRoot?: boolean;

/**
* When true, ALL env peer dependencies are forced to the workspace root manifest,
* even when different envs specify conflicting versions. The best version is chosen
* (satisfying the most envs) and a warning is logged for unsatisfied envs.
* When false (default), conflicting peers without `workspaceSingleton` are injected
* per-component, allowing different envs to use different versions.
* Only applies when resolveEnvPeersFromRoot is true.
*/
forceEnvPeersToRoot?: boolean;
Comment thread
davidfirst marked this conversation as resolved.

/**
* By default, Bit saves component dependencies with exact versions (pinned) in the package.json,
* even if the dependency-resolver policy specifies a version range.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,15 @@ export class DependencyResolverMain {
...defaultCreateFromComponentsOptions,
...options,
};
const workspaceManifestFactory = new WorkspaceManifestFactory(this, this.aspectLoader);
const resolveEnvPeersFromRoot = context?.inCapsule ? false : (this.config.resolveEnvPeersFromRoot ?? true);
const forceEnvPeersToRoot = this.config.forceEnvPeersToRoot ?? false;
const workspaceManifestFactory = new WorkspaceManifestFactory(this,
this.aspectLoader,
this.logger,
resolveEnvPeersFromRoot,
forceEnvPeersToRoot
);

const res = await workspaceManifestFactory.createFromComponents(
name,
version,
Expand Down Expand Up @@ -893,7 +901,7 @@ export class DependencyResolverMain {
const packageManager = this.getPackageManager();
let peerDependencyIssues!: PeerDependencyIssuesByProjects;
const installer = this.getInstaller();
const manifests = await installer.getComponentManifests({
const { manifests } = await installer.getComponentManifests({
...options,
componentDirectoryMap,
rootPolicy,
Expand Down Expand Up @@ -1157,9 +1165,14 @@ export class DependencyResolverMain {
}
const policy = envManifest?.policy;
if (!policy) return undefined;
const allPoliciesFromEnv = EnvPolicy.fromConfigObject(policy, {
includeLegacyPeersInSelfPolicy: envComponent && this.envs.isCoreEnv(envComponent.id.toStringWithoutVersion()),
});
const envId = envComponent?.id.toStringWithoutVersion();
const allPoliciesFromEnv = EnvPolicy.fromConfigObject(
policy,
{
includeLegacyPeersInSelfPolicy: envComponent && this.envs.isCoreEnv(envComponent.id.toStringWithoutVersion()),
},
envId
);
return allPoliciesFromEnv;
}

Expand Down Expand Up @@ -1213,9 +1226,11 @@ export class DependencyResolverMain {
const policiesFromEnvConfig = await env.getDependencies();
if (policiesFromEnvConfig) {
const idWithoutVersion = options.envId.split('@')[0];
const allPoliciesFromEnv = EnvPolicy.fromConfigObject(policiesFromEnvConfig, {
includeLegacyPeersInSelfPolicy: this.envs.isCoreEnv(idWithoutVersion),
});
const allPoliciesFromEnv = EnvPolicy.fromConfigObject(
policiesFromEnvConfig,
{ includeLegacyPeersInSelfPolicy: this.envs.isCoreEnv(idWithoutVersion) },
idWithoutVersion
);
return allPoliciesFromEnv;
}
}
Expand Down
Loading