Skip to content

Less statics - #5

Open
tomerqodo wants to merge 2 commits into
coderabbit_full_base_less_statics_pr5from
coderabbit_full_head_less_statics_pr5
Open

Less statics#5
tomerqodo wants to merge 2 commits into
coderabbit_full_base_less_statics_pr5from
coderabbit_full_head_less_statics_pr5

Conversation

@tomerqodo

@tomerqodo tomerqodo commented Jan 30, 2026

Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#5

Summary by CodeRabbit

  • Refactor
    • Internal refactoring of path resolution and configuration handling to improve code maintainability and reduce reliance on static constructs. No user-facing changes.

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This refactor reduces internal static constructs by introducing a centralized Dirs struct to carry resolved tauri and frontend paths. Global static helpers like tauri_dir() and frontend_dir() are removed; configuration is now loaded per-call instead of via a global ConfigHandle mutex. Directory and config contexts are explicitly threaded through function signatures.

Changes

Cohort / File(s) Summary
Changelog Entry
.changes/reduce-internal-statics.md
New changelog documenting the refactor with patch entries for CLI packages and note of no user-facing changes.
Path Resolution Core
crates/tauri-cli/src/helpers/app_paths.rs, crates/tauri-cli/src/helpers/cargo_manifest.rs
Introduces public Dirs struct and resolve_dirs() function to consolidate tauri and frontend path resolution; removes old tauri_dir(), frontend_dir(), and resolve() functions. Updates cargo manifest helper to accept tauri_dir parameter.
Config Module Refactor
crates/tauri-cli/src/helpers/config.rs
Removes global ConfigHandle static mutex; replaces with per-call get_config(), reload_config(), and merge_config_with() functions. Config now passed explicitly through signatures instead of locked/unlocked globally.
Hook Execution
crates/tauri-cli/src/helpers/mod.rs
Updates run_hook() signature to accept frontend_dir: &Path parameter; removes private frontend_dir() import and uses provided path instead.
Primary Commands Threading Dirs/Config
crates/tauri-cli/src/build.rs, crates/tauri-cli/src/dev.rs, crates/tauri-cli/src/bundle.rs, crates/tauri-cli/src/add.rs
Each command now resolves Dirs once and threads through to dependent functions. Signatures updated for AppInterface::new(), setup(), and related calls to accept explicit dirs and/or tauri_dir parameters. Config loaded per-call instead of globally.
ACL and Permission Modules
crates/tauri-cli/src/acl/capability/new.rs, crates/tauri-cli/src/acl/permission/ls.rs
Replaces tauri_dir() calls with resolve_dirs() flow; uses dirs.tauri for path construction instead of calling static helpers.
Info and Icon Commands
crates/tauri-cli/src/info/mod.rs, crates/tauri-cli/src/info/app.rs, crates/tauri-cli/src/info/plugins.rs, crates/tauri-cli/src/icon.rs
Updates signatures to pass ConfigMetadata instead of tauri_dir to items(); icon.rs switches to resolve_dirs() for output directory resolution.
Interface Trait and Implementations
crates/tauri-cli/src/interface/mod.rs, crates/tauri-cli/src/interface/rust.rs, crates/tauri-cli/src/interface/rust/desktop.rs, crates/tauri-cli/src/interface/rust/manifest.rs
Public trait signatures expanded to accept tauri_dir: &Path and/or dirs: &Dirs. AppInterface::new(), build(), dev(), mobile_dev(), watch() all updated. Internal helpers like get_cargo_metadata(), get_workspace_dir(), get_cargo_target_dir() now accept tauri_dir parameter.
Migrate Modules
crates/tauri-cli/src/migrate/mod.rs, crates/tauri-cli/src/migrate/migrations/v1/mod.rs, crates/tauri-cli/src/migrate/migrations/v2_beta.rs
Migration runners updated to accept dirs: &Dirs parameter; path construction switched from static helpers to dirs.tauri and dirs.frontend.
Android Mobile Module
crates/tauri-cli/src/mobile/android/mod.rs, crates/tauri-cli/src/mobile/android/dev.rs, crates/tauri-cli/src/mobile/android/build.rs, crates/tauri-cli/src/mobile/android/run.rs, crates/tauri-cli/src/mobile/android/android_studio_script.rs
Android commands and helpers updated to resolve and thread Dirs through flow. Config type changed from ConfigHandle to ConfigMetadata. Helper imports updated from get/reload to get_config/reload_config. AppInterface::new() and config loading calls updated to accept new parameters.
iOS Mobile Module
crates/tauri-cli/src/mobile/ios/mod.rs, crates/tauri-cli/src/mobile/ios/dev.rs, crates/tauri-cli/src/mobile/ios/build.rs, crates/tauri-cli/src/mobile/ios/run.rs, crates/tauri-cli/src/mobile/ios/xcode_script.rs
iOS commands and helpers refactored to use Dirs for path resolution and ConfigMetadata instead of locked ConfigHandle. Public signatures (get_config(), synchronize_project_config()) updated for new parameters and types.
Mobile Core and Inspection
crates/tauri-cli/src/mobile/mod.rs, crates/tauri-cli/src/mobile/init.rs, crates/tauri-cli/src/inspect.rs, crates/tauri-cli/src/remove.rs
Mobile module functions updated to accept tauri_dir: &Path and propagate Dirs; ensure_init(), get_app(), use_network_address_for_dev_url() signatures changed. inspect.rs updates wix_upgrade_code() to accept tauri_dir. remove.rs simplified to use resolve_dirs().

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes


Poem

🐰 Hop, hop! No more static paths to roam,
Dirs now carry tauri and frontend home,
Config flows free—no locks to unlock,
Thread the context through every block!
A refactor so clean, the code hops along,
Goodbye globals, hello—where we belong! 🌿✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.10% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Less statics' is vague and does not clearly convey the main purpose of the refactoring. While it relates to the changes (reducing static/global path resolution), it lacks specificity about what aspect of the codebase was modified. Consider a more descriptive title such as 'Refactor path resolution to reduce static/global helpers' or 'Replace static path helpers with explicit directory passing' to better communicate the primary refactoring objective.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch coderabbit_full_head_less_statics_pr5

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.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/tauri-cli/src/mobile/android/android_studio_script.rs (1)

88-97: ⚠️ Potential issue | 🔴 Critical

Remove the redundant merge_config_with call or clarify the necessity of both functions.

The code applies the same config overrides twice: reload_config (lines 54–62) reloads the config from disk and applies the merge configs during the load process via load_config(merge_configs, true, ...), and then merge_config_with (lines 88–97) applies the identical cli_options.config values to the already-reloaded configuration again.

reload_config replaces the entire config object with a fresh load that includes the merges, while merge_config_with performs an in-place merge on the existing config. Unless there is a specific reason to apply these overrides a second time after reloading, the second call should be removed.

🤖 Fix all issues with AI agents
In @.changes/reduce-internal-statics.md:
- Line 6: Update the changelog sentence "Refactored internal use of static on
config and directory resolvings, no user facing changes, please report any
regressions if you encounter any" to correct grammar and punctuation: hyphenate
"user-facing", break the run-on into two sentences or use proper punctuation,
fix "resolvings" to "resolving", and ensure the line ends with a period; e.g.
split into "Refactored internal use of 'static' on config and directory
resolving. No user-facing changes; please report any regressions if you
encounter any."

In `@crates/tauri-cli/src/remove.rs`:
- Line 49: The call to manager.remove currently passes dirs.tauri instead of the
frontend directory and loses ownership of frontend_dir via the earlier .map(),
causing npm removal to run in the wrong working directory; fix by preserving
frontend_dir (avoid consuming it with .map()) and construct PackageManager with
PackageManager::from_project(&frontend_dir) then call
manager.remove(&[npm_name], &frontend_dir) inside an if let Some(frontend_dir) =
frontend_dir block so the correct frontend_dir is passed to manager.remove
(reference symbols: frontend_dir, PackageManager::from_project, manager.remove,
npm_name).
🧹 Nitpick comments (3)
crates/tauri-cli/src/helpers/app_paths.rs (1)

130-144: Consider the safety of parent().unwrap() fallback.

On line 141, tauri.parent().unwrap() is used as a fallback when resolve_frontend_dir() returns None. While the tauri directory should always have a parent (since it must be a valid project directory containing config files), this could theoretically panic if the tauri path is the filesystem root.

Given that the preceding logic in resolve_tauri_dir() ensures the path contains configuration files and is not a root path, this should be safe in practice. However, you might consider adding a comment explaining this assumption or using unwrap_or_else with a descriptive panic message for consistency with the error handling pattern above.

crates/tauri-cli/src/mobile/mod.rs (1)

476-488: Redundant to_path_buf() call.

tauri_dir is converted to PathBuf on line 476, then to_path_buf() is called again on line 477. The second conversion is unnecessary.

♻️ Proposed fix
   let app_settings = interface.app_settings();
   let tauri_dir = tauri_dir.to_path_buf();
-  App::from_raw(tauri_dir.to_path_buf(), raw)
+  App::from_raw(tauri_dir.clone(), raw)
     .unwrap()
     .with_target_dir_resolver(move |target, profile| {
crates/tauri-cli/src/mobile/ios/build.rs (1)

329-329: Unnecessary double reference.

dirs is already &Dirs, so &dirs creates &&Dirs. While this works due to auto-deref, it's inconsistent with other call sites.

♻️ Proposed fix
     &mut config,
     &mut env,
     noise_level,
-    &dirs,
+    dirs,
   )?;

"tauri-cli": patch:changes
---

Refactored internal use of static on config and directory resolvings, no user facing changes, please report any regressions if you encounter any

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix grammar and punctuation in the changelog description.

The description has the following issues:

  • "user facing" should be hyphenated as "user-facing"
  • Run-on sentence structure needs proper punctuation
  • Missing period at the end
📝 Proposed fix
-Refactored internal use of static on config and directory resolvings, no user facing changes, please report any regressions if you encounter any
+Refactored internal use of static on config and directory resolvings. No user-facing changes; please report any regressions if you encounter any.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Refactored internal use of static on config and directory resolvings, no user facing changes, please report any regressions if you encounter any
Refactored internal use of static on config and directory resolvings. No user-facing changes; please report any regressions if you encounter any.
🧰 Tools
🪛 LanguageTool

[grammar] ~6-~6: Use a hyphen to join words.
Context: ...config and directory resolvings, no user facing changes, please report any regres...

(QB_NEW_EN_HYPHEN)

🤖 Prompt for AI Agents
In @.changes/reduce-internal-statics.md at line 6, Update the changelog sentence
"Refactored internal use of static on config and directory resolvings, no user
facing changes, please report any regressions if you encounter any" to correct
grammar and punctuation: hyphenate "user-facing", break the run-on into two
sentences or use proper punctuation, fix "resolvings" to "resolving", and ensure
the line ends with a period; e.g. split into "Refactored internal use of
'static' on config and directory resolving. No user-facing changes; please
report any regressions if you encounter any."

if let Some(manager) = frontend_dir.map(PackageManager::from_project) {
let npm_name = format!("@tauri-apps/plugin-{plugin}");
manager.remove(&[npm_name], tauri_dir)?;
manager.remove(&[npm_name], dirs.tauri)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Find the PackageManager remove method signature and implementation
rg -n "fn remove" crates/tauri-cli/src/helpers/npm.rs -A 15

Repository: agentic-review-benchmarks/tauri-combined-coderabbit

Length of output: 558


🏁 Script executed:

# Also search for the full file to understand context
fd "npm.rs" crates/tauri-cli/src

Repository: agentic-review-benchmarks/tauri-combined-coderabbit

Length of output: 130


🏁 Script executed:

# Look at the remove.rs file to see the full context around line 49
cat -n crates/tauri-cli/src/remove.rs | head -60

Repository: agentic-review-benchmarks/tauri-combined-coderabbit

Length of output: 2138


Fix incorrect working directory for npm package removal.

The manager.remove() call at line 49 passes dirs.tauri as the second argument, but the method signature explicitly expects frontend_dir. NPM operations must run in the frontend directory where package.json exists, not the Rust source directory.

The frontend_dir is consumed by the .map() on line 47, so it needs to be preserved. Refactor as follows:

  if let Some(frontend_dir) = frontend_dir {
    let manager = PackageManager::from_project(&frontend_dir);
    let npm_name = format!("@tauri-apps/plugin-{plugin}");
    manager.remove(&[npm_name], &frontend_dir)?;
  }
🤖 Prompt for AI Agents
In `@crates/tauri-cli/src/remove.rs` at line 49, The call to manager.remove
currently passes dirs.tauri instead of the frontend directory and loses
ownership of frontend_dir via the earlier .map(), causing npm removal to run in
the wrong working directory; fix by preserving frontend_dir (avoid consuming it
with .map()) and construct PackageManager with
PackageManager::from_project(&frontend_dir) then call
manager.remove(&[npm_name], &frontend_dir) inside an if let Some(frontend_dir) =
frontend_dir block so the correct frontend_dir is passed to manager.remove
(reference symbols: frontend_dir, PackageManager::from_project, manager.remove,
npm_name).

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.

1 participant