Skip to content

Commit

Permalink
Merge pull request #3908 from jeremymeng/fix-pnpm-v7-local-path-3652
Browse files Browse the repository at this point in the history
[rush-lib] react to pnpm v7 local install path breaking change
  • Loading branch information
iclanton authored Jan 24, 2023
2 parents 339d7ef + 05fd45c commit 8e37354
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix linking error due to PNPM v7 local install path breaking change",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
4 changes: 4 additions & 0 deletions common/config/rush/browser-approved-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"name": "cors",
"allowedCategories": [ "libraries" ]
},
{
"name": "dependency-path",
"allowedCategories": [ "libraries" ]
},
{
"name": "office-ui-fabric-core",
"allowedCategories": [ "libraries" ]
Expand Down
56 changes: 55 additions & 1 deletion common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/config/rush/repo-state.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "2b28a3b0d2c74bd1a0a620cb83c8e67329d0d13e",
"pnpmShrinkwrapHash": "63cf094bd4876739348f39843a52fae39798f004",
"preferredVersionsHash": "5222ca779ae69ebfd201e39c17f48ce9eaf8c3c2"
}
1 change: 1 addition & 0 deletions libraries/rush-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"builtin-modules": "~3.1.0",
"cli-table": "~0.3.1",
"colors": "~1.2.1",
"dependency-path": "~9.2.8",
"figures": "3.0.0",
"git-repo-info": "~2.1.0",
"glob-escape": "~0.0.2",
Expand Down
24 changes: 22 additions & 2 deletions libraries/rush-lib/src/logic/pnpm/PnpmLinkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as crypto from 'crypto';
import uriEncode from 'strict-uri-encode';
import pnpmLinkBins from '@pnpm/link-bins';
import * as semver from 'semver';
import { depPathToFilename } from 'dependency-path';
import colors from 'colors/safe';

import {
Expand Down Expand Up @@ -217,6 +218,7 @@ export class PnpmLinkManager extends BaseLinkManager {

// e.g.: C:\wbt\common\temp\node_modules\.local\C%3A%2Fwbt%2Fcommon%2Ftemp%2Fprojects%2Fapi-documenter.tgz\node_modules
const pathToLocalInstallation: string = this._getPathToLocalInstallation(
tarballEntry,
absolutePathToTgzFile,
folderNameSuffix
);
Expand Down Expand Up @@ -272,8 +274,12 @@ export class PnpmLinkManager extends BaseLinkManager {
});
}

private _getPathToLocalInstallation(absolutePathToTgzFile: string, folderSuffix: string): string {
if (this._pnpmVersion.major >= 6) {
private _getPathToLocalInstallation(
tarballEntry: string,
absolutePathToTgzFile: string,
folderSuffix: string
): string {
if (this._pnpmVersion.major === 6) {
// PNPM 6 changed formatting to replace all ':' and '/' chars with '+'. Additionally, folder names > 120
// are trimmed and hashed. NOTE: PNPM internally uses fs.realpath.native, which will cause additional
// issues in environments that do not support long paths.
Expand All @@ -294,6 +300,20 @@ export class PnpmLinkManager extends BaseLinkManager {
.digest('hex')}`;
}

return path.join(
this._rushConfiguration.commonTempFolder,
RushConstants.nodeModulesFolderName,
'.pnpm',
folderName,
RushConstants.nodeModulesFolderName
);
} else if (this._pnpmVersion.major >= 7) {
// PNPM 7 changed the local path format again and the hashing algorithm
// See https://github.com/pnpm/pnpm/releases/tag/v7.0.0
// e.g.:
// [email protected]
const escapedLocalPath: string = depPathToFilename(tarballEntry);
const folderName: string = `${escapedLocalPath}${folderSuffix}`;
return path.join(
this._rushConfiguration.commonTempFolder,
RushConstants.nodeModulesFolderName,
Expand Down

0 comments on commit 8e37354

Please sign in to comment.