Skip to content

Commit 4ede8ee

Browse files
committed
docs: add dependency management strategy and fix analysis warnings script
1 parent c8692d0 commit 4ede8ee

File tree

6 files changed

+432
-7
lines changed

6 files changed

+432
-7
lines changed

docs/DEPENDENCY-MANAGEMENT.md

Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
# Dependency Management Strategy
2+
3+
This guide explains how the Pillar monorepo handles dependencies between packages during development and publication.
4+
5+
## 🎯 The Challenge
6+
7+
In a monorepo with interdependent packages, we face a dilemma:
8+
9+
- **Local Development**: Need to use latest code changes (path dependencies)
10+
- **CI/CD & Publication**: Need to use published versions (version constraints)
11+
- **Breaking Changes**: Need to coordinate publication order
12+
13+
## 🔄 Our Solution: Melos Smart Dependency Management
14+
15+
Melos provides built-in solutions for this exact scenario through:
16+
17+
### 1. **Path Dependencies for Development**
18+
19+
```yaml
20+
# packages/pillar-remote-config/pubspec.yaml
21+
dependencies:
22+
pillar_core:
23+
path: ../pillar-core # ← Use during development
24+
```
25+
26+
**Benefits:**
27+
- ✅ **Instant feedback** - Changes in `pillar_core` immediately available in `pillar_remote_config`
28+
- ✅ **No publishing required** - Work with unreleased features
29+
- ✅ **Consistent development** - All packages use same codebase state
30+
31+
### 2. **Automatic Version Constraint Updates**
32+
33+
Melos configuration handles publication automatically:
34+
35+
```yaml
36+
# melos.yaml
37+
command:
38+
version:
39+
updateDependentsVersionConstraints: true
40+
updateDependentsConstraints: true
41+
```
42+
43+
**How it works:**
44+
1. **During versioning** - Melos detects path dependencies
45+
2. **Converts automatically** - Path deps become version constraints
46+
3. **Updates dependents** - Downstream packages get correct version ranges
47+
4. **Publishes in order** - Dependencies first, then dependents
48+
49+
## 🚀 Workflow Examples
50+
51+
### Scenario 1: Non-Breaking Change in pillar_core
52+
53+
```bash
54+
# 1. Make changes to pillar_core
55+
echo "// New feature" >> packages/pillar-core/lib/src/new_feature.dart
56+
57+
# 2. Test locally (uses path dependencies)
58+
melos test
59+
60+
# 3. Version and publish (Melos handles everything)
61+
melos version --minor
62+
# Melos will:
63+
# - Version pillar_core to 1.1.0
64+
# - Update pillar_remote_config to depend on "pillar_core: ^1.1.0"
65+
# - Publish pillar_core first
66+
# - Then publish pillar_remote_config
67+
```
68+
69+
### Scenario 2: Breaking Change in pillar_core
70+
71+
```bash
72+
# 1. Make breaking changes
73+
# Edit packages/pillar-core/lib/pillar_core.dart
74+
75+
# 2. Update dependent packages to handle breaking changes
76+
# Edit packages/pillar-remote-config/lib/src/service.dart
77+
78+
# 3. Version with major bump
79+
melos version --major
80+
# Melos will:
81+
# - Version pillar_core to 2.0.0
82+
# - Update pillar_remote_config dependency to "pillar_core: ^2.0.0"
83+
# - Version pillar_remote_config (major bump due to breaking dep change)
84+
# - Publish in correct order
85+
```
86+
87+
### Scenario 3: Adding New Package with Dependencies
88+
89+
```bash
90+
# 1. Create new package
91+
mkdir -p packages/pillar-analytics
92+
cd packages/pillar-analytics
93+
94+
# 2. Set up with path dependency
95+
cat > pubspec.yaml << EOF
96+
name: pillar_analytics
97+
version: 0.1.0
98+
dependencies:
99+
pillar_core:
100+
path: ../pillar-core # ← Development dependency
101+
EOF
102+
103+
# 3. Develop and test locally
104+
melos bootstrap
105+
melos test
106+
107+
# 4. When ready to publish
108+
melos version --minor
109+
# Melos automatically converts to: pillar_core: ^1.0.0
110+
```
111+
112+
## 🔧 Technical Implementation
113+
114+
### pubspec_overrides.yaml (Automatic)
115+
116+
Melos creates override files during bootstrap:
117+
118+
```yaml
119+
# packages/pillar-remote-config/pubspec_overrides.yaml (auto-generated)
120+
dependency_overrides:
121+
pillar_core:
122+
path: ../pillar-core
123+
```
124+
125+
**Purpose:**
126+
- Ensures local development uses path dependencies
127+
- Doesn't interfere with publication
128+
- Automatically managed by Melos
129+
130+
### Version Constraint Updates
131+
132+
During `melos version`, path dependencies are converted:
133+
134+
```yaml
135+
# BEFORE versioning (development)
136+
dependencies:
137+
pillar_core:
138+
path: ../pillar-core
139+
140+
# AFTER versioning (ready for publication)
141+
dependencies:
142+
pillar_core: ^2.0.0 # ← Automatically updated
143+
```
144+
145+
### Publication Order
146+
147+
Melos automatically determines publication order:
148+
149+
```
150+
1. pillar_core (no dependencies)
151+
2. pillar_remote_config (depends on pillar_core)
152+
3. pillar_analytics (depends on pillar_core)
153+
```
154+
155+
## 📋 Configuration Details
156+
157+
### Melos Configuration
158+
159+
```yaml
160+
# melos.yaml
161+
command:
162+
bootstrap:
163+
usePubspecOverrides: true # Enable override files
164+
165+
version:
166+
updateDependentsVersionConstraints: true # Update version ranges
167+
updateDependentsConstraints: true # Update all constraints
168+
```
169+
170+
### Analysis Configuration
171+
172+
To avoid warnings during development:
173+
174+
```yaml
175+
# analysis_options.yaml
176+
analyzer:
177+
errors:
178+
invalid_dependency: ignore # Allow path dependencies during development
179+
```
180+
181+
## 🎯 Best Practices
182+
183+
### 1. Always Use Path Dependencies in Source
184+
185+
```yaml
186+
# ✅ GOOD - Always use path in source
187+
dependencies:
188+
pillar_core:
189+
path: ../pillar-core
190+
191+
# ❌ BAD - Don't use version constraints in source
192+
dependencies:
193+
pillar_core: ^1.0.0
194+
```
195+
196+
### 2. Let Melos Handle Version Updates
197+
198+
```bash
199+
# ✅ GOOD - Let Melos update versions
200+
melos version --major
201+
202+
# ❌ BAD - Don't manually update version constraints
203+
# (editing pubspec.yaml to change pillar_core: ^1.0.0 to ^2.0.0)
204+
```
205+
206+
### 3. Test Before Publishing
207+
208+
```bash
209+
# Always test with current development state
210+
melos test
211+
melos analyze
212+
213+
# Then version and publish
214+
melos version --minor
215+
```
216+
217+
### 4. Use Conventional Commits
218+
219+
```bash
220+
# Breaking change
221+
git commit -m "feat!: redesign core API"
222+
223+
# New feature
224+
git commit -m "feat: add analytics tracking"
225+
226+
# Bug fix
227+
git commit -m "fix: resolve memory leak"
228+
```
229+
230+
## 🔍 Troubleshooting
231+
232+
### Issue: Path Dependencies in Published Package
233+
234+
**Error:** `Published package contains path dependency`
235+
236+
**Cause:** Manual version command bypassed Melos conversion
237+
238+
**Solution:**
239+
```bash
240+
# Use Melos versioning (not manual)
241+
melos version --patch # Instead of: dart pub version patch
242+
```
243+
244+
### Issue: Dependency Version Conflicts
245+
246+
**Error:** `Version solving failed`
247+
248+
**Solution:**
249+
```bash
250+
# Clean and re-bootstrap
251+
melos clean
252+
melos bootstrap
253+
254+
# Check dependency graph
255+
melos list --graph
256+
```
257+
258+
### Issue: Publication Order Problems
259+
260+
**Error:** `Package 'pillar_core' not found`
261+
262+
**Cause:** Dependent published before dependency
263+
264+
**Solution:** Melos handles this automatically, but if needed:
265+
```bash
266+
# Publish manually in order
267+
melos publish --scope="pillar_core"
268+
melos publish --scope="pillar_remote_config"
269+
```
270+
271+
## 📊 Development Workflow
272+
273+
### Daily Development
274+
275+
```bash
276+
# 1. Start development
277+
melos bootstrap # Sets up path dependencies
278+
279+
# 2. Make changes to any package
280+
# Files are linked, changes are immediate
281+
282+
# 3. Test continuously
283+
melos test
284+
285+
# 4. No need to publish during development
286+
```
287+
288+
### Release Workflow
289+
290+
```bash
291+
# 1. Finalize changes
292+
git add .
293+
git commit -m "feat: new feature complete"
294+
295+
# 2. Version (converts path deps to version constraints)
296+
melos version --minor
297+
298+
# 3. Publish (handles order automatically)
299+
melos publish --yes
300+
301+
# 4. Path dependencies restored for next development cycle
302+
melos bootstrap
303+
```
304+
305+
## 🎯 Summary
306+
307+
**The magic of Melos:**
308+
309+
1. **Development**: Use path dependencies for instant feedback
310+
2. **Publication**: Automatically convert to version constraints
311+
3. **Order**: Publish dependencies before dependents
312+
4. **Restoration**: Path dependencies restored after publication
313+
314+
**You get the best of both worlds:**
315+
- 🚀 **Fast development** with immediate changes
316+
- 📦 **Proper publication** with correct version constraints
317+
- 🔄 **Automatic orchestration** of complex dependency updates
318+
319+
This system handles your exact use case perfectly - breaking changes, version coordination, and development workflow all managed automatically by Melos! 🎉

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This directory contains comprehensive documentation for the Pillar monorepo.
1010
- **[TESTING.md](TESTING.md)** - Testing strategy and available test scripts
1111
- **[PUBLISHING.md](PUBLISHING.md)** - Complete guide for publishing packages to pub.dev
1212
- **[PUB-TOKEN-ROTATION.md](PUB-TOKEN-ROTATION.md)** - Step-by-step token rotation procedure
13+
- **[DEPENDENCY-MANAGEMENT.md](DEPENDENCY-MANAGEMENT.md)** - Smart dependency management between packages
1314

1415
## Structure
1516

melos.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,23 @@ scripts:
329329
ci:publish:
330330
run: |
331331
echo "📦 Publishing packages to pub.dev..."
332-
332+
333333
# Authenticate with pub.dev if token is available
334334
if [ -n "$PUB_TOKEN" ]; then
335335
echo "$PUB_TOKEN" | dart pub token add https://pub.dartlang.org
336336
fi
337-
337+
338338
# Publish all packages
339339
melos publish --no-dry-run --yes || {
340340
echo "⚠️ Some packages may have failed to publish"
341341
echo "This is often normal for packages that haven't changed"
342342
}
343-
343+
344344
echo "✅ Publishing to pub.dev completed"
345345
description: Publish packages to pub.dev
346+
347+
fix:analysis-warnings:
348+
run: |
349+
echo "🔧 Fixing analysis warnings..."
350+
./scripts/fix-analysis-warnings.sh
351+
description: Fix common analysis warnings (path dependencies, publish_to issues)

packages/pillar-core/example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: pillar_core_example
22
description: Example application demonstrating pillar_core usage
33
version: 1.0.0
4-
# Example app - not published
4+
publish_to: none
55

66
environment:
77
sdk: ">=3.6.0 <4.0.0"

packages/pillar-remote-config/pubspec.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: pillar_remote_config
22
description: Remote configuration package for Pillar framework
33
version: 1.0.0
4-
homepage: https://github.com/Core-Soft-Development/pillar
5-
repository: https://github.com/Core-Soft-Development/pillar
6-
issue_tracker: https://github.com/Core-Soft-Development/pillar/issues
4+
publish_to: none
75

86
environment:
97
sdk: ">=3.6.0 <4.0.0"

0 commit comments

Comments
 (0)