Skip to content

Commit 22753b2

Browse files
committed
Implement apply command
1 parent 05d748e commit 22753b2

File tree

8 files changed

+889
-5
lines changed

8 files changed

+889
-5
lines changed

README.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ For basic Catalogs functionality, refer to [Yarn's official documentation](https
1414

1515
While Yarn 4.10+ provides native catalog support, this plugin extends that functionality with:
1616

17+
- **Catalogs management** - Define catalogs in `catalogs.yml` with inheritance support and apply them to `.yarnrc.yml`
18+
- **Inheritance** - Hierarchical catalog groups using `/` delimiter (e.g., `stable/canary/next`)
1719
- **Default alias groups** - Automatically apply catalog protocols when adding dependencies
1820
- **Workspace ignoring** - Disable catalogs for specific workspaces using glob patterns
1921
- **Validation levels** - Enforce catalog usage with configurable warning or error levels
@@ -27,7 +29,59 @@ yarn plugin import https://raw.githubusercontent.com/toss/yarn-plugin-catalogs/m
2729

2830
## Features
2931

30-
This plugin reads extended options from `catalogs.yml` in your project root:
32+
### Catalog Management with `catalogs.yml`
33+
34+
Define your catalogs in a single `catalogs.yml` file with support for inheritance, then apply them to `.yarnrc.yml` using the `yarn catalogs apply` command.
35+
36+
**catalogs.yml:**
37+
```yaml
38+
options:
39+
default: [stable/canary]
40+
validation: warn
41+
42+
list:
43+
root:
44+
lodash: npm:4.17.21
45+
46+
stable:
47+
react: npm:18.0.0
48+
typescript: npm:5.1.0
49+
50+
stable/canary:
51+
react: npm:18.2.0 # Overrides stable
52+
# typescript: npm:5.1.0 (inherited from stable)
53+
54+
stable/canary/next:
55+
react: npm:18.3.0 # Overrides stable/canary
56+
# typescript: npm:5.1.0 (inherited from stable)
57+
```
58+
59+
**Apply to .yarnrc.yml:**
60+
```bash
61+
yarn catalogs apply
62+
# ✓ Applied 1 root catalog and 3 named catalog groups to .yarnrc.yml
63+
```
64+
65+
**After applying, .yarnrc.yml contains:**
66+
```yaml
67+
catalog:
68+
lodash: npm:4.17.21
69+
70+
catalogs:
71+
stable:
72+
react: npm:18.0.0
73+
typescript: npm:5.1.0
74+
75+
stable/canary:
76+
react: npm:18.2.0
77+
typescript: npm:5.1.0 # Inherited and resolved
78+
79+
stable/canary/next:
80+
react: npm:18.3.0
81+
typescript: npm:5.1.0 # Inherited and resolved
82+
```
83+
84+
This plugin reads extended options from the `options` field in `catalogs.yml`:
3185

3286
### Default Alias Groups
3387

@@ -176,6 +230,30 @@ catalogs:
176230

177231
When a package exists in multiple groups, the strictest validation level applies (`strict` > `warn` > `off`).
178232

233+
## Commands
234+
235+
### `yarn catalogs apply`
236+
237+
Applies catalog definitions from `catalogs.yml` to `.yarnrc.yml`, resolving all inheritance and completely replacing existing catalog configurations.
238+
239+
**Usage:**
240+
```bash
241+
# Apply catalogs to .yarnrc.yml
242+
yarn catalogs apply
243+
244+
# Preview changes without writing
245+
yarn catalogs apply --dry-run
246+
```
247+
248+
**Options:**
249+
- `--dry-run`: Show what would be applied without modifying `.yarnrc.yml`
250+
251+
**Notes:**
252+
- Completely replaces `catalog` and `catalogs` fields in `.yarnrc.yml`
253+
- Preserves all other settings in `.yarnrc.yml`
254+
- Validates inheritance chains before applying
255+
- Resolves all inheritance relationships into flat catalog definitions
256+
179257
## Contributing
180258

181259
Contributions are welcome! Please feel free to submit a Pull Request.

bundles/@yarnpkg/plugin-catalogs.js

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)