Pārlūkot izejas kodu

feat(cli.rs): validate `distDir`, closes #2554 (#2701)

Lucas Fernandes Nogueira 3 gadi atpakaļ
vecāks
revīzija
7ed3f3b7e4

+ 5 - 0
.changes/cli.rs-validate-dist-dir.md

@@ -0,0 +1,5 @@
+---
+"cli.rs": patch
+---
+
+Print warning and exit if `distDir` contains `node_modules`, `src-tauri` or `target` folders.

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
examples/api/public/build/bundle.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
examples/api/public/build/bundle.js.map


+ 1 - 1
examples/api/src-tauri/tauri.conf.json

@@ -1,6 +1,6 @@
 {
   "build": {
-    "distDir": "../public",
+    "distDir": "../",
     "devPath": "http://localhost:5000",
     "beforeDevCommand": "yarn dev",
     "beforeBuildCommand": "yarn build"

+ 21 - 0
tooling/cli.rs/src/build.rs

@@ -114,6 +114,27 @@ impl Build {
           web_asset_path
         ));
       }
+      if web_asset_path.canonicalize()?.file_name() == Some(std::ffi::OsStr::new("src-tauri")) {
+        return Err(anyhow::anyhow!(
+            "The configured distDir is the `src-tauri` folder.
+            Please isolate your web assets on a separate folder and update `tauri.conf.json > build > distDir`.",
+          ));
+      }
+
+      let mut out_folders = Vec::new();
+      for folder in &["node_modules", "src-tauri", "target"] {
+        if web_asset_path.join(folder).is_dir() {
+          out_folders.push(folder.to_string());
+        }
+      }
+      if !out_folders.is_empty() {
+        return Err(anyhow::anyhow!(
+            "The configured distDir includes the `{:?}` {}. Please isolate your web assets on a separate folder and update `tauri.conf.json > build > distDir`.",
+            out_folders,
+            if out_folders.len() == 1 { "folder" }else { "folders" }
+          )
+        );
+      }
     }
 
     let runner_from_config = config_.build.runner.clone();

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels