Skip to content

Commit 7ed3f3b

Browse files
authored
feat(cli.rs): validate distDir, closes #2554 (#2701)
1 parent 9c9dead commit 7ed3f3b

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": patch
3+
---
4+
5+
Print warning and exit if `distDir` contains `node_modules`, `src-tauri` or `target` folders.

examples/api/public/build/bundle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/public/build/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"build": {
3-
"distDir": "../public",
3+
"distDir": "../",
44
"devPath": "http://localhost:5000",
55
"beforeDevCommand": "yarn dev",
66
"beforeBuildCommand": "yarn build"

tooling/cli.rs/src/build.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,27 @@ impl Build {
114114
web_asset_path
115115
));
116116
}
117+
if web_asset_path.canonicalize()?.file_name() == Some(std::ffi::OsStr::new("src-tauri")) {
118+
return Err(anyhow::anyhow!(
119+
"The configured distDir is the `src-tauri` folder.
120+
Please isolate your web assets on a separate folder and update `tauri.conf.json > build > distDir`.",
121+
));
122+
}
123+
124+
let mut out_folders = Vec::new();
125+
for folder in &["node_modules", "src-tauri", "target"] {
126+
if web_asset_path.join(folder).is_dir() {
127+
out_folders.push(folder.to_string());
128+
}
129+
}
130+
if !out_folders.is_empty() {
131+
return Err(anyhow::anyhow!(
132+
"The configured distDir includes the `{:?}` {}. Please isolate your web assets on a separate folder and update `tauri.conf.json > build > distDir`.",
133+
out_folders,
134+
if out_folders.len() == 1 { "folder" }else { "folders" }
135+
)
136+
);
137+
}
117138
}
118139

119140
let runner_from_config = config_.build.runner.clone();

0 commit comments

Comments
 (0)