mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 15:46:51 +00:00
fix(cli/plugin/new): construct path from components iterator instead of PathBuf::join (#10128)
fixes #10082 The problem that we were calling `PathBuf::join()` with value of collecting an empty iterator of path components which was equivalent to `PathBuf::from("ios").join("")` which will result in `ios/` with a trailing slash. This is fixed by chaining iterators of path components and collecting only once into `PathBuf`, which will never append empy path component and will never append trailing slash. ```rs [ Component::Normal(OsStr::new("ios")), Component::Normal(&some_folder_name), ] .into_iter() .chain(other_components_iterator) .collect::<PathBuf>() ``` Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
1f6e478c84
commit
eb76df4c4f
@ -13,6 +13,7 @@ use clap::{Parser, ValueEnum};
|
||||
use handlebars::{to_json, Handlebars};
|
||||
use heck::{ToKebabCase, ToPascalCase, ToSnakeCase};
|
||||
use include_dir::{include_dir, Dir};
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
env::current_dir,
|
||||
@ -211,12 +212,16 @@ pub fn command(mut options: Options) -> Result<()> {
|
||||
"ios-xcode" if !matches!(ios_framework, IosFrameworkKind::Xcode) => return Ok(None),
|
||||
"ios-spm" | "ios-xcode" => {
|
||||
let folder_name = components.next().unwrap().as_os_str().to_string_lossy();
|
||||
let new_folder_name = folder_name.replace("{{ plugin_name }}", &plugin_name);
|
||||
let new_folder_name = OsString::from(&new_folder_name);
|
||||
|
||||
path = Path::new("ios")
|
||||
.join(Component::Normal(&std::ffi::OsString::from(
|
||||
&folder_name.replace("{{ plugin_name }}", &plugin_name),
|
||||
)))
|
||||
.join(components.collect::<PathBuf>());
|
||||
path = [
|
||||
Component::Normal(OsStr::new("ios")),
|
||||
Component::Normal(&new_folder_name),
|
||||
]
|
||||
.into_iter()
|
||||
.chain(components)
|
||||
.collect::<PathBuf>();
|
||||
}
|
||||
"guest-js" | "rollup.config.js" | "tsconfig.json" | "package.json"
|
||||
if options.no_api =>
|
||||
@ -236,7 +241,7 @@ pub fn command(mut options: Options) -> Result<()> {
|
||||
File::create(path).map(Some)
|
||||
},
|
||||
)
|
||||
.with_context(|| "failed to render plugin Android template")?;
|
||||
.with_context(|| "failed to render plugin template")?;
|
||||
}
|
||||
|
||||
let permissions_dir = template_target_path.join("permissions");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user