Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/reduce-internal-statics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tauri-apps/cli": patch:changes
"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

Minor grammar fix: hyphenate "user-facing".

When used as a compound adjective before a noun, "user-facing" should be hyphenated.

📝 Suggested 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 phrase "user
facing changes" in the .changes/reduce-internal-statics.md diff to the
hyphenated form "user-facing changes"; locate the string "user facing changes"
and replace it with "user-facing changes" to correct the compound adjective
grammar.

12 changes: 3 additions & 9 deletions crates/tauri-cli/src/acl/capability/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ use std::{collections::HashSet, path::PathBuf};
use clap::Parser;
use tauri_utils::acl::capability::{Capability, PermissionEntry};

use crate::{
acl::FileFormat,
error::ErrorExt,
helpers::{app_paths::tauri_dir, prompts},
Result,
};
use crate::{acl::FileFormat, error::ErrorExt, helpers::prompts, Result};

#[derive(Debug, Parser)]
#[clap(about = "Create a new permission file")]
Expand All @@ -37,7 +32,7 @@ pub struct Options {
}

pub fn command(options: Options) -> Result<()> {
crate::helpers::app_paths::resolve();
let dirs = crate::helpers::app_paths::resolve_dirs();

let identifier = match options.identifier {
Some(i) => i,
Expand Down Expand Up @@ -111,8 +106,7 @@ pub fn command(options: Options) -> Result<()> {
.canonicalize()
.fs_context("failed to canonicalize capability file path", o.clone())?,
None => {
let dir = tauri_dir();
let capabilities_dir = dir.join("capabilities");
let capabilities_dir = dirs.tauri.join("capabilities");
capabilities_dir.join(format!(
"{}.{}",
capability.identifier,
Expand Down
6 changes: 3 additions & 3 deletions crates/tauri-cli/src/acl/permission/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use clap::Parser;

use crate::{
error::{Context, ErrorExt},
helpers::app_paths::tauri_dir,
Result,
};
use colored::Colorize;
Expand All @@ -25,9 +24,10 @@ pub struct Options {
}

pub fn command(options: Options) -> Result<()> {
crate::helpers::app_paths::resolve();
let dirs = crate::helpers::app_paths::resolve_dirs();

let acl_manifests_path = tauri_dir()
let acl_manifests_path = dirs
.tauri
.join("gen")
.join("schemas")
.join("acl-manifests.json");
Expand Down
20 changes: 11 additions & 9 deletions crates/tauri-cli/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
acl,
error::ErrorExt,
helpers::{
app_paths::{resolve_frontend_dir, tauri_dir},
app_paths::{resolve_frontend_dir, Dirs},
cargo,
npm::PackageManager,
},
Expand Down Expand Up @@ -39,11 +39,11 @@ pub struct Options {
}

pub fn command(options: Options) -> Result<()> {
crate::helpers::app_paths::resolve();
run(options)
let dirs = crate::helpers::app_paths::resolve_dirs();
run(options, &dirs)
}

pub fn run(options: Options) -> Result<()> {
pub fn run(options: Options, dirs: &Dirs) -> Result<()> {
let (plugin, version) = options
.plugin
.split_once('@')
Expand Down Expand Up @@ -71,7 +71,6 @@ pub fn run(options: Options) -> Result<()> {
}

let frontend_dir = resolve_frontend_dir();
let tauri_dir = tauri_dir();

let target_str = metadata
.desktop_only
Expand All @@ -90,7 +89,7 @@ pub fn run(options: Options) -> Result<()> {
branch: options.branch.as_deref(),
rev: options.rev.as_deref(),
tag: options.tag.as_deref(),
cwd: Some(tauri_dir),
cwd: Some(dirs.tauri),
target: target_str,
})?;

Expand All @@ -117,7 +116,7 @@ pub fn run(options: Options) -> Result<()> {
(None, None, None, None) => npm_name,
_ => crate::error::bail!("Only one of --tag, --rev and --branch can be specified"),
};
manager.install(&[npm_spec], tauri_dir)?;
manager.install(&[npm_spec], 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:

# First, let's examine the add.rs file around lines 97 and 119
head -130 crates/tauri-cli/src/add.rs | tail -40

Repository: qodo-benchmark/tauri-combined-coderabbit

Length of output: 224


🏁 Script executed:

# Check PackageManager::install implementation
rg -n -B5 -A15 'pub fn install\(' crates/tauri-cli/src/helpers/npm.rs

Repository: qodo-benchmark/tauri-combined-coderabbit

Length of output: 66


🏁 Script executed:

# Check how PackageManager is initialized and if cwd is set during creation
rg -n -B3 -A10 'PackageManager::new\|fn new\(' crates/tauri-cli/src/helpers/npm.rs | head -50

Repository: qodo-benchmark/tauri-combined-coderabbit

Length of output: 66


🏁 Script executed:

# Look at remove.rs to compare the pattern
rg -n -B5 -A5 'manager\.install\|PackageManager' crates/tauri-cli/src/remove.rs | head -60

Repository: qodo-benchmark/tauri-combined-coderabbit

Length of output: 66


🏁 Script executed:

cat -n crates/tauri-cli/src/add.rs | sed -n '85,130p'

Repository: qodo-benchmark/tauri-combined-coderabbit

Length of output: 2024


🏁 Script executed:

cat -n crates/tauri-cli/src/helpers/npm.rs | sed -n '1,200p'

Repository: qodo-benchmark/tauri-combined-coderabbit

Length of output: 6885


🏁 Script executed:

cat -n crates/tauri-cli/src/remove.rs | sed -n '85,135p'

Repository: qodo-benchmark/tauri-combined-coderabbit

Length of output: 66


Fix NPM install directory mismatch.

The PackageManager is detected from frontend_dir (line 97), but manager.install() at line 119 is called with dirs.tauri. This will execute npm in the wrong directory. Since PackageManager::install() uses its second parameter as the working directory (via current_dir), npm will attempt to add the plugin to the Tauri crate directory instead of the frontend project where the dependency should be installed.

Pass the frontend directory to install() instead of dirs.tauri.

🤖 Prompt for AI Agents
In `@crates/tauri-cli/src/add.rs` at line 119, The install is being run in the
wrong directory: PackageManager is detected using frontend_dir but
manager.install(&[npm_spec], dirs.tauri) uses dirs.tauri as the working
directory; change the second argument to the frontend directory (frontend_dir)
so PackageManager::install() runs npm in the frontend project (refer to
manager.install, PackageManager::install, frontend_dir and dirs.tauri when
updating the call).

}

let _ = acl::permission::add::command(acl::permission::add::Options {
Expand All @@ -143,7 +142,10 @@ pub fn run(options: Options) -> Result<()> {
let plugin_init = format!(".plugin(tauri_plugin_{plugin_snake_case}::{plugin_init_fn})");

let re = Regex::new(r"(tauri\s*::\s*Builder\s*::\s*default\(\))(\s*)").unwrap();
for file in [tauri_dir.join("src/main.rs"), tauri_dir.join("src/lib.rs")] {
for file in [
dirs.tauri.join("src/main.rs"),
dirs.tauri.join("src/lib.rs"),
] {
let contents =
std::fs::read_to_string(&file).fs_context("failed to read Rust entry point", file.clone())?;

Expand All @@ -166,7 +168,7 @@ pub fn run(options: Options) -> Result<()> {
log::info!("Running `cargo fmt`...");
let _ = Command::new("cargo")
.arg("fmt")
.current_dir(tauri_dir)
.current_dir(dirs.tauri)
.status();
}

Expand Down
45 changes: 23 additions & 22 deletions crates/tauri-cli/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
error::{Context, ErrorExt},
helpers::{
self,
app_paths::{frontend_dir, tauri_dir},
config::{get as get_config, ConfigMetadata, FrontendDist},
app_paths::Dirs,
config::{get_config, ConfigMetadata, FrontendDist},
},
info::plugins::check_mismatched_packages,
interface::{rust::get_cargo_target_dir, AppInterface, Interface},
Expand Down Expand Up @@ -82,7 +82,7 @@ pub struct Options {
}

pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
crate::helpers::app_paths::resolve();
let dirs = crate::helpers::app_paths::resolve_dirs();

if options.no_sign {
log::warn!("--no-sign flag detected: Signing will be skipped.");
Expand All @@ -99,42 +99,38 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
let config = get_config(
target,
&options.config.iter().map(|c| &c.0).collect::<Vec<_>>(),
dirs.tauri,
)?;

let mut interface = AppInterface::new(
config.lock().unwrap().as_ref().unwrap(),
options.target.clone(),
)?;

let config_guard = config.lock().unwrap();
let config_ = config_guard.as_ref().unwrap();
let mut interface = AppInterface::new(&config, options.target.clone(), dirs.tauri)?;

setup(&interface, &mut options, config_, false)?;
setup(&interface, &mut options, &config, false, &dirs)?;

if let Some(minimum_system_version) = &config_.bundle.macos.minimum_system_version {
if let Some(minimum_system_version) = &config.bundle.macos.minimum_system_version {
std::env::set_var("MACOSX_DEPLOYMENT_TARGET", minimum_system_version);
}

let app_settings = interface.app_settings();
let interface_options = options.clone().into();

let out_dir = app_settings.out_dir(&interface_options)?;
let out_dir = app_settings.out_dir(&interface_options, dirs.tauri)?;

let bin_path = interface.build(interface_options)?;
let bin_path = interface.build(interface_options, &dirs)?;

log::info!(action ="Built"; "application at: {}", tauri_utils::display_path(bin_path));

let app_settings = interface.app_settings();

if !options.no_bundle && (config_.bundle.active || options.bundles.is_some()) {
if !options.no_bundle && (config.bundle.active || options.bundles.is_some()) {
crate::bundle::bundle(
&options.into(),
verbosity,
ci,
&interface,
&*app_settings,
config_,
&config,
&out_dir,
&dirs,
)?;
}

Expand All @@ -146,21 +142,20 @@ pub fn setup(
options: &mut Options,
config: &ConfigMetadata,
mobile: bool,
dirs: &Dirs,
) -> Result<()> {
let tauri_path = tauri_dir();

// TODO: Maybe optimize this to run in parallel in the future
// see https://github.com/tauri-apps/tauri/pull/13993#discussion_r2280697117
log::info!("Looking up installed tauri packages to check mismatched versions...");
if let Err(error) = check_mismatched_packages(frontend_dir(), tauri_path) {
if let Err(error) = check_mismatched_packages(dirs.frontend, dirs.tauri) {
if options.ignore_version_mismatches {
log::error!("{error}");
} else {
return Err(error);
}
}

set_current_dir(tauri_path).context("failed to set current directory")?;
set_current_dir(dirs.tauri).context("failed to set current directory")?;

let bundle_identifier_source = config
.find_bundle_identifier_overwriter()
Expand Down Expand Up @@ -191,7 +186,13 @@ pub fn setup(
}

if let Some(before_build) = config.build.before_build_command.clone() {
helpers::run_hook("beforeBuildCommand", before_build, interface, options.debug)?;
helpers::run_hook(
"beforeBuildCommand",
before_build,
interface,
options.debug,
dirs.frontend,
)?;
}

if let Some(FrontendDist::Directory(web_asset_path)) = &config.build.frontend_dist {
Expand Down Expand Up @@ -219,7 +220,7 @@ pub fn setup(

// Issue #13287 - Allow the use of target dir inside frontendDist/distDir
// https://github.com/tauri-apps/tauri/issues/13287
let target_path = get_cargo_target_dir(&options.args)?;
let target_path = get_cargo_target_dir(&options.args, dirs.tauri)?;
let mut out_folders = Vec::new();
if let Ok(web_asset_canonical) = dunce::canonicalize(web_asset_path) {
if let Ok(relative_path) = target_path.strip_prefix(&web_asset_canonical) {
Expand Down
35 changes: 19 additions & 16 deletions crates/tauri-cli/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::{
error::{Context, ErrorExt},
helpers::{
self,
app_paths::tauri_dir,
config::{get as get_config, ConfigMetadata},
app_paths::Dirs,
config::{get_config, ConfigMetadata},
updater_signature,
},
interface::{AppInterface, AppSettings, Interface},
Expand Down Expand Up @@ -118,7 +118,7 @@ impl From<crate::build::Options> for Options {
}

pub fn command(options: Options, verbosity: u8) -> crate::Result<()> {
crate::helpers::app_paths::resolve();
let dirs = crate::helpers::app_paths::resolve_dirs();

let ci = options.ci;

Expand All @@ -131,36 +131,31 @@ pub fn command(options: Options, verbosity: u8) -> crate::Result<()> {
let config = get_config(
target,
&options.config.iter().map(|c| &c.0).collect::<Vec<_>>(),
dirs.tauri,
)?;

let interface = AppInterface::new(
config.lock().unwrap().as_ref().unwrap(),
options.target.clone(),
)?;

let tauri_path = tauri_dir();
std::env::set_current_dir(tauri_path).context("failed to set current directory")?;
let interface = AppInterface::new(&config, options.target.clone(), dirs.tauri)?;

let config_guard = config.lock().unwrap();
let config_ = config_guard.as_ref().unwrap();
std::env::set_current_dir(dirs.tauri).context("failed to set current directory")?;

if let Some(minimum_system_version) = &config_.bundle.macos.minimum_system_version {
if let Some(minimum_system_version) = &config.bundle.macos.minimum_system_version {
std::env::set_var("MACOSX_DEPLOYMENT_TARGET", minimum_system_version);
}

let app_settings = interface.app_settings();
let interface_options = options.clone().into();

let out_dir = app_settings.out_dir(&interface_options)?;
let out_dir = app_settings.out_dir(&interface_options, dirs.tauri)?;

bundle(
&options,
verbosity,
ci,
&interface,
&*app_settings,
config_,
&config,
&out_dir,
&dirs,
)
}

Expand All @@ -173,6 +168,7 @@ pub fn bundle<A: AppSettings>(
app_settings: &A,
config: &ConfigMetadata,
out_dir: &Path,
dirs: &Dirs,
) -> crate::Result<()> {
let package_types: Vec<PackageType> = if let Some(bundles) = &options.bundles {
bundles.iter().map(|bundle| bundle.0).collect::<Vec<_>>()
Expand All @@ -198,12 +194,19 @@ pub fn bundle<A: AppSettings>(
before_bundle,
interface,
options.debug,
dirs.frontend,
)?;
}
}

let mut settings = app_settings
.get_bundler_settings(options.clone().into(), config, out_dir, package_types)
.get_bundler_settings(
options.clone().into(),
config,
out_dir,
package_types,
dirs.tauri,
)
.with_context(|| "failed to build bundler settings")?;
settings.set_no_sign(options.no_sign);

Expand Down
Loading