设置 (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