From 4963d00e5d0ca91513972a2278a9daea075eaaa0 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sat, 20 Feb 2021 23:35:01 -0300 Subject: [PATCH] fix(cli): do not serialize `None` config values (#1266) --- cli/core/Cargo.lock | 64 +++++++++++++++++++++++++++++++++++ cli/core/Cargo.toml | 2 ++ cli/core/config_definition.rs | 13 +++++++ cli/core/schema.json | 59 +++----------------------------- 4 files changed, 83 insertions(+), 55 deletions(-) diff --git a/cli/core/Cargo.lock b/cli/core/Cargo.lock index 26ca8f6c7..513d47862 100755 --- a/cli/core/Cargo.lock +++ b/cli/core/Cargo.lock @@ -406,6 +406,41 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "darling" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11947000d710ff98138229f633039982f0fef2d9a3f546c21d610fee5f8631d5" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae53b4d9cc89c40314ccf2bf9e6ff1eb19c31e3434542445a41893dbf041aec2" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.10.0", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9cd9ac4d50d023af5e710cae1501afb063efcd917bd3fc026e8ed6493cc9755" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "deflate" version = "0.8.6" @@ -721,6 +756,12 @@ dependencies = [ "png", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.2.1" @@ -1848,6 +1889,28 @@ dependencies = [ "serde 1.0.123", ] +[[package]] +name = "serde_with" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b44be9227e214a0420707c9ca74c2d4991d9955bae9415a8f93f05cebf561be5" +dependencies = [ + "serde 1.0.123", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48b35457e9d855d3dc05ef32a73e0df1e2c0fd72c38796a4ee909160c8eeec2" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sha-1" version = "0.8.2" @@ -1999,6 +2062,7 @@ dependencies = [ "schemars", "serde 1.0.123", "serde_json 1.0.62", + "serde_with", "shared_child", "tauri-bundler", "toml_edit", diff --git a/cli/core/Cargo.toml b/cli/core/Cargo.toml index 3c2cef4eb..724456991 100644 --- a/cli/core/Cargo.toml +++ b/cli/core/Cargo.toml @@ -18,6 +18,7 @@ colored = "2.0" once_cell = "1.5" serde = { version = "1.0", features = [ "derive" ] } serde_json = "1.0" +serde_with = "1.6" notify = "4.0" shared_child = "0.3" toml_edit = "0.2" @@ -29,6 +30,7 @@ valico = "3.5" schemars = "0.8" serde = { version = "1.0", features = [ "derive" ] } serde_json = "1.0" +serde_with = "1.6" [target."cfg(target_os = \"windows\")".dependencies] which = "4.0" diff --git a/cli/core/config_definition.rs b/cli/core/config_definition.rs index e384e8990..85ab4f088 100644 --- a/cli/core/config_definition.rs +++ b/cli/core/config_definition.rs @@ -1,6 +1,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; +use serde_with::skip_serializing_none; use std::{collections::HashMap, path::PathBuf}; @@ -11,6 +12,7 @@ pub enum BundleTarget { One(String), } +#[skip_serializing_none] #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct DebConfig { @@ -19,6 +21,7 @@ pub struct DebConfig { pub use_bootstrapper: bool, } +#[skip_serializing_none] #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct OsxConfig { @@ -30,6 +33,7 @@ pub struct OsxConfig { pub use_bootstrapper: bool, } +#[skip_serializing_none] #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct BundleConfig { @@ -60,6 +64,7 @@ pub struct BundleConfig { } /// A CLI argument definition +#[skip_serializing_none] #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct CliArg { @@ -147,6 +152,7 @@ pub struct CliArg { } /// describes a CLI configuration +#[skip_serializing_none] #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct CliConfig { @@ -181,6 +187,7 @@ pub enum Port { } /// The embeddedServer configuration object. +#[skip_serializing_none] #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct EmbeddedServerConfig { @@ -196,6 +203,7 @@ pub struct EmbeddedServerConfig { } /// The window configuration object. +#[skip_serializing_none] #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct WindowConfig { @@ -244,6 +252,7 @@ pub struct WindowConfig { pub always_on_top: bool, } +#[skip_serializing_none] #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct SecurityConfig { @@ -477,8 +486,10 @@ impl Allowlist for AllowlistConfig { } /// The Tauri configuration object. +#[skip_serializing_none] #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] + pub struct TauriConfig { /// The windows configuration. #[serde(default)] @@ -503,6 +514,7 @@ impl TauriConfig { } /// The Build configuration object. +#[skip_serializing_none] #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct BuildConfig { @@ -532,6 +544,7 @@ fn default_dist_dir() -> String { type JsonObject = HashMap; /// The tauri.conf.json mapper. +#[skip_serializing_none] #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct Config { diff --git a/cli/core/schema.json b/cli/core/schema.json index 4941a9018..54ca78644 100644 --- a/cli/core/schema.json +++ b/cli/core/schema.json @@ -7,8 +7,6 @@ "build": { "description": "The build configuration.", "default": { - "beforeBuildCommand": null, - "beforeDevCommand": null, "devPath": "", "distDir": "../dist", "withGlobalTauri": false @@ -74,37 +72,14 @@ }, "bundle": { "active": false, - "category": null, - "copyright": null, "deb": { - "depends": null, "useBootstrapper": false }, - "externalBin": null, - "icon": null, - "identifier": null, - "longDescription": null, - "name": null, "osx": { - "exceptionDomain": null, - "frameworks": null, - "license": null, - "minimumSystemVersion": null, "useBootstrapper": false - }, - "resources": null, - "script": null, - "shortDescription": null, - "targets": null, - "version": null + } }, - "cli": null, - "embeddedServer": { - "host": null, - "port": null, - "publicPath": null - }, - "security": null, + "embeddedServer": {}, "windows": [] }, "allOf": [ @@ -273,7 +248,6 @@ }, "deb": { "default": { - "depends": null, "useBootstrapper": false }, "allOf": [ @@ -322,10 +296,6 @@ }, "osx": { "default": { - "exceptionDomain": null, - "frameworks": null, - "license": null, - "minimumSystemVersion": null, "useBootstrapper": false }, "allOf": [ @@ -936,29 +906,12 @@ "description": "The bundler configuration.", "default": { "active": false, - "category": null, - "copyright": null, "deb": { - "depends": null, "useBootstrapper": false }, - "externalBin": null, - "icon": null, - "identifier": null, - "longDescription": null, - "name": null, "osx": { - "exceptionDomain": null, - "frameworks": null, - "license": null, - "minimumSystemVersion": null, "useBootstrapper": false - }, - "resources": null, - "script": null, - "shortDescription": null, - "targets": null, - "version": null + } }, "allOf": [ { @@ -978,11 +931,7 @@ ] }, "embeddedServer": { - "default": { - "host": null, - "port": null, - "publicPath": null - }, + "default": {}, "allOf": [ { "$ref": "#/definitions/EmbeddedServerConfig"