Skip to content

Commit e824819

Browse files
authored
Merge pull request #1393 from microsoft/sachinjoseph/fix1392
[rush] Fix #1392 "rush install not working on pnpm 3.5" by getting the temporary project dependency key from the shrinkwrap
2 parents 1d593b9 + fdf1670 commit e824819

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,18 @@ export class PnpmLinkManager extends BaseLinkManager {
155155
// file:projects/bentleyjs-core.tgz
156156
// file:projects/build-tools.tgz_dc21d88642e18a947127a751e00b020a
157157
// file:projects/[email protected]
158-
const topLevelDependencyVersion: string | undefined =
158+
const tempProjectDependencyKey: string | undefined =
159159
pnpmShrinkwrapFile.getTopLevelDependencyVersion(project.tempProjectName);
160160

161-
if (!topLevelDependencyVersion) {
162-
throw new InternalError(`Cannot find top level dependency for "${project.tempProjectName}"` +
163-
` in shrinkwrap.`);
161+
if (!tempProjectDependencyKey) {
162+
throw new Error(`Cannot get dependency key for temp project: `
163+
+ `${project.tempProjectName}`);
164164
}
165-
166165
// e.g.: file:projects/project-name.tgz
167-
const tarballEntry: string | undefined = pnpmShrinkwrapFile.getTarballPath(topLevelDependencyVersion);
166+
const tarballEntry: string | undefined = pnpmShrinkwrapFile.getTarballPath(tempProjectDependencyKey);
168167

169168
if (!tarballEntry) {
170-
throw new InternalError(`Cannot find tarball path for "${topLevelDependencyVersion}"` +
169+
throw new InternalError(`Cannot find tarball path for "${project.tempProjectName}"` +
171170
` in shrinkwrap.`);
172171
}
173172

@@ -191,8 +190,8 @@ export class PnpmLinkManager extends BaseLinkManager {
191190
// '' [empty string]
192191
193192
// _2a665c89609864b4e75bc5365d7f8f56
194-
const folderNameSuffix: string = (tarballEntry && tarballEntry.length < topLevelDependencyVersion.length ?
195-
topLevelDependencyVersion.slice(tarballEntry.length) : '');
193+
const folderNameSuffix: string = (tarballEntry && tarballEntry.length < tempProjectDependencyKey.length ?
194+
tempProjectDependencyKey.slice(tarballEntry.length) : '');
196195

197196
// e.g.:
198197
// C%3A%2Fwbt%2Fcommon%2Ftemp%2Fprojects%2Fapi-documenter.tgz

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as yaml from 'js-yaml';
22
import * as os from 'os';
33
import * as semver from 'semver';
4-
import { PackageName, FileSystem } from '@microsoft/node-core-library';
4+
import { FileSystem } from '@microsoft/node-core-library';
55

66
import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile';
77

@@ -162,7 +162,14 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
162162

163163
/**
164164
* Gets the version number from the list of top-level dependencies in the "dependencies" section
165-
* of the shrinkwrap file
165+
* of the shrinkwrap file. Sample return values:
166+
* '2.1.113'
167+
168+
* '5.0.0_25c559a5921686293a001a397be4dce0'
169+
* 'file:projects/empty-webpart-project.tgz'
170+
171+
* 'file:projects/i18n-utilities.tgz_462eaf34881863298955eb323c130fc7'
172+
* undefined
166173
*/
167174
public getTopLevelDependencyVersion(dependencyName: string): string | undefined {
168175
return BaseShrinkwrapFile.tryGetValue(this._shrinkwrapJson.dependencies, dependencyName);
@@ -191,7 +198,13 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
191198
// Because of this, we actually need to check for a version that this package is directly
192199
// linked to.
193200

194-
const tempProjectDependencyKey: string = this._getTempProjectKey(tempProjectName);
201+
const tempProjectDependencyKey: string | undefined = this.getTopLevelDependencyVersion(tempProjectName);
202+
203+
if (!tempProjectDependencyKey) {
204+
throw new Error(`Cannot get dependency key for temp project: `
205+
+ `${tempProjectName}`);
206+
}
207+
195208
const packageDescription: IPnpmShrinkwrapDependencyYaml | undefined =
196209
this._getPackageDescription(tempProjectDependencyKey);
197210
if (!packageDescription) {
@@ -259,7 +272,13 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
259272
* Returns the version of a dependency being used by a given project
260273
*/
261274
private _getDependencyVersion(dependencyName: string, tempProjectName: string): string | undefined {
262-
const tempProjectDependencyKey: string = this._getTempProjectKey(tempProjectName);
275+
const tempProjectDependencyKey: string | undefined = this.getTopLevelDependencyVersion(tempProjectName);
276+
277+
if (!tempProjectDependencyKey) {
278+
throw new Error(`Cannot get dependency key for temp project: `
279+
+ `${tempProjectName}`);
280+
}
281+
263282
const packageDescription: IPnpmShrinkwrapDependencyYaml | undefined =
264283
this._getPackageDescription(tempProjectDependencyKey);
265284
if (!packageDescription) {
@@ -292,12 +311,6 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
292311
return semver.valid(validDependencyVersion) ? validDependencyVersion : dependencyVersion.split('_')[0]!;
293312
}
294313

295-
private _getTempProjectKey(tempProjectName: string): string {
296-
// Example: "project1"
297-
const unscopedTempProjectName: string = PackageName.getUnscopedName(tempProjectName);
298-
return `file:projects/${unscopedTempProjectName}.tgz`;
299-
}
300-
301314
private _normalizeDependencyVersion(dependencyName: string, version: string): string | undefined {
302315
if (version) {
303316
const extractedVersion: string | undefined = extractVersionFromPnpmVersionSpecifier(version);

apps/rush-lib/src/logic/test/shrinkwrapFile/pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Fix 1392 \"rush install not working on pnpm 3.5\" by getting the temporary project dependency key from the shrinkwrap file. See https://github.com/microsoft/web-build-tools/issues/1392.",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "[email protected]"
11+
}

0 commit comments

Comments
 (0)