dependency-grouper 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +185 -196
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,227 +84,221 @@ Run `dependency-grouper generate` and it merges the groups with automatic sortin
|
|
|
84
84
|
}
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
##
|
|
87
|
+
## Quick Start
|
|
88
88
|
|
|
89
|
-
###
|
|
89
|
+
### Option A: Bootstrap from Existing Monorepo (Recommended)
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
If you already have a monorepo with dependencies:
|
|
92
92
|
|
|
93
93
|
```bash
|
|
94
|
-
# 1. Install
|
|
94
|
+
# 1. Install at workspace root
|
|
95
95
|
pnpm add -D dependency-grouper
|
|
96
96
|
|
|
97
|
-
# 2. Add
|
|
98
|
-
#
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
# 2. Add "depGroups": [] to ALL package.json files
|
|
98
|
+
# ├── package.json → "depGroups": []
|
|
99
|
+
# └── packages/
|
|
100
|
+
# ├── app1/package.json → "depGroups": []
|
|
101
|
+
# └── app2/package.json → "depGroups": []
|
|
102
102
|
|
|
103
|
-
#
|
|
104
|
-
{
|
|
105
|
-
"depGroups": [] // ← Will become ["common"]
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
# 3. Run initial generate - this does EVERYTHING automatically:
|
|
103
|
+
# 3. Run generate (does everything automatically):
|
|
109
104
|
npx dependency-grouper generate
|
|
110
105
|
```
|
|
111
106
|
|
|
112
|
-
**What
|
|
113
|
-
1.
|
|
114
|
-
2.
|
|
115
|
-
3.
|
|
116
|
-
|
|
117
|
-
- Sub-packages → `["common"]`
|
|
118
|
-
4. **Merges** group dependencies back into all package.json files
|
|
119
|
-
5. **Injects** `"preinstall": "dependency-grouper generate"` script (or appends to existing)
|
|
120
|
-
|
|
121
|
-
After this one command, everything is set up! Future `pnpm install` will auto-sync.
|
|
107
|
+
**What just happened:**
|
|
108
|
+
1. ✅ Created `.dep-groups.yaml` with all your dependencies organized
|
|
109
|
+
2. ✅ Root dependencies → `root` group, sub-packages → `common` group
|
|
110
|
+
3. ✅ Auto-populated `depGroups: ["root"]` or `["common"]` in all files
|
|
111
|
+
4. ✅ Injected `preinstall` script for automatic sync
|
|
122
112
|
|
|
113
|
+
**Next steps:**
|
|
123
114
|
```bash
|
|
124
|
-
# 4.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
#
|
|
115
|
+
# 4. Review and reorganize the generated .dep-groups.yaml
|
|
116
|
+
code .dep-groups.yaml
|
|
117
|
+
|
|
118
|
+
# Example: Split 'common' into specific groups:
|
|
119
|
+
# groups:
|
|
120
|
+
# common:
|
|
121
|
+
# dependencies:
|
|
122
|
+
# axios: ^1.6.0 → Move to 'shared-utils'
|
|
123
|
+
# react: ← New group
|
|
124
|
+
# dependencies:
|
|
125
|
+
# react: ^18.2.0
|
|
126
|
+
# react-dom: ^18.2.0
|
|
127
|
+
|
|
128
|
+
# 5. Update package.json files to use new groups:
|
|
129
|
+
# packages/react-app/package.json:
|
|
130
|
+
# "depGroups": ["react", "shared-utils"]
|
|
131
|
+
|
|
132
|
+
# 6. Regenerate to apply changes:
|
|
128
133
|
npx dependency-grouper generate
|
|
129
|
-
```
|
|
130
134
|
|
|
131
|
-
|
|
135
|
+
# 7. Install and you're done!
|
|
136
|
+
pnpm install
|
|
137
|
+
```
|
|
132
138
|
|
|
133
|
-
###
|
|
139
|
+
### Option B: Fresh Setup (New Monorepo)
|
|
134
140
|
|
|
135
|
-
|
|
136
|
-
# pnpm
|
|
137
|
-
pnpm add -D dependency-grouper
|
|
141
|
+
Starting from scratch:
|
|
138
142
|
|
|
139
|
-
|
|
140
|
-
npm install -D dependency-grouper
|
|
143
|
+
#### 1. Install
|
|
141
144
|
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
```bash
|
|
146
|
+
pnpm add -D dependency-grouper # or npm / yarn
|
|
144
147
|
```
|
|
145
148
|
|
|
146
|
-
|
|
149
|
+
#### 2. Create `.dep-groups.yaml` at workspace root
|
|
150
|
+
|
|
151
|
+
Define your dependency groups:
|
|
147
152
|
|
|
148
153
|
```yaml
|
|
149
154
|
groups:
|
|
150
|
-
|
|
155
|
+
react:
|
|
151
156
|
dependencies:
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
react: ^18.2.0
|
|
158
|
+
react-dom: ^18.2.0
|
|
159
|
+
devDependencies:
|
|
160
|
+
'@types/react': ^18.2.0
|
|
154
161
|
|
|
155
|
-
|
|
162
|
+
shared-utils:
|
|
156
163
|
dependencies:
|
|
157
|
-
|
|
164
|
+
axios: ^1.6.0
|
|
165
|
+
lodash: ^4.17.21
|
|
158
166
|
```
|
|
159
167
|
|
|
160
|
-
|
|
168
|
+
#### 3. Add `depGroups` to package.json files
|
|
161
169
|
|
|
162
170
|
```json
|
|
163
171
|
{
|
|
164
|
-
"name": "my-
|
|
165
|
-
"depGroups": ["
|
|
166
|
-
"dependencies": {
|
|
167
|
-
"my-custom-dep": "^1.0.0"
|
|
168
|
-
}
|
|
172
|
+
"name": "my-react-app",
|
|
173
|
+
"depGroups": ["react", "shared-utils"]
|
|
169
174
|
}
|
|
170
175
|
```
|
|
171
176
|
|
|
172
|
-
|
|
177
|
+
#### 4. Generate and install
|
|
173
178
|
|
|
174
179
|
```bash
|
|
175
|
-
dependency-grouper generate
|
|
180
|
+
npx dependency-grouper generate
|
|
181
|
+
pnpm install
|
|
176
182
|
```
|
|
177
183
|
|
|
178
|
-
|
|
184
|
+
---
|
|
179
185
|
|
|
180
|
-
|
|
181
|
-
# pnpm
|
|
182
|
-
pnpm install
|
|
186
|
+
## How It Works
|
|
183
187
|
|
|
184
|
-
|
|
185
|
-
|
|
188
|
+
1. **You define groups** in `.dep-groups.yaml` (shared dependency sets)
|
|
189
|
+
2. **You reference groups** in `package.json` with `"depGroups": ["group1", "group2"]`
|
|
190
|
+
3. **Run `generate`** → Merges group dependencies into each package.json
|
|
191
|
+
4. **Run package manager** → Installs the merged dependencies
|
|
186
192
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
193
|
+
**Bidirectional sync:**
|
|
194
|
+
- `.dep-groups.yaml` → `package.json` (group deps added to packages)
|
|
195
|
+
- `package.json` → `.dep-groups.yaml` (new deps captured in groups)
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## CLI Commands
|
|
200
|
+
|
|
201
|
+
### `dependency-grouper generate`
|
|
202
|
+
|
|
203
|
+
**Full bidirectional sync** - Use this most of the time.
|
|
204
|
+
|
|
205
|
+
1. Scans all package.json files
|
|
206
|
+
2. Updates `.dep-groups.yaml` with new dependencies
|
|
207
|
+
3. Merges group dependencies back into package.json files
|
|
208
|
+
4. Auto-populates empty `depGroups: []` arrays
|
|
209
|
+
5. Injects preinstall scripts
|
|
210
|
+
|
|
211
|
+
**When to use:**
|
|
212
|
+
- Initial setup
|
|
213
|
+
- After reorganizing groups
|
|
214
|
+
- In preinstall hooks
|
|
215
|
+
|
|
216
|
+
### `dependency-grouper sync`
|
|
217
|
+
|
|
218
|
+
**One-way sync only** - package.json → `.dep-groups.yaml`
|
|
219
|
+
|
|
220
|
+
Captures new dependencies without modifying package.json files. Faster, good for postinstall hooks.
|
|
221
|
+
|
|
222
|
+
**When to use:**
|
|
223
|
+
- Postinstall hooks to capture new deps
|
|
224
|
+
- CI/CD to keep `.dep-groups.yaml` updated
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Automation (Optional)
|
|
190
229
|
|
|
191
|
-
|
|
230
|
+
Add hooks to your **workspace root** `package.json` for automatic syncing:
|
|
192
231
|
|
|
193
|
-
###
|
|
232
|
+
### Preinstall Hook (Recommended)
|
|
194
233
|
|
|
195
|
-
|
|
234
|
+
Runs `generate` before every `pnpm install`:
|
|
196
235
|
|
|
197
236
|
```json
|
|
198
237
|
{
|
|
199
|
-
"name": "my-monorepo",
|
|
200
|
-
"private": true,
|
|
201
238
|
"scripts": {
|
|
202
239
|
"preinstall": "dependency-grouper generate"
|
|
203
240
|
}
|
|
204
241
|
}
|
|
205
242
|
```
|
|
206
243
|
|
|
207
|
-
|
|
244
|
+
✅ Always in sync
|
|
245
|
+
✅ Team members don't need to remember
|
|
246
|
+
❌ Slower if you install frequently
|
|
208
247
|
|
|
209
|
-
|
|
248
|
+
### Postinstall Hook (Lightweight Alternative)
|
|
249
|
+
|
|
250
|
+
Runs `sync` after install to capture new deps:
|
|
210
251
|
|
|
211
252
|
```json
|
|
212
253
|
{
|
|
213
|
-
"name": "my-monorepo",
|
|
214
|
-
"private": true,
|
|
215
254
|
"scripts": {
|
|
216
255
|
"postinstall": "dependency-grouper sync"
|
|
217
256
|
}
|
|
218
257
|
}
|
|
219
258
|
```
|
|
220
259
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
3. postinstall hook automatically runs `dependency-grouper sync`
|
|
225
|
-
4. axios is captured in .dep-groups.yaml
|
|
226
|
-
5. Next time you/anyone runs `generate`, all packages in that group get axios
|
|
260
|
+
✅ Faster
|
|
261
|
+
✅ Captures new deps automatically
|
|
262
|
+
⚠️ Need to run `generate` manually to share with other packages
|
|
227
263
|
|
|
228
|
-
|
|
264
|
+
---
|
|
229
265
|
|
|
230
|
-
|
|
266
|
+
---
|
|
231
267
|
|
|
232
|
-
|
|
233
|
-
|------|---------|------|--------------------------|---------------------|
|
|
234
|
-
| preinstall | `generate` | Before install | ✅ | ✅ |
|
|
235
|
-
| postinstall | `sync` | After install | ✅ | ❌ |
|
|
268
|
+
## Advanced Usage
|
|
236
269
|
|
|
237
|
-
|
|
238
|
-
- ✅ No manual `generate` command needed
|
|
239
|
-
- ✅ Dependencies always up-to-date before install
|
|
240
|
-
- ✅ Team members don't need to remember to run generate
|
|
270
|
+
### Multiple Groups per Package
|
|
241
271
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
272
|
+
```json
|
|
273
|
+
{
|
|
274
|
+
"name": "my-app",
|
|
275
|
+
"depGroups": ["react", "shared-utils", "testing"]
|
|
276
|
+
}
|
|
277
|
+
```
|
|
246
278
|
|
|
247
|
-
|
|
279
|
+
All groups are merged together into the package.
|
|
248
280
|
|
|
249
|
-
|
|
281
|
+
### Root vs Sub-Packages
|
|
250
282
|
|
|
251
|
-
|
|
252
|
-
-
|
|
253
|
-
-
|
|
254
|
-
- ✅ **Automatic sorting** - package.json keys and dependencies alphabetically sorted
|
|
255
|
-
- ✅ **Type-safe** - Full TypeScript support with type definitions
|
|
256
|
-
- ✅ **Smart merging** - Preserves project-specific dependencies
|
|
257
|
-
- ✅ **Version control** - Update versions in one place
|
|
258
|
-
- ✅ **CI/CD ready** - Optional preinstall hook for automation
|
|
259
|
-
- ✅ **Nested projects** - Recursively finds all package.json files in monorepo
|
|
260
|
-
- ✅ **Bootstrap from existing** - Generate .dep-groups.yaml from current dependencies
|
|
283
|
+
When bootstrapping with empty `depGroups: []`:
|
|
284
|
+
- **Root** package.json → Auto-assigned `["root"]` group
|
|
285
|
+
- **Sub-packages** → Auto-assigned `["common"]` group
|
|
261
286
|
|
|
262
|
-
|
|
287
|
+
This separates monorepo tooling (root) from app dependencies (common).
|
|
263
288
|
|
|
264
|
-
###
|
|
289
|
+
### Nested Monorepos
|
|
265
290
|
|
|
266
|
-
|
|
267
|
-
groups:
|
|
268
|
-
groupName:
|
|
269
|
-
dependencies:
|
|
270
|
-
package-name: version
|
|
271
|
-
devDependencies:
|
|
272
|
-
dev-package: version
|
|
291
|
+
Recursively finds ALL package.json files:
|
|
273
292
|
```
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
{
|
|
279
|
-
"depGroups": ["groupName1", "groupName2"]
|
|
280
|
-
}
|
|
293
|
+
monorepo/
|
|
294
|
+
├── packages/app1/package.json ← Found
|
|
295
|
+
├── packages/nested/deep/app2/package.json ← Found
|
|
296
|
+
└── apps/frontend/utils/package.json ← Found
|
|
281
297
|
```
|
|
282
298
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
4. Finds all package.json files with `depGroups` field
|
|
287
|
-
5. Merges specified groups with existing dependencies
|
|
288
|
-
6. Sorts dependencies alphabetically within each section
|
|
289
|
-
7. Formats entire package.json with proper key ordering
|
|
290
|
-
8. Writes updated package.json files
|
|
291
|
-
9. Preserves project-specific dependencies
|
|
292
|
-
|
|
293
|
-
**Supports nested structures:**
|
|
294
|
-
```
|
|
295
|
-
monorepo/
|
|
296
|
-
├── .dep-groups.yaml
|
|
297
|
-
├── packages/
|
|
298
|
-
│ ├── app1/package.json
|
|
299
|
-
│ └── nested/
|
|
300
|
-
│ └── deep/
|
|
301
|
-
│ └── app2/package.json ← Found!
|
|
302
|
-
└── apps/
|
|
303
|
-
└── frontend/
|
|
304
|
-
└── utils/package.json ← Found!
|
|
305
|
-
``` key ordering
|
|
306
|
-
7. Writes updated package.json files
|
|
307
|
-
8. Preserves project-specific dependencies
|
|
299
|
+
Skips `node_modules/` and `.git/` automatically.
|
|
300
|
+
|
|
301
|
+
---
|
|
308
302
|
|
|
309
303
|
## Development
|
|
310
304
|
|
|
@@ -353,75 +347,70 @@ dependency-grouper sync
|
|
|
353
347
|
- Faster, useful for postinstall hooks to capture new dependencies
|
|
354
348
|
- Good for CI/CD to keep .dep-groups.yaml in sync
|
|
355
349
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
### Initial Setup
|
|
350
|
+
---
|
|
359
351
|
|
|
360
|
-
|
|
361
|
-
# 1. Install at workspace root
|
|
362
|
-
pnpm add -D dependency-grouper
|
|
352
|
+
## Example Workflows
|
|
363
353
|
|
|
364
|
-
|
|
365
|
-
cat > .dep-groups.yaml << EOF
|
|
366
|
-
groups:
|
|
367
|
-
react:
|
|
368
|
-
dependencies:
|
|
369
|
-
react: "^18.2.0"
|
|
370
|
-
react-dom: "^18.2.0"
|
|
371
|
-
EOF
|
|
354
|
+
### Sharing a New Dependency
|
|
372
355
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
"version": "1.0.0",
|
|
378
|
-
"depGroups": ["react"]
|
|
379
|
-
}
|
|
380
|
-
EOF
|
|
356
|
+
```bash
|
|
357
|
+
# 1. Add to one package
|
|
358
|
+
cd packages/app1
|
|
359
|
+
pnpm add axios
|
|
381
360
|
|
|
382
|
-
#
|
|
383
|
-
|
|
361
|
+
# 2. If you have postinstall hook, it's already in .dep-groups.yaml!
|
|
362
|
+
# Otherwise, run manually:
|
|
363
|
+
npx dependency-grouper sync
|
|
384
364
|
|
|
385
|
-
#
|
|
386
|
-
|
|
365
|
+
# 3. Share with other packages:
|
|
366
|
+
npx dependency-grouper generate
|
|
387
367
|
```
|
|
388
368
|
|
|
389
|
-
###
|
|
369
|
+
### Reorganizing Groups
|
|
390
370
|
|
|
391
371
|
```bash
|
|
392
|
-
#
|
|
393
|
-
|
|
394
|
-
pnpm add axios
|
|
395
|
-
# ↑ postinstall hook runs automatically!
|
|
396
|
-
# → dependency-grouper sync
|
|
397
|
-
# → axios is now in .dep-groups.yaml
|
|
372
|
+
# 1. Edit .dep-groups.yaml - split 'common' into specific groups
|
|
373
|
+
code .dep-groups.yaml
|
|
398
374
|
|
|
399
|
-
#
|
|
400
|
-
|
|
401
|
-
# → All packages with same depGroups get axios
|
|
375
|
+
# 2. Update package.json files with new group names
|
|
376
|
+
# "depGroups": ["react", "api-utils"] # was ["common"]
|
|
402
377
|
|
|
403
|
-
#
|
|
404
|
-
|
|
405
|
-
# → generate runs automatically before install
|
|
378
|
+
# 3. Regenerate
|
|
379
|
+
npx dependency-grouper generate
|
|
406
380
|
```
|
|
407
381
|
|
|
408
|
-
|
|
382
|
+
### Updating a Dependency Version
|
|
383
|
+
|
|
409
384
|
```bash
|
|
410
|
-
|
|
411
|
-
#
|
|
412
|
-
# 2. pnpm installs lodash
|
|
413
|
-
# 3. postinstall runs: dependency-grouper sync
|
|
414
|
-
# 4. lodash automatically added to .dep-groups.yaml
|
|
415
|
-
# 5. Next time anyone runs generate, they get lodash too
|
|
416
|
-
```
|
|
385
|
+
# Just update the version in .dep-groups.yaml:
|
|
386
|
+
# react: ^18.2.0 → react: ^18.3.0
|
|
417
387
|
|
|
418
|
-
|
|
388
|
+
npx dependency-grouper generate
|
|
389
|
+
pnpm install
|
|
390
|
+
# All packages using the 'react' group get v18.3.0!
|
|
391
|
+
```
|
|
419
392
|
|
|
420
|
-
|
|
421
|
-
1. Detect the new package in your package.json
|
|
422
|
-
2. Automatically add it to all groups listed in `depGroups`
|
|
423
|
-
3. Sync it across all packages using those groups
|
|
393
|
+
---
|
|
424
394
|
|
|
425
395
|
## License
|
|
426
396
|
|
|
427
397
|
MIT
|
|
398
|
+
|
|
399
|
+
## Troubleshooting
|
|
400
|
+
|
|
401
|
+
**Q: `.dep-groups.yaml` wasn't created**
|
|
402
|
+
A: Add `"depGroups": []` to at least one package.json, then run `generate`.
|
|
403
|
+
|
|
404
|
+
**Q: Dependencies not merging**
|
|
405
|
+
A: Check that:
|
|
406
|
+
- `depGroups` field exists in package.json
|
|
407
|
+
- Group names match exactly (case-sensitive)
|
|
408
|
+
- You ran `generate` (not just `sync`)
|
|
409
|
+
|
|
410
|
+
**Q: How to use AI to organize dependencies?**
|
|
411
|
+
A:
|
|
412
|
+
1. Run `npx dependency-grouper generate` → creates `.dep-groups.yaml`
|
|
413
|
+
2. Give `.dep-groups.yaml` to AI: *"Reorganize into logical groups (react, testing, build-tools, etc.)"*
|
|
414
|
+
3. AI rewrites with better organization
|
|
415
|
+
4. Update `depGroups` in package.json files to use new group names
|
|
416
|
+
5. Run `npx dependency-grouper generate` to apply
|