summaryrefslogtreecommitdiff
path: root/cli/tools/compile.rs
diff options
context:
space:
mode:
authorƁukasz Czerniawski <33061335+lczerniawski@users.noreply.github.com>2024-03-15 00:53:46 +0100
committerGitHub <noreply@github.com>2024-03-14 23:53:46 +0000
commit5403e4f06b2bb9da60c67b7c1909f4d412c20307 (patch)
treefeffd2a905c6b01d0bf2599cd6c72d04286636f1 /cli/tools/compile.rs
parent85116226b3b5faae0aa85ce5d053487e82dcc824 (diff)
chore(cli): move away from PathBuf in clap (#22036)
Diffstat (limited to 'cli/tools/compile.rs')
-rw-r--r--cli/tools/compile.rs32
1 files changed, 17 insertions, 15 deletions
diff --git a/cli/tools/compile.rs b/cli/tools/compile.rs
index ed8f07542..2825c92c7 100644
--- a/cli/tools/compile.rs
+++ b/cli/tools/compile.rs
@@ -4,7 +4,6 @@ use crate::args::CompileFlags;
use crate::args::Flags;
use crate::factory::CliFactory;
use crate::standalone::is_standalone_binary;
-use crate::util::path::path_has_trailing_slash;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
use deno_core::error::generic_error;
@@ -174,31 +173,34 @@ async fn resolve_compile_executable_output_path(
let module_specifier =
resolve_url_or_path(&compile_flags.source_file, current_dir)?;
- let mut output = compile_flags.output.clone();
-
- if let Some(out) = output.as_ref() {
- if path_has_trailing_slash(out) {
+ let output_flag = compile_flags.output.clone();
+ let mut output_path = if let Some(out) = output_flag.as_ref() {
+ let mut out_path = PathBuf::from(out);
+ if out.ends_with('/') || out.ends_with('\\') {
if let Some(infer_file_name) = infer_name_from_url(&module_specifier)
.await
.map(PathBuf::from)
{
- output = Some(out.join(infer_file_name));
+ out_path = out_path.join(infer_file_name);
}
} else {
- output = Some(out.to_path_buf());
+ out_path = out_path.to_path_buf();
}
- }
+ Some(out_path)
+ } else {
+ None
+ };
- if output.is_none() {
- output = infer_name_from_url(&module_specifier)
+ if output_flag.is_none() {
+ output_path = infer_name_from_url(&module_specifier)
.await
.map(PathBuf::from)
}
- output.ok_or_else(|| generic_error(
+ output_path.ok_or_else(|| generic_error(
"An executable name was not provided. One could not be inferred from the URL. Aborting.",
- )).map(|output| {
- get_os_specific_filepath(output, &compile_flags.target)
+ )).map(|output_path| {
+ get_os_specific_filepath(output_path, &compile_flags.target)
})
}
@@ -231,7 +233,7 @@ mod test {
let path = resolve_compile_executable_output_path(
&CompileFlags {
source_file: "mod.ts".to_string(),
- output: Some(PathBuf::from("./file")),
+ output: Some(String::from("./file")),
args: Vec::new(),
target: Some("x86_64-unknown-linux-gnu".to_string()),
no_terminal: false,
@@ -253,7 +255,7 @@ mod test {
let path = resolve_compile_executable_output_path(
&CompileFlags {
source_file: "mod.ts".to_string(),
- output: Some(PathBuf::from("./file")),
+ output: Some(String::from("./file")),
args: Vec::new(),
target: Some("x86_64-pc-windows-msvc".to_string()),
include: vec![],