diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-03-13 21:12:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 01:12:09 +0000 |
commit | 48ede89f1f192df28cc74822d7bb79b0b4bd0957 (patch) | |
tree | d6dd65cf03152fb0253aba551f7ed016e3b7b09f /cli/tools/standalone.rs | |
parent | c4771356f27b250e7fdbcede0de5682982720455 (diff) |
refactor(core): resolve_url_or_path and resolve_url_or_path_deprecated (#18170)
This commit changes current "deno_core::resolve_url_or_path" API to
"resolve_url_or_path_deprecated" and adds new "resolve_url_or_path"
API that requires to explicitly pass the directory from which paths
should be resolved to.
Some of the call sites were updated to use the new API, the reminder
of them will be updated in a follow up PR.
Towards landing https://github.com/denoland/deno/pull/15454
Diffstat (limited to 'cli/tools/standalone.rs')
-rw-r--r-- | cli/tools/standalone.rs | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/cli/tools/standalone.rs b/cli/tools/standalone.rs index 4573717a3..f0f53d417 100644 --- a/cli/tools/standalone.rs +++ b/cli/tools/standalone.rs @@ -39,11 +39,15 @@ pub async fn compile( compile_flags: CompileFlags, ) -> Result<(), AnyError> { let ps = ProcState::build(flags).await?; - let module_specifier = resolve_url_or_path(&compile_flags.source_file)?; + let module_specifier = + resolve_url_or_path(&compile_flags.source_file, ps.options.initial_cwd())?; let deno_dir = &ps.dir; - let output_path = - resolve_compile_executable_output_path(&compile_flags).await?; + let output_path = resolve_compile_executable_output_path( + &compile_flags, + ps.options.initial_cwd(), + ) + .await?; let graph = Arc::try_unwrap( create_graph_and_maybe_check(module_specifier.clone(), &ps).await?, @@ -282,8 +286,10 @@ async fn write_standalone_binary( async fn resolve_compile_executable_output_path( compile_flags: &CompileFlags, + current_dir: &Path, ) -> Result<PathBuf, AnyError> { - let module_specifier = resolve_url_or_path(&compile_flags.source_file)?; + let module_specifier = + resolve_url_or_path(&compile_flags.source_file, current_dir)?; let mut output = compile_flags.output.clone(); @@ -339,12 +345,15 @@ mod test { #[tokio::test] async fn resolve_compile_executable_output_path_target_linux() { - let path = resolve_compile_executable_output_path(&CompileFlags { - source_file: "mod.ts".to_string(), - output: Some(PathBuf::from("./file")), - args: Vec::new(), - target: Some("x86_64-unknown-linux-gnu".to_string()), - }) + let path = resolve_compile_executable_output_path( + &CompileFlags { + source_file: "mod.ts".to_string(), + output: Some(PathBuf::from("./file")), + args: Vec::new(), + target: Some("x86_64-unknown-linux-gnu".to_string()), + }, + &std::env::current_dir().unwrap(), + ) .await .unwrap(); @@ -356,12 +365,15 @@ mod test { #[tokio::test] async fn resolve_compile_executable_output_path_target_windows() { - let path = resolve_compile_executable_output_path(&CompileFlags { - source_file: "mod.ts".to_string(), - output: Some(PathBuf::from("./file")), - args: Vec::new(), - target: Some("x86_64-pc-windows-msvc".to_string()), - }) + let path = resolve_compile_executable_output_path( + &CompileFlags { + source_file: "mod.ts".to_string(), + output: Some(PathBuf::from("./file")), + args: Vec::new(), + target: Some("x86_64-pc-windows-msvc".to_string()), + }, + &std::env::current_dir().unwrap(), + ) .await .unwrap(); assert_eq!(path.file_name().unwrap(), "file.exe"); |