summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-10-12 22:25:25 +1100
committerGitHub <noreply@github.com>2020-10-12 22:25:25 +1100
commit26639b3bac463768c65f7fc40a1c53317549e1eb (patch)
tree4164b44e0530f6ec2d6316028aca65a04f320751 /cli
parente877b36072039811066726ab1619e7b5142f5680 (diff)
chore(cli): remove dead code (#7941)
Diffstat (limited to 'cli')
-rw-r--r--cli/colors.rs29
-rw-r--r--cli/disk_cache.rs5
-rw-r--r--cli/flags.rs1
-rw-r--r--cli/http_cache.rs9
-rw-r--r--cli/http_util.rs10
-rw-r--r--cli/main.rs35
-rw-r--r--cli/media_type.rs29
-rw-r--r--cli/module_graph.rs6
-rw-r--r--cli/ops/io.rs5
-rw-r--r--cli/ops/tty.rs8
-rw-r--r--cli/permissions.rs102
-rw-r--r--cli/worker.rs15
12 files changed, 20 insertions, 234 deletions
diff --git a/cli/colors.rs b/cli/colors.rs
index 3a1616d97..93f252716 100644
--- a/cli/colors.rs
+++ b/cli/colors.rs
@@ -4,9 +4,7 @@ use regex::Regex;
use std::env;
use std::fmt;
use std::io::Write;
-use termcolor::Color::{
- Ansi256, Black, Blue, Cyan, Green, Magenta, Red, White, Yellow,
-};
+use termcolor::Color::{Ansi256, Black, Blue, Cyan, Green, Red, White, Yellow};
use termcolor::{Ansi, ColorSpec, WriteColor};
#[cfg(windows)]
@@ -24,6 +22,7 @@ lazy_static! {
}
/// Helper function to strip ansi codes.
+#[cfg(test)]
pub fn strip_ansi_codes(s: &str) -> std::borrow::Cow<str> {
STRIP_ANSI_RE.replace_all(s, "")
}
@@ -67,24 +66,12 @@ pub fn italic_bold(s: &str) -> impl fmt::Display {
style(&s, style_spec)
}
-pub fn black_on_white(s: &str) -> impl fmt::Display {
- let mut style_spec = ColorSpec::new();
- style_spec.set_bg(Some(White)).set_fg(Some(Black));
- style(&s, style_spec)
-}
-
pub fn white_on_red(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_bg(Some(Red)).set_fg(Some(White));
style(&s, style_spec)
}
-pub fn white_on_green(s: &str) -> impl fmt::Display {
- let mut style_spec = ColorSpec::new();
- style_spec.set_bg(Some(Green)).set_fg(Some(White));
- style(&s, style_spec)
-}
-
pub fn black_on_green(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_bg(Some(Green)).set_fg(Some(Black));
@@ -115,12 +102,6 @@ pub fn green(s: &str) -> impl fmt::Display {
style(&s, style_spec)
}
-pub fn magenta(s: &str) -> impl fmt::Display {
- let mut style_spec = ColorSpec::new();
- style_spec.set_fg(Some(Magenta));
- style(&s, style_spec)
-}
-
pub fn bold(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_bold(true);
@@ -133,12 +114,6 @@ pub fn gray(s: &str) -> impl fmt::Display {
style(&s, style_spec)
}
-pub fn italic_gray(s: &str) -> impl fmt::Display {
- let mut style_spec = ColorSpec::new();
- style_spec.set_fg(Some(Ansi256(8))).set_italic(true);
- style(&s, style_spec)
-}
-
pub fn italic_bold_gray(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec
diff --git a/cli/disk_cache.rs b/cli/disk_cache.rs
index 808a1c9b7..8978065de 100644
--- a/cli/disk_cache.rs
+++ b/cli/disk_cache.rs
@@ -147,11 +147,6 @@ impl DiskCache {
deno_fs::write_file(&path, data, 0o666)
.map_err(|e| with_io_context(&e, format!("{:#?}", &path)))
}
-
- pub fn remove(&self, filename: &Path) -> std::io::Result<()> {
- let path = self.location.join(filename);
- fs::remove_file(path)
- }
}
#[cfg(test)]
diff --git a/cli/flags.rs b/cli/flags.rs
index 12d4e9bc6..856a51a9b 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -43,7 +43,6 @@ pub enum DenoSubcommand {
files: Vec<String>,
ignore: Vec<String>,
},
- Help,
Info {
json: bool,
file: Option<String>,
diff --git a/cli/http_cache.rs b/cli/http_cache.rs
index 995532e60..73d569851 100644
--- a/cli/http_cache.rs
+++ b/cli/http_cache.rs
@@ -89,6 +89,7 @@ impl Metadata {
Ok(())
}
+ #[cfg(test)]
pub fn read(cache_filename: &Path) -> Result<Metadata, AnyError> {
let metadata_filename = Metadata::filename(&cache_filename);
let metadata = fs::read_to_string(metadata_filename)?;
@@ -145,14 +146,6 @@ impl HttpCache {
Ok((file, metadata.headers))
}
- pub fn get_metadata(&self, url: &Url) -> Result<Metadata, AnyError> {
- let cache_filename = self.location.join(url_to_filename(url));
- let metadata_filename = Metadata::filename(&cache_filename);
- let metadata = fs::read_to_string(metadata_filename)?;
- let metadata: Metadata = serde_json::from_str(&metadata)?;
- Ok(metadata)
- }
-
pub fn set(
&self,
url: &Url,
diff --git a/cli/http_util.rs b/cli/http_util.rs
index f54684f15..1a8fcab62 100644
--- a/cli/http_util.rs
+++ b/cli/http_util.rs
@@ -170,16 +170,6 @@ pub struct HttpBody {
pos: usize,
}
-impl HttpBody {
- pub fn from(body: Response) -> Self {
- Self {
- response: body,
- chunk: None,
- pos: 0,
- }
- }
-}
-
impl AsyncRead for HttpBody {
fn poll_read(
self: Pin<&mut Self>,
diff --git a/cli/main.rs b/cli/main.rs
index 96cef4d77..f6bef9688 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -9,28 +9,28 @@ extern crate log;
mod ast;
mod checksum;
-pub mod colors;
+mod colors;
mod coverage;
-pub mod deno_dir;
-pub mod diagnostics;
+mod deno_dir;
+mod diagnostics;
mod diff;
mod disk_cache;
-pub mod errors;
+mod errors;
mod file_fetcher;
mod file_watcher;
-pub mod flags;
+mod flags;
mod flags_allow_net;
mod fmt;
-pub mod fmt_errors;
+mod fmt_errors;
mod fs;
-pub mod global_state;
+mod global_state;
mod global_timer;
-pub mod http_cache;
+mod http_cache;
mod http_util;
mod import_map;
mod info;
mod inspector;
-pub mod installer;
+mod installer;
mod js;
mod lint;
mod lockfile;
@@ -39,22 +39,22 @@ mod metrics;
mod module_graph;
mod module_graph2;
mod op_fetch_asset;
-pub mod ops;
-pub mod permissions;
+mod ops;
+mod permissions;
mod repl;
-pub mod resolve_addr;
-pub mod signal;
-pub mod source_maps;
+mod resolve_addr;
+mod signal;
+mod source_maps;
mod specifier_handler;
-pub mod state;
+mod state;
mod test_runner;
mod text_encoding;
mod tokio_util;
mod tsc;
mod tsc_config;
mod upgrade;
-pub mod version;
-pub mod worker;
+mod version;
+mod worker;
use crate::coverage::CoverageCollector;
use crate::coverage::PrettyCoverageReporter;
@@ -783,7 +783,6 @@ pub fn main() {
} => {
upgrade_command(dry_run, force, version, output, ca_file).boxed_local()
}
- _ => unreachable!(),
};
let result = tokio_util::run_basic(fut);
diff --git a/cli/media_type.rs b/cli/media_type.rs
index 823112fa2..cc3700a66 100644
--- a/cli/media_type.rs
+++ b/cli/media_type.rs
@@ -19,7 +19,6 @@ pub enum MediaType {
TSX = 4,
Json = 5,
Wasm = 6,
- BuildInfo = 7,
Unknown = 8,
}
@@ -33,7 +32,6 @@ impl fmt::Display for MediaType {
MediaType::TSX => "TSX",
MediaType::Json => "Json",
MediaType::Wasm => "Wasm",
- MediaType::BuildInfo => "BuildInfo",
MediaType::Unknown => "Unknown",
};
write!(f, "{}", value)
@@ -75,30 +73,6 @@ impl MediaType {
},
}
}
-
- /// Convert a MediaType to a `ts.Extension`.
- ///
- /// *NOTE* This is defined in TypeScript as a string based enum. Changes to
- /// that enum in TypeScript should be reflected here.
- pub fn as_ts_extension(&self) -> &str {
- match self {
- MediaType::JavaScript => ".js",
- MediaType::JSX => ".jsx",
- MediaType::TypeScript => ".ts",
- MediaType::Dts => ".d.ts",
- MediaType::TSX => ".tsx",
- MediaType::Json => ".json",
- // TypeScript doesn't have an "unknown", so we will treat WASM as JS for
- // mapping purposes, though in reality, it is unlikely to ever be passed
- // to the compiler.
- MediaType::Wasm => ".js",
- MediaType::BuildInfo => ".tsbuildinfo",
- // TypeScript doesn't have an "unknown", so we will treat WASM as JS for
- // mapping purposes, though in reality, it is unlikely to ever be passed
- // to the compiler.
- MediaType::Unknown => ".js",
- }
- }
}
impl Serialize for MediaType {
@@ -114,7 +88,6 @@ impl Serialize for MediaType {
MediaType::TSX => 4 as i32,
MediaType::Json => 5 as i32,
MediaType::Wasm => 6 as i32,
- MediaType::BuildInfo => 7 as i32,
MediaType::Unknown => 8 as i32,
};
Serialize::serialize(&value, serializer)
@@ -175,7 +148,6 @@ mod tests {
assert_eq!(json!(MediaType::TSX), json!(4));
assert_eq!(json!(MediaType::Json), json!(5));
assert_eq!(json!(MediaType::Wasm), json!(6));
- assert_eq!(json!(MediaType::BuildInfo), json!(7));
assert_eq!(json!(MediaType::Unknown), json!(8));
}
@@ -188,7 +160,6 @@ mod tests {
assert_eq!(format!("{}", MediaType::TSX), "TSX");
assert_eq!(format!("{}", MediaType::Json), "Json");
assert_eq!(format!("{}", MediaType::Wasm), "Wasm");
- assert_eq!(format!("{}", MediaType::BuildInfo), "BuildInfo");
assert_eq!(format!("{}", MediaType::Unknown), "Unknown");
}
}
diff --git a/cli/module_graph.rs b/cli/module_graph.rs
index 1c422b9b2..a0ecb6d40 100644
--- a/cli/module_graph.rs
+++ b/cli/module_graph.rs
@@ -244,12 +244,6 @@ pub struct ModuleGraphFile {
pub source_code: String,
}
-impl ModuleGraphFile {
- pub fn size(&self) -> usize {
- self.source_code.as_bytes().len()
- }
-}
-
type SourceFileFuture = Pin<
Box<dyn Future<Output = Result<(ModuleSpecifier, SourceFile), AnyError>>>,
>;
diff --git a/cli/ops/io.rs b/cli/ops/io.rs
index 80ae6bc9e..0f8af905a 100644
--- a/cli/ops/io.rs
+++ b/cli/ops/io.rs
@@ -2,7 +2,6 @@
use super::dispatch_minimal::minimal_op;
use super::dispatch_minimal::MinimalOp;
-use crate::http_util::HttpBody;
use crate::metrics::metrics_op;
use deno_core::error::bad_resource_id;
use deno_core::error::resource_unavailable;
@@ -184,14 +183,12 @@ impl StreamResourceHolder {
}
pub enum StreamResource {
- Stdin(tokio::io::Stdin, TTYMetadata),
FsFile(Option<(tokio::fs::File, FileMetadata)>),
TcpStream(Option<tokio::net::TcpStream>),
#[cfg(not(windows))]
UnixStream(tokio::net::UnixStream),
ServerTlsStream(Box<ServerTlsStream<TcpStream>>),
ClientTlsStream(Box<ClientTlsStream<TcpStream>>),
- HttpBody(Box<HttpBody>),
ChildStdin(tokio::process::ChildStdin),
ChildStdout(tokio::process::ChildStdout),
ChildStderr(tokio::process::ChildStderr),
@@ -223,7 +220,6 @@ impl DenoAsyncRead for StreamResource {
let f: &mut dyn UnpinAsyncRead = match self {
FsFile(Some((f, _))) => f,
FsFile(None) => return Poll::Ready(Err(resource_unavailable())),
- Stdin(f, _) => f,
TcpStream(Some(f)) => f,
#[cfg(not(windows))]
UnixStream(f) => f,
@@ -231,7 +227,6 @@ impl DenoAsyncRead for StreamResource {
ServerTlsStream(f) => f,
ChildStdout(f) => f,
ChildStderr(f) => f,
- HttpBody(f) => f,
_ => return Err(bad_resource_id()).into(),
};
let v = ready!(Pin::new(f).poll_read(cx, buf))?;
diff --git a/cli/ops/tty.rs b/cli/ops/tty.rs
index 01ed73a05..52c89ee11 100644
--- a/cli/ops/tty.rs
+++ b/cli/ops/tty.rs
@@ -90,7 +90,6 @@ fn op_set_raw(
// For now, only stdin.
let handle = match &mut resource_holder.resource {
- StreamResource::Stdin(..) => std::io::stdin().as_raw_handle(),
StreamResource::FsFile(ref mut option_file_metadata) => {
if let Some((tokio_file, metadata)) = option_file_metadata.take() {
match tokio_file.try_into_std() {
@@ -156,9 +155,6 @@ fn op_set_raw(
if is_raw {
let (raw_fd, maybe_tty_mode) =
match &mut resource_holder.unwrap().resource {
- StreamResource::Stdin(_, ref mut metadata) => {
- (std::io::stdin().as_raw_fd(), &mut metadata.mode)
- }
StreamResource::FsFile(Some((f, ref mut metadata))) => {
(f.as_raw_fd(), &mut metadata.tty.mode)
}
@@ -198,9 +194,6 @@ fn op_set_raw(
// Try restore saved mode.
let (raw_fd, maybe_tty_mode) =
match &mut resource_holder.unwrap().resource {
- StreamResource::Stdin(_, ref mut metadata) => {
- (std::io::stdin().as_raw_fd(), &mut metadata.mode)
- }
StreamResource::FsFile(Some((f, ref mut metadata))) => {
(f.as_raw_fd(), &mut metadata.tty.mode)
}
@@ -253,7 +246,6 @@ fn op_isatty(
}
}
Err(StreamResource::FsFile(_)) => unreachable!(),
- Err(StreamResource::Stdin(..)) => Ok(atty::is(atty::Stream::Stdin)),
_ => Ok(false),
})?;
Ok(json!(isatty))
diff --git a/cli/permissions.rs b/cli/permissions.rs
index c2e11080e..ae020c7af 100644
--- a/cli/permissions.rs
+++ b/cli/permissions.rs
@@ -42,16 +42,6 @@ impl PermissionState {
let message = format!("{}, run again with the {} flag", msg, flag_name);
Err(custom_error("PermissionDenied", message))
}
-
- /// Check that the permissions represented by `other` don't escalate ours.
- fn check_fork(self, other: &Self) -> Result<(), AnyError> {
- if self == PermissionState::Denied && other != &PermissionState::Denied
- || self == PermissionState::Prompt && other == &PermissionState::Granted
- {
- return Err(permission_escalation_error());
- }
- Ok(())
- }
}
impl From<usize> for PermissionState {
@@ -98,20 +88,6 @@ pub struct UnaryPermission<T: Eq + Hash> {
pub denied_list: HashSet<T>,
}
-impl<T: Eq + Hash> UnaryPermission<T> {
- /// Check that the permissions represented by `other` don't escalate ours.
- fn check_fork(&self, other: &Self) -> Result<(), AnyError> {
- self.global_state.check_fork(&other.global_state)?;
- if !self.granted_list.is_superset(&other.granted_list) {
- return Err(permission_escalation_error());
- }
- if !self.denied_list.is_subset(&other.denied_list) {
- return Err(permission_escalation_error());
- }
- Ok(())
- }
-}
-
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
pub struct Permissions {
pub read: UnaryPermission<PathBuf>,
@@ -595,35 +571,6 @@ impl Permissions {
.hrtime
.check("access to high precision time", "--allow-hrtime")
}
-
- #[allow(clippy::too_many_arguments)]
- pub fn fork(
- &self,
- read: UnaryPermission<PathBuf>,
- write: UnaryPermission<PathBuf>,
- net: UnaryPermission<String>,
- env: PermissionState,
- run: PermissionState,
- plugin: PermissionState,
- hrtime: PermissionState,
- ) -> Result<Permissions, AnyError> {
- self.read.check_fork(&read)?;
- self.write.check_fork(&write)?;
- self.net.check_fork(&net)?;
- self.env.check_fork(&env)?;
- self.run.check_fork(&run)?;
- self.plugin.check_fork(&plugin)?;
- self.hrtime.check_fork(&hrtime)?;
- Ok(Permissions {
- read,
- write,
- net,
- env,
- run,
- plugin,
- hrtime,
- })
- }
}
impl deno_fetch::FetchPermissions for Permissions {
@@ -726,10 +673,6 @@ fn check_host_and_port_list(
&& allowlist.contains(&format!("{}:{}", host, port.unwrap())))
}
-fn permission_escalation_error() -> AnyError {
- custom_error("PermissionDenied", "Arguments escalate parent permissions")
-}
-
#[cfg(test)]
mod tests {
use super::*;
@@ -936,51 +879,6 @@ mod tests {
}
#[test]
- fn test_fork() {
- let perms0 = Permissions::from_flags(&Flags::default());
- perms0
- .fork(
- UnaryPermission {
- global_state: PermissionState::Prompt,
- ..Default::default()
- },
- UnaryPermission {
- global_state: PermissionState::Prompt,
- ..Default::default()
- },
- UnaryPermission {
- global_state: PermissionState::Prompt,
- ..Default::default()
- },
- PermissionState::Prompt,
- PermissionState::Prompt,
- PermissionState::Denied,
- PermissionState::Denied,
- )
- .expect("Fork should succeed.");
- perms0
- .fork(
- UnaryPermission {
- global_state: PermissionState::Granted,
- ..Default::default()
- },
- UnaryPermission {
- global_state: PermissionState::Granted,
- ..Default::default()
- },
- UnaryPermission {
- global_state: PermissionState::Granted,
- ..Default::default()
- },
- PermissionState::Granted,
- PermissionState::Granted,
- PermissionState::Denied,
- PermissionState::Denied,
- )
- .expect_err("Fork should fail.");
- }
-
- #[test]
fn test_query() {
let perms1 = Permissions {
read: UnaryPermission {
diff --git a/cli/worker.rs b/cli/worker.rs
index b5855e653..8cf175cc5 100644
--- a/cli/worker.rs
+++ b/cli/worker.rs
@@ -194,21 +194,6 @@ impl Worker {
self.js_runtime.mod_evaluate(id)
}
- /// Loads, instantiates and executes provided source code
- /// as module.
- pub async fn execute_module_from_code(
- &mut self,
- module_specifier: &ModuleSpecifier,
- code: String,
- ) -> Result<(), AnyError> {
- let id = self
- .js_runtime
- .load_module(module_specifier, Some(code))
- .await?;
- self.wait_for_inspector_session();
- self.js_runtime.mod_evaluate(id)
- }
-
/// Returns a way to communicate with the Worker from other threads.
pub fn thread_safe_handle(&self) -> WorkerHandle {
self.external_channels.clone()