配置依赖项
配置依赖项在所有其他类型的依赖项之前安装(在“dependencies”、“devDependencies”、“optionalDependencies”之前)。
配置依赖项不能具有其自己的依赖项或生命周期脚本。 应该使用精确的版本和完整性校验来添加它们。 示例:
{
"pnpm": {
"configDependencies": {
"my-configs": "1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="
}
}
}
使用方法
加载一个允许的构建的依赖列表
你可以通过配置依赖项和 pnpm.onlyBuiltDependenciesFile
设置加载允许构建的包名称列表。 例如,你可以发布一个在其根目录中带有“allow.json”文件的包:
[
"esbuild",
"fsevents"
]
假设这个包名为 my-configs
,那么你的项目的 package.json
将如下所示:
{
"pnpm": {
"configDependencies": {
"my-configs": "1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="
},
"onlyBuiltDependenciesFile": "node_modules/.pnpm-config/my-configs/allow.json"
}
}
这样,你的项目将加载允许从 my-configs
构建的包列表。
Installing dependencies used in hooks
Configurational dependencies are installed before the hooks from .pnpmfile.cjs
are loaded, so you can use them as dependencies for your hooks.
For instance, you may have a configurational dependency called "my-hooks" that exports a readPackage
hook. In this case, you can import it into your .pnpmfile.cjs
like this:
const { readPackage } = require('.pnpm-config/my-hooks')
module.exports = {
hooks: {
readPackage
}
}
Loading patches
You can reference patch files installed via configurational dependencies. For instance, if you have a configurational dependency called "my-patches", you can load patches from it:
{
"pnpm": {
"configDependencies": {
"my-patches": "1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="
},
"patchedDependencies": {
"react": "node_modules/.pnpm-config/react.patch"
}
}
}