package.json
包的清单文件。它包含包的所有元数据,包括依赖、标题、作者等。这是所有主要 Node.js 包管理器(包括 pnpm)中保留的标准。
¥The manifest file of a package. It contains all the package's metadata, including dependencies, title, author, et cetera. This is a standard preserved across all major Node.js package managers, including pnpm.
除了传统的 package.json
格式外,pnpm 还支持 package.json5
(通过 json5)和 package.yaml
(通过 js-yaml)。
¥In addition to the traditional package.json
format, pnpm also supports package.json5
(via json5) and package.yaml
(via js-yaml).
engines
你可以指定你的软件运行的 Node 和 pnpm 版本:
¥You can specify the version of Node and pnpm that your software works on:
{
"engines": {
"node": ">=10",
"pnpm": ">=3"
}
}
在本地开发期间,如果 pnpm 的版本与 engines
字段中指定的版本不匹配,则它将始终失败并显示错误消息。
¥During local development, pnpm will always fail with an error message
if its version does not match the one specified in the engines
field.
除非用户设置了 engineStrict
配置标志(参见 settings),否则此字段仅供参考,并且仅在你的包作为依赖安装时才会产生警告。
¥Unless the user has set the engineStrict
config flag (see settings), this
field is advisory only and will only produce warnings when your package is
installed as a dependency.
dependenciesMeta
用于在 dependencies
、optionalDependencies
和 devDependencies
中声明的依赖的附加元信息。
¥Additional meta information used for dependencies declared inside dependencies
, optionalDependencies
, and devDependencies
.
dependencyMeta.*.injected
如果将依赖设置为本地工作区包的 true
,则将通过在虚拟存储 (node_modules/.pnpm
) 中创建硬链接副本来安装该包。
¥If this is set to true
for a dependency that is a local workspace package, that package will be installed by creating a hard linked copy in the virtual store (node_modules/.pnpm
).
如果将其设置为 false
或未设置,则将通过创建指向工作区中包的源目录的 node_modules
符号链接来安装依赖。这是默认设置,因为它更快并确保对依赖的任何修改都会立即对其消费者可见。
¥If this is set to false
or not set, then the dependency will instead be installed by creating a node_modules
symlink that points to the package's source directory in the workspace. This is the default, as it is faster and ensures that any modifications to the dependency will be immediately visible to its consumers.
例如,假设以下 package.json
是本地工作区包:
¥For example, suppose the following package.json
is a local workspace package:
{
"name": "card",
"dependencies": {
"button": "workspace:1.0.0"
}
}
button
依赖通常会通过在 card
的 node_modules
目录中创建符号链接来安装,指向 button
的开发目录。