Skip to content
Merged
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/toml-json5-configs-in-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
tauri-cli: minor:enhance
"@tauri-apps/cli": minor:enhance
---

Add support for passing TOML and JSON5 config files to `--config` arg
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/tauri-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ tauri-bundler = { version = "2.3.0", default-features = false, path = "../tauri-
colored = "2"
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
json5 = "0.4"
notify = "8"
notify-debouncer-full = "0.5"
shared_child = "1"
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-cli/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct Options {
/// Skip the bundling step even if `bundle > active` is `true` in tauri config.
#[clap(long)]
pub no_bundle: bool,
/// JSON strings or path to JSON files to merge with the default configuration file
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
///
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-cli/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct Options {
/// Space or comma separated list of bundles to package.
#[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')]
pub bundles: Option<Vec<BundleFormat>>,
/// JSON strings or path to JSON files to merge with the default configuration file
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
///
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-cli/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct Options {
/// Exit on panic
#[clap(short, long)]
pub exit_on_panic: bool,
/// JSON strings or path to JSON files to merge with the default configuration file
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
///
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
///
Expand Down
20 changes: 16 additions & 4 deletions crates/tauri-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,22 @@ impl FromStr for ConfigValue {
} else {
let path = PathBuf::from(config);
if path.exists() {
Ok(Self(serde_json::from_str(
&read_to_string(&path)
.with_context(|| format!("invalid configuration at file {config}"))?,
)?))
let raw = &read_to_string(&path)
.with_context(|| format!("invalid configuration at file {config}"))?;
match path.extension() {
Some(ext) if ext == "toml" => Ok(Self(::toml::from_str(raw)?)),
Some(ext) if ext == "json5" => Ok(Self(::json5::from_str(raw)?)),
// treat all other extensions as json
_ => Ok(Self(
// from tauri-utils/src/config/parse.rs:
// we also want to support **valid** json5 in the .json extension
// if the json5 is not valid the serde_json error for regular json will be returned.
match ::json5::from_str(raw) {
Ok(json5) => json5,
Err(_) => serde_json::from_str(raw)?,
},
)),
}
} else {
anyhow::bail!("provided configuration path does not exist")
}
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-cli/src/mobile/android/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct Options {
/// List of cargo features to activate
#[clap(short, long, action = ArgAction::Append, num_args(0..))]
pub features: Option<Vec<String>>,
/// JSON strings or path to JSON files to merge with the default configuration file
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
///
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-cli/src/mobile/android/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct Options {
/// Exit on panic
#[clap(short, long)]
exit_on_panic: bool,
/// JSON strings or path to JSON files to merge with the default configuration file
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
///
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-cli/src/mobile/ios/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct Options {
/// List of cargo features to activate
#[clap(short, long, action = ArgAction::Append, num_args(0..))]
pub features: Option<Vec<String>>,
/// JSON strings or path to JSON files to merge with the default configuration file
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
///
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-cli/src/mobile/ios/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct Options {
/// Exit on panic
#[clap(short, long)]
exit_on_panic: bool,
/// JSON strings or path to JSON files to merge with the default configuration file
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
///
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
///
Expand Down