feat: new setting - maxsockets (#3889)

This commit is contained in:
Zoltan Kochan
2021-10-19 00:45:36 +03:00
committed by GitHub
parent 930e104da3
commit bd7bcdbe8e
5 changed files with 22 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/store-connection-manager": minor
---
Make the maximum amount of sockets configurable through the `maxSockets` option.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/config": minor
---
New setting supported: maxsockets. maxsockets allows to set the maximum number of connections to use per origin (protocol/host/post combination).

View File

@@ -96,6 +96,7 @@ export interface Config {
storeDir?: string
virtualStoreDir?: string
verifyStoreIntegrity?: boolean
maxSockets?: number
networkConcurrency?: number
fetchingConcurrency?: number
lockfileOnly?: boolean // like npm's --package-lock-only

View File

@@ -66,6 +66,7 @@ export const types = Object.assign({
'lockfile-directory': String, // TODO: deprecate
'lockfile-only': Boolean,
loglevel: ['silent', 'error', 'warn', 'info', 'debug'],
maxsockets: Number,
'modules-cache-max-age': Number,
'modules-dir': String,
'network-concurrency': Number,
@@ -224,6 +225,10 @@ export default async (
...Object.entries(cliOptions).filter(([name, value]) => typeof value !== 'undefined').map(([name, value]) => [camelcase(name), value]),
]) as unknown as ConfigWithDeprecatedSettings
const cwd = (cliOptions.dir && path.resolve(cliOptions.dir)) ?? npmConfig.localPrefix
pnpmConfig.maxSockets = npmConfig.maxsockets
delete pnpmConfig['maxsockets']
pnpmConfig.workspaceDir = opts.workspaceDir
pnpmConfig.workspaceRoot = cliOptions['workspace-root'] as boolean // This is needed to prevent pnpm reading workspaceRoot from env variables
pnpmConfig.rawLocalConfig = Object.assign.apply(Object, [

View File

@@ -26,6 +26,7 @@ export type CreateNewStoreControllerOptions = CreateResolverOptions & Pick<Confi
| 'httpsProxy'
| 'key'
| 'localAddress'
| 'maxSockets'
| 'networkConcurrency'
| 'noProxy'
| 'offline'
@@ -64,9 +65,11 @@ export default async (
strictSsl: opts.strictSsl ?? true,
timeout: opts.fetchTimeout,
userAgent: opts.userAgent,
maxSockets: opts.networkConcurrency != null
? (opts.networkConcurrency * 3)
: undefined,
maxSockets: opts.maxSockets ?? (
opts.networkConcurrency != null
? (opts.networkConcurrency * 3)
: undefined
),
})
await fs.mkdir(opts.storeDir, { recursive: true })
return {