Skip to content

Commit 6807d78

Browse files
committed
Add a command-line option for specifying PNPM's "--network-concurrency"
1 parent 8f4706d commit 6807d78

File tree

5 files changed

+48
-16
lines changed

5 files changed

+48
-16
lines changed

apps/rush-lib/src/cli/actions/BaseInstallAction.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import * as colors from 'colors';
55
import * as os from 'os';
66

7-
import { CommandLineFlagParameter } from '@microsoft/ts-command-line';
7+
import { CommandLineFlagParameter, CommandLineIntegerParameter } from '@microsoft/ts-command-line';
88

99
import { BaseRushAction } from './BaseRushAction';
1010
import { Event } from '../../api/EventHooks';
@@ -21,6 +21,7 @@ export abstract class BaseInstallAction extends BaseRushAction {
2121
protected _purgeParameter: CommandLineFlagParameter;
2222
protected _bypassPolicyParameter: CommandLineFlagParameter;
2323
protected _noLinkParameter: CommandLineFlagParameter;
24+
protected _networkConcurrencyParameter: CommandLineIntegerParameter;
2425
protected _debugPackageManagerParameter: CommandLineFlagParameter;
2526

2627
protected onDefineParameters(): void {
@@ -40,6 +41,12 @@ export abstract class BaseInstallAction extends BaseRushAction {
4041
+ ' This flag is useful for automated builds that want to report stages individually'
4142
+ ' or perform extra operations in between the two stages.'
4243
});
44+
this._networkConcurrencyParameter = this.defineIntegerParameter({
45+
parameterLongName: '--network-concurrency',
46+
argumentName: 'COUNT',
47+
description: 'If specified, limits the maximum number of concurrent network requests.'
48+
+ ' This is useful when troubleshooting network failures.'
49+
});
4350
this._debugPackageManagerParameter = this.defineFlagParameter({
4451
parameterLongName: '--debug-package-manager',
4552
description: 'Activates verbose logging for the package manager. You will probably want to pipe'
@@ -71,6 +78,13 @@ export abstract class BaseInstallAction extends BaseRushAction {
7178
console.log('');
7279
}
7380

81+
if (this._networkConcurrencyParameter.value) {
82+
if (this.rushConfiguration.packageManager !== 'pnpm') {
83+
throw new Error(`The ${this._networkConcurrencyParameter.longName} parameter is currently`
84+
+ ` only supported when using the PNPM package manager.`);
85+
}
86+
}
87+
7488
const installManagerOptions: IInstallManagerOptions = this.buildInstallOptions();
7589

7690
return installManager.doInstall(installManagerOptions)

apps/rush-lib/src/cli/actions/InstallAction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class InstallAction extends BaseInstallAction {
3232
noLink: this._noLinkParameter.value!,
3333
fullUpgrade: false,
3434
recheckShrinkwrap: false,
35+
networkConcurrency: this._networkConcurrencyParameter.value,
3536
collectLogFile: this._debugPackageManagerParameter.value!
3637
};
3738
}

apps/rush-lib/src/cli/actions/UpdateAction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class UpdateAction extends BaseInstallAction {
5959
noLink: this._noLinkParameter.value!,
6060
fullUpgrade: this._fullParameter.value!,
6161
recheckShrinkwrap: this._recheckParameter.value!,
62+
networkConcurrency: this._networkConcurrencyParameter.value,
6263
collectLogFile: this._debugPackageManagerParameter.value!
6364
};
6465
}

apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Optional arguments:
188188
189189
exports[`CommandLineHelp prints the help for "rush install" 1`] = `
190190
"usage: rush install [-h] [-p] [--bypass-policy] [--no-link]
191-
[--debug-package-manager]
191+
[--network-concurrency COUNT] [--debug-package-manager]
192192
193193
194194
The \\"rush install\\" command installs package dependencies for all your
@@ -214,6 +214,10 @@ Optional arguments:
214214
is useful for automated builds that want to report
215215
stages individually or perform extra operations in
216216
between the two stages.
217+
--network-concurrency COUNT
218+
If specified, limits the maximum number of concurrent
219+
network requests. This is useful when troubleshooting
220+
network failures.
217221
--debug-package-manager
218222
Activates verbose logging for the package manager.
219223
You will probably want to pipe the output of Rush to
@@ -396,7 +400,8 @@ Optional arguments:
396400
397401
exports[`CommandLineHelp prints the help for "rush update" 1`] = `
398402
"usage: rush update [-h] [-p] [--bypass-policy] [--no-link]
399-
[--debug-package-manager] [--full] [--recheck]
403+
[--network-concurrency COUNT] [--debug-package-manager]
404+
[--full] [--recheck]
400405
401406
402407
The \\"rush update\\" command installs the dependencies described in your package.
@@ -421,6 +426,10 @@ Optional arguments:
421426
is useful for automated builds that want to report
422427
stages individually or perform extra operations in
423428
between the two stages.
429+
--network-concurrency COUNT
430+
If specified, limits the maximum number of concurrent
431+
network requests. This is useful when troubleshooting
432+
network failures.
424433
--debug-package-manager
425434
Activates verbose logging for the package manager.
426435
You will probably want to pipe the output of Rush to

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ export interface IInstallManagerOptions {
7979
* (pnpmfile.js script logic, registry changes, etc).
8080
*/
8181
recheckShrinkwrap: boolean;
82+
83+
/**
84+
* The value of the "--network-concurrency" command-line parameter, which
85+
* is a diagnostic option used to troubleshoot network failures.
86+
*/
87+
networkConcurrency: number | undefined;
88+
8289
/**
8390
* Whether or not to collect verbose logs from the package manager.
8491
* If specified when using PNPM, the logs will be in /common/temp/pnpm.log
@@ -239,8 +246,7 @@ export class InstallManager {
239246
}
240247
}
241248

242-
return this._installCommonModules(shrinkwrapIsUpToDate,
243-
options.allowShrinkwrapUpdates, options.collectLogFile)
249+
return this._installCommonModules(shrinkwrapIsUpToDate, options)
244250
.then(() => {
245251
if (!options.noLink) {
246252
const linkManager: BaseLinkManager = LinkManagerFactory.getLinkManager(this._rushConfiguration);
@@ -616,10 +622,7 @@ export class InstallManager {
616622
/**
617623
* Runs "npm install" in the common folder.
618624
*/
619-
private _installCommonModules(
620-
shrinkwrapIsUpToDate: boolean,
621-
allowShrinkwrapUpdates: boolean,
622-
collectLogFile: boolean): Promise<void> {
625+
private _installCommonModules(shrinkwrapIsUpToDate: boolean, options: IInstallManagerOptions): Promise<void> {
623626
return Promise.resolve().then(() => {
624627
console.log(os.EOL + colors.bold('Checking node_modules in ' + this._rushConfiguration.commonTempFolder)
625628
+ os.EOL);
@@ -726,7 +729,7 @@ export class InstallManager {
726729
console.log(`Running "${this._rushConfiguration.packageManager} prune"`
727730
+ ` in ${this._rushConfiguration.commonTempFolder}`);
728731
const args: string[] = ['prune'];
729-
this._pushConfigurationArgs(args, collectLogFile);
732+
this._pushConfigurationArgs(args, options);
730733

731734
Utilities.executeCommandWithRetry(MAX_INSTALL_ATTEMPTS, packageManagerFilename, args,
732735
this._rushConfiguration.commonTempFolder);
@@ -771,7 +774,7 @@ export class InstallManager {
771774
// people would have different node_modules based on their system.
772775

773776
const installArgs: string[] = ['install', '--no-optional'];
774-
this._pushConfigurationArgs(installArgs, collectLogFile);
777+
this._pushConfigurationArgs(installArgs, options);
775778

776779
console.log(os.EOL + colors.bold(`Running "${this._rushConfiguration.packageManager} install" in`
777780
+ ` ${this._rushConfiguration.commonTempFolder}`) + os.EOL);
@@ -799,15 +802,15 @@ export class InstallManager {
799802

800803
console.log(os.EOL + colors.bold('Running "npm shrinkwrap"...'));
801804
const npmArgs: string[] = ['shrinkwrap'];
802-
this._pushConfigurationArgs(npmArgs, collectLogFile);
805+
this._pushConfigurationArgs(npmArgs, options);
803806
Utilities.executeCommand(this._rushConfiguration.packageManagerToolFilename,
804807
npmArgs, this._rushConfiguration.commonTempFolder);
805808
console.log('"npm shrinkwrap" completed' + os.EOL);
806809

807810
this._fixupNpm5Regression();
808811
}
809812

810-
if (allowShrinkwrapUpdates && !shrinkwrapIsUpToDate) {
813+
if (options.allowShrinkwrapUpdates && !shrinkwrapIsUpToDate) {
811814
// Copy (or delete) common\temp\shrinkwrap.yaml --> common\config\rush\shrinkwrap.yaml
812815
this._syncFile(this._rushConfiguration.tempShrinkwrapFilename,
813816
this._rushConfiguration.committedShrinkwrapFilename);
@@ -939,12 +942,12 @@ export class InstallManager {
939942
* Used when invoking the NPM tool. Appends the common configuration options
940943
* to the command-line.
941944
*/
942-
private _pushConfigurationArgs(args: string[], collectLogFile: boolean): void {
945+
private _pushConfigurationArgs(args: string[], options: IInstallManagerOptions): void {
943946
if (this._rushConfiguration.packageManager === 'npm') {
944947
args.push('--cache', this._rushConfiguration.npmCacheFolder);
945948
args.push('--tmp', this._rushConfiguration.npmTmpFolder);
946949

947-
if (collectLogFile) {
950+
if (options.collectLogFile) {
948951
args.push('--verbose');
949952
}
950953
} else if (this._rushConfiguration.packageManager === 'pnpm') {
@@ -957,9 +960,13 @@ export class InstallManager {
957960
// last install flag, which encapsulates the entire installation
958961
args.push('--no-lock');
959962

960-
if (collectLogFile) {
963+
if (options.collectLogFile) {
961964
args.push('--reporter', 'ndjson');
962965
}
966+
967+
if (options.networkConcurrency) {
968+
args.push('--network-concurrency', options.networkConcurrency.toString());
969+
}
963970
}
964971
}
965972

0 commit comments

Comments
 (0)