Skip to content

Commit 2b1ae17

Browse files
committed
fix(rush): Allow 'rush-pnpm' to forward arbitrary commands
1 parent 981ef14 commit 2b1ae17

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
4+
import { RUSH_PNPM_SCRIPT_NAME } from '../../logic/pnpm/PnpmProjectDependencyManifest';
5+
import { BaseRushAction } from './BaseRushAction';
6+
import { RushCommandLineParser } from '../RushCommandLineParser';
7+
import { PnpmInstallManager } from '../../logic/pnpm/PnpmInstallManager';
8+
import { RushConfiguration } from '../../api/RushConfiguration';
9+
import { Utilities } from '../../utilities/Utilities';
10+
11+
export class PnpmAction extends BaseRushAction {
12+
public constructor(
13+
protected rushConfiguration: RushConfiguration | undefined,
14+
parser?: RushCommandLineParser
15+
) {
16+
super({
17+
actionName: RUSH_PNPM_SCRIPT_NAME,
18+
summary:
19+
'When rush is configured to use pnpm, this command is a wrapper for "pnpm".' +
20+
' It will always use the version of pnpm that is specified in your rush.json file.' +
21+
' Any command-line parameters will be passed through to the underlying "pnpm" executable.',
22+
documentation:
23+
'When rush is configured to use pnpm, this command is a wrapper for "pnpm".' +
24+
' It will always use the version of pnpm that is specified in your rush.json file.' +
25+
' Any command-line parameters will be passed through to the underlying "pnpm" executable.' +
26+
' If you want to use a global pnpm installation instead, you can add a "pnpm" entry to the' +
27+
' "preferredVersions" setting in your command-path.json file.',
28+
safeForSimultaneousRushProcesses: true,
29+
parser: parser,
30+
default: true
31+
});
32+
}
33+
34+
public onDefineParameters(): void {
35+
// No parameters are defined because this action passes all parameters to the pnpm executable
36+
}
37+
38+
public async run(): Promise<void> {
39+
if (!this.rushConfiguration) {
40+
// This should be impossible, but might as well check
41+
throw new Error('The "rush-pnpm" command must be run inside a Rush repository.');
42+
}
43+
44+
const pnpmInstallManager: PnpmInstallManager = this.rushConfiguration.packageManagerTool as PnpmInstallManager;
45+
46+
const pnpmArgs: string[] = this.parser.remainder.raw.slice();
47+
48+
Utilities.executeCommand({
49+
command: pnpmInstallManager.pnpmPath,
50+
args: pnpmArgs,
51+
workingDirectory: this.rushConfiguration.commonTempFolder,
52+
allowConsoleOutput: true
53+
});
54+
}
55+
}

0 commit comments

Comments
 (0)