Skip to content

Commit 7c6bd39

Browse files
committed
Use shrinkwrap to resolve version
1 parent dce3308 commit 7c6bd39

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

‎apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import pnpmLinkBins from '@pnpm/link-bins';
99
import {
1010
JsonFile,
1111
Text,
12-
IPackageJson,
1312
PackageName,
1413
FileSystem,
1514
FileConstants,
@@ -23,7 +22,7 @@ import { BasePackage } from '../base/BasePackage';
2322
import { RushConstants } from '../../logic/RushConstants';
2423
import { IRushLinkJson } from '../../api/RushConfiguration';
2524
import { RushConfigurationProject } from '../../api/RushConfigurationProject';
26-
import { PnpmShrinkwrapFile } from './PnpmShrinkwrapFile';
25+
import { PnpmShrinkwrapFile, IPnpmShrinkwrapDependencyYaml } from './PnpmShrinkwrapFile';
2726
import { PnpmProjectDependencyManifest } from './PnpmProjectDependencyManifest';
2827

2928
// special flag for debugging, will print extra diagnostic information,
@@ -249,11 +248,17 @@ export class PnpmLinkManager extends BaseLinkManager {
249248

250249
const newLocalFolderPath: string = path.join(localPackage.folderPath, 'node_modules', dependencyName);
251250

252-
// read the version number
253-
const packageJsonForDependency: IPackageJson = JsonFile.load(
254-
path.join(dependencyLocalInstallationRealpath, FileConstants.PackageJson)
255-
);
256-
const version: string | undefined = packageJsonForDependency.version;
251+
// read the version number from the shrinkwrap entry
252+
const shrinkwrapEntry: IPnpmShrinkwrapDependencyYaml | undefined =
253+
pnpmShrinkwrapFile.getShrinkwrapEntryFromTempProjectDependencyKey(tempProjectDependencyKey);
254+
if (!shrinkwrapEntry) {
255+
throw new InternalError(`Cannot find shrinkwrap entry using dependency key for temp project: ${project.tempProjectName}`);
256+
}
257+
258+
const version: string | undefined = shrinkwrapEntry.dependencies[dependencyName];
259+
if (!version) {
260+
throw new InternalError(`Cannot find shrinkwrap entry dependency "${dependencyName}" for temp project: ${project.tempProjectName}`);
261+
}
257262

258263
const newLocalPackage: BasePackage = BasePackage.createLinkedPackage(
259264
dependencyName,

‎apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,14 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
226226
return undefined;
227227
}
228228

229-
public getShrinkwrapEntry(name: string, version: string): IPnpmShrinkwrapDependencyYaml | undefined {
230-
const packagePath: string = `/${name}/${version}`;
231-
const foundEntry: IPnpmShrinkwrapDependencyYaml | undefined = this._shrinkwrapJson.packages[packagePath];
232-
if (foundEntry) {
233-
return foundEntry;
234-
}
229+
public getShrinkwrapEntryFromTempProjectDependencyKey(
230+
tempProjectDependencyKey: string
231+
): IPnpmShrinkwrapDependencyYaml | undefined {
232+
return this._shrinkwrapJson.packages[tempProjectDependencyKey];
233+
}
235234

236-
const extendedPackagePath: string = `${packagePath}_`;
237-
const similarPackages: string[] =
238-
Object.keys(this._shrinkwrapJson.packages).filter(p => p.lastIndexOf(extendedPackagePath, 0) === 0);
239-
return similarPackages.length === 1 ? this._shrinkwrapJson.packages[similarPackages[0]] : undefined;
235+
public getShrinkwrapEntry(name: string, version: string): IPnpmShrinkwrapDependencyYaml | undefined {
236+
return this._shrinkwrapJson.packages[`/${name}/${version}`];
240237
}
241238

242239
/**

0 commit comments

Comments
 (0)