summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/installer.rs211
-rw-r--r--cli/tools/test.rs10
-rw-r--r--cli/tools/upgrade.rs41
3 files changed, 144 insertions, 118 deletions
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs
index c32423f71..4fbc03c0f 100644
--- a/cli/tools/installer.rs
+++ b/cli/tools/installer.rs
@@ -2,6 +2,7 @@
use crate::flags::CheckFlag;
use crate::flags::Flags;
+use crate::flags::InstallFlags;
use crate::fs_util::canonicalize_path;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
@@ -192,13 +193,9 @@ pub fn uninstall(name: String, root: Option<PathBuf>) -> Result<(), AnyError> {
pub fn install(
flags: Flags,
- module_url: &str,
- args: Vec<String>,
- name: Option<String>,
- root: Option<PathBuf>,
- force: bool,
+ install_flags: InstallFlags,
) -> Result<(), AnyError> {
- let root = if let Some(root) = root {
+ let root = if let Some(root) = install_flags.root {
canonicalize_path(&root)?
} else {
get_installer_root()?
@@ -215,9 +212,11 @@ pub fn install(
};
// Check if module_url is remote
- let module_url = resolve_url_or_path(module_url)?;
+ let module_url = resolve_url_or_path(&install_flags.module_url)?;
- let name = name.or_else(|| infer_name_from_url(&module_url));
+ let name = install_flags
+ .name
+ .or_else(|| infer_name_from_url(&module_url));
let name = match name {
Some(name) => name,
@@ -233,7 +232,7 @@ pub fn install(
file_path = file_path.with_extension("cmd");
}
- if file_path.exists() && !force {
+ if file_path.exists() && !install_flags.force {
return Err(generic_error(
"Existing installation found. Aborting (Use -f to overwrite).",
));
@@ -331,7 +330,7 @@ pub fn install(
}
executable_args.push(module_url.to_string());
- executable_args.extend_from_slice(&args);
+ executable_args.extend_from_slice(&install_flags.args);
generate_executable_file(file_path.to_owned(), executable_args)?;
for (path, contents) in extra_files {
@@ -471,11 +470,13 @@ mod tests {
install(
Flags::default(),
- "http://localhost:4545/echo_server.ts",
- vec![],
- Some("echo_test".to_string()),
- None,
- false,
+ InstallFlags {
+ module_url: "http://localhost:4545/echo_server.ts".to_string(),
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: None,
+ force: false,
+ },
)
.expect("Install failed");
@@ -519,11 +520,13 @@ mod tests {
unstable: true,
..Flags::default()
},
- "http://localhost:4545/echo_server.ts",
- vec![],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- false,
+ InstallFlags {
+ module_url: "http://localhost:4545/echo_server.ts".to_string(),
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: false,
+ },
)
.expect("Install failed");
@@ -554,11 +557,13 @@ mod tests {
install(
Flags::default(),
- "http://localhost:4545/echo_server.ts",
- vec![],
- None,
- Some(temp_dir.path().to_path_buf()),
- false,
+ InstallFlags {
+ module_url: "http://localhost:4545/echo_server.ts".to_string(),
+ args: vec![],
+ name: None,
+ root: Some(temp_dir.path().to_path_buf()),
+ force: false,
+ },
)
.expect("Install failed");
@@ -586,11 +591,13 @@ mod tests {
install(
Flags::default(),
- "http://localhost:4545/subdir/main.ts",
- vec![],
- None,
- Some(temp_dir.path().to_path_buf()),
- false,
+ InstallFlags {
+ module_url: "http://localhost:4545/subdir/main.ts".to_string(),
+ args: vec![],
+ name: None,
+ root: Some(temp_dir.path().to_path_buf()),
+ force: false,
+ },
)
.expect("Install failed");
@@ -618,11 +625,13 @@ mod tests {
install(
Flags::default(),
- "http://localhost:4545/echo_server.ts",
- vec![],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- false,
+ InstallFlags {
+ module_url: "http://localhost:4545/echo_server.ts".to_string(),
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: false,
+ },
)
.expect("Install failed");
@@ -653,11 +662,13 @@ mod tests {
install(
Flags::default(),
- "http://localhost:4545/echo_server.ts",
- vec![],
- Some("echo_test".to_string()),
- None,
- false,
+ InstallFlags {
+ module_url: "http://localhost:4545/echo_server.ts".to_string(),
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: None,
+ force: false,
+ },
)
.expect("Install failed");
@@ -694,11 +705,13 @@ mod tests {
log_level: Some(Level::Error),
..Flags::default()
},
- "http://localhost:4545/echo_server.ts",
- vec!["--foobar".to_string()],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- false,
+ InstallFlags {
+ module_url: "http://localhost:4545/echo_server.ts".to_string(),
+ args: vec!["--foobar".to_string()],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: false,
+ },
)
.expect("Install failed");
@@ -727,11 +740,13 @@ mod tests {
install(
Flags::default(),
- &local_module_str,
- vec![],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- false,
+ InstallFlags {
+ module_url: local_module_str.to_string(),
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: false,
+ },
)
.expect("Install failed");
@@ -753,11 +768,13 @@ mod tests {
install(
Flags::default(),
- "http://localhost:4545/echo_server.ts",
- vec![],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- false,
+ InstallFlags {
+ module_url: "http://localhost:4545/echo_server.ts".to_string(),
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: false,
+ },
)
.expect("Install failed");
@@ -770,11 +787,13 @@ mod tests {
// No force. Install failed.
let no_force_result = install(
Flags::default(),
- "http://localhost:4545/cat.ts", // using a different URL
- vec![],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- false,
+ InstallFlags {
+ module_url: "http://localhost:4545/cat.ts".to_string(), // using a different URL
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: false,
+ },
);
assert!(no_force_result.is_err());
assert!(no_force_result
@@ -788,11 +807,13 @@ mod tests {
// Force. Install success.
let force_result = install(
Flags::default(),
- "http://localhost:4545/cat.ts", // using a different URL
- vec![],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- true,
+ InstallFlags {
+ module_url: "http://localhost:4545/cat.ts".to_string(), // using a different URL
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: true,
+ },
);
assert!(force_result.is_ok());
// Assert modified
@@ -815,11 +836,13 @@ mod tests {
config_path: Some(config_file_path.to_string_lossy().to_string()),
..Flags::default()
},
- "http://localhost:4545/cat.ts",
- vec![],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- true,
+ InstallFlags {
+ module_url: "http://localhost:4545/cat.ts".to_string(),
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: true,
+ },
);
eprintln!("result {:?}", result);
assert!(result.is_ok());
@@ -842,11 +865,13 @@ mod tests {
install(
Flags::default(),
- "http://localhost:4545/echo_server.ts",
- vec!["\"".to_string()],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- false,
+ InstallFlags {
+ module_url: "http://localhost:4545/echo_server.ts".to_string(),
+ args: vec!["\"".to_string()],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: false,
+ },
)
.expect("Install failed");
@@ -883,11 +908,13 @@ mod tests {
install(
Flags::default(),
- &local_module_str,
- vec![],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- false,
+ InstallFlags {
+ module_url: local_module_str.to_string(),
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: false,
+ },
)
.expect("Install failed");
@@ -917,11 +944,13 @@ mod tests {
import_map_path: Some(import_map_path.to_string_lossy().to_string()),
..Flags::default()
},
- "http://localhost:4545/cat.ts",
- vec![],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- true,
+ InstallFlags {
+ module_url: "http://localhost:4545/cat.ts".to_string(),
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: true,
+ },
);
assert!(result.is_ok());
@@ -958,11 +987,13 @@ mod tests {
let result = install(
Flags::default(),
- &file_module_string,
- vec![],
- Some("echo_test".to_string()),
- Some(temp_dir.path().to_path_buf()),
- true,
+ InstallFlags {
+ module_url: file_module_string.to_string(),
+ args: vec![],
+ name: Some("echo_test".to_string()),
+ root: Some(temp_dir.path().to_path_buf()),
+ force: true,
+ },
);
assert!(result.is_ok());
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index 2e5c8b503..959cefcc1 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -487,10 +487,7 @@ async fn test_specifier(
worker.execute_side_module(&specifier).await?;
}
- worker.js_runtime.execute_script(
- &located_script_name!(),
- "window.dispatchEvent(new Event('load'));",
- )?;
+ worker.dispatch_load_event(&located_script_name!())?;
let test_result = worker.js_runtime.execute_script(
&located_script_name!(),
@@ -505,10 +502,7 @@ async fn test_specifier(
worker.js_runtime.resolve_value(test_result).await?;
- worker.js_runtime.execute_script(
- &located_script_name!(),
- "window.dispatchEvent(new Event('unload'));",
- )?;
+ worker.dispatch_unload_event(&located_script_name!())?;
if let Some(coverage_collector) = maybe_coverage_collector.as_mut() {
worker
diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs
index b0fddc39c..49c8d7423 100644
--- a/cli/tools/upgrade.rs
+++ b/cli/tools/upgrade.rs
@@ -2,6 +2,7 @@
//! This module provides feature to upgrade deno executable
+use crate::flags::UpgradeFlags;
use deno_core::anyhow::bail;
use deno_core::error::AnyError;
use deno_core::futures::StreamExt;
@@ -21,18 +22,11 @@ static ARCHIVE_NAME: Lazy<String> =
const RELEASE_URL: &str = "https://github.com/denoland/deno/releases";
-pub async fn upgrade_command(
- dry_run: bool,
- force: bool,
- canary: bool,
- version: Option<String>,
- output: Option<PathBuf>,
- ca_file: Option<String>,
-) -> Result<(), AnyError> {
+pub async fn upgrade(upgrade_flags: UpgradeFlags) -> Result<(), AnyError> {
let mut client_builder = Client::builder();
// If we have been provided a CA Certificate, add it into the HTTP client
- if let Some(ca_file) = ca_file {
+ if let Some(ca_file) = upgrade_flags.ca_file {
let buf = std::fs::read(ca_file)?;
let cert = reqwest::Certificate::from_pem(&buf)?;
client_builder = client_builder.add_root_certificate(cert);
@@ -40,17 +34,18 @@ pub async fn upgrade_command(
let client = client_builder.build()?;
- let install_version = match version {
+ let install_version = match upgrade_flags.version {
Some(passed_version) => {
- if canary
+ if upgrade_flags.canary
&& !regex::Regex::new("^[0-9a-f]{40}$")?.is_match(&passed_version)
{
bail!("Invalid commit hash passed");
- } else if !canary && semver_parse(&passed_version).is_err() {
+ } else if !upgrade_flags.canary && semver_parse(&passed_version).is_err()
+ {
bail!("Invalid semver passed");
}
- let current_is_passed = if canary {
+ let current_is_passed = if upgrade_flags.canary {
crate::version::GIT_COMMIT_HASH == passed_version
} else if !crate::version::is_canary() {
crate::version::deno() == passed_version
@@ -58,7 +53,10 @@ pub async fn upgrade_command(
false
};
- if !force && output.is_none() && current_is_passed {
+ if !upgrade_flags.force
+ && upgrade_flags.output.is_none()
+ && current_is_passed
+ {
println!("Version {} is already installed", crate::version::deno());
return Ok(());
} else {
@@ -66,13 +64,13 @@ pub async fn upgrade_command(
}
}
None => {
- let latest_version = if canary {
+ let latest_version = if upgrade_flags.canary {
get_latest_canary_version(&client).await?
} else {
get_latest_release_version(&client).await?
};
- let current_is_most_recent = if canary {
+ let current_is_most_recent = if upgrade_flags.canary {
let mut latest_hash = latest_version.clone();
latest_hash.truncate(7);
crate::version::GIT_COMMIT_HASH == latest_hash
@@ -84,7 +82,10 @@ pub async fn upgrade_command(
false
};
- if !force && output.is_none() && current_is_most_recent {
+ if !upgrade_flags.force
+ && upgrade_flags.output.is_none()
+ && current_is_most_recent
+ {
println!(
"Local deno version {} is the most recent release",
crate::version::deno()
@@ -97,7 +98,7 @@ pub async fn upgrade_command(
}
};
- let download_url = if canary {
+ let download_url = if upgrade_flags.canary {
format!(
"https://dl.deno.land/canary/{}/{}",
install_version, *ARCHIVE_NAME
@@ -119,8 +120,8 @@ pub async fn upgrade_command(
fs::set_permissions(&new_exe_path, permissions)?;
check_exe(&new_exe_path)?;
- if !dry_run {
- match output {
+ if !upgrade_flags.dry_run {
+ match upgrade_flags.output {
Some(path) => {
fs::rename(&new_exe_path, &path)
.or_else(|_| fs::copy(&new_exe_path, &path).map(|_| ()))?;