Skip to content

Refactor: Migrate monorepo to Dart pub workspaces #4530

Merged
hoangdat merged 8 commits into
masterfrom
migrate-dart-pub-workspaces
May 21, 2026
Merged

Refactor: Migrate monorepo to Dart pub workspaces #4530
hoangdat merged 8 commits into
masterfrom
migrate-dart-pub-workspaces

Conversation

@dab246
Copy link
Copy Markdown
Member

@dab246 dab246 commented May 18, 2026

Why

Before this PR, each of the 11 sub-packages maintained its own pubspec.lock and duplicated dependency_overrides for git-sourced packages. That caused several problems:

  • Dependency resolution happened independently per package — two packages could silently resolve the same transitive dependency to different versions.
  • Any git ref update (jmap_dart_client, linagora_design_flutter, intl_generator) required editing up to 12 files.
  • CI cached 12 separate lock files with no guarantee they represented a consistent dependency graph.
  • prebuild.sh ran flutter pub get + build_runner 11 times sequentially.

What changed

Workspace migration

  • Add workspace: key to root pubspec.yaml listing all 11 sub-packages.
  • Add resolution: workspace to each sub-package pubspec.yaml; remove their pubspec.lock files and dependency_overrides blocks.
  • Consolidate git-sourced dependency_overrides (jmap_dart_client, linagora_design_flutter, intl_generator) into root pubspec.yaml only.
  • A single shared pubspec.lock at the root now represents the entire monorepo.

CI & build

  • Update cache key in all 4 workflows (analyze-test, build, gh-pages, release) from hashFiles('**/pubspec.lock') to hashFiles('pubspec.lock').
  • Simplify prebuild.sh: one flutter pub get + one dart run build_runner build --workspace replaces 12 sequential invocations.

Dependency updates

Package Before After Reason
hive_ce 2.11.3 2.16.0 Required by hive_ce_generator 1.11.2
hive_generator (dev) 2.0.0 hive_ce_generator 1.11.2 Generator for hive_ce; auto-generates HiveRegistrar extension
hive override git shim (IO-Design-Team) removed No longer needed — hive_ce_generator 1.11.2 uses hive_ce directly
worker_manager Linagora git fork 7.2.9 (pub.dev) Upstream PR #123 merged 2026-04-09

Code improvements

  • HiveCacheConfig._registerAdapter: replaced 22 manual registerCacheAdapter calls with IsolatedHive.registerAdapters() / Hive.registerAdapters() from the generated hive_registrar.g.dart. New adapters are now picked up automatically.
  • Null-safety: removed redundant ! operators in single_email_controller.dart, sentry_ecosystem.dart, and caching_manager.dart where flow analysis already proves non-null.

Documentation

  • Add ADR-0090 documenting the previous architecture, migration rationale, dependency changes, and consequences.

Blocker

Summary by CodeRabbit

  • Chores

    • Migrated to Dart pub workspaces with a consolidated root manifest and dependency_overrides.
    • Raised Dart SDK constraint to >=3.9.0 and bumped build/tooling/dev-dependency versions.
    • CI workflows now hash the root lockfile for cache reuse.
    • Consolidated prebuild/build to a workspace-wide flow and added ADR documenting the migration.
  • Bug Fixes

    • Improved null-safety usage in caching and email controllers.
  • Refactor

    • Streamlined Hive adapter registration to avoid repeated registrations.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c7361538-6ef6-485a-a18d-52f5d3b73c32

📥 Commits

Reviewing files that changed from the base of the PR and between d0d4851 and 5a08d7f.

⛔ Files ignored due to path filters (1)
  • pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • pubspec.yaml

Walkthrough

This PR migrates the monorepo to a Dart pub workspace: the root pubspec.yaml declares a workspace and central dependency_overrides, and the root Dart SDK constraint is raised to >=3.9.0. Sub-packages adopt resolution: workspace, remove inline git blocks, and update dev-tool constraints. CI workflows now hash the root pubspec.lock for Flutter cache keys. scripts/prebuild.sh is refactored to run pub get and build_runner once at the workspace root and centralizes intl generation. Hive adapter registration is consolidated via generated bulk registration with guards to avoid duplicates. Redundant non-null assertions are removed in several source files.

Possibly related PRs

Suggested reviewers

  • hoangdat
  • tddang-linagora
  • codescene-delta-analysis
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Refactor: Migrate monorepo to Dart pub workspaces' directly and clearly summarizes the main change of this comprehensive migration PR, covering the workspace setup consolidation across all configuration files and build scripts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch migrate-dart-pub-workspaces

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

chibenwa
chibenwa previously approved these changes May 18, 2026
Copy link
Copy Markdown
Member

@chibenwa chibenwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool

codescene-delta-analysis[bot]

This comment was marked as outdated.

@dab246 dab246 marked this pull request as ready for review May 18, 2026 06:45
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/adr/0089-migrate-to-dart-pub-workspaces.md`:
- Line 15: Add language identifiers to the two fenced code blocks that show the
tmail-flutter directory trees (the triple-backtick blocks around "tmail-flutter/
├── pubspec.yaml ..."), changing ``` to ```text for both occurrences so the
blocks are tagged and MD040 is resolved; ensure both the first example block and
the second workspace declaration block use ```text.

In `@scripts/prebuild.sh`:
- Around line 20-21: The script uses chained `&&` between the intl_generator
invocations ("dart run intl_generator:extract_to_arb --output-dir=./lib/l10n
lib/main/localizations/app_localizations.dart > /dev/null 2>&1" and "dart run
intl_generator:generate_from_arb --output-dir=lib/l10n --no-use-deferred-loading
lib/main/localizations/app_localizations.dart lib/l10n/intl*.arb > /dev/null
2>&1"), which suppresses set -e errexit behavior on failure; change each
intl_generator invocation so it is on its own line (do not chain with &&) so a
failing `extract_to_arb` or `generate_from_arb` immediately stops execution and
preserves error handling; apply the same change for the later duplicate commands
(the other extract/generate pair) in the script.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: effa3610-d600-4594-8ac0-b63f137b2ecd

📥 Commits

Reviewing files that changed from the base of the PR and between f8938e5 and 876b8ae.

⛔ Files ignored due to path filters (12)
  • contact/pubspec.lock is excluded by !**/*.lock
  • core/pubspec.lock is excluded by !**/*.lock
  • cozy/pubspec.lock is excluded by !**/*.lock
  • email_recovery/pubspec.lock is excluded by !**/*.lock
  • fcm/pubspec.lock is excluded by !**/*.lock
  • forward/pubspec.lock is excluded by !**/*.lock
  • labels/pubspec.lock is excluded by !**/*.lock
  • model/pubspec.lock is excluded by !**/*.lock
  • pubspec.lock is excluded by !**/*.lock
  • rule_filter/pubspec.lock is excluded by !**/*.lock
  • scribe/pubspec.lock is excluded by !**/*.lock
  • server_settings/pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (21)
  • .github/workflows/analyze-test.yaml
  • .github/workflows/build.yaml
  • .github/workflows/gh-pages.yaml
  • .github/workflows/release.yaml
  • contact/pubspec.yaml
  • core/pubspec.yaml
  • cozy/pubspec.yaml
  • docs/adr/0089-migrate-to-dart-pub-workspaces.md
  • email_recovery/pubspec.yaml
  • fcm/pubspec.yaml
  • forward/pubspec.yaml
  • labels/pubspec.yaml
  • lib/features/caching/caching_manager.dart
  • lib/features/email/presentation/controller/single_email_controller.dart
  • lib/features/mailbox_dashboard/presentation/sentry_ecosystem.dart
  • model/pubspec.yaml
  • pubspec.yaml
  • rule_filter/pubspec.yaml
  • scribe/pubspec.yaml
  • scripts/prebuild.sh
  • server_settings/pubspec.yaml

Comment thread docs/adr/0089-migrate-to-dart-pub-workspaces.md Outdated
Comment thread scripts/prebuild.sh Outdated
@dab246 dab246 force-pushed the migrate-dart-pub-workspaces branch from 876b8ae to 76db6d7 Compare May 20, 2026 04:25
codescene-delta-analysis[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
scripts/prebuild.sh (1)

15-16: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Split intl_generator commands; && weakens fail-fast behavior with set -e.

At Line 15 and Line 23, a failing extract_to_arb can bypass immediate exit semantics and the script may continue to later "Done" logs with stale l10n outputs. Run each command on its own line.

Suggested patch
-dart run intl_generator:extract_to_arb --output-dir=./lib/l10n lib/main/localizations/app_localizations.dart > /dev/null 2>&1 &&
-    dart run intl_generator:generate_from_arb --output-dir=lib/l10n --no-use-deferred-loading lib/main/localizations/app_localizations.dart lib/l10n/intl*.arb > /dev/null 2>&1
+dart run intl_generator:extract_to_arb --output-dir=./lib/l10n lib/main/localizations/app_localizations.dart > /dev/null 2>&1
+dart run intl_generator:generate_from_arb --output-dir=lib/l10n --no-use-deferred-loading lib/main/localizations/app_localizations.dart lib/l10n/intl*.arb > /dev/null 2>&1
@@
-   dart run intl_generator:extract_to_arb --output-dir=./lib/scribe/ai/l10n lib/scribe/ai/localizations/scribe_localizations.dart > /dev/null 2>&1 &&
-      dart run intl_generator:generate_from_arb --output-dir=lib/scribe/ai/l10n --no-use-deferred-loading lib/scribe/ai/localizations/scribe_localizations.dart lib/scribe/ai/l10n/intl*.arb > /dev/null 2>&1
+   dart run intl_generator:extract_to_arb --output-dir=./lib/scribe/ai/l10n lib/scribe/ai/localizations/scribe_localizations.dart > /dev/null 2>&1
+   dart run intl_generator:generate_from_arb --output-dir=lib/scribe/ai/l10n --no-use-deferred-loading lib/scribe/ai/localizations/scribe_localizations.dart lib/scribe/ai/l10n/intl*.arb > /dev/null 2>&1
#!/usr/bin/env bash
set -euo pipefail

echo "1) Demonstrate bash errexit behavior for left side of &&"
bash -c 'set -e; false && echo SHOULD_NOT_PRINT; echo STILL_RUNNING'

echo "2) Inspect the relevant section in prebuild script"
nl -ba scripts/prebuild.sh | sed -n '12,26p'

Also applies to: 23-24

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/prebuild.sh` around lines 15 - 16, The combined pipeline using "dart
run intl_generator:extract_to_arb ... > /dev/null 2>&1 && dart run
intl_generator:generate_from_arb ..." in scripts/prebuild.sh weakens set -e
fail-fast behavior; split these into two separate commands (one per line) so a
failing extract_to_arb immediately causes the script to exit, and do the same
for the generate_from_arb invocation elsewhere (the occurrences of
"extract_to_arb" and "generate_from_arb" should be run on their own lines rather
than chained with &&).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/features/caching/config/hive_cache_config.dart`:
- Around line 127-145: The closeHive method is resetting the
adapter-registration guards which causes duplicate adapter registration later;
update closeHive({bool isolated = true}) to stop modifying
_isolatedAdaptersRegistered and _regularAdaptersRegistered (i.e., remove the
lines that set them to false) and only await IsolatedHive.close() or
Hive.close() respectively so that _registerAdapter() remains the authoritative
guard for adapter registration.

---

Duplicate comments:
In `@scripts/prebuild.sh`:
- Around line 15-16: The combined pipeline using "dart run
intl_generator:extract_to_arb ... > /dev/null 2>&1 && dart run
intl_generator:generate_from_arb ..." in scripts/prebuild.sh weakens set -e
fail-fast behavior; split these into two separate commands (one per line) so a
failing extract_to_arb immediately causes the script to exit, and do the same
for the generate_from_arb invocation elsewhere (the occurrences of
"extract_to_arb" and "generate_from_arb" should be run on their own lines rather
than chained with &&).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c175ac56-9e39-4b61-8046-967421db5832

📥 Commits

Reviewing files that changed from the base of the PR and between 876b8ae and 76db6d7.

⛔ Files ignored due to path filters (12)
  • contact/pubspec.lock is excluded by !**/*.lock
  • core/pubspec.lock is excluded by !**/*.lock
  • cozy/pubspec.lock is excluded by !**/*.lock
  • email_recovery/pubspec.lock is excluded by !**/*.lock
  • fcm/pubspec.lock is excluded by !**/*.lock
  • forward/pubspec.lock is excluded by !**/*.lock
  • labels/pubspec.lock is excluded by !**/*.lock
  • model/pubspec.lock is excluded by !**/*.lock
  • pubspec.lock is excluded by !**/*.lock
  • rule_filter/pubspec.lock is excluded by !**/*.lock
  • scribe/pubspec.lock is excluded by !**/*.lock
  • server_settings/pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (22)
  • .github/workflows/analyze-test.yaml
  • .github/workflows/build.yaml
  • .github/workflows/gh-pages.yaml
  • .github/workflows/release.yaml
  • contact/pubspec.yaml
  • core/pubspec.yaml
  • cozy/pubspec.yaml
  • docs/adr/0090-migrate-to-dart-pub-workspaces.md
  • email_recovery/pubspec.yaml
  • fcm/pubspec.yaml
  • forward/pubspec.yaml
  • labels/pubspec.yaml
  • lib/features/caching/caching_manager.dart
  • lib/features/caching/config/hive_cache_config.dart
  • lib/features/email/presentation/controller/single_email_controller.dart
  • lib/features/mailbox_dashboard/presentation/sentry_ecosystem.dart
  • model/pubspec.yaml
  • pubspec.yaml
  • rule_filter/pubspec.yaml
  • scribe/pubspec.yaml
  • scripts/prebuild.sh
  • server_settings/pubspec.yaml
✅ Files skipped from review due to trivial changes (1)
  • docs/adr/0090-migrate-to-dart-pub-workspaces.md

Comment thread lib/features/caching/config/hive_cache_config.dart
codescene-delta-analysis[bot]

This comment was marked as outdated.

@github-actions
Copy link
Copy Markdown

This PR has been deployed to https://linagora.github.io/tmail-flutter/4530.

@chibenwa
Copy link
Copy Markdown
Member

I love -10K lines of code diffs :-)

@hoangdat
Copy link
Copy Markdown
Member

linagora/intl_generator#5 was merged, please update

Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gates Passed
3 Quality Gates Passed

See analysis details in CodeScene

Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

@dab246
Copy link
Copy Markdown
Member Author

dab246 commented May 20, 2026

linagora/intl_generator#5 was merged, please update

updated

@hoangdat hoangdat merged commit 7e8fbbb into master May 21, 2026
17 of 20 checks passed
@hoangdat hoangdat deleted the migrate-dart-pub-workspaces branch May 28, 2026 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants