Browse Source

fix(build): do not rewrite unchanged schema (#8757)

* fix(build): do not rewrite unchanged schema

* typo
Lucas Fernandes Nogueira 1 năm trước cách đây
mục cha
commit
0f2789cd67

+ 5 - 0
.changes/fix-rewrite-schema.md

@@ -0,0 +1,5 @@
+---
+"tauri-build": patch:bug
+---
+
+Do not rewrite capability JSON schema if it did not change.

+ 16 - 16
core/tauri-build/src/acl.rs

@@ -4,8 +4,7 @@
 
 use std::{
   collections::{BTreeMap, BTreeSet},
-  fs::{copy, create_dir_all, read_to_string, File},
-  io::{BufWriter, Write},
+  fs::{copy, create_dir_all, read_to_string, write},
   path::PathBuf,
 };
 
@@ -181,20 +180,21 @@ pub fn generate_schema(
   create_dir_all(&out_dir).context("unable to create schema output directory")?;
 
   let schema_path = out_dir.join(format!("{target}-{CAPABILITIES_SCHEMA_FILE_NAME}"));
-  let mut schema_file = BufWriter::new(File::create(&schema_path)?);
-  write!(schema_file, "{schema_str}")?;
-
-  copy(
-    schema_path,
-    out_dir.join(format!(
-      "{}-{CAPABILITIES_SCHEMA_FILE_NAME}",
-      if target.is_desktop() {
-        "desktop"
-      } else {
-        "mobile"
-      }
-    )),
-  )?;
+  if schema_str != read_to_string(&schema_path).unwrap_or_default() {
+    write(&schema_path, "{schema_str}")?;
+
+    copy(
+      schema_path,
+      out_dir.join(format!(
+        "{}-{CAPABILITIES_SCHEMA_FILE_NAME}",
+        if target.is_desktop() {
+          "desktop"
+        } else {
+          "mobile"
+        }
+      )),
+    )?;
+  }
 
   Ok(())
 }

+ 1 - 1
core/tauri-utils/src/acl/capability.rs

@@ -56,7 +56,7 @@ pub struct Capability {
   pub description: String,
   /// Execution context of the capability.
   ///
-  /// At runtime, Tauri filters the IPC command together with the context to determine wheter it is allowed or not and its scope.
+  /// At runtime, Tauri filters the IPC command together with the context to determine whether it is allowed or not and its scope.
   #[serde(default)]
   pub context: CapabilityContext,
   /// List of windows that uses this capability. Can be a glob pattern.

+ 1 - 1
examples/api/src-tauri/Cargo.lock

@@ -3677,7 +3677,7 @@ checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae"
 
 [[package]]
 name = "tauri"
-version = "2.0.0-beta.0"
+version = "2.0.0-beta.1"
 dependencies = [
  "anyhow",
  "bytes",