|
3 | 3 |
|
4 | 4 | import * as path from 'node:path'; |
5 | 5 |
|
6 | | -import { FileSystem, Import, JsonFile, type IDependenciesMetaTable } from '@rushstack/node-core-library'; |
| 6 | +import * as semver from 'semver'; |
| 7 | + |
| 8 | +import { |
| 9 | + FileSystem, |
| 10 | + Import, |
| 11 | + JsonFile, |
| 12 | + MapExtensions, |
| 13 | + type IDependenciesMetaTable |
| 14 | +} from '@rushstack/node-core-library'; |
7 | 15 |
|
8 | 16 | import { subspacePnpmfileShimFilename, scriptsFolderPath } from '../../utilities/PathConstants'; |
9 | 17 | import type { ISubspacePnpmfileShimSettings, IWorkspaceProjectInfo } from './IPnpmfile'; |
10 | 18 | import type { RushConfiguration } from '../../api/RushConfiguration'; |
11 | 19 | import type { RushConfigurationProject } from '../../api/RushConfigurationProject'; |
12 | 20 | import type { PnpmPackageManager } from '../../api/packageManager/PnpmPackageManager'; |
| 21 | +import type { CommonVersionsConfiguration } from '../../api/CommonVersionsConfiguration'; |
13 | 22 | import { RushConstants } from '../RushConstants'; |
14 | 23 | import type { Subspace } from '../../api/Subspace'; |
15 | 24 | import type { PnpmOptionsConfiguration } from './PnpmOptionsConfiguration'; |
@@ -80,9 +89,35 @@ export class SubspacePnpmfileConfiguration { |
80 | 89 | (subspace.contains(project) ? subspaceProjects : workspaceProjects)[packageName] = workspaceProjectInfo; |
81 | 90 | } |
82 | 91 |
|
| 92 | + let allPreferredVersions: { [dependencyName: string]: string } = {}; |
| 93 | + let allowedAlternativeVersions: { [dependencyName: string]: readonly string[] } = {}; |
| 94 | + |
| 95 | + // Populate preferred versions from subspace's common-versions.json (same as non-subspace pnpmfile shim) |
| 96 | + const pnpmOptions: PnpmOptionsConfiguration = |
| 97 | + rushConfiguration.packageManagerOptions as PnpmOptionsConfiguration; |
| 98 | + if (pnpmOptions?.useWorkspaces) { |
| 99 | + const commonVersionsConfiguration: CommonVersionsConfiguration = subspace.getCommonVersions(variant); |
| 100 | + const preferredVersions: Map<string, string> = new Map(); |
| 101 | + MapExtensions.mergeFromMap( |
| 102 | + preferredVersions, |
| 103 | + rushConfiguration.getImplicitlyPreferredVersions(subspace, variant) |
| 104 | + ); |
| 105 | + for (const [name, version] of commonVersionsConfiguration.getAllPreferredVersions()) { |
| 106 | + if (!preferredVersions.has(name) || semver.subset(version, preferredVersions.get(name)!)) { |
| 107 | + preferredVersions.set(name, version); |
| 108 | + } |
| 109 | + } |
| 110 | + allPreferredVersions = MapExtensions.toObject(preferredVersions); |
| 111 | + allowedAlternativeVersions = MapExtensions.toObject( |
| 112 | + commonVersionsConfiguration.allowedAlternativeVersions |
| 113 | + ); |
| 114 | + } |
| 115 | + |
83 | 116 | const settings: ISubspacePnpmfileShimSettings = { |
84 | 117 | workspaceProjects, |
85 | 118 | subspaceProjects, |
| 119 | + allPreferredVersions, |
| 120 | + allowedAlternativeVersions, |
86 | 121 | semverPath: Import.resolveModule({ modulePath: 'semver', baseFolderPath: __dirname }) |
87 | 122 | }; |
88 | 123 |
|
|
0 commit comments