网络和请求设置

网络设置#

httpsProxy#

  • 默认值: null
  • 类型:url

用于传出 HTTPS 请求的代理。 If httpsProxy is unset, pnpm uses the legacy proxy setting, then the HTTPS_PROXY or https_proxy environment variable.

如果你的代理 URL 包含用户名和密码,请确保对它们进行 URL 编码。例如:

pnpm-workspace.yaml
httpsProxy: "https://use%21r:pas%2As@my.proxy:1234/foo"

不要对用户名和密码之间的冒号 (:) 进行编码。

An empty value reads as unset. If neither httpsProxy nor proxy is configured, a shell that exports HTTPS_PROXY= disables the proxy. A false or null value in pnpm-workspace.yaml or the .npmrc also reads as unset, so pnpm still falls back to proxy and the environment. To turn proxying off, set proxy to false. 在命令行中,false 与 null 就是普通的主机名,因为标志会原样传递其值。

httpProxy#

  • 默认值: null
  • 类型:url

用于传输 HTTP 请求的代理。 If httpProxy is unset, pnpm uses the proxy resolved for httpsProxy, then the HTTP_PROXY or http_proxy environment variable, then PROXY or proxy.

空值、false 和 null 的表现与 httpsProxy 中所述一致。

.npmrc 还支持 npm 的旧版 proxy 设置,它作为 https-proxy 和 http-proxy 的后备值使用。 An empty proxy= reads as unset, so it does not suppress the HTTPS_PROXY environment variable. proxy=false (or proxy: false in pnpm-workspace.yaml) turns proxying off.

noProxy#

  • 默认值: null
  • 类型:字符串

一个由逗号分割的域名字符串,表示不应该被使用的代理 If noProxy is unset, pnpm uses noproxy, then the NO_PROXY or no_proxy environment variable.

An entry may be written with or without a leading dot: both npmjs.org and .npmjs.org bypass the proxy for the domain itself and for its subdomains.

空值、false 和 null 的表现与 httpsProxy 中所述一致。

localAddress#

  • 默认值:undefined
  • 类型:IP 地址

与 npm 注册源建立连接时要使用的本地接口的 IP 地址。

Pass --local-address <ip> on the command line to set this value.

maxsockets#

  • Default: unset
  • 类型:Number

每个源(由协议/主机/端口号组合而成)允许的最大连接数。 When unset, connections through a proxy are limited to 50 per origin, and direct connections are bounded only by networkConcurrency. Set 0 to remove the limit for proxied connections too.

maxSockets is accepted as an alias. Both spellings are read from pnpm-workspace.yaml, the global configuration file, the environment, and the command line, in that increasing order of precedence, so a value passed on the command line wins even when the two sides spelled the setting differently.

strictSsl#

  • 默认值:true
  • 类型:Boolean

通过 HTTPS 向registry发出请求时是否进行 SSL 密钥验证。

Use --strict-ssl to enable validation or --no-strict-ssl to disable it.

userAgent#

  • Default: pnpm/<version> npm/? node/? <platform> <arch>
  • 类型:字符串

The value of the User-Agent header that pnpm sends with every request to the registry.

请求设置#

gitShallowHosts#

  • 默认值:['github.com', 'gist.github.com', 'gitlab.com', 'bitbucket.com', 'bitbucket.org']
  • 类型:string[]

当获取 Git 仓库中的依赖项时,如果域名在此设置中列出,pnpm 将使用浅克隆仅获取所需的提交,而不是所有历史记录。

networkConcurrency#

  • Default: auto (workers × 3 clamped to 64-96)
  • 类型:Number

控制同时处理的最大 HTTP(S) 的网络请求数。

pnpm selects a value between 64 and 96 based on the number of workers, which is the available parallelism minus one (networkConcurrency = clamp(workers × 3, 64, 96)). 明确设置这个值以覆盖自动缩放。

If a request times out while other requests to the same host are still in flight, pnpm lowers the limit for that host to one request for the rest of the command. Requests that are already running finish first. Requests to other hosts keep the full limit. Requests sent through the same proxy count as one host.

To limit requests to one registry, set networkConcurrency on its entry in the registries setting.

fetchRetries#

  • 默认值:2
  • 类型:Number

如果 pnpm 无法从registry中获取,重试次数。

fetchRetryFactor#

  • 默认值:10
  • 类型:Number

重试回退的指数因子。

fetchRetryMintimeout#

  • 默认值:10000(10 秒)
  • 类型:Number

重试指数退避的下限(以毫秒为单位)。

fetchRetryMaxtimeout#

  • 默认值:60000(1 分钟)
  • 类型:Number

重试指数退避的上限(以毫秒为单位)。

fetchTimeout#

  • 默认值:60000(1 分钟)
  • 类型:Number

How long an HTTP request may go without making progress. The clock is reset on every chunk pnpm receives, so a large tarball on a slow connection is not cut off while data is still arriving; a stalled request is.

Before v12.4.0, this bounded the whole request, which meant the value had to be large enough to download the largest package over the slowest connection you cared about.

fetchWarnTimeoutMs#

  • 默认: 1000毫秒 (10 秒)
  • 类型:Number

如果对注册表的元数据请求所花的时间超过指定的阈值(以毫秒为单位),则会显示警告消息。

fetchMinSpeedKiBps#

  • 默认值:50 KiB/s
  • 类型:Number

如果从注册表下载 tarball 的速度低于指定的阈值(以 KiB/s 为单位),则会显示警告消息。

maxTarballUnpackedSize#

新增于:v12.15.0

  • Default: 4294967296 (4 GiB)
  • 类型:Number

The most bytes the files of one package may unpack to. A package whose files total more fails to install. A package from a tar registry is also held to its dist.unpackedSize.

pnpm checks this as it decodes a tarball, before it can verify the tarball's hash, so a hostile registry cannot make it write more than this much.