Skip to content

Commit

Permalink
feat(cli.rs): validate distDir, closes #2554 (#2701)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Oct 4, 2021
1 parent 9c9dead commit 7ed3f3b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/cli.rs-validate-dist-dir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cli.rs": patch
---

Print warning and exit if `distDir` contains `node_modules`, `src-tauri` or `target` folders.
4 changes: 2 additions & 2 deletions examples/api/public/build/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/api/public/build/bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/api/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"build": {
"distDir": "../public",
"distDir": "../",
"devPath": "http://localhost:5000",
"beforeDevCommand": "yarn dev",
"beforeBuildCommand": "yarn build"
Expand Down
21 changes: 21 additions & 0 deletions tooling/cli.rs/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7ed3f3b

Please sign in to comment.