Skip to content

Commit b9af294

Browse files
authored
Merge pull request microsoft#1542 from microsoft/sachinjoseph/ImproveSupportForPnpmLockfile5_1
[rush] Improve support for pnpm lockfile format 5.1
2 parents f7a39bc + 8f2a10c commit b9af294

3 files changed

Lines changed: 65 additions & 13 deletions

File tree

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

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,55 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
184184
* Gets the version number from the list of top-level dependencies in the "dependencies" section
185185
* of the shrinkwrap file. Sample return values:
186186
* '2.1.113'
187-
* '1.9.0-dev.27_typescript@2.9.2'
188-
* '5.0.0_25c559a5921686293a001a397be4dce0'
187+
* '1.9.0-dev.27'
189188
* 'file:projects/empty-webpart-project.tgz'
190-
* 'file:projects/article-site-demo.tgz_jest@22.4.4+typescript@2.9.2'
191-
* 'file:projects/i18n-utilities.tgz_462eaf34881863298955eb323c130fc7'
192189
* undefined
193190
*
194191
* @override
195192
*/
196193
public getTopLevelDependencyVersion(dependencyName: string): DependencySpecifier | undefined {
197-
const value: string | undefined = BaseShrinkwrapFile.tryGetValue(this._shrinkwrapJson.dependencies, dependencyName);
194+
let value: string | undefined = BaseShrinkwrapFile.tryGetValue(this._shrinkwrapJson.dependencies, dependencyName);
198195
if (value) {
196+
197+
// Getting the top level depenedency version from a PNPM lockfile version 5.1
198+
// --------------------------------------------------------------------------
199+
//
200+
// 1) Top-level tarball dependency entries in pnpm-lock.yaml look like:
201+
// '@rush-temp/sp-filepicker': 'file:projects/sp-filepicker.tgz_0ec79d3b08edd81ebf49cd19ca50b3f5'
202+
203+
// Then, it would be defined below:
204+
// 'file:projects/sp-filepicker.tgz_0ec79d3b08edd81ebf49cd19ca50b3f5':
205+
// dependencies:
206+
// '@microsoft/load-themed-styles': 1.10.7
207+
// ...
208+
// resolution:
209+
// integrity: sha512-guuoFIc**==
210+
// tarball: 'file:projects/sp-filepicker.tgz'
211+
212+
// Here, we are interested in the part 'file:projects/sp-filepicker.tgz'. Splitting by underscores is not the
213+
// best way to get this because file names could have underscores in them. Instead, we could use the tarball
214+
// field in the resolution section.
215+
216+
// 2) Top-level non-tarball dependency entries in pnpm-lock.yaml would look like:
217+
// '@microsoft/set-webpack-public-path-plugin': 2.1.133
218+
// @microsoft/sp-build-node': 1.9.0-dev.27_typescript@2.9.2
219+
220+
// Here, we could just split by underscores and take the first part.
221+
222+
// The below code is also compatible with lockfile versions < 5.1
223+
224+
const dependency: IPnpmShrinkwrapDependencyYaml = this._shrinkwrapJson.packages[value];
225+
226+
if (dependency && dependency.resolution && dependency.resolution.tarball &&
227+
value.startsWith(dependency.resolution.tarball)) {
228+
return new DependencySpecifier(dependencyName, dependency.resolution.tarball);
229+
} else {
230+
const underscoreIndex: number = value.indexOf('_');
231+
if (underscoreIndex >= 0) {
232+
value = value.substr(0, underscoreIndex);
233+
}
234+
}
235+
199236
return new DependencySpecifier(dependencyName, value);
200237
}
201238
return undefined;
@@ -206,23 +243,27 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
206243
*
207244
* ```
208245
* dependencies:
209-
* '@rush-temp/my-app': 'file:projects/my-app.tgz'
246+
* '@rush-temp/my-app': 'file:projects/my-app.tgz_25c559a5921686293a001a397be4dce0'
210247
* packages:
211248
* /@types/node/10.14.15:
212249
* dev: false
213-
* 'file:projects/my-app.tgz':
250+
* 'file:projects/my-app.tgz_25c559a5921686293a001a397be4dce0':
214251
* dev: false
215252
* name: '@rush-temp/my-app'
216253
* version: 0.0.0
217254
* ```
218255
*
219-
* We refer to "file:projects/my-app.tgz" as the temp project dependency key.
256+
* We refer to 'file:projects/my-app.tgz_25c559a5921686293a001a397be4dce0' as the temp project dependency key
257+
* of the temp project '@rush-temp/my-app'.
220258
*/
221259
public getTempProjectDependencyKey(tempProjectName: string): string | undefined {
222-
const tempProjectSpecifier: DependencySpecifier | undefined = this.getTopLevelDependencyVersion(tempProjectName);
223-
if (tempProjectSpecifier) {
224-
return tempProjectSpecifier.versionSpecifier;
260+
const tempProjectDependencyKey: string | undefined =
261+
BaseShrinkwrapFile.tryGetValue(this._shrinkwrapJson.dependencies, tempProjectName);
262+
263+
if (tempProjectDependencyKey) {
264+
return tempProjectDependencyKey;
225265
}
266+
226267
return undefined;
227268
}
228269

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

Lines changed: 2 additions & 2 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": "Improve support for pnpm lockfile version 5.1. Also fixes a regression in Rush 5.12.0 in which rush install can fail on pnpm 3.5+ with the error message \"ERROR: Invalid Version\"",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "sachinjoseph@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)