diff options
Diffstat (limited to 'cli/installer.rs')
-rw-r--r-- | cli/installer.rs | 82 |
1 files changed, 56 insertions, 26 deletions
diff --git a/cli/installer.rs b/cli/installer.rs index e017ad16b..120facaf1 100644 --- a/cli/installer.rs +++ b/cli/installer.rs @@ -81,17 +81,6 @@ deno {} "$@" Ok(()) } -fn generate_config_file( - file_path: PathBuf, - config_file_name: String, -) -> Result<(), io::Error> { - let config_file_copy_path = get_config_file_path(&file_path); - let cwd = std::env::current_dir().unwrap(); - let config_file_path = cwd.join(config_file_name); - fs::copy(config_file_path, config_file_copy_path)?; - Ok(()) -} - fn get_installer_root() -> Result<PathBuf, io::Error> { if let Ok(env_dir) = env::var("DENO_INSTALL_ROOT") { if !env_dir.is_empty() { @@ -189,6 +178,8 @@ pub fn install( )); }; + let mut extra_files: Vec<(PathBuf, String)> = vec![]; + let mut executable_args = vec!["run".to_string()]; executable_args.extend_from_slice(&flags.to_permission_args()); if let Some(ca_file) = flags.ca_file { @@ -219,21 +210,65 @@ pub fn install( executable_args.push("--unstable".to_string()); } - if flags.config_path.is_some() { - let config_file_path = get_config_file_path(&file_path); - let config_file_path_option = config_file_path.to_str(); - if let Some(config_file_path_string) = config_file_path_option { - executable_args.push("--config".to_string()); - executable_args.push(config_file_path_string.to_string()); - } + if flags.no_remote { + executable_args.push("--no-remote".to_string()); + } + + if flags.lock_write { + executable_args.push("--lock-write".to_string()); + } + + if flags.cached_only { + executable_args.push("--cached_only".to_string()); + } + + if let Some(v8_flags) = flags.v8_flags { + executable_args.push(format!("--v8-flags={}", v8_flags.join(","))); + } + + if let Some(seed) = flags.seed { + executable_args.push("--seed".to_string()); + executable_args.push(seed.to_string()); + } + + if let Some(inspect) = flags.inspect { + executable_args.push(format!("--inspect={}", inspect.to_string())); + } + + if let Some(inspect_brk) = flags.inspect_brk { + executable_args.push(format!("--inspect-brk={}", inspect_brk.to_string())); + } + + if let Some(import_map_path) = flags.import_map_path { + let mut copy_path = file_path.clone(); + copy_path.set_extension("import_map.json"); + executable_args.push("--importmap".to_string()); + executable_args.push(copy_path.to_str().unwrap().to_string()); + extra_files.push((copy_path, fs::read_to_string(import_map_path)?)); + } + + if let Some(config_path) = flags.config_path { + let mut copy_path = file_path.clone(); + copy_path.set_extension("tsconfig.json"); + executable_args.push("--config".to_string()); + executable_args.push(copy_path.to_str().unwrap().to_string()); + extra_files.push((copy_path, fs::read_to_string(config_path)?)); + } + + if let Some(lock_path) = flags.lock { + let mut copy_path = file_path.clone(); + copy_path.set_extension("lock.json"); + executable_args.push("--lock".to_string()); + executable_args.push(copy_path.to_str().unwrap().to_string()); + extra_files.push((copy_path, fs::read_to_string(lock_path)?)); } executable_args.push(module_url.to_string()); executable_args.extend_from_slice(&args); generate_executable_file(file_path.to_owned(), executable_args)?; - if let Some(config_path) = flags.config_path { - generate_config_file(file_path.to_owned(), config_path)?; + for (path, contents) in extra_files { + fs::write(path, contents)?; } println!("✅ Successfully installed {}", name); @@ -263,12 +298,6 @@ fn is_in_path(dir: &PathBuf) -> bool { false } -fn get_config_file_path(file_path: &PathBuf) -> PathBuf { - let mut config_file_copy_path = PathBuf::from(file_path); - config_file_copy_path.set_extension("tsconfig.json"); - config_file_copy_path -} - #[cfg(test)] mod tests { use super::*; @@ -588,6 +617,7 @@ mod tests { assert!(file_path.exists()); let content = fs::read_to_string(file_path).unwrap(); + dbg!(&content); assert!(content.contains(r#""run" "--allow-read" "--allow-net" "--quiet" "--no-check" "http://localhost:4545/cli/tests/echo_server.ts" "--foobar""#)); } |