浏览代码

refactor(cli): disable api-all on templates (#5538)

Lucas Fernandes Nogueira 2 年之前
父节点
当前提交
582c25a0f0

+ 6 - 0
.changes/templates-allowlist-false.md

@@ -0,0 +1,6 @@
+---
+"cli.rs": patch
+"cli.js": patch
+---
+
+Changed the project template to not enable all APIs by default.

+ 1 - 2
tooling/cli/src/build.rs

@@ -63,8 +63,7 @@ pub fn command(mut options: Options) -> Result<()> {
     } else {
       (
         Some(
-          std::fs::read_to_string(&config)
-            .with_context(|| "failed to read custom configuration")?,
+          std::fs::read_to_string(config).with_context(|| "failed to read custom configuration")?,
         ),
         Some(config.clone()),
       )

+ 1 - 1
tooling/cli/src/dev.rs

@@ -79,7 +79,7 @@ fn command_internal(mut options: Options) -> Result<()> {
     Some(if config.starts_with('{') {
       config.to_string()
     } else {
-      std::fs::read_to_string(&config).with_context(|| "failed to read custom configuration")?
+      std::fs::read_to_string(config).with_context(|| "failed to read custom configuration")?
     })
   } else {
     None

+ 4 - 4
tooling/cli/src/helpers/updater_signature.rs

@@ -22,7 +22,7 @@ pub struct KeyPair {
 
 fn create_file(path: &Path) -> crate::Result<BufWriter<File>> {
   if let Some(parent) = path.parent() {
-    fs::create_dir_all(&parent)?;
+    fs::create_dir_all(parent)?;
   }
   let file = File::create(path)?;
   Ok(BufWriter::new(file))
@@ -72,12 +72,12 @@ where
         sk_path.display()
       ));
     } else {
-      std::fs::remove_file(&sk_path)?;
+      std::fs::remove_file(sk_path)?;
     }
   }
 
   if pk_path.exists() {
-    std::fs::remove_file(&pk_path)?;
+    std::fs::remove_file(pk_path)?;
   }
 
   let mut sk_writer = create_file(sk_path)?;
@@ -88,7 +88,7 @@ where
   write!(pk_writer, "{:}", pubkey)?;
   pk_writer.flush()?;
 
-  Ok((fs::canonicalize(&sk_path)?, fs::canonicalize(&pk_path)?))
+  Ok((fs::canonicalize(sk_path)?, fs::canonicalize(pk_path)?))
 }
 
 /// Read key from file

+ 1 - 1
tooling/cli/src/helpers/web_dev_server.rs

@@ -96,7 +96,7 @@ async fn handler<T>(req: Request<T>, state: Arc<State>) -> impl IntoResponse {
     uri.strip_prefix('/').unwrap_or(&uri)
   };
 
-  let file = std::fs::read(state.serve_dir.join(&uri))
+  let file = std::fs::read(state.serve_dir.join(uri))
     .or_else(|_| std::fs::read(state.serve_dir.join(format!("{}.html", &uri))))
     .or_else(|_| std::fs::read(state.serve_dir.join(format!("{}/index.html", &uri))))
     .or_else(|_| std::fs::read(state.serve_dir.join("index.html")));

+ 7 - 12
tooling/cli/src/info.rs

@@ -159,7 +159,7 @@ fn npm_latest_version(pm: &PackageManager, name: &str) -> crate::Result<Option<S
       let output = cmd
         .arg("info")
         .arg(name)
-        .args(&["version", "--json"])
+        .args(["version", "--json"])
         .output()?;
       if output.status.success() {
         let stdout = String::from_utf8_lossy(&output.stdout);
@@ -219,9 +219,9 @@ fn npm_package_version<P: AsRef<Path>>(
   let (output, regex) = match pm {
     PackageManager::Yarn => (
       cross_command("yarn")
-        .args(&["list", "--pattern"])
+        .args(["list", "--pattern"])
         .arg(name)
-        .args(&["--depth", "0"])
+        .args(["--depth", "0"])
         .current_dir(app_dir)
         .output()?,
       None,
@@ -238,7 +238,7 @@ fn npm_package_version<P: AsRef<Path>>(
       cross_command("npm")
         .arg("list")
         .arg(name)
-        .args(&["version", "--depth", "0"])
+        .args(["version", "--depth", "0"])
         .current_dir(app_dir)
         .output()?,
       None,
@@ -247,7 +247,7 @@ fn npm_package_version<P: AsRef<Path>>(
       cross_command("pnpm")
         .arg("list")
         .arg(name)
-        .args(&["--parseable", "--depth", "0"])
+        .args(["--parseable", "--depth", "0"])
         .current_dir(app_dir)
         .output()?,
       None,
@@ -273,11 +273,7 @@ fn get_version(command: &str, args: &[&str]) -> crate::Result<Option<String>> {
     .arg("--version")
     .output()?;
   let version = if output.status.success() {
-    Some(
-      String::from_utf8_lossy(&output.stdout)
-        .replace('\n', "")
-        .replace('\r', ""),
-    )
+    Some(String::from_utf8_lossy(&output.stdout).replace(['\n', '\r'], ""))
   } else {
     None
   };
@@ -380,8 +376,7 @@ fn active_rust_toolchain() -> crate::Result<Option<String>> {
   let toolchain = if output.status.success() {
     Some(
       String::from_utf8_lossy(&output.stdout)
-        .replace('\n', "")
-        .replace('\r', "")
+        .replace(['\n', '\r'], "")
         .split('(')
         .collect::<Vec<&str>>()[0]
         .into(),

+ 2 - 5
tooling/cli/src/init.rs

@@ -167,7 +167,7 @@ pub fn command(mut options: Options) -> Result<()> {
     let (tauri_dep, tauri_build_dep) = if let Some(tauri_path) = options.tauri_path {
       (
         format!(
-          r#"{{  path = {:?}, features = [ "api-all" ] }}"#,
+          r#"{{  path = {:?} }}"#,
           resolve_tauri_path(&tauri_path, "core/tauri")
         ),
         format!(
@@ -177,10 +177,7 @@ pub fn command(mut options: Options) -> Result<()> {
       )
     } else {
       (
-        format!(
-          r#"{{ version = "{}", features = [ "api-all" ] }}"#,
-          metadata.tauri
-        ),
+        format!(r#"{{ version = "{}" }}"#, metadata.tauri),
         format!(r#"{{ version = "{}" }}"#, metadata.tauri_build),
       )
     };

+ 3 - 3
tooling/cli/src/interface/rust.rs

@@ -476,7 +476,7 @@ impl Rust {
               info!(
                 "File {} changed. Rebuilding application...",
                 event_path
-                  .strip_prefix(&app_path)
+                  .strip_prefix(app_path)
                   .unwrap_or(&event_path)
                   .display()
               );
@@ -626,7 +626,7 @@ impl AppSettings for RustAppSettings {
         .package_settings
         .default_run
         .clone()
-        .unwrap_or_else(|| "".to_string());
+        .unwrap_or_default();
       for binary in bin {
         binaries.push(
           if Some(&binary.name) == self.cargo_package_settings.name.as_ref()
@@ -759,7 +759,7 @@ impl RustAppSettings {
         .target()
         .map(|t| t.to_string())
         .unwrap_or_else(|| {
-          let output = Command::new("rustc").args(&["-vV"]).output().unwrap();
+          let output = Command::new("rustc").args(["-vV"]).output().unwrap();
           let stdout = String::from_utf8_lossy(&output.stdout);
           stdout
             .split('\n')

+ 4 - 4
tooling/cli/src/interface/rust/desktop.rs

@@ -96,13 +96,13 @@ pub fn build(
   }
 
   if options.target == Some("universal-apple-darwin".into()) {
-    std::fs::create_dir_all(&out_dir).with_context(|| "failed to create project out directory")?;
+    std::fs::create_dir_all(out_dir).with_context(|| "failed to create project out directory")?;
 
     let mut lipo_cmd = Command::new("lipo");
     lipo_cmd
       .arg("-create")
       .arg("-output")
-      .arg(out_dir.join(&bin_name));
+      .arg(out_dir.join(bin_name));
     for triple in ["aarch64-apple-darwin", "x86_64-apple-darwin"] {
       let mut options = options.clone();
       options.target.replace(triple.into());
@@ -114,7 +114,7 @@ pub fn build(
       build_production_app(options, available_targets, config_features.clone())
         .with_context(|| format!("failed to build {} binary", triple))?;
 
-      lipo_cmd.arg(triple_out_dir.join(&bin_name));
+      lipo_cmd.arg(triple_out_dir.join(bin_name));
     }
 
     let lipo_status = lipo_cmd.output_ok()?.status;
@@ -344,7 +344,7 @@ fn rename_app(bin_path: &Path, product_name: Option<&str>) -> crate::Result<Path
       .join(&product_name)
       .with_extension(bin_path.extension().unwrap_or_default());
 
-    rename(&bin_path, &product_path).with_context(|| {
+    rename(bin_path, &product_path).with_context(|| {
       format!(
         "failed to rename `{}` to `{}`",
         bin_path.display(),

+ 1 - 4
tooling/cli/src/interface/rust/manifest.rs

@@ -164,10 +164,7 @@ fn write_features(
       }
       Value::String(version) => {
         let mut def = InlineTable::default();
-        def.get_or_insert(
-          "version",
-          version.to_string().replace('\"', "").replace(' ', ""),
-        );
+        def.get_or_insert("version", version.to_string().replace(['\"', ' '], ""));
         def.get_or_insert("features", Value::Array(toml_array(features)));
         *dep = Value::InlineTable(def);
       }

+ 2 - 5
tooling/cli/src/plugin/init.rs

@@ -72,7 +72,7 @@ pub fn command(mut options: Options) -> Result<()> {
             resolve_tauri_path(&tauri_path, "core/tauri")
           ),
           format!(
-            r#"{{  path = {:?}, features = [ "api-all" ] }}"#,
+            r#"{{  path = {:?} }}"#,
             resolve_tauri_path(&tauri_path, "core/tauri")
           ),
           format!(
@@ -83,10 +83,7 @@ pub fn command(mut options: Options) -> Result<()> {
       } else {
         (
           format!(r#"{{ version = "{}" }}"#, metadata.tauri),
-          format!(
-            r#"{{ version = "{}", features = [ "api-all" ] }}"#,
-            metadata.tauri
-          ),
+          format!(r#"{{ version = "{}" }}"#, metadata.tauri),
           format!(r#"{{ version = "{}" }}"#, metadata.tauri_build),
         )
       };

+ 1 - 1
tooling/cli/templates/plugin/backend/examples/vanilla/src-tauri/tauri.conf.json

@@ -44,7 +44,7 @@
       "active": false
     },
     "allowlist": {
-      "all": true
+      "all": false
     },
     "windows": [
       {

+ 1 - 1
tooling/cli/templates/plugin/with-api/examples/svelte-app/src-tauri/tauri.conf.json

@@ -32,7 +32,7 @@
       }
     },
     "allowlist": {
-      "all": true
+      "all": false
     },
     "windows": [
       {

+ 1 - 1
tooling/cli/templates/tauri.conf.json

@@ -47,7 +47,7 @@
       "active": false
     },
     "allowlist": {
-      "all": true
+      "all": false
     },
     "windows": [
       {