mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
chore(cli): remove dead code (#7941)
This commit is contained in:
parent
e877b36072
commit
26639b3bac
12 changed files with 20 additions and 234 deletions
|
@ -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
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -43,7 +43,6 @@ pub enum DenoSubcommand {
|
|||
files: Vec<String>,
|
||||
ignore: Vec<String>,
|
||||
},
|
||||
Help,
|
||||
Info {
|
||||
json: bool,
|
||||
file: Option<String>,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>,
|
||||
|
|
35
cli/main.rs
35
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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>>>,
|
||||
>;
|
||||
|
|
|
@ -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))?;
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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::*;
|
||||
|
@ -935,51 +878,6 @@ mod tests {
|
|||
assert_eq!(perms0, deserialized_perms);
|
||||
}
|
||||
|
||||
#[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 {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue