Skip to content

Commit 2c1ffc5

Browse files
authored
Merge pull request #3872 from stekycz/stekycz-install-run-rush-pnpm
[rush] Add install-run-rush-pnpm.js script
2 parents 8387963 + a833cb7 commit 2c1ffc5

File tree

6 files changed

+61
-4
lines changed

6 files changed

+61
-4
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Add install-run-rush-pnpm.js script",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}

libraries/rush-lib/src/logic/StandardScriptUpdater.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { RushConfiguration } from '../api/RushConfiguration';
77
import {
88
installRunRushScriptFilename,
99
installRunRushxScriptFilename,
10+
installRunRushPnpmScriptFilename,
1011
installRunScriptFilename,
1112
scriptsFolderPath
1213
} from '../utilities/PathConstants';
@@ -65,6 +66,30 @@ const _scripts: IScriptSpecifier[] = [
6566
}
6667
];
6768

69+
const _pnpmOnlyScripts: IScriptSpecifier[] = [
70+
{
71+
scriptName: installRunRushPnpmScriptFilename,
72+
headerLines: [
73+
'// This script is intended for usage in an automated build environment where the Rush command may not have',
74+
'// been preinstalled, or may have an unpredictable version. This script will automatically install the version of Rush',
75+
'// specified in the rush.json configuration file (if not already installed), and then pass a command-line to the',
76+
'// rush-pnpm command.',
77+
'//',
78+
'// An example usage would be:',
79+
'//',
80+
`// node common/scripts/${installRunRushPnpmScriptFilename} pnpm-command`
81+
]
82+
}
83+
];
84+
85+
const getScripts = (rushConfiguration: RushConfiguration): IScriptSpecifier[] => {
86+
if (rushConfiguration.packageManager === 'pnpm') {
87+
return _scripts.concat(_pnpmOnlyScripts);
88+
}
89+
90+
return _scripts;
91+
};
92+
6893
/**
6994
* Checks whether the common/scripts files are up to date, and recopies them if needed.
7095
* This is used by the "rush install" and "rush update" commands.
@@ -79,7 +104,7 @@ export class StandardScriptUpdater {
79104

80105
let anyChanges: boolean = false;
81106
await Async.forEachAsync(
82-
_scripts,
107+
getScripts(rushConfiguration),
83108
async (script: IScriptSpecifier) => {
84109
const changed: boolean = await StandardScriptUpdater._updateScriptOrThrowAsync(
85110
script,
@@ -104,7 +129,7 @@ export class StandardScriptUpdater {
104129
*/
105130
public static async validateAsync(rushConfiguration: RushConfiguration): Promise<void> {
106131
await Async.forEachAsync(
107-
_scripts,
132+
getScripts(rushConfiguration),
108133
async (script: IScriptSpecifier) => {
109134
await StandardScriptUpdater._updateScriptOrThrowAsync(script, rushConfiguration, true);
110135
},
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See the @microsoft/rush package's LICENSE file for license information.
3+
4+
__non_webpack_require__('./install-run-rush');

libraries/rush-lib/src/scripts/install-run-rush.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ function _getRushVersion(logger: ILogger): string {
4343
}
4444
}
4545

46+
function _getBin(scriptName: string): string {
47+
switch (scriptName.toLowerCase()) {
48+
case 'install-run-rush-pnpm.js':
49+
return 'rush-pnpm';
50+
case 'install-run-rushx.js':
51+
return 'rushx';
52+
default:
53+
return 'rush';
54+
}
55+
}
56+
4657
function _run(): void {
4758
const [
4859
nodePath /* Ex: /bin/node */,
@@ -53,7 +64,7 @@ function _run(): void {
5364
// Detect if this script was directly invoked, or if the install-run-rushx script was invokved to select the
5465
// appropriate binary inside the rush package to run
5566
const scriptName: string = path.basename(scriptPath);
56-
const bin: string = scriptName.toLowerCase() === 'install-run-rushx.js' ? 'rushx' : 'rush';
67+
const bin: string = _getBin(scriptName);
5768
if (!nodePath || !scriptPath) {
5869
throw new Error('Unexpected exception: could not detect node path or script path');
5970
}
@@ -82,7 +93,9 @@ function _run(): void {
8293

8394
if (!commandFound) {
8495
console.log(`Usage: ${scriptName} <command> [args...]`);
85-
if (scriptName === 'install-run-rush.js') {
96+
if (scriptName === 'install-run-rush-pnpm.js') {
97+
console.log(`Example: ${scriptName} pnpm-command`);
98+
} else if (scriptName === 'install-run-rush.js') {
8699
console.log(`Example: ${scriptName} build --to myproject`);
87100
} else {
88101
console.log(`Example: ${scriptName} custom-command`);

libraries/rush-lib/src/utilities/PathConstants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const pnpmfileShimFilename: string = 'PnpmfileShim.js';
2222
export const installRunScriptFilename: string = 'install-run.js';
2323
export const installRunRushScriptFilename: string = 'install-run-rush.js';
2424
export const installRunRushxScriptFilename: string = 'install-run-rushx.js';
25+
export const installRunRushPnpmScriptFilename: string = 'install-run-rush-pnpm.js';
2526

2627
/**
2728
* The path to the scripts folder in rush-lib/dist.

libraries/rush-lib/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ module.exports = () => {
117117
[PathConstants.installRunRushxScriptFilename]: {
118118
import: `${__dirname}/lib-esnext/scripts/install-run-rushx.js`,
119119
...SCRIPT_ENTRY_OPTIONS
120+
},
121+
[PathConstants.installRunRushPnpmScriptFilename]: {
122+
import: `${__dirname}/lib-esnext/scripts/install-run-rush-pnpm.js`,
123+
...SCRIPT_ENTRY_OPTIONS
120124
}
121125
})
122126
];

0 commit comments

Comments
 (0)