Skip to content

Commit 9428ecb

Browse files
authored
Merge pull request microsoft#1577 from microsoft/sachinjoseph/SupportForPnpm4
[rush] Support for PNPM 4 (Experimental)
2 parents 588979d + 51bc40a commit 9428ecb

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ yarn-error.log*
99
*.seed
1010
*.pid.lock
1111

12+
# Visual Studio Code
13+
.vscode
14+
1215
# Directory for instrumented libs generated by jscoverage/JSCover
1316
lib-cov
1417

apps/rush-lib/src/api/packageManager/PnpmPackageManager.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import * as semver from 'semver';
55
import { RushConstants } from '../../logic/RushConstants';
66
import { PackageManager } from './PackageManager';
7+
import * as path from 'path';
78

89
/**
910
* Support for interacting with the PNPM package manager.
@@ -14,6 +15,9 @@ export class PnpmPackageManager extends PackageManager {
1415
*/
1516
public readonly supportsResolutionStrategy: boolean;
1617

18+
// example: node_modules/.pnpm/lock.yaml
19+
public readonly internalShrinkwrapRelativePath: string;
20+
1721
/** @internal */
1822
public constructor(version: string) {
1923
super(version, 'pnpm');
@@ -32,5 +36,17 @@ export class PnpmPackageManager extends PackageManager {
3236
} else {
3337
this._shrinkwrapFilename = RushConstants.pnpmV1ShrinkwrapFilename;
3438
}
39+
40+
if (parsedVersion.major <= 2) {
41+
// node_modules/.shrinkwrap.yaml
42+
this.internalShrinkwrapRelativePath = path.join('node_modules', '.shrinkwrap.yaml');
43+
} else if (parsedVersion.major <= 3) {
44+
// node_modules/.pnpm-lock.yaml
45+
this.internalShrinkwrapRelativePath = path.join('node_modules', '.pnpm-lock.yaml');
46+
} else {
47+
// node_modules/.pnpm/lock.yaml
48+
// See https://github.com/pnpm/pnpm/releases/tag/v4.0.0 for more details.
49+
this.internalShrinkwrapRelativePath = path.join('node_modules', '.pnpm', 'lock.yaml');
50+
}
3551
}
3652
}

apps/rush-lib/src/logic/InstallManager.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,6 @@ export class InstallManager {
740740
FileSystem.deleteFile(this._rushConfiguration.tempShrinkwrapFilename);
741741

742742
if (this._rushConfiguration.packageManager === 'pnpm') {
743-
const commonNodeModulesFolder: string = path.join(this._rushConfiguration.commonTempFolder, 'node_modules');
744-
745743
// Workaround for https://github.com/pnpm/pnpm/issues/1890
746744
//
747745
// When "rush update --full" is run, rush deletes common/temp/pnpm-lock.yaml so that
@@ -750,10 +748,11 @@ export class InstallManager {
750748
// new lockfile. Deleting this file in addition to deleting common/temp/pnpm-lock.yaml
751749
// ensures that a new lockfile will be generated with "rush update --full".
752750

753-
// Note that there is period in the file name: common/temp/node_modules/.pnpm-lock.yaml
754-
const pnpmShrinkwrapInNodeModulesFolder: string = path.join(commonNodeModulesFolder, '.'
755-
+ this._rushConfiguration.shrinkwrapFilename);
756-
FileSystem.deleteFile(pnpmShrinkwrapInNodeModulesFolder);
751+
const pnpmPackageManager: PnpmPackageManager =
752+
(this._rushConfiguration.packageManagerWrapper as PnpmPackageManager);
753+
754+
FileSystem.deleteFile(path.join(this._rushConfiguration.commonTempFolder,
755+
pnpmPackageManager.internalShrinkwrapRelativePath));
757756
}
758757
}
759758

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as os from 'os';
55
import * as path from 'path';
66
import uriEncode = require('strict-uri-encode');
77
import pnpmLinkBins from '@pnpm/link-bins';
8+
import * as semver from 'semver';
89

910
import {
1011
JsonFile,
@@ -30,6 +31,10 @@ import { PnpmProjectDependencyManifest } from './PnpmProjectDependencyManifest';
3031
const DEBUG: boolean = false;
3132

3233
export class PnpmLinkManager extends BaseLinkManager {
34+
35+
private readonly _pnpmVersion: semver.SemVer
36+
= new semver.SemVer(this._rushConfiguration.packageManagerToolVersion);
37+
3338
protected _linkProjects(): Promise<void> {
3439
try {
3540
const rushLinkJson: IRushLinkJson = {
@@ -207,13 +212,8 @@ export class PnpmLinkManager extends BaseLinkManager {
207212

208213
// tslint:disable-next-line:max-line-length
209214
// e.g.: C:\wbt\common\temp\node_modules\.local\C%3A%2Fwbt%2Fcommon%2Ftemp%2Fprojects%2Fapi-documenter.tgz\node_modules
210-
const pathToLocalInstallation: string = path.join(
211-
this._rushConfiguration.commonTempFolder,
212-
RushConstants.nodeModulesFolderName,
213-
'.local',
214-
folderNameInLocalInstallationRoot,
215-
RushConstants.nodeModulesFolderName
216-
);
215+
216+
const pathToLocalInstallation: string = this.GetPathToLocalInstallation(folderNameInLocalInstallationRoot);
217217

218218
const parentShrinkwrapEntry: IPnpmShrinkwrapDependencyYaml | undefined =
219219
pnpmShrinkwrapFile.getShrinkwrapEntryFromTempProjectDependencyKey(tempProjectDependencyKey);
@@ -276,6 +276,23 @@ export class PnpmLinkManager extends BaseLinkManager {
276276
.then(() => { /* empty block */ });
277277
}
278278

279+
private GetPathToLocalInstallation(folderNameInLocalInstallationRoot: string): string {
280+
// See https://github.com/pnpm/pnpm/releases/tag/v4.0.0
281+
if (this._pnpmVersion.major >= 4) {
282+
return path.join(this._rushConfiguration.commonTempFolder,
283+
RushConstants.nodeModulesFolderName,
284+
'.pnpm',
285+
'local',
286+
folderNameInLocalInstallationRoot,
287+
RushConstants.nodeModulesFolderName);
288+
} else {
289+
return path.join(this._rushConfiguration.commonTempFolder,
290+
RushConstants.nodeModulesFolderName,
291+
'.local',
292+
folderNameInLocalInstallationRoot,
293+
RushConstants.nodeModulesFolderName);
294+
}
295+
}
279296
private _createLocalPackageForDependency(
280297
pnpmProjectDependencyManifest: PnpmProjectDependencyManifest,
281298
project: RushConfigurationProject,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Support PNPM 4 on Rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "sachinjoseph@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)