Skip to content

Commit

Permalink
Merge pull request #1577 from microsoft/sachinjoseph/SupportForPnpm4
Browse files Browse the repository at this point in the history
[rush] Support for PNPM 4 (Experimental)
  • Loading branch information
iclanton committed Oct 16, 2019
2 parents 588979d + 51bc40a commit 9428ecb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ yarn-error.log*
*.seed
*.pid.lock

# Visual Studio Code
.vscode

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

Expand Down
16 changes: 16 additions & 0 deletions apps/rush-lib/src/api/packageManager/PnpmPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as semver from 'semver';
import { RushConstants } from '../../logic/RushConstants';
import { PackageManager } from './PackageManager';
import * as path from 'path';

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

// example: node_modules/.pnpm/lock.yaml
public readonly internalShrinkwrapRelativePath: string;

/** @internal */
public constructor(version: string) {
super(version, 'pnpm');
Expand All @@ -32,5 +36,17 @@ export class PnpmPackageManager extends PackageManager {
} else {
this._shrinkwrapFilename = RushConstants.pnpmV1ShrinkwrapFilename;
}

if (parsedVersion.major <= 2) {
// node_modules/.shrinkwrap.yaml
this.internalShrinkwrapRelativePath = path.join('node_modules', '.shrinkwrap.yaml');
} else if (parsedVersion.major <= 3) {
// node_modules/.pnpm-lock.yaml
this.internalShrinkwrapRelativePath = path.join('node_modules', '.pnpm-lock.yaml');
} else {
// node_modules/.pnpm/lock.yaml
// See https://github.com/pnpm/pnpm/releases/tag/v4.0.0 for more details.
this.internalShrinkwrapRelativePath = path.join('node_modules', '.pnpm', 'lock.yaml');
}
}
}
11 changes: 5 additions & 6 deletions apps/rush-lib/src/logic/InstallManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,6 @@ export class InstallManager {
FileSystem.deleteFile(this._rushConfiguration.tempShrinkwrapFilename);

if (this._rushConfiguration.packageManager === 'pnpm') {
const commonNodeModulesFolder: string = path.join(this._rushConfiguration.commonTempFolder, 'node_modules');

// Workaround for https://github.com/pnpm/pnpm/issues/1890
//
// When "rush update --full" is run, rush deletes common/temp/pnpm-lock.yaml so that
Expand All @@ -750,10 +748,11 @@ export class InstallManager {
// new lockfile. Deleting this file in addition to deleting common/temp/pnpm-lock.yaml
// ensures that a new lockfile will be generated with "rush update --full".

// Note that there is period in the file name: common/temp/node_modules/.pnpm-lock.yaml
const pnpmShrinkwrapInNodeModulesFolder: string = path.join(commonNodeModulesFolder, '.'
+ this._rushConfiguration.shrinkwrapFilename);
FileSystem.deleteFile(pnpmShrinkwrapInNodeModulesFolder);
const pnpmPackageManager: PnpmPackageManager =
(this._rushConfiguration.packageManagerWrapper as PnpmPackageManager);

FileSystem.deleteFile(path.join(this._rushConfiguration.commonTempFolder,
pnpmPackageManager.internalShrinkwrapRelativePath));
}
}

Expand Down
31 changes: 24 additions & 7 deletions apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as os from 'os';
import * as path from 'path';
import uriEncode = require('strict-uri-encode');
import pnpmLinkBins from '@pnpm/link-bins';
import * as semver from 'semver';

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

export class PnpmLinkManager extends BaseLinkManager {

private readonly _pnpmVersion: semver.SemVer
= new semver.SemVer(this._rushConfiguration.packageManagerToolVersion);

protected _linkProjects(): Promise<void> {
try {
const rushLinkJson: IRushLinkJson = {
Expand Down Expand Up @@ -207,13 +212,8 @@ export class PnpmLinkManager extends BaseLinkManager {

// tslint:disable-next-line:max-line-length
// e.g.: C:\wbt\common\temp\node_modules\.local\C%3A%2Fwbt%2Fcommon%2Ftemp%2Fprojects%2Fapi-documenter.tgz\node_modules
const pathToLocalInstallation: string = path.join(
this._rushConfiguration.commonTempFolder,
RushConstants.nodeModulesFolderName,
'.local',
folderNameInLocalInstallationRoot,
RushConstants.nodeModulesFolderName
);

const pathToLocalInstallation: string = this.GetPathToLocalInstallation(folderNameInLocalInstallationRoot);

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

private GetPathToLocalInstallation(folderNameInLocalInstallationRoot: string): string {
// See https://github.com/pnpm/pnpm/releases/tag/v4.0.0
if (this._pnpmVersion.major >= 4) {
return path.join(this._rushConfiguration.commonTempFolder,
RushConstants.nodeModulesFolderName,
'.pnpm',
'local',
folderNameInLocalInstallationRoot,
RushConstants.nodeModulesFolderName);
} else {
return path.join(this._rushConfiguration.commonTempFolder,
RushConstants.nodeModulesFolderName,
'.local',
folderNameInLocalInstallationRoot,
RushConstants.nodeModulesFolderName);
}
}
private _createLocalPackageForDependency(
pnpmProjectDependencyManifest: PnpmProjectDependencyManifest,
project: RushConfigurationProject,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Support PNPM 4 on Rush",
"type": "none"
}
],
"packageName": "@microsoft/rush",
"email": "sachinjoseph@users.noreply.github.com"
}

0 comments on commit 9428ecb

Please sign in to comment.