设置 (pnpm-workspace.yaml)
pnpm 从命令行、环境变量、pnpm-workspace.yaml
和 .npmrc
文件获取其配置。
¥pnpm gets its configuration from the command line, environment variables, pnpm-workspace.yaml
, and
.npmrc
files.
pnpm config
命令可用于读取和编辑项目和全局配置文件的内容。
¥The pnpm config
command can be used to read and edit the contents of the project and global configuration files.
相关的配置文件如下:
¥The relevant configuration files are:
-
每个项目的配置文件:
/path/to/my/project/pnpm-workspace.yaml
¥Per-project configuration file:
/path/to/my/project/pnpm-workspace.yaml
-
全局配置文件:
~/.config/pnpm/rc
(key = value
参数的 INI-formatted 列表)¥Global configuration file:
~/.config/pnpm/rc
(an INI-formatted list ofkey = value
parameters)
与授权相关的设置由 npm 的配置系统处理。因此,pnpm config set registry=<value>
实际上会将设置保存到 npm 的全局配置文件中。
¥Authorization-related settings are handled by npm's configuration system. So, pnpm config set registry=<value>
will actually save the setting to npm's global configuration file.
配置文件中的值可以包含使用 ${NAME}
语法的环境变量。环境变量也可以指定默认值。如果未设置 NAME
,则使用 ${NAME-fallback}
将返回 fallback
。如果 NAME
未设置或者为空字符串,则 ${NAME:-fallback}
将返回 fallback
。
¥Values in the configuration files may contain env variables using the ${NAME}
syntax. The env variables may also be specified with default values. Using ${NAME-fallback}
will return fallback
if NAME
isn't set. ${NAME:-fallback}
will return fallback
if NAME
isn't set, or is an empty string.
依赖解析
¥Dependency Resolution
overrides
此字段允许你指示 pnpm 覆盖依赖图中的任何依赖。这对于强制所有软件包使用依赖的单一版本、反向移植修复、用 fork 替换依赖或删除未使用的依赖很有用。
¥This field allows you to instruct pnpm to override any dependency in the dependency graph. This is useful for enforcing all your packages to use a single version of a dependency, backporting a fix, replacing a dependency with a fork, or removing an unused dependency.
请注意,覆盖字段只能在项目的根目录中设置。
¥Note that the overrides field can only be set at the root of the project.
overrides
字段的示例:
¥An example of the overrides
field:
overrides:
"foo": "^1.0.0"
"quux": "npm:@myorg/quux@^1.0.0"
"bar@^2.1.0": "3.0.0"
"qar@1>zoo": "2"
你可以通过用 ">" 将包选择器与依赖选择器分开来指定覆盖依赖所属的包,例如 qar@1>zoo
将仅覆盖 qar@1
的 zoo
依赖,而不会覆盖任何其他依赖。
¥You may specify the package the overridden dependency belongs to by
separating the package selector from the dependency selector with a ">", for
example qar@1>zoo
will only override the zoo
dependency of qar@1
, not for
any other dependencies.
覆盖可以定义为对直接依赖规范的引用。这是通过在依赖名称前加上 $
来实现的:
¥An override may be defined as a reference to a direct dependency's spec.
This is achieved by prefixing the name of the dependency with a $
:
{
"dependencies": {
"foo": "^1.0.0"
}
}
overrides:
foo: "$foo"
引用的包不需要与 被覆盖的包匹配:
¥The referenced package does not need to match the overridden one:
overrides:
bar: "$foo"
如果你发现某个软件包不需要它的某个依赖,你可以使用 -
将其删除。例如,如果软件包 foo@1.0.0
需要一个名为 bar
的大型软件包来实现你不使用的功能,则删除它可以缩短安装时间:
¥If you find that your use of a certain package doesn't require one of its dependencies, you may use -
to remove it. For example, if package foo@1.0.0
requires a large package named bar
for a function that you don't use, removing it could reduce install time:
overrides:
"foo@1.0.0>bar": "-"
此功能对于 optionalDependencies
尤其有用,因为大多数可选包都可以安全跳过。
¥This feature is especially useful with optionalDependencies
, where most optional packages can be safely skipped.
packageExtensions
packageExtensions
字段提供了一种使用附加信息扩展现有包定义的方法。例如,如果 react-redux
的 peerDependencies
中应该有 react-dom
,但它没有,则可以使用 packageExtensions
修补 react-redux
:
¥The packageExtensions
fields offer a way to extend the existing package definitions with additional information. For example, if react-redux
should have react-dom
in its peerDependencies
but it has not, it is possible to patch react-redux
using packageExtensions
:
packageExtensions:
react-redux:
peerDependencies:
react-dom: "*"
packageExtensions
中的键是包名称或包名称和 semver 范围,因此可以仅修补包的某些版本:
¥The keys in packageExtensions
are package names or package names and semver ranges, so it is possible to patch only some versions of a package:
packageExtensions:
react-redux@1:
peerDependencies:
react-dom: "*"
可以使用 packageExtensions
扩展以下字段:dependencies
、optionalDependencies
、peerDependencies
和 peerDependenciesMeta
。
¥The following fields may be extended using packageExtensions
: dependencies
, optionalDependencies
, peerDependencies
, and peerDependenciesMeta
.
一个更大的例子:
¥A bigger example:
packageExtensions:
express@1:
optionalDependencies:
typescript: "2"
fork-ts-checker-webpack-plugin:
dependencies:
"@babel/core": "1"
peerDependencies:
eslint: ">= 6"
peerDependenciesMeta:
eslint: {
optional: true
我们与 Yarn 一起维护 packageExtensions
的数据库,以修补生态系统中损坏的软件包。如果你使用 packageExtensions
,请考虑向上游发送 PR 并将你的扩展贡献给 @yarnpkg/extensions
数据库。
¥Together with Yarn, we maintain a database of packageExtensions
to patch broken packages in the ecosystem.
If you use packageExtensions
, consider sending a PR upstream and contributing your extension to the @yarnpkg/extensions
database.
allowedDeprecatedVersions
此设置允许静音特定包的弃用警告。
¥This setting allows muting deprecation warnings of specific packages.
示例:
¥Example:
allowedDeprecatedVersions:
express: "1"
request: "*"
通过上述配置,pnpm 将不会打印有关 request
的任何版本和 express
v1 的弃用警告。
¥With the above configuration pnpm will not print deprecation warnings about any version of request
and about v1 of express
.
updateConfig
updateConfig.ignoreDependencies
有时你无法更新依赖。例如,最新版本的依赖开始使用 ESM,但你的项目尚未使用 ESM。令人烦恼的是,当运行 pnpm update --latest
时,这样的包总是会被 pnpm outdated
命令打印出来并更新。但是,你可以在 ignoreDependencies
字段中列出你不想升级的软件包:
¥Sometimes you can't update a dependency. For instance, the latest version of the dependency started to use ESM but your project is not yet in ESM. Annoyingly, such a package will be always printed out by the pnpm outdated
command and updated, when running pnpm update --latest
. However, you may list packages that you don't want to upgrade in the ignoreDependencies
field:
updateConfig: {
ignoreDependencies:
- load-json-file
还支持模式,因此你可以忽略某个范围内的任何包:@babel/*
。
¥Patterns are also supported, so you may ignore any packages from a scope: @babel/*
.
supportedArchitectures
你可以指定要安装可选依赖的体系结构,即使它们与运行安装的系统的体系结构不匹配。
¥You can specify architectures for which you'd like to install optional dependencies, even if they don't match the architecture of the system running the install.
例如,以下配置指示安装 Windows x64 的可 选依赖:
¥For example, the following configuration tells to install optional dependencies for Windows x64:
supportedArchitectures:
os:
- win32
cpu:
- x64
而此配置将为 Windows、macOS 以及当前运行安装的系统架构安装可选依赖。它包括 x64 和 arm64 CPU 的工件:
¥Whereas this configuration will install optional dependencies for Windows, macOS, and the architecture of the system currently running the install. It includes artifacts for both x64 and arm64 CPUs:
supportedArchitectures:
os:
- win32
- darwin
- current
cpu:
- x64
- arm64
另外,supportedArchitectures
还支持指定系统的 libc
。
¥Additionally, supportedArchitectures
also supports specifying the libc
of the system.
ignoredOptionalDependencies
如果可选依赖的名称包含在此数组中,则会跳过该依赖。例如:
¥If an optional dependency has its name included in this array, it will be skipped. For example:
ignoredOptionalDependencies:
- fsevents
- "@esbuild/*"
依赖提升设置
¥Dependency Hoisting Settings
hoist
-
默认:true
¥Default: true
-
类型:boolean
¥Type: boolean
当 true
时,所有依赖都提升到 node_modules/.pnpm/node_modules
。这使得 node_modules
内的所有包都可以访问未列出的依赖。
¥When true
, all dependencies are hoisted to node_modules/.pnpm/node_modules
. This makes
unlisted dependencies accessible to all packages inside node_modules
.
hoistWorkspacePackages
-
默认:true
¥Default: true
-
类型:boolean
¥Type: boolean
当 true
时,工作区中的包将符号链接到 <workspace_root>/node_modules/.pnpm/node_modules
或 <workspace_root>/node_modules
,具体取决于其他提升设置(hoistPattern
和 publicHoistPattern
)。
¥When true
, packages from the workspaces are symlinked to either <workspace_root>/node_modules/.pnpm/node_modules
or to <workspace_root>/node_modules
depending on other hoisting settings (hoistPattern
and publicHoistPattern
).
hoistPattern
-
默认:['*']
¥Default: ['*']
-
类型:string[]
¥Type: string[]
告诉 pnpm 哪些包应该提升到 node_modules/.pnpm/node_modules
。默认情况下,所有包都会被吊起 - 但是,如果你知道只有某些有缺陷的包具有幻像依赖,则可以使用此选项专门提升幻像依赖(推荐)。
¥Tells pnpm which packages should be hoisted to node_modules/.pnpm/node_modules
. By
default, all packages are hoisted - however, if you know that only some flawed
packages have phantom dependencies, you can use this option to exclusively hoist
the phantom dependencies (recommended).
例如:
¥For instance:
hoistPattern:
- "*eslint*"
- "*babel*"
你还 可以使用 !
从提升中排除模式。
¥You may also exclude patterns from hoisting using !
.
例如:
¥For instance:
hoistPattern:
- "*types*"
- "!@types/react"
publicHoistPattern
-
默认:[]
¥Default: []
-
类型:string[]
¥Type: string[]
与 hoistPattern
将依赖提升到虚拟存储内的隐藏模块目录不同,publicHoistPattern
将与模式匹配的依赖提升到根模块目录。提升到根模块目录意味着应用代码将有权访问幻像依赖,即使它们不正确地修改了解析策略。
¥Unlike hoistPattern
, which hoists dependencies to a hidden modules directory
inside the virtual store, publicHoistPattern
hoists dependencies matching
the pattern to the root modules directory. Hoisting to the root modules
directory means that application code will have access to phantom dependencies,
even if they modify the resolution strategy improperly.
当处理一些有缺陷且无法正确解析依赖的可插入工具时,此设置非常有用。
¥This setting is useful when dealing with some flawed pluggable tools that don't resolve dependencies properly.
例如:
¥For instance:
publicHoistPattern:
- "*plugin*"
注意:设置 shamefullyHoist
至 true
与设置 publicHoistPattern
至 *
相同。
¥Note: Setting shamefullyHoist
to true
is the same as setting
publicHoistPattern
to *
.
你还可以使用 !
从提升中排除模式。
¥You may also exclude patterns from hoisting using !
.
例如:
¥For instance:
publicHoistPattern:
- "*types*"
- "!@types/react"
shamefullyHoist
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
默认情况下,pnpm 创建半严格 node_modules
,这意味着依赖可以访问未声明的依赖,但 node_modules
之外的模块则不能。通过这种布局,生态系统中的大多数软件包都可以正常工作。但是,如果某些工具仅在提升的依赖位于 node_modules
的根目录中时才起作用,则可以将其设置为 true
来为你提升它们。
¥By default, pnpm creates a semistrict node_modules
, meaning dependencies have
access to undeclared dependencies but modules outside of node_modules
do not.
With this layout, most of the packages in the ecosystem work with no issues.
However, if some tooling only works when the hoisted dependencies are in the
root of node_modules
, you can set this to true
to hoist them for you.
Node 模块设置
¥Node-Modules Settings
modulesDir
-
默认:node_modules
¥Default: node_modules
-
类型:path
¥Type: path
将安装依赖的目录(而不是 node_modules
)。
¥The directory in which dependencies will be installed (instead of
node_modules
).
nodeLinker
-
默认:isolated
¥Default: isolated
-
类型:isolated, hoisted, pnp
¥Type: isolated, hoisted, pnp
定义应使用什么链接器来安装 Node 包。
¥Defines what linker should be used for installing Node packages.
-
isolated - 依赖从
node_modules/.pnpm
处的虚拟存储进行符号链接。¥isolated - dependencies are symlinked from a virtual store at
node_modules/.pnpm
. -
hoisted - 创建了一个没有符号链接的扁平
node_modules
。与 npm 或 Yarn Classic 创建的node_modules
相同。当使用此设置时,Yarn 的库之一用于提升。使用此设置的正当理由:¥hoisted - a flat
node_modules
without symlinks is created. Same as thenode_modules
created by npm or Yarn Classic. One of Yarn's libraries is used for hoisting, when this setting is used. Legitimate reasons to use this setting:-
你的工具不能很好地处理符号链接。React Native 项目很可能只有在使用提升的
node_modules
时才能工作。¥Your tooling doesn't work well with symlinks. A React Native project will most probably only work if you use a hoisted
node_modules
. -
你的项目已部署到无服务器托管提供商。某些无服务器提供商(例如 AWS Lambda)不支持符号链接。此问题的另一种解决方案是在部署之前打包应用。
¥Your project is deployed to a serverless hosting provider. Some serverless providers (for instance, AWS Lambda) don't support symlinks. An alternative solution for this problem is to bundle your application before deployment.
-
如果你想用
"bundledDependencies"
发布你的包。¥If you want to publish your package with
"bundledDependencies"
. -
如果你正在使用 --preserve-symlinks 标志运行 Node.js。
¥If you are running Node.js with the --preserve-symlinks flag.
-
-
pnp - no
node_modules
。Plug'n'Play 是针对 Node 由 Yarn Berry 使用 的创新策略。当使用pnp
作为链接器时,建议将symlink
设置为false
。¥pnp - no
node_modules
. Plug'n'Play is an innovative strategy for Node that is used by Yarn Berry. It is recommended to also setsymlink
setting tofalse
when usingpnp
as your linker.
symlink
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
当 symlink
设置为 false
时,pnpm 将创建一个不带任何符号链接的虚拟存储目录。与 nodeLinker=pnp
一起使用是一个有用的设置。
¥When symlink
is set to false
, pnpm creates a virtual store directory without
any symlinks. It is a useful setting together with nodeLinker=pnp
.
enableModulesDir
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
当 false
时,pnpm 不会向模块目录(node_modules
)写入任何文件。当模块目录与用户空间(FUSE)中的文件系统一起安装时,这非常有用。有一个实验性的 CLI,允许你使用 FUSE 挂载模块目录:@pnpm/mount-modules。
¥When false
, pnpm will not write any files to the modules directory
(node_modules
). This is useful for when the modules directory is mounted with
filesystem in userspace (FUSE). There is an experimental CLI that allows you to
mount a modules directory with FUSE: @pnpm/mount-modules.
virtualStoreDir
-
默认:node_modules/.pnpm
¥Default: node_modules/.pnpm
-
类型:path
¥Types: path
包含存储链接的目录。项目的所有直接和间接依赖都链接到此目录中。
¥The directory with links to the store. All direct and indirect dependencies of the project are linked into this directory.
这是一个有用的设置,可以解决 Windows 上的长路径问题。如果你有一些路径很长的依赖,你可以在驱动器的根目录中选择一个虚拟存储(例如 C:\my-project-store
)。
¥This is a useful setting that can solve issues with long paths on Windows. If
you have some dependencies with very long paths, you can select a virtual store
in the root of your drive (for instance C:\my-project-store
).
或者你可以将虚拟存储设置为 .pnpm
并将其添加到 .gitignore
。这将使堆栈跟踪更清晰,因为依赖的路径将高一个目录。
¥Or you can set the virtual store to .pnpm
and add it to .gitignore
. This
will make stacktraces cleaner as paths to dependencies will be one directory
higher.
注意:虚拟存储不能在多个项目之间共享。每个项目都应该有自己的虚拟存储(共享根目录的工作区除外)。
¥NOTE: the virtual store cannot be shared between several projects. Every project should have its own virtual store (except for in workspaces where the root is shared).
virtualStoreDirMaxLength
-
默认:
¥Default:
-
在 Linux/macOS 上:120
¥On Linux/macOS: 120
-
在 Windows 上:60
¥On Windows: 60
-
-
类型:number
¥Types: number
设置虚拟存储目录 (node_modules/.pnpm
) 内目录名称的最大允许长度。如果你在 Windows 上遇到长路径问题,可以将其设置为较低的数字。
¥Sets the maximum allowed length of directory names inside the virtual store directory (node_modules/.pnpm
). You may set this to a lower number if you encounter long path issues on Windows.
packageImportMethod
-
默认:auto
¥Default: auto
-
类型:自动、硬链接、复制、克隆、克隆或复制
¥Type: auto, hardlink, copy, clone, clone-or-copy
控制从存储导入包的方式(如果要禁用 node_modules
内的符号链接,则需要更改 nodeLinker 设置,而不是此设置)。
¥Controls the way packages are imported from the store (if you want to disable symlinks inside node_modules
, then you need to change the nodeLinker setting, not this one).
-
auto - 尝试从 存储克隆包。如果不支持克隆,则从存储硬链接包。如果克隆和链接都不可能,则退回到复制
¥auto - try to clone packages from the store. If cloning is not supported then hardlink packages from the store. If neither cloning nor linking is possible, fall back to copying
-
hardlink - 来自存储的硬链接包
¥hardlink - hard link packages from the store
-
clone-or-copy - 尝试从存储克隆包。如果不支持克隆,则退回到复制
¥clone-or-copy - try to clone packages from the store. If cloning is not supported then fall back to copying
-
copy - 从存储复制包
¥copy - copy packages from the store
-
clone - 从存储克隆(又名写入时复制或参考链接)包
¥clone - clone (AKA copy-on-write or reference link) packages from the store
克隆是将包写入 node_modules 的最佳方法。这是最快的方法,也是最安全的方法。使用克隆时,你可以编辑 node_modules 中的文件,并且它们不会在中央内容可寻址存储中被修改。
¥Cloning is the best way to write packages to node_modules. It is the fastest way and safest way. When cloning is used, you may edit files in your node_modules and they will not be modified in the central content-addressable store.
不幸的是,并非所有文件系统都支持克隆。我们建议使用写时复制 (CoW) 文件系统(例如,Linux 上的 Btrfs 而不是 Ext4),以获得 pnpm 的最佳体验。
¥Unfortunately, not all file systems support cloning. We recommend using a copy-on-write (CoW) file system (for instance, Btrfs instead of Ext4 on Linux) for the best experience with pnpm.
modulesCacheMaxAge
-
默认:10080(7 天分钟)
¥Default: 10080 (7 days in minutes)
-
类型:number
¥Type: number
应从模块目录中删除孤立包的时间(以分钟为单位)。pnpm 在模块目录中保留包的缓存。这可以提高切换分支或降级依赖时的安装速度。
¥The time in minutes after which orphan packages from the modules directory should be removed. pnpm keeps a cache of packages in the modules directory. This boosts installation speed when switching branches or downgrading dependencies.
dlxCacheMaxAge
-
默认:1440(1 天的分钟数)
¥Default: 1440 (1 day in minutes)
-
类型:number
¥Type: number
dlx 缓存过期的时间(以分钟为单位)。执行 dlx 命令后,pnpm 会保留一个缓存,该缓存会省略后续调用同一 dlx 命令的安装步骤。
¥The time in minutes after which dlx cache expires. After executing a dlx command, pnpm keeps a cache that omits the installation step for subsequent calls to the same dlx command.
存储设置
¥Store Settings
storeDir
-
默认:
¥Default:
-
如果设置了 $PNPM_HOME 环境变量,则 $PNPM_HOME/store
¥If the $PNPM_HOME env variable is set, then $PNPM_HOME/store
-
如果设置了 $XDG_DATA_HOME 环境变量,则 $XDG_DATA_HOME/pnpm/store
¥If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/store
-
在 Windows 上:~/AppData/Local/pnpm/store
¥On Windows: ~/AppData/Local/pnpm/store
-
在 macOS 上:~/Library/pnpm/store
¥On macOS: ~/Library/pnpm/store
-
在 Linux 上:~/.local/share/pnpm/store
¥On Linux: ~/.local/share/pnpm/store
-
-
类型:path
¥Type: path
所有包在磁盘上的保存位置。
¥The location where all the packages are saved on the disk.
该存储应始终位于进行安装的同一磁盘上,因此每个磁盘将有一个存储。如果当前磁盘上有主目录,则在其中创建存储。如果磁盘上没有主目录,则在文件系统的根目录下创建存储。例如,如果安装发生在安装在 /mnt
的文件系统上,则存储将在 /mnt/.pnpm-store
创建。Windows 系统也是如此。
¥The store should be always on the same disk on which installation is happening,
so there will be one store per disk. If there is a home directory on the current
disk, then the store is created inside it. If there is no home on the disk,
then the store is created at the root of the filesystem. For
example, if installation is happening on a filesystem mounted at /mnt
,
then the store will be created at /mnt/.pnpm-store
. The same goes for Windows
systems.
可以从不同的磁盘设置存储,但在这种情况下,pnpm 将从存储中复制包而不是硬链接它们,因为硬链接只能在同一文件系统上使用。
¥It is possible to set a store from a different disk but in that case pnpm will copy packages from the store instead of hard-linking them, as hard links are only possible on the same filesystem.
verifyStoreIntegrity
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
默认情况下,如果存储中的文件已被修改,则在将其链接到项目的 node_modules
之前会检查该文件的内容。如果 verifyStoreIntegrity
设置为 false
,则在安装过程中不会检查内容寻址存储中的文件。
¥By default, if a file in the store has been modified, the content of this file is checked before linking it to a project's node_modules
. If verifyStoreIntegrity
is set to false
, files in the content-addressable store will not be checked during installation.
useRunningStoreServer
已弃用的 功能
¥Deprecated feature
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
仅允许使用存储服务器进行安装。如果没有正在运行的存储服务器,安装将失败。
¥Only allows installation with a store server. If no store server is running, installation will fail.
strictStorePkgContentCheck
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
某些注册表允许在不同的包名称和/或版本下发布完全相同的内容。这会破坏存储中软件包的有效性检查。为了避免在存储中验证此类软件包的名称和版本时出现错误,你可以将 strictStorePkgContentCheck
设置设置为 false
。
¥Some registries allow the exact same content to be published under different package names and/or versions. This breaks the validity checks of packages in the store. To avoid errors when verifying the names and versions of such packages in the store, you may set the strictStorePkgContentCheck
setting to false
.
锁定文件设置
¥Lockfile Settings
lockfile
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
当设置为 false
时,pnpm 将不会读取或生成 pnpm-lock.yaml
文件。
¥When set to false
, pnpm won't read or generate a pnpm-lock.yaml
file.
preferFrozenLockfile
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
当设置为 true
并且可用的 pnpm-lock.yaml
满足 package.json
依赖指令时,将执行无头安装。无头安装会跳过所有依赖解析,因为它不需要修改锁定文件。
¥When set to true
and the available pnpm-lock.yaml
satisfies the
package.json
dependencies directive, a headless installation is performed. A
headless installation skips all dependency resolution as it does not need to
modify the lockfile.
lockfileIncludeTarballUrl
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
将软件包 tarball 的完整 URL 添加到 pnpm-lock.yaml
中的每个条目。
¥Add the full URL to the package's tarball to every entry in pnpm-lock.yaml
.
gitBranchLockfile
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
当设置为 true
时,安装后生成的锁定文件名称将根据当前分支名称命名,以完全避免合并冲突。例如,如果当前分支名称为 feature-foo
,则对应的锁文件名称将为 pnpm-lock.feature-foo.yaml
,而不是 pnpm-lock.yaml
。它通常与命令行参数 --merge-git-branch-lockfiles
结合使用,或者通过在 pnpm-workspace.yaml
文件中设置 mergeGitBranchLockfilesBranchPattern
来使用。
¥When set to true
, the generated lockfile name after installation will be named
based on the current branch name to completely avoid merge conflicts. For example,
if the current branch name is feature-foo
, the corresponding lockfile name will
be pnpm-lock.feature-foo.yaml
instead of pnpm-lock.yaml
. It is typically used
in conjunction with the command line argument --merge-git-branch-lockfiles
or by
setting mergeGitBranchLockfilesBranchPattern
in the pnpm-workspace.yaml
file.
mergeGitBranchLockfilesBranchPattern
-
默认:null
¥Default: null
-
类型:数组或空值
¥Type: Array or null
该配置匹配当前分支名称来确定是否合并所有 git 分支 lockfile 文件。默认情况下,需要手动传递 --merge-git-branch-lockfiles
命令行参数。此配置允许该过程自动补齐。
¥This configuration matches the current branch name to determine whether to merge
all git branch lockfile files. By default, you need to manually pass the
--merge-git-branch-lockfiles
command line parameter. This configuration allows
this process to be automatically completed.
例如:
¥For instance:
mergeGitBranchLockfilesBranchPattern:
- main
- release*
你还可以使用 !
排除模式。
¥You may also exclude patterns using !
.
peersSuffixMaxLength
-
默认:1000
¥Default: 1000
-
类型:number
¥Type: number
添加到锁文件中依赖密钥的对等 ID 后缀的最大长度。如果后缀较长,则用哈希替换。
¥Max length of the peer IDs suffix added to dependency keys in the lockfile. If the suffix is longer, it is replaced with a hash.
注册表和身份验证设置
¥Registry & Authentication Settings
registry
-
默认:https://registry.npmjs.org/
¥Default: https://registry.npmjs.org/
-
类型:url
¥Type: url
npm 包注册表的基本 URL(包括尾部斜杠)。
¥The base URL of the npm package registry (trailing slash included).
<scope>:registry
应用于指定范围的包的 npm 注 册表。例如,设置 @babel:registry=https://example.com/packages/npm/
将强制当你使用 pnpm add @babel/core
或任何 @babel
范围的包时,将从 https://example.com/packages/npm
而不是默认注册表获取该包。
¥The npm registry that should be used for packages of the specified scope. For
example, setting @babel:registry=https://example.com/packages/npm/
will enforce that when you use pnpm add @babel/core
, or any @babel
scoped
package, the package will be fetched from https://example.com/packages/npm
instead of the default registry.
<URL>:_authToken
定义访问指定注册表时要使用的身份验证承载令牌。例如:
¥Define the authentication bearer token to use when accessing the specified registry. For example:
//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
你还可以使用环境变量。例如:
¥You may also use an environment variable. For example:
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
或者你可以直接使用环境变量,根本不更改 .npmrc
:
¥Or you may just use an environment variable directly, without changing .npmrc
at all:
npm_config_//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
<URL>:tokenHelper
令牌助手是一个输出身份验证令牌的可执行文件。这可以用于 authToken 不是常量值而是定期刷新的情况,其中脚本或其他工具可以使用现有刷新令牌来获取新的访问令牌。
¥A token helper is an executable which outputs an auth token. This can be used in situations where the authToken is not a constant value but is something that refreshes regularly, where a script or other tool can use an existing refresh token to obtain a new access token.
辅助程序的路径配置必须是绝对路径,不带任何参数。为了安全起见,只允许在用户 .npmrc
中设置该值。否则,项目可以在项目的本地 .npmrc
中放置一个值并运行任意可执行文件。
¥The configuration for the path to the helper must be an absolute path, with no arguments. In order to be secure, it is only permitted to set this value in the user .npmrc
. Otherwise a project could place a value in a project's local .npmrc
and run arbitrary executables.
为默认注册表设置令牌助手:
¥Setting a token helper for the default registry:
tokenHelper=/home/ivan/token-generator
为指定注册表设置令牌助手:
¥Setting a token helper for the specified registry:
//registry.corp.com:tokenHelper=/home/ivan/token-generator
请求设置
¥Request Settings
ca
-
默认:npm CA 证书
¥Default: The npm CA certificate
-
类型:字符串、数组或 null
¥Type: String, Array or null
与注册表的 SSL 连接受信任的证书颁发机构签名证书。值应采用 PEM 格式(AKA "Base-64 编码的 X.509 (.CER)")。例如:
¥The Certificate Authority signing certificate that is trusted for SSL connections to the registry. Values should be in PEM format (AKA "Base-64 encoded X.509 (.CER)"). For example:
ca="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"
设置为 null 以仅允许已知的注册商,或设置为特定 CA 证书以仅信任该特定签名机构。
¥Set to null to only allow known registrars, or to a specific CA cert to trust only that specific signing authority.
通过指定证书数组可以信任多个 CA:
¥Multiple CAs can be trusted by specifying an array of certificates:
ca[]="..."
ca[]="..."
另请参阅 strict-ssl
配置。
¥See also the strict-ssl
config.
cafile
-
默认:null
¥Default: null
-
类型:path
¥Type: path
包含一个或多个证书颁发机构签名证书的文件的路径。与 ca
设置类似,但允许多个 CA,以及将 CA 信息存储在文件中而不是通过 CLI 指定。
¥A path to a file containing one or multiple Certificate Authority signing
certificates. Similar to the ca
setting, but allows for multiple CAs, as well
as for the CA information to be stored in a file instead of being specified via
CLI.
<URL>:cafile
定义访问指定注册表时要使用的证书颁发机构文件的路径。例如:
¥Define the path to a Certificate Authority file to use when accessing the specified registry. For example:
//registry.npmjs.org/:cafile=ca-cert.pem
cert
-
默认:null
¥Default: null
-
类型:字符串
¥Type: String
访问注册表时要传递的客户端证书。值应采用 PEM 格式(AKA "Base-64 编码的 X.509 (.CER)")。例如:
¥A client certificate to pass when accessing the registry. Values should be in PEM format (AKA "Base-64 encoded X.509 (.CER)"). For example:
cert="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"
它不是证书文件的路径。
¥It is not the path to a certificate file.
<URL>:certfile
定义访问指定注册表时要使用的证书文件的路径。例如:
¥Define the path to a certificate file to use when accessing the specified registry. For example:
//registry.npmjs.org/:certfile=server-cert.pem
key
-
默认:null
¥Default: null
-
类型:字符串
¥Type: String
访问注册表时传递的客户端密钥。值应采用 PEM 格式(AKA "Base-64 编码的 X.509 (.CER)")。例如:
¥A client key to pass when accessing the registry. Values should be in PEM format (AKA "Base-64 encoded X.509 (.CER)"). For example:
key="-----BEGIN PRIVATE KEY-----\nXXXX\nXXXX\n-----END PRIVATE KEY-----"
它不是密钥文件的路径(并且没有 keyfile
选项)。
¥It is not the path to a key file (and there is no keyfile
option).
此设置包含敏感信息。不要将其写入提交到存储库的本地 .npmrc
文件。
¥This setting contains sensitive information. Don't write it to a local .npmrc
file committed to the repository.
<URL>:keyfile
定义访问指定注册表时要使用的客户端密钥文件的路径。例如:
¥Define the path to a client key file to use when accessing the specified registry. For example:
//registry.npmjs.org/:keyfile=server-key.pem
gitShallowHosts
-
默认:['github.com', 'gist.github.com', 'gitlab.com', 'bitbucket.com', 'bitbucket.org']
¥Default: ['github.com', 'gist.github.com', 'gitlab.com', 'bitbucket.com', 'bitbucket.org']
-
类型:string[]
¥Type: string[]
当获取 Git 存储库的依赖时,如果主机在此设置中列出,pnpm 将使用浅克隆仅获取所需的提交,而不是所有历史记录。
¥When fetching dependencies that are Git repositories, if the host is listed in this setting, pnpm will use shallow cloning to fetch only the needed commit, not all the history.
https-proxy
-
默认:null
¥Default: null
-
类型:url
¥Type: url
用于传出 HTTPS 请求的代理。如果设置了 HTTPS_PROXY
、https_proxy
、HTTP_PROXY
或 http_proxy
环境变量,则将使用它们的值。
¥A proxy to use for outgoing HTTPS requests. If the HTTPS_PROXY
, https_proxy
,
HTTP_PROXY
or http_proxy
environment variables are set, their values will be
used instead.
如果你的代理 URL 包含用户名和密码,请确保对它们进行 URL 编码。例如:
¥If your proxy URL contains a username and password, make sure to URL-encode them. For instance:
https-proxy=https://use%21r:pas%2As@my.proxy:1234/foo
不要对用户名和密码之间的冒号 (:
) 进行编码。
¥Do not encode the colon (:
) between the username and password.
http-proxy
proxy
-
默认:null
¥Default: null
-
类型:url
¥Type: url
用于传出 http 请求的代理。如果设置了 HTTP_PROXY 或 http_proxy 环境变量,底层请求库将遵循代理设置。
¥A proxy to use for outgoing http requests. If the HTTP_PROXY or http_proxy environment variables are set, proxy settings will be honored by the underlying request library.
local-address
-
默认:undefined
¥Default: undefined
-
类型:IP 地址
¥Type: IP Address
连接到 npm 注册表时使用的本地接口的 IP 地址。
¥The IP address of the local interface to use when making connections to the npm registry.
maxsockets
-
默认:网络并发数 x 3
¥Default: networkConcurrency x 3
-
类型:数字
¥Type: Number
每个源使用的最大连接数(协议/主机/端口组合)。
¥The maximum number of connections to use per origin (protocol/host/port combination).
noproxy
-
默认:null
¥Default: null
-
类型:字符串
¥Type: String
不应使用代理的以逗号分隔的域扩展字符串。
¥A comma-separated string of domain extensions that a proxy should not be used for.
strict-ssl
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
通过 HTTPS 向注册表发送请求时是否进行 SSL 密钥验证。
¥Whether or not to do SSL key validation when making requests to the registry via HTTPS.
另请参见 ca
选项。
¥See also the ca
option.
networkConcurrency
-
默认:16
¥Default: 16
-
类型:数字
¥Type: Number
控制同时处理的 HTTP(S) 请求的最大数量。
¥Controls the maximum number of HTTP(S) requests to process simultaneously.
fetchRetries
-
默认:2
¥Default: 2
-
类型:数字
¥Type: Number
如果 pnpm 无法从注册表获取,则重试多少次。
¥How many times to retry if pnpm fails to fetch from the registry.
fetchRetryFactor
-
默认:10
¥Default: 10
-
类型:数字
¥Type: Number
重试退避的指数因子。
¥The exponential factor for retry backoff.
fetchRetryMintimeout
-
默认:10000(10 秒)
¥Default: 10000 (10 seconds)
-
类型:数字
¥Type: Number
重试请求的最小(基本)超时。
¥The minimum (base) timeout for retrying requests.
fetchRetryMaxtimeout
-
默认:60000(1 分钟)
¥Default: 60000 (1 minute)
-
类型:数字
¥Type: Number
确保重试因子不会使请求过长的最大回退超时。
¥The maximum fallback timeout to ensure the retry factor does not make requests too long.
fetchTimeout
-
默认:60000(1 分钟)
¥Default: 60000 (1 minute)
-
类型:数字
¥Type: Number
等待 HTTP 请求完成的最长时间。
¥The maximum amount of time to wait for HTTP requests to complete.
对等依赖设置
¥Peer Dependency Settings
autoInstallPeers
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
当 true
时,将自动安装任何缺失的非可选对等依赖。
¥When true
, any missing non-optional peer dependencies are automatically installed.
版本冲突
¥Version Conflicts
如果来自不同包的对等依赖存在版本要求冲突,pnpm 将不会自动安装冲突对等依赖的任何版本。相反,会打印一条警告。例如,如果一个依赖需要 react@^16.0.0
,而另一个依赖需要 react@^17.0.0
,则这些要求会发生冲突,并且不会发生自动安装。
¥If there are conflicting version requirements for a peer dependency from different packages, pnpm will not install any version of the conflicting peer dependency automatically. Instead, a warning is printed. For example, if one dependency requires react@^16.0.0
and another requires react@^17.0.0
, these requirements conflict, and no automatic installation will occur.
解决冲突
¥Conflict Resolution
如果出现版本冲突,你需要评估自己安装哪个版本的对等依赖,或更新依赖以符合其对等依赖要求。
¥In case of a version conflict, you'll need to evaluate which version of the peer dependency to install yourself, or update the dependencies to align their peer dependency requirements.
dedupePeerDependents
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
当此设置设置为 true
时,具有对等依赖的包将在对等解析后进行数据去重。
¥When this setting is set to true
, packages with peer dependencies will be deduplicated after peers resolution.
例如,假设我们有一个包含两个项目的工作区,并且它们的依赖中都有 webpack
。webpack
在其可选对等依赖中具有 esbuild
,其中一个项目在其依赖中具有 esbuild
。在这种情况下,pnpm 会将 webpack
的两个实例链接到 node_modules/.pnpm
目录:一个带 esbuild
,另一个不带 esbuild
:
¥For instance, let's say we have a workspace with two projects and both of them have webpack
in their dependencies. webpack
has esbuild
in its optional peer dependencies, and one of the projects has esbuild
in its dependencies. In this case, pnpm will link two instances of webpack
to the node_modules/.pnpm
directory: one with esbuild
and another one without it:
node_modules
.pnpm
webpack@1.0.0_esbuild@1.0.0
webpack@1.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0/node_modules/webpack
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild
这是有道理的,因为 webpack
在两个项目中使用,而其中一个项目没有 esbuild
,因此这两个项目不能共享 webpack
的同一个实例。然而,这并不是大多数开发者所期望的,特别是因为在提升的 node_modules
中,只会有一个 webpack
实例。因此,当 webpack
不存在冲突的对等依赖时,你现在可以使用 dedupePeerDependents
设置来对 webpack
进行数据去重(解释在最后)。在这种情况下,如果我们将 dedupePeerDependents
设置为 true
,则两个项目都将使用相同的 webpack
实例,即已解析 esbuild
的实例:
¥This makes sense because webpack
is used in two projects, and one of the projects doesn't have esbuild
, so the two projects cannot share the same instance of webpack
. However, this is not what most developers expect, especially since in a hoisted node_modules
, there would only be one instance of webpack
. Therefore, you may now use the dedupePeerDependents
setting to deduplicate webpack
when it has no conflicting peer dependencies (explanation at the end). In this case, if we set dedupePeerDependents
to true
, both projects will use the same webpack
instance, which is the one that has esbuild
resolved:
node_modules
.pnpm
webpack@1.0.0_esbuild@1.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild
什么是冲突的对等依赖?通过冲突 的对等依赖,我们指的是如下场景:
¥What are conflicting peer dependencies? By conflicting peer dependencies we mean a scenario like the following one:
node_modules
.pnpm
webpack@1.0.0_react@16.0.0_esbuild@1.0.0
webpack@1.0.0_react@17.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0/node_modules/webpack
react (v17)
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild
react (v16)
在这种情况下,我们无法对 webpack
进行数据去重,因为 webpack
在其对等依赖中具有 react
,而 react
是从两个项目上下文中的两个不同版本解析的。
¥In this case, we cannot dedupe webpack
as webpack
has react
in its peer dependencies and react
is resolved from two different versions in the context of the two projects.
strictPeerDependencies
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果启用此功能,如果树中缺少或无效的对等依赖,命令将失败。
¥If this is enabled, commands will fail if there is a missing or invalid peer dependency in the tree.
resolvePeersFromWorkspaceRoot
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
启用后,根工作区项目的依赖用于解决工作区中任何项目的对等依赖。这是一个有用的功能,因为你只能在工作区的根目录中安装对等依赖,并且你可以确保工作区中的所有项目都使用相同版本的对等依赖。
¥When enabled, dependencies of the root workspace project are used to resolve peer dependencies of any projects in the workspace. It is a useful feature as you can install your peer dependencies only in the root of the workspace, and you can be sure that all projects in the workspace use the same versions of the peer dependencies.
peerDependencyRules
peerDependencyRules.ignoreMissing
pnpm 不会打印有关此列表中缺少对等依赖的警告。
¥pnpm will not print warnings about missing peer dependencies from this list.
例如,使用以下配置,如果依赖需要 react
但未安装 react
,pnpm 将不会打印警告:
¥For instance, with the following configuration, pnpm will not print warnings if a dependency needs react
but react
is not installed:
peerDependencyRules:
ignoreMissing:
- react
还可以使用包名称模式:
¥Package name patterns may also be used:
peerDependencyRules:
ignoreMissing:
- "@babel/*"
- "@eslint/*"
peerDependencyRules.allowedVersions
对于指定范围的对等依赖,不会打印未满足的对等依赖警告。
¥Unmet peer dependency warnings will not be printed for peer dependencies of the specified range.
例如,如果你有一些依赖需要 react@16
,但你知道它们可以与 react@17
一起正常工作,那么你可以使用以下配置 :
¥For instance, if you have some dependencies that need react@16
but you know that they work fine with react@17
, then you may use the following configuration:
peerDependencyRules:
allowedVersions:
react: "17"
这将告诉 pnpm,任何在其对等依赖中发生反应的依赖都应该允许安装 react
v17。
¥This will tell pnpm that any dependency that has react in its peer dependencies should allow react
v17 to be installed.
还可以仅针对特定包的对等依赖抑制警告。例如,使用以下配置,仅当 react
v17 位于 button
v2 包的对等依赖或任何 card
包的依赖中时,才允许使用 react
v17:
¥It is also possible to suppress the warnings only for peer dependencies of specific packages. For instance, with the following configuration react
v17 will be only allowed when it is in the peer dependencies of the button
v2 package or in the dependencies of any card
package:
peerDependencyRules:
allowedVersions:
"button@2>react": "17",
"card>react": "17"
peerDependencyRules.allowAny
allowAny
是包名称模式的数组,任何与该模式匹配的对等依赖都将从任何版本解析,无论 peerDependencies
中指定的范围如何。例如:
¥allowAny
is an array of package name patterns, any peer dependency matching the pattern will be resolved from any version, regardless of the range specified in peerDependencies
. For instance:
peerDependencyRules:
allowAny:
- "@babel/*"
- "eslint"
上述设置将消除有关与 @babel/
包或 eslint
相关的对等依赖版本不匹配的任何警告。
¥The above setting will mute any warnings about peer dependency version mismatches related to @babel/
packages or eslint
.
CLI 设置
¥CLI Settings
[no-]color
-
默认:auto
¥Default: auto
-
类型:auto, always, never
¥Type: auto, always, never
控制输出中的颜色。
¥Controls colors in the output.
-
auto - 当标准输出是终端或 TTY 时,输出使用颜色。
¥auto - output uses colors when the standard output is a terminal or TTY.
-
always - 忽略端子和管道之间的差异。你很少会想要这个;在大多数情况下,如果你希望在重定向输出中使用颜色代码,则可以将
--color
标志传递给 pnpm 命令以强制其使用颜色代码。默认设置几乎总是你想要的。¥always - ignore the difference between terminals and pipes. You’ll rarely want this; in most scenarios, if you want color codes in your redirected output, you can instead pass a
--color
flag to the pnpm command to force it to use color codes. The default setting is almost always what you’ll want. -
never - turns off colors.这是
--no-color
使用的设置。¥never - turns off colors. This is the setting used by
--no-color
.
loglevel
-
默认:info
¥Default: info
-
类型:debug, info, warn, error
¥Type: debug, info, warn, error
将显示任何等于或高于给定 级别的日志。你可以改为传递 --silent
来关闭所有输出日志。
¥Any logs at or higher than the given level will be shown.
You can instead pass --silent
to turn off all output logs.
useBetaCli
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
启用 CLI 测试版功能的实验选项。这意味着你可能会对 CLI 功能进行一些更改,这些更改可能是重大更改或潜在的错误。
¥Experimental option that enables beta features of the CLI. This means that you may get some changes to the CLI functionality that are breaking changes, or potentially bugs.
recursiveInstall
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
如果启用此选项,pnpm install
的主要行为将成为 pnpm install -r
的主要行为,这意味着安装将在所有工作区或子目录包上执行。
¥If this is enabled, the primary behaviour of pnpm install
becomes that of
pnpm install -r
, meaning the install is performed on all workspace or
subdirectory packages.
否则,pnpm install
将在当前目录中专门构建包。
¥Else, pnpm install
will exclusively build the package in the current
directory.
engineStrict
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果启用此功能,pnpm 将不会安装任何声称与当前 Node 版本不兼容的软件包。
¥If this is enabled, pnpm will not install any package that claims to not be compatible with the current Node version.
无论此配置如何,如果项目(不是依赖)在其 engines
字段中指定了不兼容的版本,安装将始终失败。
¥Regardless of this configuration, installation will always fail if a project
(not a dependency) specifies an incompatible version in its engines
field.
npmPath
-
类型:path
¥Type: path
pnpm 用于某些操作(例如发布)的 npm 二进制文件的位置。
¥The location of the npm binary that pnpm uses for some actions, like publishing.
packageManagerStrict
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
如果禁用此设置,如果在 package.json
的 packageManager
字段中指定了不同的包管理器,pnpm 将不会失败。启用后,只会检查软件包名称(自 pnpm v9.2.0 起),因此无论 packageManager
字段中指定的版本如何,你仍然可以运行任何版本的 pnpm。
¥If this setting is disabled, pnpm will not fail if a different package manager is specified in the packageManager
field of package.json
. When enabled, only the package name is checked (since pnpm v9.2.0), so you can still run any version of pnpm regardless of the version specified in the packageManager
field.
或者,你可以通过将 COREPACK_ENABLE_STRICT
环境变量设置为 0
来禁用此设置。
¥Alternatively, you can disable this setting by setting the COREPACK_ENABLE_STRICT
environment variable to 0
.
packageManagerStrictVersion
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
启用后,如果 pnpm 的版本与 package.json
的 packageManager
字段中指定的版本不完全匹配,则 pnpm 将失败。
¥When enabled, pnpm will fail if its version doesn't exactly match the version specified in the packageManager
field of package.json
.
managePackageManagerVersions
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
启用后,pnpm 将自动下载并运行 package.json
的 packageManager
字段中指定的 pnpm 版本。这是 Corepack 使用的相同字段。示例:
¥When enabled, pnpm will automatically download and run the version of pnpm specified in the packageManager
field of package.json
. This is the same field used by Corepack. Example:
{
"packageManager": "pnpm@9.3.0"
}
构建设置
¥Build Settings
ignoreScripts
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
不要执行项目 package.json
及其依赖中定义的任何脚本。
¥Do not execute any scripts defined in the project package.json
and its
dependencies.
该标志不会阻止 .pnpmfile.cjs 的执行
¥This flag does not prevent the execution of .pnpmfile.cjs
ignoreDepScripts
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
不要执行已安装软件包的任何脚本。执行项目的脚本。
¥Do not execute any scripts of the installed packages. Scripts of the projects are executed.
从 v10 开始,除非依赖在 onlyBuiltDependencies
中列出,否则 pnpm 不会运行依赖的生命周期脚本。
¥Since v10, pnpm doesn't run the lifecycle scripts of dependencies unless they are listed in onlyBuiltDependencies
.
childConcurrency
-
默认:5
¥Default: 5
-
类型:数字
¥Type: Number
同时分配以构建 node_modules 的子进程的最大数量。
¥The maximum number of child processes to allocate simultaneously to build node_modules.
sideEffectsCache
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
使用并缓存(前/后)安装钩子的结果。
¥Use and cache the results of (pre/post)install hooks.
sideEffectsCacheReadonly
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
仅使用副作用缓存(如果存在),不要为新包创建它。
¥Only use the side effects cache if present, do not create it for new packages.
unsafePerm
-
默认:如果以 root 身份运行则为 false,否则为 true
¥Default: false IF running as root, ELSE true
-
类型:布尔值
¥Type: Boolean
设置为 true 以在运行包脚本时启用 UID/GID 切换。如果明确设置为 false,则以非 root 用户身份安装将会失败。
¥Set to true to enable UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.
nodeOptions
-
默认:NULL
¥Default: NULL
-
类型:字符串
¥Type: String
通过 NODE_OPTIONS
环境变量传递 到 Node.js 的选项。这不会影响 pnpm 本身的执行方式,但会影响生命周期脚本的调用方式。
¥Options to pass through to Node.js via the NODE_OPTIONS
environment variable. This does not impact how pnpm itself is executed but it does impact how lifecycle scripts are called.
verifyDepsBeforeRun
-
默认:false
¥Default: false
-
类型:install、warn、error、prompt、false
¥Type: install, warn, error, prompt, false
此设置允许在运行脚本之前检查依赖的状态。检查在 pnpm run
和 pnpm exec
命令上运行。支持以下值:
¥This setting allows the checking of the state of dependencies before running scripts. The check runs on pnpm run
and pnpm exec
commands. The following values are supported:
-
install
- 如果node_modules
不是最新的,则自动运行安装。¥
install
- Automatically runs install ifnode_modules
is not up to date. -
warn
- 如果node_modules
不是最新的,则打印警告。¥
warn
- Prints a warning ifnode_modules
is not up to date. -
prompt
- 如果node_modules
不是最新的,则提示用户允许运行安装。¥
prompt
- Prompts the user for permission to run install ifnode_modules
is not up to date. -
error
- 如果node_modules
不是最新的,则抛出错误。¥
error
- Throws an error ifnode_modules
is not up to date. -
false
- 禁用依赖检查。¥
false
- Disables dependency checks.
strictDepBuilds
已添加于:v10.3.0
¥Added in: v10.3.0
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
启用 strictDepBuilds
后,如果任何依赖具有未审核的构建脚本(又名安装后脚本),则安装将以非零退出代码退出。
¥When strictDepBuilds
is enabled, the installation will exit with a non-zero exit code if any dependencies have unreviewed build scripts (aka postinstall scripts).
neverBuiltDependencies
该字段允许忽略特定依赖的构建。列出的软件包的 "preinstall"、"install" 和 "postinstall" 脚本在安装过程中不会执行。
¥This field allows to ignore the builds of specific dependencies. The "preinstall", "install", and "postinstall" scripts of the listed packages will not be executed during installation.
neverBuiltDependencies
字段的示例:
¥An example of the neverBuiltDependencies
field:
neverBuiltDependencies:
- fsevents
- level
onlyBuiltDependencies
安装期间允许执行的包名称列表。只有此数组中列出的包才能运行安装脚本。如果未设置 onlyBuiltDependenciesFile
和 neverBuiltDependencies
,则此配置选项将默认阻止所有安装脚本。
¥A list of package names that are allowed to be executed during installation. Only packages listed in this array will be able to run install scripts. If onlyBuiltDependenciesFile
and neverBuiltDependencies
are not set, this configuration option will default to blocking all install scripts.
示例:
¥Example:
onlyBuiltDependencies:
- fsevents
onlyBuiltDependenciesFile
此配置选项允许用户指定一个 JSON 文件,该文件列出了在 pnpm 安装过程中允许运行安装脚本的唯一包。通过使用它,你可以增强安全性或确保在安装过程中只有特定的依赖执行脚本。
¥This configuration option allows users to specify a JSON file that lists the only packages permitted to run installation scripts during the pnpm install process. By using this, you can enhance security or ensure that only specific dependencies execute scripts during installation.
示例:
¥Example:
configDependencies:
"@my-org/policy": 1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==
onlyBuiltDependenciesFile: node_modules/.pnpm-config/@my-org/policy/onlyBuiltDependencies.json
JSON 文件本身应包含一组包名称:
¥The JSON file itself should contain an array of package names:
[
"fsevents"
]
ignoredBuiltDependencies
已添加于:v10.1.0
¥Added in: v10.1.0
不应在安装期间构建的软件包名称列表。
¥A list of package names that should not be built during installation.
示例:
¥Example:
ignoredBuiltDependencies:
- fsevents
dangerouslyAllowAllBuilds
已添加于:v10.9.0
¥Added in: v10.9.0
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果设置为 true
,则依赖中的所有构建脚本(例如 preinstall
、install
、postinstall
)将自动运行,无需批准。
¥If set to true
, all build scripts (e.g. preinstall
, install
, postinstall
) from dependencies will run automatically, without requiring approval.
此设置允许所有依赖(包括传递依赖)现在和将来运行安装脚本。即使你当前的依赖图看起来是安全的:
¥This setting allows all dependencies—including transitive ones—to run install scripts, both now and in the future. Even if your current dependency graph appears safe:
-
未来的更新可能会引入新的、不受信任的依赖。
¥Future updates may introduce new, untrusted dependencies.
-
现有包可能会在更高版本中添加脚本。
¥Existing packages may add scripts in later versions.
-
软件包可能被劫持或入侵,并开始执行恶意代码。
¥Packages can be hijacked or compromised and begin executing malicious code.
为了最大限度地 保证安全,请仅在你完全了解风险并信任你正在从中提取数据的整个生态系统的情况下才启用此功能。建议明确审核并允许构建。
¥For maximum safety, only enable this if you’re fully aware of the risks and trust the entire ecosystem you’re pulling from. It’s recommended to review and allow builds explicitly.
Node.js 设置
¥Node.js Settings
useNodeVersion
-
默认:undefined
¥Default: undefined
-
类型:semver
¥Type: semver
指定项目运行时应使用哪个确切的 Node.js 版本。pnpm 将自动安装指定版本的 Node.js 并使用它来运行 pnpm run
命令或 pnpm node
命令。
¥Specifies which exact Node.js version should be used for the project's runtime.
pnpm will automatically install the specified version of Node.js and use it for
running pnpm run
commands or the pnpm node
command.
这可以用来代替 .nvmrc
和 nvm
。而不是以下 .nvmrc
文件:
¥This may be used instead of .nvmrc
and nvm
. Instead of the following .nvmrc
file:
16.16.0
使用此 pnpm-workspace.yaml
文件:
¥Use this pnpm-workspace.yaml
file:
useNodeVersion: 16.16.0
此设置仅适用于工作区根目录中的 pnpm-workspace.yaml
文件 。如果你需要为工作区中的项目指定自定义 Node.js,请改用 package.json
的 executionEnv.nodeVersion
字段。
¥This setting works only in a pnpm-workspace.yaml
file that is in the root of your workspace. If you need to specify a custom Node.js for a project in the workspace, use the executionEnv.nodeVersion
field of package.json
instead.
nodeVersion
-
默认:node -v 返回的值,不带 v 前缀
¥Default: the value returned by node -v, without the v prefix
-
类型:semver
¥Type: semver
检查包的 engines
设置时使用的 Node.js 版本。
¥The Node.js version to use when checking a package's engines
setting.
如果你想阻止项目的贡献者添加新的不兼容依赖,请在项目根目录的 pnpm-workspace.yaml
文件中使用 nodeVersion
和 engineStrict
:
¥If you want to prevent contributors of your project from adding new incompatible dependencies, use nodeVersion
and engineStrict
in a pnpm-workspace.yaml
file at the root of the project:
nodeVersion: 12.22.0
engineStrict: true
这样,即使有人使用 Node.js v16,他们也无法安装不支持 Node.js v12.22.0 的新依赖。
¥This way, even if someone is using Node.js v16, they will not be able to install a new dependency that doesn't support Node.js v12.22.0.
node-mirror
-
默认:
https://nodejs.cn/download/<releaseDir>/
¥Default:
https://nodejs.cn/download/<releaseDir>/
-
类型:URL
¥Type: URL
设置下载 Node.js 的基本 URL。此设置的 <releaseDir>
部分可以是 [https://nodejs.cn/download]https://nodejs.cn/download 中的任何目录:release
、rc
、nightly
、v8-canary
等
¥Sets the base URL for downloading Node.js. The <releaseDir>
portion of this setting can be any directory from https://nodejs.cn/download: release
, rc
, nightly
, v8-canary
, etc.
以下是如何配置 pnpm 从中国的 Node.js 镜像下载 Node.js:
¥Here is how pnpm may be configured to download Node.js from Node.js mirror in China:
node-mirror:release=https://npmmirror.com/mirrors/node/
node-mirror:rc=https://npmmirror.com/mirrors/node-rc/
node-mirror:nightly=https://npmmirror.com/mirrors/node-nightly/
executionEnv.nodeVersion
指定项目运行时应使用哪个确切的 Node.js 版本。pnpm 将自动安装指定版本的 Node.js 并使用它来运行 pnpm run
命令或 pnpm node
命令。
¥Specifies which exact Node.js version should be used for the project's runtime.
pnpm will automatically install the specified version of Node.js and use it for
running pnpm run
commands or the pnpm node
command.
例如:
¥For example:
executionEnv:
nodeVersion: 16.16.0
工作区设置
¥Workspace Settings
linkWorkspacePackages
-
默认:false
¥Default: false
-
类型:true, false, deep
¥Type: true, false, deep
如果启用此功能,本地可用的软件包将链接到 node_modules
,而不是从注册表下载。这在 monorepo 中非常方便。如果你还需要将本地包链接到子依赖,则可以使用 deep
设置。
¥If this is enabled, locally available packages are linked to node_modules
instead of being downloaded from the registry. This is very convenient in a
monorepo. If you need local packages to also be linked to subdependencies, you
can use the deep
setting.
否则,将从注册表下载并安装软件包。但是,仍然可以使用 workspace:
范围协议链接工作区包。
¥Else, packages are downloaded and installed from the registry. However,
workspace packages can still be linked by using the workspace:
range protocol.
只有当软件包的版本满足依赖范围时,才会链接软件包。
¥Packages are only linked if their versions satisfy the dependency ranges.
injectWorkspacePackages
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
启用所有本地工 作区依赖的硬链接,而不是符号链接它们。或者,可以使用 dependenciesMeta[].injected
实现,它允许有选择地为特定依赖启用硬链接。
¥Enables hard-linking of all local workspace dependencies instead of symlinking them. Alternatively, this can be achieved using dependenciesMeta[].injected
, which allows to selectively enable hard-linking for specific dependencies.
syncInjectedDepsAfterScripts
已添加于:v10.5.0
¥Added in: v10.5.0
-
默认:undefined
¥Default: undefined
-
类型:String[]
¥Type: String[]
注入的工作区依赖是硬链接的集合,当文件的源发生更改时,它们不会添加或删除文件。这会导致需要构建的包出现问题(例如在 TypeScript 项目中)。
¥Injected workspace dependencies are collections of hardlinks, which don't add or remove the files when their sources change. This causes problems in packages that need to be built (such as in TypeScript projects).
此设置是脚本名称列表。当在工作区包中执行这些脚本中的任何一个时,node_modules
中注入的依赖也将被同步。
¥This setting is a list of script names. When any of these scripts are executed in a workspace package, the injected dependencies inside node_modules
will also be synchronized.
preferWorkspacePackages
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果启用此功能,则工作区中的本地包优先于注册表中的包,即使注册表中存在较新版本的包也是如此。
¥If this is enabled, local packages from the workspace are preferred over packages from the registry, even if there is a newer version of the package in the registry.
仅当工作区不使用 saveWorkspaceProtocol
时,此设置才有用。
¥This setting is only useful if the workspace doesn't use
saveWorkspaceProtocol
.
sharedWorkspaceLockfile
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
如果启用此功能,pnpm 将在工作区的根目录中创建单个 pnpm-lock.yaml
文件。这也意味着工作区包的所有依赖都将位于单个 node_modules
中(并符号链接到其包 node_modules
文件夹以进行 Node 的模块解析)。
¥If this is enabled, pnpm creates a single pnpm-lock.yaml
file in the root of
the workspace. This also means that all dependencies of workspace packages will
be in a single node_modules
(and get symlinked to their package node_modules
folder for Node's module resolution).
此选项的优点:
¥Advantages of this option:
-
每个依赖都是一个单例
¥every dependency is a singleton
-
monorepo 中的安装速度更快
¥faster installations in a monorepo
-
代码审查中的更改较少,因为它们都在一个文件中
¥fewer changes in code reviews as they are all in one file
尽管所有依赖都将硬链接到根 node_modules
,但包只能访问在其 package.json
中声明的那些依赖,因此保留了 pnpm 的严格性。这是上述符号链接的结果。
¥Even though all the dependencies will be hard linked into the root
node_modules
, packages will have access only to those dependencies
that are declared in their package.json
, so pnpm's strictness is preserved.
This is a result of the aforementioned symbolic linking.
saveWorkspaceProtocol
-
默认:rolling
¥Default: rolling
-
类型:true, false, rolling
¥Type: true, false, rolling
此设置控制如何将从工作 区链接的依赖添加到 package.json
。
¥This setting controls how dependencies that are linked from the workspace are added to package.json
.
如果 foo@1.0.0
在工作区中,并且你在工作区的另一个项目中运行 pnpm add foo
,则以下是将 foo
添加到依赖字段的方式。savePrefix
设置还会影响规范的创建方式。
¥If foo@1.0.0
is in the workspace and you run pnpm add foo
in another project of the workspace, below is how foo
will be added to the dependencies field. The savePrefix
setting also influences how the spec is created.
saveWorkspaceProtocol | savePrefix | 规范 |
---|---|---|
false | '' | 1.0.0 |
false | '~' | ~1.0.0 |
false | '^' | ^1.0.0 |
true | '' | workspace:1.0.0 |
true | '~' | workspace:~1.0.0 |
true | '^' | workspace:^1.0.0 |
rolling | '' | workspace:* |
rolling | '~' | workspace:~ |
rolling | '^' | workspace:^ |
includeWorkspaceRoot
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
在工作区中递归执行命令时,也在根工作区项目上执行它们。
¥When executing commands recursively in a workspace, execute them on the root workspace project as well.
ignoreWorkspaceCycles
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
当设置为 true
时,不会打印工作区循环警告。
¥When set to true
, no workspace cycle warnings will be printed.
disallowWorkspaceCycles
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
当设置为 true
时,如果工作区有循环,安装将失败。
¥When set to true
, installation will fail if the workspace has cycles.
部署设置
¥Deploy Settings
forceLegacyDeploy
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
默认情况下,pnpm deploy
将尝试从共享锁定文件创建专用锁定文件以进行部署。如果将此设置设置为 true
,则将使用旧版 deploy
行为。
¥By default, pnpm deploy
will try creating a dedicated lockfile from a shared lockfile for deployment. If this setting is set to true
, the legacy deploy
behavior will be used.
修补依赖
¥Patching Dependencies
patchedDependencies
当你运行 pnpm patch-commit 时,此字段会自动添加/更新。它使用字典定义依赖的补丁,其中:
¥This field is added/updated automatically when you run pnpm patch-commit. It defines patches for dependencies using a dictionary where:
-
键:包含精确版本、版本范围或仅包含名称的包名称。
¥Keys: Package names with an exact version, a version range, or just the name.
-
值:补丁文件的相对路径。
¥Values: Relative paths to patch files.
示例:
¥Example:
patchedDependencies:
express@4.18.1: patches/express@4.18.1.patch
依赖可以按版本范围进行修补。优先级顺序为:
¥Dependencies can be patched by version range. The priority order is:
-
精确版本(最高优先级)
¥Exact versions (highest priority)
-
版本范围
¥Version ranges
-
仅指定名称的补丁(适用于所有版本,除非被覆盖)
¥Name-only patches (applies to all versions unless overridden)
特殊情况:版本范围 *
的行为类似于仅名称补丁,但不会忽略补丁失败。
¥A special case: the version range *
behaves like a name-only patch but does not ignore patch failures.
示例:
¥Exampe:
patchedDependencies:
foo: patches/foo-1.patch
foo@^2.0.0: patches/foo-2.patch
foo@2.1.0: patches/foo-3.patch
-
patches/foo-3.patch
应用于foo@2.1.0
。¥
patches/foo-3.patch
is applied tofoo@2.1.0
. -
patches/foo-2.patch
适用于所有与^2.0.0
匹配的 foo 版本,2.1.0
除外。¥
patches/foo-2.patch
applies to all foo versions matching^2.0.0
, except2.1.0
. -
patches/foo-1.patch
适用于所有其他 foo 版本。¥
patches/foo-1.patch
applies to all other foo versions.
避免版本范围重叠。如果你需要专门化某个子范围,请将其从更广泛的范围中明确排除。
¥Avoid overlapping version ranges. If you need to specialize a sub-range, explicitly exclude it from the broader range.
示例:
¥Example:
patchedDependencies:
# Specialized sub-range
"foo@2.2.0-2.8.0": patches/foo.2.2.0-2.8.0.patch
# General patch, excluding the sub-range above
"foo@>=2.0.0 <2.2.0 || >2.8.0": patches/foo.gte2.patch
在大多数情况下,定义一个精确的版本就足以覆盖更大范围的补丁。
¥In most cases, defining an exact version is enough to override a broader range.
allowUnusedPatches
已添加于:v10.7.0(之前名为 allowNonAppliedPatches
)
¥Added in: v10.7.0 (Previously named allowNonAppliedPatches
)
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
true
时,如果未应用 patchedDependencies
字段中的某些补丁,安 装也不会失败。
¥When true
, installation won't fail if some of the patches from the patchedDependencies
field were not applied.
patchedDependencies:
express@4.18.1: patches/express@4.18.1.patch
allowUnusedPatches: true
ignorePatchFailures
已添加于:v10.7.0
¥Added in: v10.7.0
-
默认:undefined
¥Default: undefined
-
类型:布尔值,未定义
¥Type: Boolean, undefined
控制补丁失败的处理方式。
¥Controls how patch failures are handled.
行为:
¥Behaviour:
-
未定义(默认值):
¥undefined (default):
-
当具有精确版本或版本范围的补丁失败时会抛出错误。
¥Errors out when a patch with an exact version or version range fails.
-
忽略仅指定名称的补丁导致的失败。
¥Ignores failures from name-only patches.
-
-
false:任何补丁失败都会抛出错误。
¥false: Errors out for any patch failure.
-
true:当任何补丁无法应用时,打印警告而不是失败。
¥true: Prints a warning instead of failing when any patch cannot be applied.
审计设置
¥Audit Settings
auditConfig
auditConfig.ignoreCves
将被 pnpm audit
命令忽略的 CVE ID 列表。
¥A list of CVE IDs that will be ignored by the pnpm audit
command.
auditConfig:
ignoreCves:
CVE-2022-36313
auditConfig.ignoreGhsas
pnpm audit
命令将忽略的 GHSA 代码列表。
¥A list of GHSA Codes that will be ignored by the pnpm audit
command.
auditConfig:
ignoreGhsas:
GHSA-42xw-2xvc-qx8m
GHSA-4w2v-q235-vp99
GHSA-cph5-m8f7-6c5x
GHSA-vh95-rmgr-6w4m
其他设置
¥Other Settings
savePrefix
-
默认:'^'
¥Default: '^'
-
类型:'^'、'~'、''
¥Type: '^', '~', ''
配置安装到 package.json
文件的软件包版本如何添加前缀。
¥Configure how versions of packages installed to a package.json
file get
prefixed.
例如,如果某个软件包的版本为 1.2.3
,则默认情况下其版本设置为 ^1.2.3
,允许对该软件包进行小幅升级,但在 pnpm config set save-prefix='~'
之后,它将设置为 ~1.2.3
,仅允许补丁升级。
¥For example, if a package has version 1.2.3
, by default its version is set to
^1.2.3
which allows minor upgrades for that package, but after
pnpm config set save-prefix='~'
it would be set to ~1.2.3
which only allows
patch upgrades.
当添加的包指定了范围时,此设置将被忽略。例如,pnpm add foo@2
会将 package.json
中 foo
的版本设置为 2
,而不管 savePrefix
的值如何。
¥This setting is ignored when the added package has a range specified. For
instance, pnpm add foo@2
will set the version of foo
in package.json
to
2
, regardless of the value of savePrefix
.
tag
-
默认:latest
¥Default: latest
-
类型:字符串
¥Type: String
如果你 pnpm add
软件包并且不提供特定版本,那么它将安装在此设置的标签下注册的版本的软件包。
¥If you pnpm add
a package and you don't provide a specific version, then it
will install the package at the version registered under the tag from this
setting.
如果未给出显式标记,这还会设置添加到 pnpm tag
命令指定的 package@version
的标记。
¥This also sets the tag that is added to the package@version
specified by the
pnpm tag
command if no explicit tag is given.
globalDir
-
默认:
¥Default:
-
如果设置了 $XDG_DATA_HOME 环境变量,则 $XDG_DATA_HOME/pnpm/global
¥If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/global
-
在 Windows 上:~/AppData/Local/pnpm/global
¥On Windows: ~/AppData/Local/pnpm/global
-
在 macOS 上:~/Library/pnpm/global
¥On macOS: ~/Library/pnpm/global
-
在 Linux 上:~/.local/share/pnpm/global
¥On Linux: ~/.local/share/pnpm/global
-
-
类型:path
¥Type: path
指定自定义目录来存储全局包。
¥Specify a custom directory to store global packages.
globalBinDir
-
默认:
¥Default:
-
如果设置了 $XDG_DATA_HOME 环境变量,则 $XDG_DATA_HOME/pnpm
¥If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm
-
在 Windows 上:~/AppData/Local/pnpm
¥On Windows: ~/AppData/Local/pnpm
-
在 macOS 上:~/Library/pnpm
¥On macOS: ~/Library/pnpm
-
在 Linux 上:~/.local/share/pnpm
¥On Linux: ~/.local/share/pnpm
-
-
类型:path
¥Type: path
允许设置全局安装包的 bin 文件的目标目录。
¥Allows to set the target directory for the bin files of globally installed packages.
stateDir
-
默认:
¥Default:
-
如果设置了 $XDG_STATE_HOME 环境变量,则 $XDG_STATE_HOME/pnpm
¥If the $XDG_STATE_HOME env variable is set, then $XDG_STATE_HOME/pnpm
-
在 Windows 上:~/AppData/Local/pnpm-state
¥On Windows: ~/AppData/Local/pnpm-state
-
在 macOS 上:~/.pnpm-state
¥On macOS: ~/.pnpm-state
-
在 Linux 上:~/.local/state/pnpm
¥On Linux: ~/.local/state/pnpm
-
-
类型:path
¥Type: path
pnpm 创建当前仅由更新检查程序使用的 pnpm-state.json
文件的目录。
¥The directory where pnpm creates the pnpm-state.json
file that is currently used only by the update checker.
cacheDir
-
默认:
¥Default:
-
如果设置了 $XDG_CACHE_HOME 环境变量,则 $XDG_CACHE_HOME/pnpm
¥If the $XDG_CACHE_HOME env variable is set, then $XDG_CACHE_HOME/pnpm
-
在 Windows 上:~/AppData/Local/pnpm-cache
¥On Windows: ~/AppData/Local/pnpm-cache
-
在 macOS 上:~/Library/Caches/pnpm
¥On macOS: ~/Library/Caches/pnpm
-
在 Linux 上:~/.cache/pnpm
¥On Linux: ~/.cache/pnpm
-
-
类型:path
¥Type: path
缓存的位置(包元数据和 dlx)。
¥The location of the cache (package metadata and dlx).
useStderr
-
默认:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
当 true 时,所有输出都写入 stderr。
¥When true, all the output is written to stderr.
updateNotifier
-
默认:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
设置为 false
可在使用比最新版本更旧的 pnpm 时抑制更新通知。
¥Set to false
to suppress the update notification when using an older version of pnpm than the latest.
preferSymlinkedExecutables
-
默认:true,当节点链接器设置为提升且系统为 POSIX 时
¥Default: true, when node-linker is set to hoisted and the system is POSIX
-
类型:布尔值
¥Type: Boolean