Repository: tauri-apps/tauri
File: crates/tauri-cli/src/build.rs (Rust)

Code before:
  }

  if let Some(FrontendDist::Directory(web_asset_path)) = &config_.build.frontend_dist {
    if !web_asset_path.exists() {
      let absolute_path = web_asset_path
        .parent()
        .and_then(|p| p.canonicalize().ok())
        .map(|p| p.join(web_asset_path.file_name().unwrap()))
        .unwrap_or_else(|| std::env::current_dir().unwrap().join(web_asset_path));
      return Err(anyhow::anyhow!(
          "Unable to find your web assets, did you forget to build your web app? Your frontendDist is set to \"{}\" (which is `{}`).",
          web_asset_path.display(), absolute_path.display(),
        ));
    }
    if web_asset_path.canonicalize()?.file_name() == Some(std::ffi::OsStr::new("src-tauri")) {
      return Err(anyhow::anyhow!(
          "The configured frontendDist is the `src-tauri` folder. Please isolate your web assets on a separate folder and update `tauri.conf.json > build > frontendDist`.",
        ));
    }

    // Issue #13287 - Allow the use of target dir inside frontendDist/distDir
    // https://github.com/tauri-apps/tauri/issues/13287
    let target_path = fs::canonicalize(get_cargo_target_dir(&options.args)?)?;
    let mut out_folders = Vec::new();
    if let Ok(web_asset_canonical) = web_asset_path.canonicalize() {
      if target_path.starts_with(&web_asset_canonical) {
        if let Ok(relative_path) = target_path.strip_prefix(web_asset_path) {
          let relative_str = relative_path.to_string_lossy();
          if !relative_str.is_empty() {
            out_folders.push(relative_str.to_string());
          }
        }
      }

      for folder in &["node_modules", "src-tauri"] {
        let sub_path = web_asset_path.join(folder);
        if sub_path.is_dir() {
          out_folders.push(folder.to_string());
        }
      }
    }

    if !out_folders.is_empty() {
      return Err(anyhow::anyhow!(
        "The configured frontendDist includes the `{:?}` {}. Please isolate your web assets on a separate folder and update `tauri.conf.json > build > frontendDist`.",
        out_folders,
        if out_folders.len() == 1 { "folder" } else { "folders" }
      ));
    }
  }


Review comment (suggestion):
sorry, forgot that in the first review. the outer `if target_path.starts_with(&web_asset_canonical) {` can be removed since strip_prefix already includes that check as well.

Code after:
  }

  if let Some(FrontendDist::Directory(web_asset_path)) = &config_.build.frontend_dist {
    if !web_asset_path.exists() {
      let absolute_path = web_asset_path
        .parent()
        .and_then(|p| p.canonicalize().ok())
        .map(|p| p.join(web_asset_path.file_name().unwrap()))
        .unwrap_or_else(|| std::env::current_dir().unwrap().join(web_asset_path));
      return Err(anyhow::anyhow!(
          "Unable to find your web assets, did you forget to build your web app? Your frontendDist is set to \"{}\" (which is `{}`).",
          web_asset_path.display(), absolute_path.display(),
        ));
    }
    if web_asset_path.canonicalize()?.file_name() == Some(std::ffi::OsStr::new("src-tauri")) {
      return Err(anyhow::anyhow!(
          "The configured frontendDist is the `src-tauri` folder. Please isolate your web assets on a separate folder and update `tauri.conf.json > build > frontendDist`.",
        ));
    }

    // Issue #13287 - Allow the use of target dir inside frontendDist/distDir
    // https://github.com/tauri-apps/tauri/issues/13287
    let target_path = fs::canonicalize(get_cargo_target_dir(&options.args)?)?;
    let mut out_folders = Vec::new();
    if let Ok(web_asset_canonical) = web_asset_path.canonicalize() {
      if let Ok(relative_path) = target_path.strip_prefix(&web_asset_canonical) {
        let relative_str = relative_path.to_string_lossy();
        if !relative_str.is_empty() {
          out_folders.push(relative_str.to_string());
        }
      }

      for folder in &["node_modules", "src-tauri"] {
        let sub_path = web_asset_canonical.join(folder);
        if sub_path.is_dir() {
          out_folders.push(folder.to_string());
        }
      }
    }

    if !out_folders.is_empty() {
      return Err(anyhow::anyhow!(
        "The configured frontendDist includes the `{:?}` {}. Please isolate your web assets on a separate folder and update `tauri.conf.json > build > frontendDist`.",
        out_folders,
        if out_folders.len() == 1 { "folder" } else { "folders" }
      ));
    }
  }

  if options.runner.is_none() {
    options.runner.clone_from(&config_.build.runner);