Skip to content

Commit 64e4f71

Browse files
committed
docs: improve config dependencies page
1 parent 7ee9646 commit 64e4f71

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

docs/config-dependencies.md

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,60 @@
11
---
22
id: config-dependencies
3-
title: Config dependencies
3+
title: Config Dependencies
44
---
55

6-
Config dependencies are installed before all the other types of dependencies (before "dependencies", "devDependencies", "optionalDependencies").
6+
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.
77

8-
Config dependencies cannot have dependencies of their own or lifecycle scripts. They should be added using exact version and the integrity checksum. Example:
8+
Config dependencies help you keep all the hooks, settings, patches, overrides, catalogs, rules in a single place and use them across multiple repositories.
9+
10+
## How to Add a Config Dependency
11+
12+
Config dependencies are defined in your `pnpm-workspace.yaml` and must be installed using an exact version and an integrity checksum.
13+
14+
Example:
915

1016
```yaml title="pnpm-workspace.yaml"
1117
configDependencies:
1218
my-configs: "1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="
1319
```
1420
21+
**Important:**
22+
23+
* Config dependencies **cannot** have their own dependencies.
24+
* Config dependencies **cannot** define lifecycle scripts (like `preinstall`, `postinstall`, etc.).
25+
1526
## Usage
1627

17-
### Loading an allow list of built dependencies
28+
### Loading an Allow List of Built Dependencies
1829

19-
You may load a list of package names that are allowed to be built via config dependencies and the [`onlyBuiltDependenciesFile`] setting. For example, you may publish a package with an `allow.json` file in its root directory:
30+
You can load a list of package names that are allowed to be built, using the [`onlyBuiltDependenciesFile`] setting.
2031

21-
```json
32+
Example `allow.json` file inside a config dependency:
33+
34+
```json title="allow.json"
2235
[
2336
"esbuild",
2437
"fsevents"
2538
]
2639
```
2740

28-
Let's say this package is called `my-configs`, then your project's `pnpm-workspace.yaml` will look like this:
41+
Your workspace configuration:
2942

30-
```yaml
43+
```yaml title="pnpm-workspace.yaml"
3144
configDependencies:
3245
my-configs: "1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="
3346
onlyBuiltDependenciesFile: "node_modules/.pnpm-config/my-configs/allow.json"
3447
```
3548

36-
This way your project will load the list of packages that are allowed to be built from `my-configs`.
37-
3849
[`onlyBuiltDependenciesFile`]: settings.md#onlybuiltdependenciesfile
3950

40-
### Installing dependencies used in hooks
51+
### Installing Dependencies Used in Hooks
4152

42-
Config dependencies are installed before the hooks from [`.pnpmfile.cjs`] are loaded, so you can use them as dependencies for your hooks.
53+
Config dependencies are installed **before** hooks from your [`.pnpmfile.cjs`] are loaded, allowing you to import logic from config packages.
4354

44-
For instance, you may have a config dependency called "my-hooks" that exports a `readPackage` hook. In this case, you can import it into your `.pnpmfile.cjs` like this:
55+
Example:
4556

46-
```js
57+
```js title=".pnpmfile.cjs"
4758
const { readPackage } = require('.pnpm-config/my-hooks')
4859
4960
module.exports = {
@@ -55,11 +66,11 @@ module.exports = {
5566

5667
[`.pnpmfile.cjs`]: ./pnpmfile.md
5768

58-
#### Loading any type of settings
69+
### Updating pnpm Settings Dynamically
5970

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.
71+
Using the [`updateConfig`] hook, you can dynamically update pnpm’s settings using config dependencies.
6172

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:
73+
For example, the following `pnpmfile` adds a new [catalog] entry to pnpm's configuration:
6374

6475
```js title="my-catalogs/pnpmfile.cjs"
6576
module.exports = {
@@ -73,21 +84,21 @@ module.exports = {
7384
}
7485
```
7586

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`:
87+
Install and load it:
7788

78-
```yaml
89+
```yaml title="pnpm-workspace.yaml"
7990
configDependencies:
8091
my-catalogs: "1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="
8192
pnpmfile: "node_modules/.pnpm-config/my-catalogs/pnpmfile.cjs"
8293
```
8394

84-
Now, you can run:
95+
Then you can run:
8596

8697
```
8798
pnpm add is-odd@catalog:
8899
```
89100

90-
This will install `[email protected]` into your `node_modules`, and add the following entry to your `package.json`:
101+
This will install `[email protected]` and add the following to your `package.json`:
91102

92103
```json
93104
{
@@ -99,14 +110,16 @@ This will install `[email protected]` into your `node_modules`, and add the following
99110

100111
This makes it easy to maintain and share centralized configuration and dependency versions across projects.
101112

102-
[updateConfig]: ./pnpmfile.md#hooksupdateconfigconfig-config--promiseconfig
113+
[`updateConfig`]: ./pnpmfile.md#hooksupdateconfigconfig-config--promiseconfig
103114
[catalog]: ./catalogs.md
104115

105-
### Loading patches
116+
### Loading Patch Files
117+
118+
You can reference [patch files] stored inside config dependencies.
106119

107-
You can reference [patch files] installed via config dependencies. For instance, if you have a config dependency called "my-patches", you can load patches from it:
120+
Example:
108121

109-
```yaml
122+
```yaml title="pnpm-workspace.yaml"
110123
configDependencies:
111124
my-patches: "1.0.0+sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="
112125
patchedDependencies:

0 commit comments

Comments
 (0)