From 9cdcf9b3a8fa27612b3156c1702a4e776627e869 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Wed, 25 May 2022 06:51:33 -0700 Subject: [PATCH] feat(build): create `dev` alias (#4212) --- .changes/dev-alias.md | 5 +++++ core/tauri-build/Cargo.toml | 1 + core/tauri-build/src/lib.rs | 23 +++++++++++++++++++++++ core/tauri/src/manager.rs | 2 +- examples/api/src-tauri/Cargo.lock | 3 ++- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .changes/dev-alias.md diff --git a/.changes/dev-alias.md b/.changes/dev-alias.md new file mode 100644 index 000000000..60832c864 --- /dev/null +++ b/.changes/dev-alias.md @@ -0,0 +1,5 @@ +--- +"tauri-build": patch +--- + +Create `dev` cfg alias. diff --git a/core/tauri-build/Cargo.toml b/core/tauri-build/Cargo.toml index 15a1e9bbc..e596b4dea 100644 --- a/core/tauri-build/Cargo.toml +++ b/core/tauri-build/Cargo.toml @@ -23,6 +23,7 @@ tauri-codegen = { version = "1.0.0-rc.7", path = "../tauri-codegen", optional = tauri-utils = { version = "1.0.0-rc.7", path = "../tauri-utils", features = [ "build", "resources" ] } cargo_toml = "0.11" serde_json = "1" +heck = "0.4" [target."cfg(windows)".dependencies] winres = "0.1" diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 7cfe4e5ea..f2ba731e3 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -5,6 +5,7 @@ #![cfg_attr(doc_cfg, feature(doc_cfg))] pub use anyhow::Result; +use heck::ToSnakeCase; use tauri_utils::resources::{external_binaries, resource_relpath, ResourcePaths}; use std::path::{Path, PathBuf}; @@ -61,6 +62,26 @@ fn copy_resources(resources: ResourcePaths<'_>, path: &Path) -> Result<()> { Ok(()) } +// checks if the given Cargo feature is enabled. +fn has_feature(feature: &str) -> bool { + // when a feature is enabled, Cargo sets the `CARGO_FEATURE_ Result<()> { )?)? }; + cfg_alias("dev", !has_feature("custom-protocol")); + let mut manifest = Manifest::from_path("Cargo.toml")?; if let Some(tauri) = manifest.dependencies.remove("tauri") { let features = match tauri { diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index b6e2b3085..66df4890b 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -338,7 +338,7 @@ impl WindowManager { /// /// * In dev mode, this will be based on the `devPath` configuration value. /// * Otherwise, this will be based on the `distDir` configuration value. - #[cfg(custom_protocol)] + #[cfg(not(dev))] fn base_path(&self) -> &AppUrl { &self.inner.config.build.dist_dir } diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index b97dcfe76..e8ec76e07 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -3052,7 +3052,7 @@ dependencies = [ [[package]] name = "tauri" -version = "1.0.0-rc.12" +version = "1.0.0-rc.13" dependencies = [ "anyhow", "attohttpc", @@ -3117,6 +3117,7 @@ version = "1.0.0-rc.10" dependencies = [ "anyhow", "cargo_toml", + "heck 0.4.0", "semver 1.0.9", "serde_json", "tauri-codegen",