Config Dependencies
Config dependencies allow you to share and centralize configuration files, settings, and hooks across multiple projects. They are installed before all regular dependencies ("dependencies", "devDependencies", "optionalDependencies"), making them ideal for setting up custom hooks, patches, and catalog entries.
Config dependencies help you keep all the hooks, settings, patches, overrides, catalogs, rules in a single place and use them across multiple repositories.
If your config dependency is named following thepnpm-plugin-*
pattern, pnpm will automatically load thepnpmfile.cjs
from its root.
How to Add a Config Dependency
Config dependencies are defined in yourpnpm-workspace.yaml
and must be installed using an exact version and an integrity checksum.
예시:
configDependencies:
my-configs:"1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="
Important:
- Config dependenciescannot have their own dependencies.
- Config dependenciescannot define lifecycle scripts (like
preinstall
,postinstall
, etc.).
사용
Loading an Allow List of Built Dependencies
You can load a list of package names that are allowed to be built, using theonlyBuiltDependenciesFile
setting.
Exampleallow.json
file inside a config dependency (@pnpm/trusted-deps):
[
"@airbnb/node-memwatch",
"@apollo/protobufjs",
...
]
Your workspace configuration:
configDependencies:
'@pnpm/trusted-deps': 0.1.0+sha512-IERT0uXPBnSZGsCmoSuPzYNWhXWWnKkuc9q78KzLdmDWJhnrmvc7N4qaHJmaNKIusdCH2riO3iE34Osohj6n8w==
onlyBuiltDependenciesFile: node_modules/.pnpm-config/@pnpm/trusted-deps/allow.json
Installing Dependencies Used in Hooks
Config dependencies are installedbefore hooks from your.pnpmfile.cjs
are loaded, allowing you to import logic from config packages.
예시:
const{ readPackage}=require('.pnpm-config/my-hooks')
module.exports={
hooks:{
readPackage
}
}
Updating pnpm Settings Dynamically
Using theupdateConfig
hook, you can dynamically update pnpm’s settings using config dependencies.
For example, the followingpnpmfile
adds a newcatalog entry to pnpm's configuration:
module.exports={
hooks:{
updateConfig(config){
config.catalogs.default??={}
config.catalogs.default['is-odd']='1.0.0'
return config
}
}
}
Install and load it:
configDependencies:
my-catalogs:"1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="
pnpmfile:"node_modules/.pnpm-config/my-catalogs/pnpmfile.cjs"
Then you can run:
pnpm add is-odd@catalog:
This will installis-odd@1.0.0
and add the following to yourpackage.json
:
{
"dependencies":{
"is-odd":"catalog:"
}
}
This makes it easy to maintain and share centralized configuration and dependency versions across projects.
Loading Patch Files
You can referencepatch files stored inside config dependencies.
예시:
configDependencies:
my-patches:"1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="
patchedDependencies:
react:"node_modules/.pnpm-config/my-patches/react.patch"