Skip to content

Commit 6282eeb

Browse files
committed
docs: add example about catalogs in config deps
1 parent 02f6070 commit 6282eeb

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/config-dependencies.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,53 @@ module.exports = {
5555

5656
[`.pnpmfile.cjs`]: ./pnpmfile.md
5757

58+
#### Loading any type of settings
59+
60+
Using the [`updateConfig`] hook, you can dynamically update any configuration settings used by pnpm. Because hooks can be loaded from config dependencies, you can also share settings across projects by publishing them as config dependencies.
61+
62+
For example, the following pnpmfile defines a hook that adds a new [catalog] entry to pnpm's configuration. This allows you to refer to the catalog entry when specifying dependency versions:
63+
64+
```js title="my-catalogs/pnpmfile.cjs"
65+
module.exports = {
66+
hooks: {
67+
updateConfig (config) {
68+
config.catalogs.default ??= {}
69+
config.catalogs.default['is-odd'] = '1.0.0'
70+
return config
71+
}
72+
}
73+
}
74+
```
75+
76+
You can publish this pnpmfile inside a config dependency. Once published and installed, you can load it by specifying the following settings in your `pnpm-workspace.yaml`:
77+
78+
```yaml
79+
configDependencies:
80+
my-catalogs: "1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="
81+
pnpmfile: "node_modules/.pnpm-config/my-catalogs/pnpmfile.cjs"
82+
```
83+
84+
Now, you can run:
85+
86+
```
87+
pnpm add is-odd@catalog:
88+
```
89+
90+
This will install `[email protected]` into your `node_modules`, and add the following entry to your `package.json`:
91+
92+
```json
93+
{
94+
"dependencies": {
95+
"is-odd": "catalog:"
96+
}
97+
}
98+
```
99+
100+
This makes it easy to maintain and share centralized configuration and dependency versions across projects.
101+
102+
[updateConfig]: ./pnpmfile.md#hooksupdateconfigconfig-config--promiseconfig
103+
[catalog]: ./catalogs.md
104+
58105
### Loading patches
59106

60107
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:

0 commit comments

Comments
 (0)