diff --git a/.dprint.json b/.dprint.json index b9c2d1ebc14313..bd1279fd4a0c1d 100644 --- a/.dprint.json +++ b/.dprint.json @@ -13,7 +13,7 @@ }, "exec": { "commands": [{ - "command": "rustfmt --config imports_granularity=item", + "command": "rustfmt --config imports_granularity=item --config group_imports=StdExternalCrate", "exts": ["rs"] }] }, diff --git a/bench_util/README.md b/bench_util/README.md index 12474a86b60392..30616a08fdabae 100644 --- a/bench_util/README.md +++ b/bench_util/README.md @@ -7,7 +7,6 @@ use deno_bench_util::bench_js_sync; use deno_bench_util::bench_or_profile; use deno_bench_util::bencher::benchmark_group; use deno_bench_util::bencher::Bencher; - use deno_core::Extension; #[op2] diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 2b0b9a2908d54e..cd6db5eea28e04 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -43,11 +43,10 @@ use log::Level; use serde::Deserialize; use serde::Serialize; -use crate::args::resolve_no_prompt; -use crate::util::fs::canonicalize_path; - use super::flags_net; use super::jsr_url; +use crate::args::resolve_no_prompt; +use crate::util::fs::canonicalize_path; #[derive(Clone, Debug, Default, Eq, PartialEq)] pub enum ConfigFlag { @@ -6059,9 +6058,10 @@ pub fn resolve_urls(urls: Vec) -> Vec { #[cfg(test)] mod tests { - use super::*; use pretty_assertions::assert_eq; + use super::*; + /// Creates vector of strings, Vec macro_rules! svec { ($($x:expr),* $(,)?) => (vec![$($x.to_string().into()),*]); diff --git a/cli/args/flags_net.rs b/cli/args/flags_net.rs index abfcf2838279ca..3d19a06183effc 100644 --- a/cli/args/flags_net.rs +++ b/cli/args/flags_net.rs @@ -1,10 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::url::Url; -use deno_runtime::deno_permissions::NetDescriptor; use std::net::IpAddr; use std::str::FromStr; +use deno_core::url::Url; +use deno_runtime::deno_permissions::NetDescriptor; + #[derive(Debug, PartialEq, Eq)] pub struct ParsePortError(String); diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs index 7d5fe57bc34912..5d93aa6a4af7cb 100644 --- a/cli/args/lockfile.rs +++ b/cli/args/lockfile.rs @@ -10,6 +10,7 @@ use deno_core::error::AnyError; use deno_core::parking_lot::Mutex; use deno_core::parking_lot::MutexGuard; use deno_core::serde_json; +use deno_lockfile::Lockfile; use deno_lockfile::WorkspaceMemberConfig; use deno_package_json::PackageJsonDepValue; use deno_path_util::fs::atomic_write_file_with_retries; @@ -17,15 +18,12 @@ use deno_runtime::deno_node::PackageJson; use deno_semver::jsr::JsrDepPackageReq; use crate::args::deno_json::import_map_deps; +use crate::args::DenoSubcommand; +use crate::args::InstallFlags; use crate::cache; use crate::sys::CliSys; use crate::Flags; -use crate::args::DenoSubcommand; -use crate::args::InstallFlags; - -use deno_lockfile::Lockfile; - #[derive(Debug)] pub struct CliLockfileReadFromPathOptions { pub file_path: PathBuf, diff --git a/cli/args/mod.rs b/cli/args/mod.rs index a059b07757c3d6..4516cfe06ad710 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -7,10 +7,37 @@ mod import_map; mod lockfile; mod package_json; +use std::borrow::Cow; +use std::collections::HashMap; +use std::env; +use std::io::BufReader; +use std::io::Cursor; +use std::io::Read; +use std::io::Seek; +use std::net::SocketAddr; +use std::num::NonZeroUsize; +use std::path::Path; +use std::path::PathBuf; +use std::sync::Arc; + use deno_ast::MediaType; +use deno_ast::ModuleSpecifier; use deno_ast::SourceMapOption; use deno_cache_dir::file_fetcher::CacheSetting; +pub use deno_config::deno_json::BenchConfig; +pub use deno_config::deno_json::ConfigFile; +use deno_config::deno_json::FmtConfig; +pub use deno_config::deno_json::FmtOptionsConfig; +use deno_config::deno_json::LintConfig; +pub use deno_config::deno_json::LintRulesConfig; use deno_config::deno_json::NodeModulesDirMode; +pub use deno_config::deno_json::ProseWrap; +use deno_config::deno_json::TestConfig; +pub use deno_config::deno_json::TsConfig; +pub use deno_config::deno_json::TsConfigForEmit; +pub use deno_config::deno_json::TsConfigType; +pub use deno_config::deno_json::TsTypeLib; +pub use deno_config::glob::FilePatterns; use deno_config::workspace::CreateResolverOptions; use deno_config::workspace::FolderConfigs; use deno_config::workspace::PackageJsonDepResolution; @@ -22,43 +49,20 @@ use deno_config::workspace::WorkspaceDiscoverOptions; use deno_config::workspace::WorkspaceDiscoverStart; use deno_config::workspace::WorkspaceLintConfig; use deno_config::workspace::WorkspaceResolver; +use deno_core::anyhow::bail; +use deno_core::anyhow::Context; +use deno_core::error::AnyError; use deno_core::resolve_url_or_path; +use deno_core::serde_json; +use deno_core::url::Url; use deno_graph::GraphKind; +pub use deno_json::check_warn_tsconfig; use deno_lint::linter::LintConfig as DenoLintConfig; use deno_npm::npm_rc::NpmRc; use deno_npm::npm_rc::ResolvedNpmRc; use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot; use deno_npm::NpmSystemInfo; use deno_path_util::normalize_path; -use deno_semver::npm::NpmPackageReqReference; -use deno_semver::StackString; -use deno_telemetry::OtelConfig; -use deno_telemetry::OtelRuntimeConfig; -use import_map::resolve_import_map_value_from_specifier; - -pub use deno_config::deno_json::BenchConfig; -pub use deno_config::deno_json::ConfigFile; -pub use deno_config::deno_json::FmtOptionsConfig; -pub use deno_config::deno_json::LintRulesConfig; -pub use deno_config::deno_json::ProseWrap; -pub use deno_config::deno_json::TsConfig; -pub use deno_config::deno_json::TsConfigForEmit; -pub use deno_config::deno_json::TsConfigType; -pub use deno_config::deno_json::TsTypeLib; -pub use deno_config::glob::FilePatterns; -pub use deno_json::check_warn_tsconfig; -pub use flags::*; -pub use lockfile::CliLockfile; -pub use lockfile::CliLockfileReadFromPathOptions; -pub use package_json::NpmInstallDepsProvider; -pub use package_json::PackageJsonDepValueParseWithLocationError; - -use deno_ast::ModuleSpecifier; -use deno_core::anyhow::bail; -use deno_core::anyhow::Context; -use deno_core::error::AnyError; -use deno_core::serde_json; -use deno_core::url::Url; use deno_runtime::deno_permissions::PermissionsOptions; use deno_runtime::deno_tls::deno_native_certs::load_native_certs; use deno_runtime::deno_tls::rustls; @@ -66,23 +70,21 @@ use deno_runtime::deno_tls::rustls::RootCertStore; use deno_runtime::deno_tls::rustls_pemfile; use deno_runtime::deno_tls::webpki_roots; use deno_runtime::inspector_server::InspectorServer; +use deno_semver::npm::NpmPackageReqReference; +use deno_semver::StackString; +use deno_telemetry::OtelConfig; +use deno_telemetry::OtelRuntimeConfig; use deno_terminal::colors; use dotenvy::from_filename; +pub use flags::*; +use import_map::resolve_import_map_value_from_specifier; +pub use lockfile::CliLockfile; +pub use lockfile::CliLockfileReadFromPathOptions; use once_cell::sync::Lazy; +pub use package_json::NpmInstallDepsProvider; +pub use package_json::PackageJsonDepValueParseWithLocationError; use serde::Deserialize; use serde::Serialize; -use std::borrow::Cow; -use std::collections::HashMap; -use std::env; -use std::io::BufReader; -use std::io::Cursor; -use std::io::Read; -use std::io::Seek; -use std::net::SocketAddr; -use std::num::NonZeroUsize; -use std::path::Path; -use std::path::PathBuf; -use std::sync::Arc; use sys_traits::EnvHomeDir; use thiserror::Error; @@ -92,10 +94,6 @@ use crate::sys::CliSys; use crate::util::fs::canonicalize_path_maybe_not_exists; use crate::version; -use deno_config::deno_json::FmtConfig; -use deno_config::deno_json::LintConfig; -use deno_config::deno_json::TestConfig; - pub fn npm_registry_url() -> &'static Url { static NPM_REGISTRY_DEFAULT_URL: Lazy = Lazy::new(|| { let env_var_name = "NPM_CONFIG_REGISTRY"; diff --git a/cli/bench/lsp.rs b/cli/bench/lsp.rs index 7baaffca7eb969..1e02291e1039fe 100644 --- a/cli/bench/lsp.rs +++ b/cli/bench/lsp.rs @@ -1,14 +1,15 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::collections::HashMap; +use std::path::Path; +use std::str::FromStr; +use std::time::Duration; + use deno_core::serde::Deserialize; use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::serde_json::Value; use lsp_types::Uri; -use std::collections::HashMap; -use std::path::Path; -use std::str::FromStr; -use std::time::Duration; use test_util::lsp::LspClientBuilder; use test_util::PathRef; use tower_lsp::lsp_types as lsp; diff --git a/cli/bench/main.rs b/cli/bench/main.rs index c3c42d24882f04..f38aa79e9e2a35 100644 --- a/cli/bench/main.rs +++ b/cli/bench/main.rs @@ -3,9 +3,6 @@ #![allow(clippy::print_stdout)] #![allow(clippy::print_stderr)] -use deno_core::error::AnyError; -use deno_core::serde_json; -use deno_core::serde_json::Value; use std::collections::HashMap; use std::convert::From; use std::env; @@ -15,6 +12,10 @@ use std::path::PathBuf; use std::process::Command; use std::process::Stdio; use std::time::SystemTime; + +use deno_core::error::AnyError; +use deno_core::serde_json; +use deno_core::serde_json::Value; use test_util::PathRef; mod lsp; diff --git a/cli/build.rs b/cli/build.rs index 3d986612841584..8367910678469b 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -8,16 +8,18 @@ use deno_runtime::*; mod shared; mod ts { - use super::*; + use std::collections::HashMap; + use std::io::Write; + use std::path::Path; + use std::path::PathBuf; + use deno_core::error::custom_error; use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use serde::Serialize; - use std::collections::HashMap; - use std::io::Write; - use std::path::Path; - use std::path::PathBuf; + + use super::*; #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] diff --git a/cli/cache/cache_db.rs b/cli/cache/cache_db.rs index 329ed2d9704dff..c25c1955b29361 100644 --- a/cli/cache/cache_db.rs +++ b/cli/cache/cache_db.rs @@ -1,5 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::io::IsTerminal; +use std::path::Path; +use std::path::PathBuf; +use std::sync::Arc; + use deno_core::error::AnyError; use deno_core::parking_lot::Mutex; use deno_core::parking_lot::MutexGuard; @@ -9,10 +14,6 @@ use deno_runtime::deno_webstorage::rusqlite::Connection; use deno_runtime::deno_webstorage::rusqlite::OptionalExtension; use deno_runtime::deno_webstorage::rusqlite::Params; use once_cell::sync::OnceCell; -use std::io::IsTerminal; -use std::path::Path; -use std::path::PathBuf; -use std::sync::Arc; use super::FastInsecureHasher; diff --git a/cli/cache/check.rs b/cli/cache/check.rs index ca4e938533b480..192d338a0945da 100644 --- a/cli/cache/check.rs +++ b/cli/cache/check.rs @@ -1,12 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use deno_ast::ModuleSpecifier; +use deno_core::error::AnyError; +use deno_runtime::deno_webstorage::rusqlite::params; + use super::cache_db::CacheDB; use super::cache_db::CacheDBConfiguration; use super::cache_db::CacheDBHash; use super::cache_db::CacheFailure; -use deno_ast::ModuleSpecifier; -use deno_core::error::AnyError; -use deno_runtime::deno_webstorage::rusqlite::params; pub static TYPE_CHECK_CACHE_DB: CacheDBConfiguration = CacheDBConfiguration { table_initializer: concat!( diff --git a/cli/cache/code_cache.rs b/cli/cache/code_cache.rs index b1d9ae757b9038..b6c9060ea0c0d4 100644 --- a/cli/cache/code_cache.rs +++ b/cli/cache/code_cache.rs @@ -7,12 +7,11 @@ use deno_core::error::AnyError; use deno_runtime::code_cache; use deno_runtime::deno_webstorage::rusqlite::params; -use crate::worker::CliCodeCache; - use super::cache_db::CacheDB; use super::cache_db::CacheDBConfiguration; use super::cache_db::CacheDBHash; use super::cache_db::CacheFailure; +use crate::worker::CliCodeCache; pub static CODE_CACHE_DB: CacheDBConfiguration = CacheDBConfiguration { table_initializer: concat!( diff --git a/cli/cache/deno_dir.rs b/cli/cache/deno_dir.rs index 90a3add54eba2a..2c0aa30bc24247 100644 --- a/cli/cache/deno_dir.rs +++ b/cli/cache/deno_dir.rs @@ -1,14 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::env; +use std::path::PathBuf; + use deno_cache_dir::DenoDirResolutionError; use once_cell::sync::OnceCell; -use crate::sys::CliSys; - use super::DiskCache; - -use std::env; -use std::path::PathBuf; +use crate::sys::CliSys; /// Lazily creates the deno dir which might be useful in scenarios /// where functionality wants to continue if the DENO_DIR can't be created. diff --git a/cli/cache/disk_cache.rs b/cli/cache/disk_cache.rs index c96a3943c04f57..b23d7b8f787193 100644 --- a/cli/cache/disk_cache.rs +++ b/cli/cache/disk_cache.rs @@ -1,13 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::sys::CliSys; - -use super::CACHE_PERM; - -use deno_cache_dir::url_to_filename; -use deno_core::url::Host; -use deno_core::url::Url; -use deno_path_util::fs::atomic_write_file_with_retries; use std::ffi::OsStr; use std::fs; use std::path::Component; @@ -16,6 +8,14 @@ use std::path::PathBuf; use std::path::Prefix; use std::str; +use deno_cache_dir::url_to_filename; +use deno_core::url::Host; +use deno_core::url::Url; +use deno_path_util::fs::atomic_write_file_with_retries; + +use super::CACHE_PERM; +use crate::sys::CliSys; + #[derive(Debug, Clone)] pub struct DiskCache { sys: CliSys, @@ -130,9 +130,10 @@ impl DiskCache { #[cfg(test)] mod tests { - use super::*; use test_util::TempDir; + use super::*; + #[test] fn test_set_get_cache_file() { let temp_dir = TempDir::new(); diff --git a/cli/cache/emit.rs b/cli/cache/emit.rs index b239cc93ba5c05..100cbfe74429ff 100644 --- a/cli/cache/emit.rs +++ b/cli/cache/emit.rs @@ -159,9 +159,8 @@ impl EmitFileSerializer { mod test { use test_util::TempDir; - use crate::sys::CliSys; - use super::*; + use crate::sys::CliSys; #[test] pub fn emit_cache_general_use() { diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index bc6f792667a2c6..ef93939c10df0c 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -1,11 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::args::jsr_url; -use crate::file_fetcher::CliFetchNoFollowErrorKind; -use crate::file_fetcher::CliFileFetcher; -use crate::file_fetcher::FetchNoFollowOptions; -use crate::file_fetcher::FetchPermissionsOptionRef; -use crate::sys::CliSys; +use std::collections::HashMap; +use std::path::PathBuf; +use std::sync::Arc; use deno_ast::MediaType; use deno_cache_dir::file_fetcher::CacheSetting; @@ -21,9 +18,13 @@ use deno_graph::source::LoadResponse; use deno_graph::source::Loader; use deno_runtime::deno_permissions::PermissionsContainer; use node_resolver::InNpmPackageChecker; -use std::collections::HashMap; -use std::path::PathBuf; -use std::sync::Arc; + +use crate::args::jsr_url; +use crate::file_fetcher::CliFetchNoFollowErrorKind; +use crate::file_fetcher::CliFileFetcher; +use crate::file_fetcher::FetchNoFollowOptions; +use crate::file_fetcher::FetchPermissionsOptionRef; +use crate::sys::CliSys; mod cache_db; mod caches; @@ -44,6 +45,8 @@ pub use caches::Caches; pub use check::TypeCheckCache; pub use code_cache::CodeCache; pub use common::FastInsecureHasher; +/// Permissions used to save a file in the disk caches. +pub use deno_cache_dir::CACHE_PERM; pub use deno_dir::DenoDir; pub use deno_dir::DenoDirProvider; pub use disk_cache::DiskCache; @@ -55,9 +58,6 @@ pub use node::NodeAnalysisCache; pub use parsed_source::LazyGraphSourceParser; pub use parsed_source::ParsedSourceCache; -/// Permissions used to save a file in the disk caches. -pub use deno_cache_dir::CACHE_PERM; - pub type GlobalHttpCache = deno_cache_dir::GlobalHttpCache; pub type LocalHttpCache = deno_cache_dir::LocalHttpCache; pub type LocalLspHttpCache = deno_cache_dir::LocalLspHttpCache; diff --git a/cli/cache/node.rs b/cli/cache/node.rs index e80342e5c017df..92f5a19d7178dd 100644 --- a/cli/cache/node.rs +++ b/cli/cache/node.rs @@ -4,12 +4,11 @@ use deno_core::error::AnyError; use deno_core::serde_json; use deno_runtime::deno_webstorage::rusqlite::params; -use crate::node::CliCjsAnalysis; - use super::cache_db::CacheDB; use super::cache_db::CacheDBConfiguration; use super::cache_db::CacheFailure; use super::CacheDBHash; +use crate::node::CliCjsAnalysis; pub static NODE_ANALYSIS_CACHE_DB: CacheDBConfiguration = CacheDBConfiguration { diff --git a/cli/emit.rs b/cli/emit.rs index 733a89d832ed6d..04547adf938d9d 100644 --- a/cli/emit.rs +++ b/cli/emit.rs @@ -1,9 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::cache::EmitCache; -use crate::cache::FastInsecureHasher; -use crate::cache::ParsedSourceCache; -use crate::resolver::CjsTracker; +use std::sync::Arc; use deno_ast::EmittedSourceText; use deno_ast::ModuleKind; @@ -21,7 +18,11 @@ use deno_core::ModuleSpecifier; use deno_graph::MediaType; use deno_graph::Module; use deno_graph::ModuleGraph; -use std::sync::Arc; + +use crate::cache::EmitCache; +use crate::cache::FastInsecureHasher; +use crate::cache::ParsedSourceCache; +use crate::resolver::CjsTracker; #[derive(Debug)] pub struct Emitter { diff --git a/cli/factory.rs b/cli/factory.rs index e33b95d2353bb1..a57f7822a8bcd8 100644 --- a/cli/factory.rs +++ b/cli/factory.rs @@ -1,5 +1,34 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::future::Future; +use std::path::PathBuf; +use std::sync::Arc; + +use deno_cache_dir::npm::NpmCacheDir; +use deno_config::workspace::PackageJsonDepResolution; +use deno_config::workspace::WorkspaceResolver; +use deno_core::error::AnyError; +use deno_core::futures::FutureExt; +use deno_core::FeatureChecker; +use deno_resolver::cjs::IsCjsResolutionMode; +use deno_resolver::npm::NpmReqResolverOptions; +use deno_resolver::DenoResolverOptions; +use deno_resolver::NodeAndNpmReqResolver; +use deno_runtime::deno_fs; +use deno_runtime::deno_fs::RealFs; +use deno_runtime::deno_node::RealIsBuiltInNodeModuleChecker; +use deno_runtime::deno_permissions::Permissions; +use deno_runtime::deno_permissions::PermissionsContainer; +use deno_runtime::deno_tls::rustls::RootCertStore; +use deno_runtime::deno_tls::RootCertStoreProvider; +use deno_runtime::deno_web::BlobStore; +use deno_runtime::inspector_server::InspectorServer; +use deno_runtime::permissions::RuntimePermissionDescriptorParser; +use log::warn; +use node_resolver::analyze::NodeCodeTranslator; +use node_resolver::InNpmPackageChecker; +use once_cell::sync::OnceCell; + use crate::args::check_warn_tsconfig; use crate::args::get_root_cert_store; use crate::args::CaData; @@ -63,35 +92,6 @@ use crate::util::progress_bar::ProgressBar; use crate::util::progress_bar::ProgressBarStyle; use crate::worker::CliMainWorkerFactory; use crate::worker::CliMainWorkerOptions; -use std::path::PathBuf; - -use deno_cache_dir::npm::NpmCacheDir; -use deno_config::workspace::PackageJsonDepResolution; -use deno_config::workspace::WorkspaceResolver; -use deno_core::error::AnyError; -use deno_core::futures::FutureExt; -use deno_core::FeatureChecker; - -use deno_resolver::cjs::IsCjsResolutionMode; -use deno_resolver::npm::NpmReqResolverOptions; -use deno_resolver::DenoResolverOptions; -use deno_resolver::NodeAndNpmReqResolver; -use deno_runtime::deno_fs; -use deno_runtime::deno_fs::RealFs; -use deno_runtime::deno_node::RealIsBuiltInNodeModuleChecker; -use deno_runtime::deno_permissions::Permissions; -use deno_runtime::deno_permissions::PermissionsContainer; -use deno_runtime::deno_tls::rustls::RootCertStore; -use deno_runtime::deno_tls::RootCertStoreProvider; -use deno_runtime::deno_web::BlobStore; -use deno_runtime::inspector_server::InspectorServer; -use deno_runtime::permissions::RuntimePermissionDescriptorParser; -use log::warn; -use node_resolver::analyze::NodeCodeTranslator; -use node_resolver::InNpmPackageChecker; -use once_cell::sync::OnceCell; -use std::future::Future; -use std::sync::Arc; struct CliRootCertStoreProvider { cell: OnceCell, diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 7e8438d6397413..3d73a7e4ea5192 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -498,10 +498,6 @@ fn validate_scheme(specifier: &Url) -> Result<(), UnsupportedSchemeError> { #[cfg(test)] mod tests { - use crate::cache::GlobalHttpCache; - use crate::http_util::HttpClientProvider; - - use super::*; use deno_cache_dir::file_fetcher::FetchNoFollowErrorKind; use deno_cache_dir::file_fetcher::HttpClient; use deno_core::resolve_url; @@ -509,6 +505,10 @@ mod tests { use deno_runtime::deno_web::InMemoryBlobPart; use test_util::TempDir; + use super::*; + use crate::cache::GlobalHttpCache; + use crate::http_util::HttpClientProvider; + fn setup( cache_setting: CacheSetting, maybe_temp_dir: Option, diff --git a/cli/http_util.rs b/cli/http_util.rs index b24dd7bc0ca07b..618ba3534658ec 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -1,7 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::util::progress_bar::UpdateGuard; -use crate::version; +use std::collections::HashMap; +use std::sync::Arc; +use std::thread::ThreadId; use boxed_error::Boxed; use deno_cache_dir::file_fetcher::RedirectHeaderParseError; @@ -23,12 +24,11 @@ use http::header::CONTENT_LENGTH; use http::HeaderMap; use http::StatusCode; use http_body_util::BodyExt; - -use std::collections::HashMap; -use std::sync::Arc; -use std::thread::ThreadId; use thiserror::Error; +use crate::util::progress_bar::UpdateGuard; +use crate::version; + #[derive(Debug, Error)] pub enum SendError { #[error(transparent)] diff --git a/cli/jsr.rs b/cli/jsr.rs index acfbb1c8e2b0d2..ef57e8fd64a0da 100644 --- a/cli/jsr.rs +++ b/cli/jsr.rs @@ -1,14 +1,16 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::args::jsr_url; -use crate::file_fetcher::CliFileFetcher; +use std::sync::Arc; + use dashmap::DashMap; use deno_core::serde_json; use deno_graph::packages::JsrPackageInfo; use deno_graph::packages::JsrPackageVersionInfo; use deno_semver::package::PackageNv; use deno_semver::package::PackageReq; -use std::sync::Arc; + +use crate::args::jsr_url; +use crate::file_fetcher::CliFileFetcher; /// This is similar to a subset of `JsrCacheResolver` which fetches rather than /// just reads the cache. Keep in sync! diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs index 8fb3454bc83ee2..116780eb7329af 100644 --- a/cli/lsp/analysis.rs +++ b/cli/lsp/analysis.rs @@ -1,25 +1,15 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::diagnostics::DenoDiagnostic; -use super::diagnostics::DiagnosticSource; -use super::documents::Document; -use super::documents::Documents; -use super::language_server; -use super::resolver::LspResolver; -use super::tsc; -use super::urls::url_to_uri; - -use crate::args::jsr_url; -use crate::lsp::logging::lsp_warn; -use crate::lsp::search::PackageSearchApi; -use crate::tools::lint::CliLinter; -use crate::util::path::relative_specifier; -use deno_config::workspace::MappedResolution; -use deno_lint::diagnostic::LintDiagnosticRange; +use std::borrow::Cow; +use std::cmp::Ordering; +use std::collections::HashMap; +use std::collections::HashSet; +use std::path::Path; use deno_ast::SourceRange; use deno_ast::SourceRangedForSpanned; use deno_ast::SourceTextInfo; +use deno_config::workspace::MappedResolution; use deno_core::error::custom_error; use deno_core::error::AnyError; use deno_core::serde::Deserialize; @@ -27,6 +17,7 @@ use deno_core::serde::Serialize; use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::ModuleSpecifier; +use deno_lint::diagnostic::LintDiagnosticRange; use deno_path_util::url_to_file_path; use deno_runtime::deno_node::PathClean; use deno_semver::jsr::JsrPackageNvReference; @@ -44,16 +35,25 @@ use node_resolver::NodeResolutionKind; use node_resolver::ResolutionMode; use once_cell::sync::Lazy; use regex::Regex; -use std::borrow::Cow; -use std::cmp::Ordering; -use std::collections::HashMap; -use std::collections::HashSet; -use std::path::Path; use text_lines::LineAndColumnIndex; use tower_lsp::lsp_types as lsp; use tower_lsp::lsp_types::Position; use tower_lsp::lsp_types::Range; +use super::diagnostics::DenoDiagnostic; +use super::diagnostics::DiagnosticSource; +use super::documents::Document; +use super::documents::Documents; +use super::language_server; +use super::resolver::LspResolver; +use super::tsc; +use super::urls::url_to_uri; +use crate::args::jsr_url; +use crate::lsp::logging::lsp_warn; +use crate::lsp::search::PackageSearchApi; +use crate::tools::lint::CliLinter; +use crate::util::path::relative_specifier; + /// Diagnostic error codes which actually are the same, and so when grouping /// fixes we treat them the same. static FIX_ALL_ERROR_CODES: Lazy> = diff --git a/cli/lsp/cache.rs b/cli/lsp/cache.rs index 24a55d495c9437..c69f66b77f13f7 100644 --- a/cli/lsp/cache.rs +++ b/cli/lsp/cache.rs @@ -1,5 +1,15 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::collections::BTreeMap; +use std::fs; +use std::path::Path; +use std::sync::Arc; +use std::time::SystemTime; + +use deno_core::url::Url; +use deno_core::ModuleSpecifier; +use deno_path_util::url_to_file_path; + use crate::cache::DenoDir; use crate::cache::GlobalHttpCache; use crate::cache::HttpCache; @@ -9,15 +19,6 @@ use crate::lsp::logging::lsp_log; use crate::lsp::logging::lsp_warn; use crate::sys::CliSys; -use deno_core::url::Url; -use deno_core::ModuleSpecifier; -use deno_path_util::url_to_file_path; -use std::collections::BTreeMap; -use std::fs; -use std::path::Path; -use std::sync::Arc; -use std::time::SystemTime; - pub fn calculate_fs_version( cache: &LspCache, specifier: &ModuleSpecifier, diff --git a/cli/lsp/client.rs b/cli/lsp/client.rs index 65865d5b324bdc..2bd1ddc2ffbddb 100644 --- a/cli/lsp/client.rs +++ b/cli/lsp/client.rs @@ -12,12 +12,11 @@ use lsp_types::Uri; use tower_lsp::lsp_types as lsp; use tower_lsp::lsp_types::ConfigurationItem; -use crate::lsp::repl::get_repl_workspace_settings; - use super::config::WorkspaceSettings; use super::config::SETTINGS_SECTION; use super::lsp_custom; use super::testing::lsp_custom as testing_lsp_custom; +use crate::lsp::repl::get_repl_workspace_settings; #[derive(Debug)] pub enum TestingNotification { diff --git a/cli/lsp/code_lens.rs b/cli/lsp/code_lens.rs index a57ca3ac9fe141..c5ef5f72234834 100644 --- a/cli/lsp/code_lens.rs +++ b/cli/lsp/code_lens.rs @@ -1,13 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::lsp::logging::lsp_warn; - -use super::analysis::source_range_to_lsp_range; -use super::config::CodeLensSettings; -use super::language_server; -use super::text::LineIndex; -use super::tsc; -use super::tsc::NavigationTree; +use std::cell::RefCell; +use std::collections::HashSet; +use std::rc::Rc; +use std::sync::Arc; use deno_ast::swc::ast; use deno_ast::swc::visit::Visit; @@ -25,13 +21,17 @@ use deno_core::ModuleSpecifier; use lazy_regex::lazy_regex; use once_cell::sync::Lazy; use regex::Regex; -use std::cell::RefCell; -use std::collections::HashSet; -use std::rc::Rc; -use std::sync::Arc; use tower_lsp::jsonrpc::Error as LspError; use tower_lsp::lsp_types as lsp; +use super::analysis::source_range_to_lsp_range; +use super::config::CodeLensSettings; +use super::language_server; +use super::text::LineIndex; +use super::tsc; +use super::tsc::NavigationTree; +use crate::lsp::logging::lsp_warn; + static ABSTRACT_MODIFIER: Lazy = lazy_regex!(r"\babstract\b"); static EXPORT_MODIFIER: Lazy = lazy_regex!(r"\bexport\b"); diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs index 31f0b066ed87dd..412ca6fd32f248 100644 --- a/cli/lsp/completions.rs +++ b/cli/lsp/completions.rs @@ -1,24 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::client::Client; -use super::config::Config; -use super::config::WorkspaceSettings; -use super::documents::Documents; -use super::documents::DocumentsFilter; -use super::jsr::CliJsrSearchApi; -use super::lsp_custom; -use super::npm::CliNpmSearchApi; -use super::registries::ModuleRegistry; -use super::resolver::LspResolver; -use super::search::PackageSearchApi; -use super::tsc; - -use crate::graph_util::to_node_resolution_mode; -use crate::jsr::JsrFetchResolver; -use crate::util::path::is_importable_ext; -use crate::util::path::relative_specifier; -use deno_runtime::deno_node::SUPPORTED_BUILTIN_NODE_MODULES; - use deno_ast::LineAndColumnIndex; use deno_ast::SourceTextInfo; use deno_core::resolve_path; @@ -29,6 +10,7 @@ use deno_core::serde_json::json; use deno_core::url::Position; use deno_core::ModuleSpecifier; use deno_path_util::url_to_file_path; +use deno_runtime::deno_node::SUPPORTED_BUILTIN_NODE_MODULES; use deno_semver::jsr::JsrPackageReqReference; use deno_semver::package::PackageNv; use import_map::ImportMap; @@ -40,6 +22,23 @@ use once_cell::sync::Lazy; use regex::Regex; use tower_lsp::lsp_types as lsp; +use super::client::Client; +use super::config::Config; +use super::config::WorkspaceSettings; +use super::documents::Documents; +use super::documents::DocumentsFilter; +use super::jsr::CliJsrSearchApi; +use super::lsp_custom; +use super::npm::CliNpmSearchApi; +use super::registries::ModuleRegistry; +use super::resolver::LspResolver; +use super::search::PackageSearchApi; +use super::tsc; +use crate::graph_util::to_node_resolution_mode; +use crate::jsr::JsrFetchResolver; +use crate::util::path::is_importable_ext; +use crate::util::path::relative_specifier; + static FILE_PROTO_RE: Lazy = lazy_regex::lazy_regex!(r#"^file:/{2}(?:/[A-Za-z]:)?"#); @@ -822,16 +821,18 @@ fn get_workspace_completions( #[cfg(test)] mod tests { + use std::collections::HashMap; + + use deno_core::resolve_url; + use pretty_assertions::assert_eq; + use test_util::TempDir; + use super::*; use crate::cache::HttpCache; use crate::lsp::cache::LspCache; use crate::lsp::documents::Documents; use crate::lsp::documents::LanguageId; use crate::lsp::search::tests::TestPackageSearchApi; - use deno_core::resolve_url; - use pretty_assertions::assert_eq; - use std::collections::HashMap; - use test_util::TempDir; fn setup( open_sources: &[(&str, &str, i32, LanguageId)], diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index ff4c2978d5a4e4..8e61b523f7cd04 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1,5 +1,14 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::collections::BTreeMap; +use std::collections::BTreeSet; +use std::collections::HashMap; +use std::ops::Deref; +use std::ops::DerefMut; +use std::path::Path; +use std::path::PathBuf; +use std::sync::Arc; + use deno_ast::MediaType; use deno_config::deno_json::DenoJsonCache; use deno_config::deno_json::FmtConfig; @@ -39,14 +48,6 @@ use deno_path_util::url_to_file_path; use deno_runtime::deno_node::PackageJson; use indexmap::IndexSet; use lsp_types::ClientCapabilities; -use std::collections::BTreeMap; -use std::collections::BTreeSet; -use std::collections::HashMap; -use std::ops::Deref; -use std::ops::DerefMut; -use std::path::Path; -use std::path::PathBuf; -use std::sync::Arc; use tower_lsp::lsp_types as lsp; use super::logging::lsp_log; diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index af6fdf53a4563a..625c777a84e2ff 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -1,32 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::analysis; -use super::client::Client; -use super::config::Config; -use super::documents; -use super::documents::Document; -use super::documents::Documents; -use super::documents::DocumentsFilter; -use super::language_server; -use super::language_server::StateSnapshot; -use super::performance::Performance; -use super::tsc; -use super::tsc::TsServer; -use super::urls::uri_parse_unencoded; -use super::urls::url_to_uri; -use super::urls::LspUrlMap; - -use crate::graph_util; -use crate::graph_util::enhanced_resolution_error_message; -use crate::lsp::lsp_custom::DiagnosticBatchNotificationParams; -use crate::resolver::CliSloppyImportsResolver; -use crate::resolver::SloppyImportsCachedFs; -use crate::sys::CliSys; -use crate::tools::lint::CliLinter; -use crate::tools::lint::CliLinterOptions; -use crate::tools::lint::LintRuleProvider; -use crate::tsc::DiagnosticCategory; -use crate::util::path::to_percent_decoded_str; +use std::collections::HashMap; +use std::collections::HashSet; +use std::path::PathBuf; +use std::sync::atomic::AtomicUsize; +use std::sync::Arc; +use std::thread; use deno_ast::MediaType; use deno_config::deno_json::LintConfig; @@ -57,18 +36,39 @@ use deno_semver::package::PackageReq; use import_map::ImportMap; use import_map::ImportMapError; use log::error; -use std::collections::HashMap; -use std::collections::HashSet; -use std::path::PathBuf; -use std::sync::atomic::AtomicUsize; -use std::sync::Arc; -use std::thread; use tokio::sync::mpsc; use tokio::sync::Mutex; use tokio::time::Duration; use tokio_util::sync::CancellationToken; use tower_lsp::lsp_types as lsp; +use super::analysis; +use super::client::Client; +use super::config::Config; +use super::documents; +use super::documents::Document; +use super::documents::Documents; +use super::documents::DocumentsFilter; +use super::language_server; +use super::language_server::StateSnapshot; +use super::performance::Performance; +use super::tsc; +use super::tsc::TsServer; +use super::urls::uri_parse_unencoded; +use super::urls::url_to_uri; +use super::urls::LspUrlMap; +use crate::graph_util; +use crate::graph_util::enhanced_resolution_error_message; +use crate::lsp::lsp_custom::DiagnosticBatchNotificationParams; +use crate::resolver::CliSloppyImportsResolver; +use crate::resolver::SloppyImportsCachedFs; +use crate::sys::CliSys; +use crate::tools::lint::CliLinter; +use crate::tools::lint::CliLinterOptions; +use crate::tools::lint::LintRuleProvider; +use crate::tsc::DiagnosticCategory; +use crate::util::path::to_percent_decoded_str; + #[derive(Debug)] pub struct DiagnosticServerUpdateMessage { pub snapshot: Arc, @@ -1646,6 +1646,12 @@ fn generate_deno_diagnostics( #[cfg(test)] mod tests { + use std::sync::Arc; + + use deno_config::deno_json::ConfigFile; + use pretty_assertions::assert_eq; + use test_util::TempDir; + use super::*; use crate::lsp::cache::LspCache; use crate::lsp::config::Config; @@ -1656,11 +1662,6 @@ mod tests { use crate::lsp::language_server::StateSnapshot; use crate::lsp::resolver::LspResolver; - use deno_config::deno_json::ConfigFile; - use pretty_assertions::assert_eq; - use std::sync::Arc; - use test_util::TempDir; - fn mock_config() -> Config { let root_url = resolve_url("file:///").unwrap(); let root_uri = url_to_uri(&root_url).unwrap(); diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index d15cfe5a6cf983..34c2deee4678de 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -1,18 +1,17 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::cache::calculate_fs_version; -use super::cache::LspCache; -use super::config::Config; -use super::resolver::LspResolver; -use super::resolver::ScopeDepInfo; -use super::resolver::SingleReferrerGraphResolver; -use super::testing::TestCollector; -use super::testing::TestModule; -use super::text::LineIndex; -use super::tsc; -use super::tsc::AssetDocument; - -use crate::graph_util::CliJsrUrlProvider; +use std::borrow::Cow; +use std::collections::BTreeMap; +use std::collections::HashMap; +use std::collections::HashSet; +use std::fs; +use std::future::Future; +use std::ops::Range; +use std::pin::Pin; +use std::str::FromStr; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::Ordering; +use std::sync::Arc; use dashmap::DashMap; use deno_ast::swc::visit::VisitWith; @@ -36,20 +35,21 @@ use indexmap::IndexMap; use indexmap::IndexSet; use node_resolver::NodeResolutionKind; use node_resolver::ResolutionMode; -use std::borrow::Cow; -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::collections::HashSet; -use std::fs; -use std::future::Future; -use std::ops::Range; -use std::pin::Pin; -use std::str::FromStr; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering; -use std::sync::Arc; use tower_lsp::lsp_types as lsp; +use super::cache::calculate_fs_version; +use super::cache::LspCache; +use super::config::Config; +use super::resolver::LspResolver; +use super::resolver::ScopeDepInfo; +use super::resolver::SingleReferrerGraphResolver; +use super::testing::TestCollector; +use super::testing::TestModule; +use super::text::LineIndex; +use super::tsc; +use super::tsc::AssetDocument; +use crate::graph_util::CliJsrUrlProvider; + pub const DOCUMENT_SCHEMES: [&str; 5] = ["data", "blob", "file", "http", "https"]; @@ -1754,9 +1754,6 @@ fn bytes_to_content( #[cfg(test)] mod tests { - use super::*; - use crate::lsp::cache::LspCache; - use deno_config::deno_json::ConfigFile; use deno_config::deno_json::ConfigParseOptions; use deno_core::serde_json; @@ -1764,6 +1761,9 @@ mod tests { use pretty_assertions::assert_eq; use test_util::TempDir; + use super::*; + use crate::lsp::cache::LspCache; + async fn setup() -> (Documents, LspCache, TempDir) { let temp_dir = TempDir::new(); temp_dir.create_dir_all(".deno_dir"); diff --git a/cli/lsp/jsr.rs b/cli/lsp/jsr.rs index fc30de2ae08a2c..48bac7ac4780b9 100644 --- a/cli/lsp/jsr.rs +++ b/cli/lsp/jsr.rs @@ -1,11 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::args::jsr_api_url; -use crate::args::jsr_url; -use crate::file_fetcher::CliFileFetcher; -use crate::file_fetcher::TextDecodedFile; -use crate::jsr::partial_jsr_package_version_info_from_slice; -use crate::jsr::JsrFetchResolver; +use std::collections::HashMap; +use std::sync::Arc; + use dashmap::DashMap; use deno_cache_dir::HttpCache; use deno_core::anyhow::anyhow; @@ -21,11 +18,15 @@ use deno_semver::package::PackageReq; use deno_semver::StackString; use deno_semver::Version; use serde::Deserialize; -use std::collections::HashMap; -use std::sync::Arc; use super::config::ConfigData; use super::search::PackageSearchApi; +use crate::args::jsr_api_url; +use crate::args::jsr_url; +use crate::file_fetcher::CliFileFetcher; +use crate::file_fetcher::TextDecodedFile; +use crate::jsr::partial_jsr_package_version_info_from_slice; +use crate::jsr::JsrFetchResolver; /// Keep in sync with `JsrFetchResolver`! #[derive(Debug)] diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 9ab1d9786ccc17..98b2fb146230eb 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -1,5 +1,16 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::collections::BTreeMap; +use std::collections::BTreeSet; +use std::collections::HashMap; +use std::collections::HashSet; +use std::collections::VecDeque; +use std::env; +use std::fmt::Write as _; +use std::path::PathBuf; +use std::str::FromStr; +use std::sync::Arc; + use deno_ast::MediaType; use deno_cache_dir::file_fetcher::CacheSetting; use deno_config::workspace::WorkspaceDirectory; @@ -27,16 +38,6 @@ use node_resolver::NodeResolutionKind; use node_resolver::ResolutionMode; use serde::Deserialize; use serde_json::from_value; -use std::collections::BTreeMap; -use std::collections::BTreeSet; -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::env; -use std::fmt::Write as _; -use std::path::PathBuf; -use std::str::FromStr; -use std::sync::Arc; use tokio::sync::mpsc::unbounded_channel; use tokio::sync::mpsc::UnboundedReceiver; use tokio::sync::mpsc::UnboundedSender; @@ -3963,10 +3964,11 @@ impl Inner { #[cfg(test)] mod tests { - use super::*; use pretty_assertions::assert_eq; use test_util::TempDir; + use super::*; + #[test] fn test_walk_workspace() { let temp_dir = TempDir::new(); diff --git a/cli/lsp/logging.rs b/cli/lsp/logging.rs index 2b85d77ec1aa17..cb803b94784248 100644 --- a/cli/lsp/logging.rs +++ b/cli/lsp/logging.rs @@ -1,8 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use chrono::DateTime; -use chrono::Utc; -use deno_core::parking_lot::Mutex; use std::fs; use std::io::prelude::*; use std::path::Path; @@ -12,6 +9,10 @@ use std::sync::atomic::Ordering; use std::thread; use std::time::SystemTime; +use chrono::DateTime; +use chrono::Utc; +use deno_core::parking_lot::Mutex; + static LSP_DEBUG_FLAG: AtomicBool = AtomicBool::new(false); static LSP_LOG_LEVEL: AtomicUsize = AtomicUsize::new(log::Level::Info as usize); static LSP_WARN_LEVEL: AtomicUsize = diff --git a/cli/lsp/mod.rs b/cli/lsp/mod.rs index afb949f68d0efa..0b00f8ef683634 100644 --- a/cli/lsp/mod.rs +++ b/cli/lsp/mod.rs @@ -2,15 +2,14 @@ use deno_core::error::AnyError; use deno_core::unsync::spawn; +pub use repl::ReplCompletionItem; +pub use repl::ReplLanguageServer; use tower_lsp::LspService; use tower_lsp::Server; +use self::diagnostics::should_send_diagnostic_batch_index_notifications; use crate::lsp::language_server::LanguageServer; use crate::util::sync::AsyncFlag; -pub use repl::ReplCompletionItem; -pub use repl::ReplLanguageServer; - -use self::diagnostics::should_send_diagnostic_batch_index_notifications; mod analysis; mod cache; diff --git a/cli/lsp/npm.rs b/cli/lsp/npm.rs index 18c7e2fccfc587..8b96eed66f0774 100644 --- a/cli/lsp/npm.rs +++ b/cli/lsp/npm.rs @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::sync::Arc; + use dashmap::DashMap; use deno_core::anyhow::anyhow; use deno_core::error::AnyError; @@ -8,15 +10,13 @@ use deno_npm::npm_rc::NpmRc; use deno_semver::package::PackageNv; use deno_semver::Version; use serde::Deserialize; -use std::sync::Arc; +use super::search::PackageSearchApi; use crate::args::npm_registry_url; use crate::file_fetcher::CliFileFetcher; use crate::file_fetcher::TextDecodedFile; use crate::npm::NpmFetchResolver; -use super::search::PackageSearchApi; - #[derive(Debug)] pub struct CliNpmSearchApi { file_fetcher: Arc, diff --git a/cli/lsp/parent_process_checker.rs b/cli/lsp/parent_process_checker.rs index b8a42cd1a4deb9..287880ae323785 100644 --- a/cli/lsp/parent_process_checker.rs +++ b/cli/lsp/parent_process_checker.rs @@ -52,10 +52,12 @@ fn is_process_active(process_id: u32) -> bool { #[cfg(test)] mod test { - use super::is_process_active; use std::process::Command; + use test_util::deno_exe_path; + use super::is_process_active; + #[test] fn process_active() { // launch a long running process diff --git a/cli/lsp/path_to_regex.rs b/cli/lsp/path_to_regex.rs index 88d8a2ec68d94a..10b0cfbdc8906d 100644 --- a/cli/lsp/path_to_regex.rs +++ b/cli/lsp/path_to_regex.rs @@ -26,15 +26,16 @@ // THE SOFTWARE. // +use std::collections::HashMap; +use std::fmt; +use std::fmt::Write as _; +use std::iter::Peekable; + use deno_core::anyhow::anyhow; use deno_core::error::AnyError; use fancy_regex::Regex as FancyRegex; use once_cell::sync::Lazy; use regex::Regex; -use std::collections::HashMap; -use std::fmt; -use std::fmt::Write as _; -use std::iter::Peekable; static ESCAPE_STRING_RE: Lazy = lazy_regex::lazy_regex!(r"([.+*?=^!:${}()\[\]|/\\])"); diff --git a/cli/lsp/performance.rs b/cli/lsp/performance.rs index b3dc53b283afb7..360bdf103ef3f5 100644 --- a/cli/lsp/performance.rs +++ b/cli/lsp/performance.rs @@ -1,9 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::parking_lot::Mutex; -use deno_core::serde::Deserialize; -use deno_core::serde::Serialize; -use deno_core::serde_json::json; use std::cmp; use std::collections::HashMap; use std::collections::VecDeque; @@ -12,6 +8,11 @@ use std::sync::Arc; use std::time::Duration; use std::time::Instant; +use deno_core::parking_lot::Mutex; +use deno_core::serde::Deserialize; +use deno_core::serde::Serialize; +use deno_core::serde_json::json; + use super::logging::lsp_debug; #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)] diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs index c8dd7fa1a79fbe..be36eeb73d7e69 100644 --- a/cli/lsp/registries.rs +++ b/cli/lsp/registries.rs @@ -1,5 +1,26 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::collections::HashMap; +use std::path::PathBuf; +use std::sync::Arc; + +use deno_cache_dir::file_fetcher::CacheSetting; +use deno_core::anyhow::anyhow; +use deno_core::error::AnyError; +use deno_core::serde::Deserialize; +use deno_core::serde_json; +use deno_core::serde_json::json; +use deno_core::serde_json::Value; +use deno_core::url::ParseError; +use deno_core::url::Position; +use deno_core::url::Url; +use deno_core::ModuleSpecifier; +use deno_graph::Dependency; +use log::error; +use once_cell::sync::Lazy; +use tower_lsp::lsp_types as lsp; + use super::completions::IMPORT_COMMIT_CHARS; use super::logging::lsp_log; use super::path_to_regex::parse; @@ -11,7 +32,6 @@ use super::path_to_regex::Matcher; use super::path_to_regex::StringOrNumber; use super::path_to_regex::StringOrVec; use super::path_to_regex::Token; - use crate::cache::GlobalHttpCache; use crate::cache::HttpCache; use crate::file_fetcher::CliFileFetcher; @@ -21,26 +41,6 @@ use crate::file_fetcher::TextDecodedFile; use crate::http_util::HttpClientProvider; use crate::sys::CliSys; -use deno_cache_dir::file_fetcher::CacheSetting; -use deno_core::anyhow::anyhow; -use deno_core::error::AnyError; -use deno_core::serde::Deserialize; -use deno_core::serde_json; -use deno_core::serde_json::json; -use deno_core::serde_json::Value; -use deno_core::url::ParseError; -use deno_core::url::Position; -use deno_core::url::Url; -use deno_core::ModuleSpecifier; -use deno_graph::Dependency; -use log::error; -use once_cell::sync::Lazy; -use std::borrow::Cow; -use std::collections::HashMap; -use std::path::PathBuf; -use std::sync::Arc; -use tower_lsp::lsp_types as lsp; - const CONFIG_PATH: &str = "/.well-known/deno-import-intellisense.json"; const COMPONENT: &percent_encoding::AsciiSet = &percent_encoding::CONTROLS .add(b' ') @@ -1128,9 +1128,10 @@ FetchPermissionsOptionRef::AllowAll, #[cfg(test)] mod tests { - use super::*; use test_util::TempDir; + use super::*; + #[test] fn test_validate_registry_configuration() { assert!(validate_config(&RegistryConfigurationJson { diff --git a/cli/lsp/resolver.rs b/cli/lsp/resolver.rs index 2dec5266f4143d..7fb4e855290014 100644 --- a/cli/lsp/resolver.rs +++ b/cli/lsp/resolver.rs @@ -1,5 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::collections::BTreeMap; +use std::collections::BTreeSet; +use std::collections::HashMap; +use std::collections::HashSet; +use std::sync::Arc; + use dashmap::DashMap; use deno_ast::MediaType; use deno_cache_dir::file_fetcher::CacheSetting; @@ -28,12 +35,6 @@ use indexmap::IndexMap; use node_resolver::InNpmPackageChecker; use node_resolver::NodeResolutionKind; use node_resolver::ResolutionMode; -use std::borrow::Cow; -use std::collections::BTreeMap; -use std::collections::BTreeSet; -use std::collections::HashMap; -use std::collections::HashSet; -use std::sync::Arc; use super::cache::LspCache; use super::jsr::JsrCacheResolver; diff --git a/cli/lsp/search.rs b/cli/lsp/search.rs index c98acde6f1b4cb..7d2760c1de9784 100644 --- a/cli/lsp/search.rs +++ b/cli/lsp/search.rs @@ -1,9 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::sync::Arc; + use deno_core::error::AnyError; use deno_semver::package::PackageNv; use deno_semver::Version; -use std::sync::Arc; #[async_trait::async_trait] pub trait PackageSearchApi { @@ -15,10 +16,12 @@ pub trait PackageSearchApi { #[cfg(test)] pub mod tests { - use super::*; - use deno_core::anyhow::anyhow; use std::collections::BTreeMap; + use deno_core::anyhow::anyhow; + + use super::*; + #[derive(Debug, Default)] pub struct TestPackageSearchApi { /// [(name -> [(version -> [export])])] diff --git a/cli/lsp/semantic_tokens.rs b/cli/lsp/semantic_tokens.rs index 0cf154d0ff71d4..cc880de8b6178a 100644 --- a/cli/lsp/semantic_tokens.rs +++ b/cli/lsp/semantic_tokens.rs @@ -7,6 +7,7 @@ use std::ops::Index; use std::ops::IndexMut; + use tower_lsp::lsp_types as lsp; use tower_lsp::lsp_types::SemanticToken; use tower_lsp::lsp_types::SemanticTokenModifier; diff --git a/cli/lsp/testing/collectors.rs b/cli/lsp/testing/collectors.rs index 2dd7ec0d96d342..141d34d79df6cf 100644 --- a/cli/lsp/testing/collectors.rs +++ b/cli/lsp/testing/collectors.rs @@ -1,8 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::lsp::analysis::source_range_to_lsp_range; - -use super::definitions::TestModule; +use std::collections::HashMap; +use std::collections::HashSet; use deno_ast::swc::ast; use deno_ast::swc::visit::Visit; @@ -11,10 +10,11 @@ use deno_ast::SourceRangedForSpanned; use deno_ast::SourceTextInfo; use deno_core::ModuleSpecifier; use lsp::Range; -use std::collections::HashMap; -use std::collections::HashSet; use tower_lsp::lsp_types as lsp; +use super::definitions::TestModule; +use crate::lsp::analysis::source_range_to_lsp_range; + /// Parse an arrow expression for any test steps and return them. fn visit_arrow( arrow_expr: &ast::ArrowExpr, @@ -626,12 +626,12 @@ impl Visit for TestCollector { #[cfg(test)] pub mod tests { - use crate::lsp::testing::definitions::TestDefinition; - - use super::*; use deno_core::resolve_url; use lsp::Position; + use super::*; + use crate::lsp::testing::definitions::TestDefinition; + pub fn new_range(l1: u32, c1: u32, l2: u32, c2: u32) -> Range { Range::new(Position::new(l1, c1), Position::new(l2, c2)) } diff --git a/cli/lsp/testing/definitions.rs b/cli/lsp/testing/definitions.rs index f23411852fd5a0..44ea5ce6fe2ee2 100644 --- a/cli/lsp/testing/definitions.rs +++ b/cli/lsp/testing/definitions.rs @@ -1,8 +1,15 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::collections::HashMap; +use std::collections::HashSet; + +use deno_core::error::AnyError; +use deno_core::ModuleSpecifier; +use lsp::Range; +use tower_lsp::lsp_types as lsp; + use super::lsp_custom; use super::lsp_custom::TestData; - use crate::lsp::client::TestingNotification; use crate::lsp::logging::lsp_warn; use crate::lsp::urls::url_to_uri; @@ -10,13 +17,6 @@ use crate::tools::test::TestDescription; use crate::tools::test::TestStepDescription; use crate::util::checksum; -use deno_core::error::AnyError; -use deno_core::ModuleSpecifier; -use lsp::Range; -use std::collections::HashMap; -use std::collections::HashSet; -use tower_lsp::lsp_types as lsp; - #[derive(Debug, Clone, PartialEq)] pub struct TestDefinition { pub id: String, diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs index 88fb496e4eccda..3378891316fd89 100644 --- a/cli/lsp/testing/execution.rs +++ b/cli/lsp/testing/execution.rs @@ -1,10 +1,34 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::collections::HashMap; +use std::collections::HashSet; +use std::num::NonZeroUsize; +use std::sync::Arc; +use std::time::Duration; +use std::time::Instant; + +use deno_core::anyhow::anyhow; +use deno_core::error::AnyError; +use deno_core::error::JsError; +use deno_core::futures::future; +use deno_core::futures::stream; +use deno_core::futures::StreamExt; +use deno_core::parking_lot::RwLock; +use deno_core::unsync::spawn; +use deno_core::unsync::spawn_blocking; +use deno_core::ModuleSpecifier; +use deno_runtime::deno_permissions::Permissions; +use deno_runtime::deno_permissions::PermissionsContainer; +use deno_runtime::tokio_util::create_and_run_current_thread; +use indexmap::IndexMap; +use tokio_util::sync::CancellationToken; +use tower_lsp::lsp_types as lsp; + use super::definitions::TestDefinition; use super::definitions::TestModule; use super::lsp_custom; use super::server::TestServerTests; - use crate::args::flags_from_vec; use crate::args::DenoSubcommand; use crate::factory::CliFactory; @@ -20,30 +44,6 @@ use crate::tools::test::create_test_event_channel; use crate::tools::test::FailFastTracker; use crate::tools::test::TestFailureFormatOptions; -use deno_core::anyhow::anyhow; -use deno_core::error::AnyError; -use deno_core::error::JsError; -use deno_core::futures::future; -use deno_core::futures::stream; -use deno_core::futures::StreamExt; -use deno_core::parking_lot::RwLock; -use deno_core::unsync::spawn; -use deno_core::unsync::spawn_blocking; -use deno_core::ModuleSpecifier; -use deno_runtime::deno_permissions::Permissions; -use deno_runtime::deno_permissions::PermissionsContainer; -use deno_runtime::tokio_util::create_and_run_current_thread; -use indexmap::IndexMap; -use std::borrow::Cow; -use std::collections::HashMap; -use std::collections::HashSet; -use std::num::NonZeroUsize; -use std::sync::Arc; -use std::time::Duration; -use std::time::Instant; -use tokio_util::sync::CancellationToken; -use tower_lsp::lsp_types as lsp; - /// Logic to convert a test request into a set of test modules to be tested and /// any filters to be applied to those tests fn as_queue_and_filters( @@ -794,9 +794,10 @@ impl LspTestReporter { #[cfg(test)] mod tests { + use deno_core::serde_json::json; + use super::*; use crate::lsp::testing::collectors::tests::new_range; - use deno_core::serde_json::json; #[test] fn test_as_queue_and_filters() { diff --git a/cli/lsp/testing/server.rs b/cli/lsp/testing/server.rs index c9c39d9ffc4d9e..a4b286671ef76e 100644 --- a/cli/lsp/testing/server.rs +++ b/cli/lsp/testing/server.rs @@ -1,16 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::definitions::TestModule; -use super::execution::TestRun; -use super::lsp_custom; - -use crate::lsp::client::Client; -use crate::lsp::client::TestingNotification; -use crate::lsp::config; -use crate::lsp::documents::DocumentsFilter; -use crate::lsp::language_server::StateSnapshot; -use crate::lsp::performance::Performance; -use crate::lsp::urls::url_to_uri; +use std::collections::HashMap; +use std::collections::HashSet; +use std::sync::Arc; +use std::thread; use deno_core::error::AnyError; use deno_core::parking_lot::Mutex; @@ -18,15 +11,22 @@ use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::ModuleSpecifier; use deno_runtime::tokio_util::create_basic_runtime; -use std::collections::HashMap; -use std::collections::HashSet; -use std::sync::Arc; -use std::thread; use tokio::sync::mpsc; use tower_lsp::jsonrpc::Error as LspError; use tower_lsp::jsonrpc::Result as LspResult; use tower_lsp::lsp_types as lsp; +use super::definitions::TestModule; +use super::execution::TestRun; +use super::lsp_custom; +use crate::lsp::client::Client; +use crate::lsp::client::TestingNotification; +use crate::lsp::config; +use crate::lsp::documents::DocumentsFilter; +use crate::lsp::language_server::StateSnapshot; +use crate::lsp::performance::Performance; +use crate::lsp::urls::url_to_uri; + fn as_delete_notification( url: &ModuleSpecifier, ) -> Result { diff --git a/cli/lsp/text.rs b/cli/lsp/text.rs index 88f27915bb0f56..3c9721bdc99520 100644 --- a/cli/lsp/text.rs +++ b/cli/lsp/text.rs @@ -1,10 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::collections::HashMap; + use deno_core::error::custom_error; use deno_core::error::AnyError; use dissimilar::diff; use dissimilar::Chunk; -use std::collections::HashMap; use text_size::TextRange; use text_size::TextSize; use tower_lsp::jsonrpc; diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index f8b972511f377c..cdd46c2ded1b5a 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -1,52 +1,29 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::analysis::CodeActionData; -use super::code_lens; -use super::config; -use super::config::LspTsConfig; -use super::documents::AssetOrDocument; -use super::documents::Document; -use super::documents::DocumentsFilter; -use super::language_server; -use super::language_server::StateSnapshot; -use super::performance::Performance; -use super::performance::PerformanceMark; -use super::refactor::RefactorCodeActionData; -use super::refactor::ALL_KNOWN_REFACTOR_ACTION_KINDS; -use super::refactor::EXTRACT_CONSTANT; -use super::refactor::EXTRACT_INTERFACE; -use super::refactor::EXTRACT_TYPE; -use super::semantic_tokens; -use super::semantic_tokens::SemanticTokensBuilder; -use super::text::LineIndex; -use super::urls::uri_to_url; -use super::urls::url_to_uri; -use super::urls::INVALID_SPECIFIER; -use super::urls::INVALID_URI; - -use crate::args::jsr_url; -use crate::args::FmtOptionsConfig; -use crate::lsp::logging::lsp_warn; -use crate::tsc; -use crate::tsc::ResolveArgs; -use crate::tsc::MISSING_DEPENDENCY_SPECIFIER; -use crate::util::path::relative_specifier; -use crate::util::path::to_percent_decoded_str; -use crate::util::result::InfallibleResultExt; -use crate::util::v8::convert; -use crate::worker::create_isolate_create_params; -use deno_core::convert::Smi; -use deno_core::convert::ToV8; -use deno_core::error::StdAnyError; -use deno_core::futures::stream::FuturesOrdered; -use deno_core::futures::StreamExt; +use std::cell::RefCell; +use std::cmp; +use std::collections::BTreeMap; +use std::collections::HashMap; +use std::collections::HashSet; +use std::convert::Infallible; +use std::net::SocketAddr; +use std::ops::Range; +use std::path::Path; +use std::rc::Rc; +use std::sync::Arc; +use std::thread; use dashmap::DashMap; use deno_ast::MediaType; use deno_core::anyhow::anyhow; use deno_core::anyhow::Context as _; +use deno_core::convert::Smi; +use deno_core::convert::ToV8; use deno_core::error::AnyError; +use deno_core::error::StdAnyError; +use deno_core::futures::stream::FuturesOrdered; use deno_core::futures::FutureExt; +use deno_core::futures::StreamExt; use deno_core::op2; use deno_core::parking_lot::Mutex; use deno_core::resolve_url; @@ -77,18 +54,6 @@ use regex::Captures; use regex::Regex; use serde_repr::Deserialize_repr; use serde_repr::Serialize_repr; -use std::cell::RefCell; -use std::cmp; -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::collections::HashSet; -use std::convert::Infallible; -use std::net::SocketAddr; -use std::ops::Range; -use std::path::Path; -use std::rc::Rc; -use std::sync::Arc; -use std::thread; use text_size::TextRange; use text_size::TextSize; use tokio::sync::mpsc; @@ -99,6 +64,41 @@ use tower_lsp::jsonrpc::Error as LspError; use tower_lsp::jsonrpc::Result as LspResult; use tower_lsp::lsp_types as lsp; +use super::analysis::CodeActionData; +use super::code_lens; +use super::config; +use super::config::LspTsConfig; +use super::documents::AssetOrDocument; +use super::documents::Document; +use super::documents::DocumentsFilter; +use super::language_server; +use super::language_server::StateSnapshot; +use super::performance::Performance; +use super::performance::PerformanceMark; +use super::refactor::RefactorCodeActionData; +use super::refactor::ALL_KNOWN_REFACTOR_ACTION_KINDS; +use super::refactor::EXTRACT_CONSTANT; +use super::refactor::EXTRACT_INTERFACE; +use super::refactor::EXTRACT_TYPE; +use super::semantic_tokens; +use super::semantic_tokens::SemanticTokensBuilder; +use super::text::LineIndex; +use super::urls::uri_to_url; +use super::urls::url_to_uri; +use super::urls::INVALID_SPECIFIER; +use super::urls::INVALID_URI; +use crate::args::jsr_url; +use crate::args::FmtOptionsConfig; +use crate::lsp::logging::lsp_warn; +use crate::tsc; +use crate::tsc::ResolveArgs; +use crate::tsc::MISSING_DEPENDENCY_SPECIFIER; +use crate::util::path::relative_specifier; +use crate::util::path::to_percent_decoded_str; +use crate::util::result::InfallibleResultExt; +use crate::util::v8::convert; +use crate::worker::create_isolate_create_params; + static BRACKET_ACCESSOR_RE: Lazy = lazy_regex!(r#"^\[['"](.+)[\['"]\]$"#); static CAPTION_RE: Lazy = @@ -5541,6 +5541,9 @@ impl TscRequest { #[cfg(test)] mod tests { + use pretty_assertions::assert_eq; + use test_util::TempDir; + use super::*; use crate::cache::HttpCache; use crate::lsp::cache::LspCache; @@ -5550,8 +5553,6 @@ mod tests { use crate::lsp::documents::LanguageId; use crate::lsp::resolver::LspResolver; use crate::lsp::text::LineIndex; - use pretty_assertions::assert_eq; - use test_util::TempDir; async fn setup( ts_config: Value, diff --git a/cli/lsp/urls.rs b/cli/lsp/urls.rs index 6c7da4f1343d6f..84dd3581d7def1 100644 --- a/cli/lsp/urls.rs +++ b/cli/lsp/urls.rs @@ -1,5 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::collections::HashMap; +use std::str::FromStr; +use std::sync::Arc; + use deno_ast::MediaType; use deno_core::error::AnyError; use deno_core::parking_lot::Mutex; @@ -8,9 +12,6 @@ use deno_core::url::Url; use deno_core::ModuleSpecifier; use lsp_types::Uri; use once_cell::sync::Lazy; -use std::collections::HashMap; -use std::str::FromStr; -use std::sync::Arc; use super::cache::LspCache; use super::logging::lsp_warn; @@ -307,9 +308,10 @@ fn file_like_to_file_specifier(specifier: &Url) -> Option { #[cfg(test)] mod tests { - use super::*; use deno_core::resolve_url; + use super::*; + #[test] fn test_hash_data_specifier() { let fixture = resolve_url("data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=").unwrap(); diff --git a/cli/main.rs b/cli/main.rs index c3c7286e71ace4..f3f3254b140361 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -28,37 +28,37 @@ mod util; mod version; mod worker; -use crate::args::flags_from_vec; -use crate::args::DenoSubcommand; -use crate::args::Flags; -use crate::util::display; -use crate::util::v8::get_v8_flags_from_env; -use crate::util::v8::init_v8_flags; +use std::env; +use std::future::Future; +use std::io::IsTerminal; +use std::ops::Deref; +use std::path::PathBuf; +use std::sync::Arc; use args::TaskFlags; -use deno_resolver::npm::ByonmResolvePkgFolderFromDenoReqError; -use deno_resolver::npm::ResolvePkgFolderFromDenoReqError; -use deno_runtime::WorkerExecutionMode; -pub use deno_runtime::UNSTABLE_GRANULAR_FLAGS; - use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::error::JsError; use deno_core::futures::FutureExt; use deno_core::unsync::JoinHandle; use deno_npm::resolution::SnapshotFromLockfileError; +use deno_resolver::npm::ByonmResolvePkgFolderFromDenoReqError; +use deno_resolver::npm::ResolvePkgFolderFromDenoReqError; use deno_runtime::fmt_errors::format_js_error; use deno_runtime::tokio_util::create_and_run_current_thread_with_maybe_metrics; +use deno_runtime::WorkerExecutionMode; +pub use deno_runtime::UNSTABLE_GRANULAR_FLAGS; use deno_terminal::colors; use factory::CliFactory; use standalone::MODULE_NOT_FOUND; use standalone::UNSUPPORTED_SCHEME; -use std::env; -use std::future::Future; -use std::io::IsTerminal; -use std::ops::Deref; -use std::path::PathBuf; -use std::sync::Arc; + +use crate::args::flags_from_vec; +use crate::args::DenoSubcommand; +use crate::args::Flags; +use crate::util::display; +use crate::util::v8::get_v8_flags_from_env; +use crate::util::v8::init_v8_flags; #[cfg(feature = "dhat-heap")] #[global_allocator] diff --git a/cli/mainrt.rs b/cli/mainrt.rs index 2b767ea89cdcb3..19e010fb5369be 100644 --- a/cli/mainrt.rs +++ b/cli/mainrt.rs @@ -24,6 +24,12 @@ mod util; mod version; mod worker; +use std::borrow::Cow; +use std::collections::HashMap; +use std::env; +use std::env::current_exe; +use std::sync::Arc; + use deno_core::error::generic_error; use deno_core::error::AnyError; use deno_core::error::JsError; @@ -34,12 +40,6 @@ use deno_terminal::colors; use indexmap::IndexMap; use standalone::DenoCompileFileSystem; -use std::borrow::Cow; -use std::collections::HashMap; -use std::env; -use std::env::current_exe; -use std::sync::Arc; - use crate::args::Flags; pub(crate) fn unstable_exit_cb(feature: &str, api_name: &str) { diff --git a/cli/module_loader.rs b/cli/module_loader.rs index ea40dbe6094a4a..c2720ac5adc08a 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -11,8 +11,6 @@ use std::sync::atomic::AtomicU16; use std::sync::atomic::Ordering; use std::sync::Arc; -use crate::node::CliNodeResolver; -use crate::sys::CliSys; use deno_ast::MediaType; use deno_ast::ModuleKind; use deno_core::anyhow::anyhow; @@ -66,6 +64,7 @@ use crate::graph_container::ModuleGraphUpdatePermit; use crate::graph_util::CreateGraphOptions; use crate::graph_util::ModuleGraphBuilder; use crate::node::CliNodeCodeTranslator; +use crate::node::CliNodeResolver; use crate::npm::CliNpmResolver; use crate::resolver::CjsTracker; use crate::resolver::CliNpmReqResolver; @@ -73,6 +72,7 @@ use crate::resolver::CliResolver; use crate::resolver::ModuleCodeStringSource; use crate::resolver::NotSupportedKindInNpmError; use crate::resolver::NpmModuleLoader; +use crate::sys::CliSys; use crate::tools::check; use crate::tools::check::TypeChecker; use crate::util::progress_bar::ProgressBar; @@ -1161,9 +1161,10 @@ impl NodeRequireLoader #[cfg(test)] mod tests { - use super::*; use deno_graph::ParsedSourceStore; + use super::*; + #[tokio::test] async fn test_inflight_module_loads_tracker() { let tracker = InFlightModuleLoadsTracker { diff --git a/cli/npm/byonm.rs b/cli/npm/byonm.rs index ca89a7399ef5cf..b8feb52f392485 100644 --- a/cli/npm/byonm.rs +++ b/cli/npm/byonm.rs @@ -4,7 +4,6 @@ use std::borrow::Cow; use std::path::Path; use std::sync::Arc; -use crate::sys::CliSys; use deno_core::error::AnyError; use deno_core::serde_json; use deno_resolver::npm::ByonmNpmResolver; @@ -14,11 +13,11 @@ use deno_runtime::deno_node::NodePermissions; use deno_runtime::ops::process::NpmProcessStateProvider; use node_resolver::NpmPackageFolderResolver; -use crate::args::NpmProcessState; -use crate::args::NpmProcessStateKind; - use super::CliNpmResolver; use super::InnerCliNpmResolverRef; +use crate::args::NpmProcessState; +use crate::args::NpmProcessStateKind; +use crate::sys::CliSys; pub type CliByonmNpmResolverCreateOptions = ByonmNpmResolverCreateOptions; diff --git a/cli/npm/managed/mod.rs b/cli/npm/managed/mod.rs index 97a87dd9b88a67..0422445e6244db 100644 --- a/cli/npm/managed/mod.rs +++ b/cli/npm/managed/mod.rs @@ -5,7 +5,6 @@ use std::path::Path; use std::path::PathBuf; use std::sync::Arc; -use crate::sys::CliSys; use deno_ast::ModuleSpecifier; use deno_cache_dir::npm::NpmCacheDir; use deno_core::anyhow::Context; @@ -35,20 +34,9 @@ use node_resolver::InNpmPackageChecker; use node_resolver::NpmPackageFolderResolver; use resolution::AddPkgReqsResult; -use crate::args::CliLockfile; -use crate::args::LifecycleScriptsConfig; -use crate::args::NpmInstallDepsProvider; -use crate::args::NpmProcessState; -use crate::args::NpmProcessStateKind; -use crate::args::PackageJsonDepValueParseWithLocationError; -use crate::cache::FastInsecureHasher; -use crate::util::progress_bar::ProgressBar; -use crate::util::sync::AtomicFlag; - use self::resolution::NpmResolution; use self::resolvers::create_npm_fs_resolver; use self::resolvers::NpmPackageFsResolver; - use super::CliNpmCache; use super::CliNpmCacheHttpClient; use super::CliNpmRegistryInfoProvider; @@ -56,6 +44,16 @@ use super::CliNpmResolver; use super::CliNpmTarballCache; use super::InnerCliNpmResolverRef; use super::ResolvePkgFolderFromDenoReqError; +use crate::args::CliLockfile; +use crate::args::LifecycleScriptsConfig; +use crate::args::NpmInstallDepsProvider; +use crate::args::NpmProcessState; +use crate::args::NpmProcessStateKind; +use crate::args::PackageJsonDepValueParseWithLocationError; +use crate::cache::FastInsecureHasher; +use crate::sys::CliSys; +use crate::util::progress_bar::ProgressBar; +use crate::util::sync::AtomicFlag; mod resolution; mod resolvers; diff --git a/cli/npm/managed/resolvers/common/bin_entries.rs b/cli/npm/managed/resolvers/common/bin_entries.rs index ca47b9a08696a5..5f203a2ba00f60 100644 --- a/cli/npm/managed/resolvers/common/bin_entries.rs +++ b/cli/npm/managed/resolvers/common/bin_entries.rs @@ -1,16 +1,18 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::npm::managed::NpmResolutionPackage; -use deno_core::anyhow::Context; -use deno_core::error::AnyError; -use deno_npm::resolution::NpmResolutionSnapshot; -use deno_npm::NpmPackageId; use std::collections::HashMap; use std::collections::HashSet; use std::collections::VecDeque; use std::path::Path; use std::path::PathBuf; +use deno_core::anyhow::Context; +use deno_core::error::AnyError; +use deno_npm::resolution::NpmResolutionSnapshot; +use deno_npm::NpmPackageId; + +use crate::npm::managed::NpmResolutionPackage; + #[derive(Default)] pub struct BinEntries<'a> { /// Packages that have colliding bin names diff --git a/cli/npm/managed/resolvers/common/lifecycle_scripts.rs b/cli/npm/managed/resolvers/common/lifecycle_scripts.rs index 958c4bcd195b11..c6527b14580820 100644 --- a/cli/npm/managed/resolvers/common/lifecycle_scripts.rs +++ b/cli/npm/managed/resolvers/common/lifecycle_scripts.rs @@ -1,24 +1,24 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::bin_entries::BinEntries; -use crate::args::LifecycleScriptsConfig; -use crate::task_runner::TaskStdio; -use crate::util::progress_bar::ProgressBar; -use deno_core::anyhow::Context; -use deno_npm::resolution::NpmResolutionSnapshot; -use deno_runtime::deno_io::FromRawIoHandle; -use deno_semver::package::PackageNv; -use deno_semver::Version; -use deno_task_shell::KillSignal; use std::borrow::Cow; use std::collections::HashSet; -use std::rc::Rc; - use std::path::Path; use std::path::PathBuf; +use std::rc::Rc; +use deno_core::anyhow::Context; use deno_core::error::AnyError; +use deno_npm::resolution::NpmResolutionSnapshot; use deno_npm::NpmResolutionPackage; +use deno_runtime::deno_io::FromRawIoHandle; +use deno_semver::package::PackageNv; +use deno_semver::Version; +use deno_task_shell::KillSignal; + +use super::bin_entries::BinEntries; +use crate::args::LifecycleScriptsConfig; +use crate::task_runner::TaskStdio; +use crate::util::progress_bar::ProgressBar; pub trait LifecycleScriptsStrategy { fn can_run_scripts(&self) -> bool { diff --git a/cli/npm/managed/resolvers/global.rs b/cli/npm/managed/resolvers/global.rs index 77e0d0ea3e4646..44157464b87a6f 100644 --- a/cli/npm/managed/resolvers/global.rs +++ b/cli/npm/managed/resolvers/global.rs @@ -7,11 +7,6 @@ use std::path::Path; use std::path::PathBuf; use std::sync::Arc; -use crate::colors; -use crate::npm::managed::PackageCaching; -use crate::npm::CliNpmCache; -use crate::npm::CliNpmTarballCache; -use crate::sys::CliSys; use async_trait::async_trait; use deno_ast::ModuleSpecifier; use deno_core::error::AnyError; @@ -24,14 +19,18 @@ use node_resolver::errors::PackageFolderResolveError; use node_resolver::errors::PackageNotFoundError; use node_resolver::errors::ReferrerNotFoundError; -use crate::args::LifecycleScriptsConfig; -use crate::cache::FastInsecureHasher; - use super::super::resolution::NpmResolution; use super::common::cache_packages; use super::common::lifecycle_scripts::LifecycleScriptsStrategy; use super::common::NpmPackageFsResolver; use super::common::RegistryReadPermissionChecker; +use crate::args::LifecycleScriptsConfig; +use crate::cache::FastInsecureHasher; +use crate::colors; +use crate::npm::managed::PackageCaching; +use crate::npm::CliNpmCache; +use crate::npm::CliNpmTarballCache; +use crate::sys::CliSys; /// Resolves packages from the global npm cache. #[derive(Debug)] diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs index 5c93c228e81d64..bff881d5f94e11 100644 --- a/cli/npm/managed/resolvers/local.rs +++ b/cli/npm/managed/resolvers/local.rs @@ -43,6 +43,10 @@ use serde::Deserialize; use serde::Serialize; use sys_traits::FsMetadata; +use super::super::resolution::NpmResolution; +use super::common::bin_entries; +use super::common::NpmPackageFsResolver; +use super::common::RegistryReadPermissionChecker; use crate::args::LifecycleScriptsConfig; use crate::args::NpmInstallDepsProvider; use crate::cache::CACHE_PERM; @@ -57,11 +61,6 @@ use crate::util::fs::LaxSingleProcessFsFlag; use crate::util::progress_bar::ProgressBar; use crate::util::progress_bar::ProgressMessagePrompt; -use super::super::resolution::NpmResolution; -use super::common::bin_entries; -use super::common::NpmPackageFsResolver; -use super::common::RegistryReadPermissionChecker; - /// Resolver that creates a local node_modules directory /// and resolves packages from it. #[derive(Debug)] diff --git a/cli/npm/managed/resolvers/mod.rs b/cli/npm/managed/resolvers/mod.rs index c2fc8d2d929952..3d3fc2e3f26341 100644 --- a/cli/npm/managed/resolvers/mod.rs +++ b/cli/npm/managed/resolvers/mod.rs @@ -7,22 +7,19 @@ mod local; use std::path::PathBuf; use std::sync::Arc; -use crate::sys::CliSys; use deno_npm::NpmSystemInfo; +pub use self::common::NpmPackageFsResolver; +use self::global::GlobalNpmPackageResolver; +use self::local::LocalNpmPackageResolver; +use super::resolution::NpmResolution; use crate::args::LifecycleScriptsConfig; use crate::args::NpmInstallDepsProvider; use crate::npm::CliNpmCache; use crate::npm::CliNpmTarballCache; +use crate::sys::CliSys; use crate::util::progress_bar::ProgressBar; -pub use self::common::NpmPackageFsResolver; - -use self::global::GlobalNpmPackageResolver; -use self::local::LocalNpmPackageResolver; - -use super::resolution::NpmResolution; - #[allow(clippy::too_many_arguments)] pub fn create_npm_fs_resolver( npm_cache: Arc, diff --git a/cli/npm/mod.rs b/cli/npm/mod.rs index 34eaf214198047..c8a6002c4f97c3 100644 --- a/cli/npm/mod.rs +++ b/cli/npm/mod.rs @@ -7,7 +7,6 @@ use std::borrow::Cow; use std::path::Path; use std::sync::Arc; -use crate::sys::CliSys; use dashmap::DashMap; use deno_core::error::AnyError; use deno_core::serde_json; @@ -28,10 +27,6 @@ use managed::create_managed_in_npm_pkg_checker; use node_resolver::InNpmPackageChecker; use node_resolver::NpmPackageFolderResolver; -use crate::file_fetcher::CliFileFetcher; -use crate::http_util::HttpClientProvider; -use crate::util::progress_bar::ProgressBar; - pub use self::byonm::CliByonmNpmResolver; pub use self::byonm::CliByonmNpmResolverCreateOptions; pub use self::managed::CliManagedInNpmPkgCheckerCreateOptions; @@ -39,6 +34,10 @@ pub use self::managed::CliManagedNpmResolverCreateOptions; pub use self::managed::CliNpmResolverManagedSnapshotOption; pub use self::managed::ManagedCliNpmResolver; pub use self::managed::PackageCaching; +use crate::file_fetcher::CliFileFetcher; +use crate::http_util::HttpClientProvider; +use crate::sys::CliSys; +use crate::util::progress_bar::ProgressBar; pub type CliNpmTarballCache = deno_npm_cache::TarballCache; diff --git a/cli/ops/jupyter.rs b/cli/ops/jupyter.rs index 5bdf97e60f6c20..da6fa657d2cd0a 100644 --- a/cli/ops/jupyter.rs +++ b/cli/ops/jupyter.rs @@ -8,17 +8,16 @@ use std::cell::RefCell; use std::rc::Rc; use std::sync::Arc; -use jupyter_runtime::InputRequest; -use jupyter_runtime::JupyterMessage; -use jupyter_runtime::JupyterMessageContent; -use jupyter_runtime::KernelIoPubConnection; -use jupyter_runtime::StreamContent; - use deno_core::error::AnyError; use deno_core::op2; use deno_core::parking_lot::Mutex; use deno_core::serde_json; use deno_core::OpState; +use jupyter_runtime::InputRequest; +use jupyter_runtime::JupyterMessage; +use jupyter_runtime::JupyterMessageContent; +use jupyter_runtime::KernelIoPubConnection; +use jupyter_runtime::StreamContent; use tokio::sync::mpsc; use crate::tools::jupyter::server::StdinConnectionProxy; diff --git a/cli/ops/testing.rs b/cli/ops/testing.rs index 3c6936971a5ae3..bc96e416509b6f 100644 --- a/cli/ops/testing.rs +++ b/cli/ops/testing.rs @@ -1,13 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::tools::test::TestContainer; -use crate::tools::test::TestDescription; -use crate::tools::test::TestEvent; -use crate::tools::test::TestEventSender; -use crate::tools::test::TestFailure; -use crate::tools::test::TestLocation; -use crate::tools::test::TestStepDescription; -use crate::tools::test::TestStepResult; +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; use deno_core::error::generic_error; use deno_core::error::type_error; @@ -18,10 +12,17 @@ use deno_core::ModuleSpecifier; use deno_core::OpState; use deno_runtime::deno_permissions::ChildPermissionsArg; use deno_runtime::deno_permissions::PermissionsContainer; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering; use uuid::Uuid; +use crate::tools::test::TestContainer; +use crate::tools::test::TestDescription; +use crate::tools::test::TestEvent; +use crate::tools::test::TestEventSender; +use crate::tools::test::TestFailure; +use crate::tools::test::TestLocation; +use crate::tools::test::TestStepDescription; +use crate::tools::test::TestStepResult; + deno_core::extension!(deno_test, ops = [ op_pledge_test_permissions, diff --git a/cli/resolver.rs b/cli/resolver.rs index c4c8ef8b361771..93c07bdbc31d4a 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -5,7 +5,6 @@ use std::path::Path; use std::path::PathBuf; use std::sync::Arc; -use crate::sys::CliSys; use async_trait::async_trait; use dashmap::DashMap; use dashmap::DashSet; @@ -40,6 +39,7 @@ use crate::args::DENO_DISABLE_PEDANTIC_NODE_WARNINGS; use crate::node::CliNodeCodeTranslator; use crate::npm::CliNpmResolver; use crate::npm::InnerCliNpmResolverRef; +use crate::sys::CliSys; use crate::util::sync::AtomicFlag; use crate::util::text_encoding::from_utf8_lossy_cow; diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs index 48af787f180d0d..5277b3d523af4e 100644 --- a/cli/standalone/binary.rs +++ b/cli/standalone/binary.rs @@ -61,6 +61,23 @@ use log::Level; use serde::Deserialize; use serde::Serialize; +use super::file_system::DenoCompileFileSystem; +use super::serialization::deserialize_binary_data_section; +use super::serialization::serialize_binary_data_section; +use super::serialization::DenoCompileModuleData; +use super::serialization::DeserializedDataSection; +use super::serialization::RemoteModulesStore; +use super::serialization::RemoteModulesStoreBuilder; +use super::serialization::SourceMapStore; +use super::virtual_fs::output_vfs; +use super::virtual_fs::BuiltVfs; +use super::virtual_fs::FileBackedVfs; +use super::virtual_fs::VfsBuilder; +use super::virtual_fs::VfsFileSubDataKind; +use super::virtual_fs::VfsRoot; +use super::virtual_fs::VirtualDirectory; +use super::virtual_fs::VirtualDirectoryEntries; +use super::virtual_fs::WindowsSystemRootablePath; use crate::args::CaData; use crate::args::CliOptions; use crate::args::CompileFlags; @@ -83,24 +100,6 @@ use crate::util::fs::canonicalize_path_maybe_not_exists; use crate::util::progress_bar::ProgressBar; use crate::util::progress_bar::ProgressBarStyle; -use super::file_system::DenoCompileFileSystem; -use super::serialization::deserialize_binary_data_section; -use super::serialization::serialize_binary_data_section; -use super::serialization::DenoCompileModuleData; -use super::serialization::DeserializedDataSection; -use super::serialization::RemoteModulesStore; -use super::serialization::RemoteModulesStoreBuilder; -use super::serialization::SourceMapStore; -use super::virtual_fs::output_vfs; -use super::virtual_fs::BuiltVfs; -use super::virtual_fs::FileBackedVfs; -use super::virtual_fs::VfsBuilder; -use super::virtual_fs::VfsFileSubDataKind; -use super::virtual_fs::VfsRoot; -use super::virtual_fs::VirtualDirectory; -use super::virtual_fs::VirtualDirectoryEntries; -use super::virtual_fs::WindowsSystemRootablePath; - pub static DENO_COMPILE_GLOBAL_NODE_MODULES_DIR_NAME: &str = ".deno_compile_node_modules"; diff --git a/cli/standalone/code_cache.rs b/cli/standalone/code_cache.rs index ec89c3ab1bdcb3..0abec9ba9e1576 100644 --- a/cli/standalone/code_cache.rs +++ b/cli/standalone/code_cache.rs @@ -395,10 +395,11 @@ fn deserialize_with_reader( #[cfg(test)] mod test { + use std::fs::File; + use test_util::TempDir; use super::*; - use std::fs::File; #[test] fn serialize_deserialize() { diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index 0fe6de0b9a5e58..7ce06b309c7205 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -5,6 +5,10 @@ #![allow(dead_code)] #![allow(unused_imports)] +use std::borrow::Cow; +use std::rc::Rc; +use std::sync::Arc; + use binary::StandaloneData; use binary::StandaloneModules; use code_cache::DenoCompileCodeCache; @@ -57,9 +61,6 @@ use node_resolver::NodeResolutionKind; use node_resolver::ResolutionMode; use serialization::DenoCompileModuleSource; use serialization::SourceMapStore; -use std::borrow::Cow; -use std::rc::Rc; -use std::sync::Arc; use virtual_fs::FileBackedVfs; use virtual_fs::VfsFileSubDataKind; @@ -107,12 +108,12 @@ mod file_system; mod serialization; mod virtual_fs; -pub use self::file_system::DenoCompileFileSystem; pub use binary::extract_standalone; pub use binary::is_standalone_binary; pub use binary::DenoCompileBinaryWriter; use self::binary::Metadata; +pub use self::file_system::DenoCompileFileSystem; struct SharedModuleLoaderState { cjs_tracker: Arc, diff --git a/cli/standalone/serialization.rs b/cli/standalone/serialization.rs index 30802aa08197dd..0f4d2dd9f4dc37 100644 --- a/cli/standalone/serialization.rs +++ b/cli/standalone/serialization.rs @@ -25,12 +25,11 @@ use deno_semver::package::PackageReq; use deno_semver::StackString; use indexmap::IndexMap; -use crate::standalone::virtual_fs::VirtualDirectory; - use super::binary::Metadata; use super::virtual_fs::BuiltVfs; use super::virtual_fs::VfsBuilder; use super::virtual_fs::VirtualDirectoryEntries; +use crate::standalone::virtual_fs::VirtualDirectory; const MAGIC_BYTES: &[u8; 8] = b"d3n0l4nd"; diff --git a/cli/standalone/virtual_fs.rs b/cli/standalone/virtual_fs.rs index 370d07a488b030..61e2e333477ac6 100644 --- a/cli/standalone/virtual_fs.rs +++ b/cli/standalone/virtual_fs.rs @@ -34,13 +34,12 @@ use serde::Deserialize; use serde::Serialize; use thiserror::Error; +use super::binary::DENO_COMPILE_GLOBAL_NODE_MODULES_DIR_NAME; use crate::util; use crate::util::display::human_size; use crate::util::display::DisplayTreeNode; use crate::util::fs::canonicalize_path; -use super::binary::DENO_COMPILE_GLOBAL_NODE_MODULES_DIR_NAME; - #[derive(Debug, PartialEq, Eq)] pub enum WindowsSystemRootablePath { /// The root of the system above any drive letters. @@ -1563,9 +1562,10 @@ impl FileBackedVfs { #[cfg(test)] mod test { + use std::io::Write; + use console_static_text::ansi::strip_ansi_codes; use deno_io::fs::File; - use std::io::Write; use test_util::assert_contains; use test_util::TempDir; diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs index 1b47c9bfb037aa..e1441e95cda3b2 100644 --- a/cli/tools/bench/mod.rs +++ b/cli/tools/bench/mod.rs @@ -1,20 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::args::BenchFlags; -use crate::args::Flags; -use crate::colors; -use crate::display::write_json_to_stdout; -use crate::factory::CliFactory; -use crate::graph_util::has_graph_root_local_dependent_changed; -use crate::ops; -use crate::sys::CliSys; -use crate::tools::test::format_test_error; -use crate::tools::test::TestFilter; -use crate::util::file_watcher; -use crate::util::fs::collect_specifiers; -use crate::util::path::is_script_ext; -use crate::util::path::matches_pattern_or_exact_path; -use crate::worker::CliMainWorkerFactory; +use std::collections::HashSet; +use std::path::Path; +use std::sync::Arc; +use std::time::Duration; use deno_config::glob::WalkEntry; use deno_core::error::generic_error; @@ -39,13 +28,25 @@ use indexmap::IndexSet; use log::Level; use serde::Deserialize; use serde::Serialize; -use std::collections::HashSet; -use std::path::Path; -use std::sync::Arc; -use std::time::Duration; use tokio::sync::mpsc::unbounded_channel; use tokio::sync::mpsc::UnboundedSender; +use crate::args::BenchFlags; +use crate::args::Flags; +use crate::colors; +use crate::display::write_json_to_stdout; +use crate::factory::CliFactory; +use crate::graph_util::has_graph_root_local_dependent_changed; +use crate::ops; +use crate::sys::CliSys; +use crate::tools::test::format_test_error; +use crate::tools::test::TestFilter; +use crate::util::file_watcher; +use crate::util::fs::collect_specifiers; +use crate::util::path::is_script_ext; +use crate::util::path::matches_pattern_or_exact_path; +use crate::worker::CliMainWorkerFactory; + mod mitata; mod reporters; diff --git a/cli/tools/bench/reporters.rs b/cli/tools/bench/reporters.rs index 9aabd760b37310..0c13d14961d8e5 100644 --- a/cli/tools/bench/reporters.rs +++ b/cli/tools/bench/reporters.rs @@ -2,11 +2,10 @@ use serde::Serialize; +use super::*; use crate::tools::test::TestFailureFormatOptions; use crate::version; -use super::*; - pub trait BenchReporter { fn report_group_summary(&mut self); fn report_plan(&mut self, plan: &BenchPlan); diff --git a/cli/tools/clean.rs b/cli/tools/clean.rs index cdc1c51dcd57fb..763aa115407ee9 100644 --- a/cli/tools/clean.rs +++ b/cli/tools/clean.rs @@ -1,8 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::path::Path; + use deno_core::anyhow::Context; use deno_core::error::AnyError; -use std::path::Path; use crate::cache::DenoDir; use crate::colors; diff --git a/cli/tools/compile.rs b/cli/tools/compile.rs index cbd376bae24c2c..243e322f55e00e 100644 --- a/cli/tools/compile.rs +++ b/cli/tools/compile.rs @@ -1,12 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::args::check_warn_tsconfig; -use crate::args::CompileFlags; -use crate::args::Flags; -use crate::factory::CliFactory; -use crate::http_util::HttpClientProvider; -use crate::standalone::binary::is_standalone_binary; -use crate::standalone::binary::WriteBinOptions; +use std::collections::HashSet; +use std::collections::VecDeque; +use std::path::Path; +use std::path::PathBuf; +use std::sync::Arc; + use deno_ast::MediaType; use deno_ast::ModuleSpecifier; use deno_core::anyhow::bail; @@ -19,13 +18,15 @@ use deno_path_util::url_from_file_path; use deno_path_util::url_to_file_path; use deno_terminal::colors; use rand::Rng; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::path::Path; -use std::path::PathBuf; -use std::sync::Arc; use super::installer::infer_name_from_url; +use crate::args::check_warn_tsconfig; +use crate::args::CompileFlags; +use crate::args::Flags; +use crate::factory::CliFactory; +use crate::http_util::HttpClientProvider; +use crate::standalone::binary::is_standalone_binary; +use crate::standalone::binary::WriteBinOptions; pub async fn compile( flags: Arc, diff --git a/cli/tools/coverage/merge.rs b/cli/tools/coverage/merge.rs index 81317df55942c7..2c69981ad1f9b7 100644 --- a/cli/tools/coverage/merge.rs +++ b/cli/tools/coverage/merge.rs @@ -3,14 +3,15 @@ // Forked from https://github.com/demurgos/v8-coverage/tree/d0ca18da8740198681e0bc68971b0a6cdb11db3e/rust // Copyright 2021 Charles Samborski. All rights reserved. MIT license. -use super::range_tree::RangeTree; -use super::range_tree::RangeTreeArena; -use crate::cdp; use std::collections::BTreeMap; use std::collections::BTreeSet; use std::collections::HashMap; use std::iter::Peekable; +use super::range_tree::RangeTree; +use super::range_tree::RangeTreeArena; +use crate::cdp; + #[derive(Eq, PartialEq, Clone, Debug)] pub struct ProcessCoverage { pub result: Vec, diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs index a9054207b00528..1a03f38c53379e 100644 --- a/cli/tools/coverage/mod.rs +++ b/cli/tools/coverage/mod.rs @@ -1,16 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::args::CliOptions; -use crate::args::CoverageFlags; -use crate::args::FileFlags; -use crate::args::Flags; -use crate::cdp; -use crate::factory::CliFactory; -use crate::file_fetcher::TextDecodedFile; -use crate::sys::CliSys; -use crate::tools::fmt::format_json; -use crate::tools::test::is_supported_test_path; -use crate::util::text_encoding::source_map_from_code; +use std::fs; +use std::fs::File; +use std::io::BufWriter; +use std::io::Write; +use std::path::Path; +use std::path::PathBuf; +use std::sync::Arc; use deno_ast::MediaType; use deno_ast::ModuleKind; @@ -29,16 +25,21 @@ use deno_core::url::Url; use deno_core::LocalInspectorSession; use node_resolver::InNpmPackageChecker; use regex::Regex; -use std::fs; -use std::fs::File; -use std::io::BufWriter; -use std::io::Write; -use std::path::Path; -use std::path::PathBuf; -use std::sync::Arc; use text_lines::TextLines; use uuid::Uuid; +use crate::args::CliOptions; +use crate::args::CoverageFlags; +use crate::args::FileFlags; +use crate::args::Flags; +use crate::cdp; +use crate::factory::CliFactory; +use crate::file_fetcher::TextDecodedFile; +use crate::sys::CliSys; +use crate::tools::fmt::format_json; +use crate::tools::test::is_supported_test_path; +use crate::util::text_encoding::source_map_from_code; + mod merge; mod range_tree; mod reporter; diff --git a/cli/tools/coverage/range_tree.rs b/cli/tools/coverage/range_tree.rs index bca52844c0c951..8e3cd95a51941e 100644 --- a/cli/tools/coverage/range_tree.rs +++ b/cli/tools/coverage/range_tree.rs @@ -3,10 +3,12 @@ // Forked from https://github.com/demurgos/v8-coverage/tree/d0ca18da8740198681e0bc68971b0a6cdb11db3e/rust // Copyright 2021 Charles Samborski. All rights reserved. MIT license. -use crate::cdp; use std::iter::Peekable; + use typed_arena::Arena; +use crate::cdp; + pub struct RangeTreeArena<'a>(Arena>); impl<'a> RangeTreeArena<'a> { diff --git a/cli/tools/coverage/reporter.rs b/cli/tools/coverage/reporter.rs index 6b0e5c885e3126..3bdb6b25f667f4 100644 --- a/cli/tools/coverage/reporter.rs +++ b/cli/tools/coverage/reporter.rs @@ -1,11 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::util; -use super::CoverageReport; -use crate::args::CoverageType; -use crate::colors; -use deno_core::error::AnyError; -use deno_core::url::Url; use std::collections::HashMap; use std::fs; use std::fs::File; @@ -15,6 +9,14 @@ use std::io::{self}; use std::path::Path; use std::path::PathBuf; +use deno_core::error::AnyError; +use deno_core::url::Url; + +use super::util; +use super::CoverageReport; +use crate::args::CoverageType; +use crate::colors; + #[derive(Default)] pub struct CoverageStats<'a> { pub line_hit: usize, diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index 0ff1806a9ef6a5..a22de0c9a9ce36 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -1,18 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::args::DocFlags; -use crate::args::DocHtmlFlag; -use crate::args::DocSourceFileFlag; -use crate::args::Flags; -use crate::colors; -use crate::display; -use crate::factory::CliFactory; -use crate::graph_util::graph_exit_integrity_errors; -use crate::graph_util::graph_walk_errors; -use crate::graph_util::GraphWalkErrorsOptions; -use crate::sys::CliSys; -use crate::tsc::get_types_declaration_file_text; -use crate::util::fs::collect_specifiers; +use std::collections::BTreeMap; +use std::rc::Rc; +use std::sync::Arc; + use deno_ast::diagnostics::Diagnostic; use deno_config::glob::FilePatterns; use deno_config::glob::PathOrPatternSet; @@ -32,9 +23,20 @@ use deno_graph::ModuleSpecifier; use doc::html::ShortPath; use doc::DocDiagnostic; use indexmap::IndexMap; -use std::collections::BTreeMap; -use std::rc::Rc; -use std::sync::Arc; + +use crate::args::DocFlags; +use crate::args::DocHtmlFlag; +use crate::args::DocSourceFileFlag; +use crate::args::Flags; +use crate::colors; +use crate::display; +use crate::factory::CliFactory; +use crate::graph_util::graph_exit_integrity_errors; +use crate::graph_util::graph_walk_errors; +use crate::graph_util::GraphWalkErrorsOptions; +use crate::sys::CliSys; +use crate::tsc::get_types_declaration_file_text; +use crate::util::fs::collect_specifiers; const JSON_SCHEMA_VERSION: u8 = 1; diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 7f9a15f4b20c65..74a85aaa099bc4 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -7,21 +7,18 @@ //! the future it can be easily extended to provide //! the same functions as ops available in JS runtime. -use crate::args::CliOptions; -use crate::args::Flags; -use crate::args::FmtFlags; -use crate::args::FmtOptions; -use crate::args::FmtOptionsConfig; -use crate::args::ProseWrap; -use crate::args::UnstableFmtOptions; -use crate::cache::Caches; -use crate::colors; -use crate::factory::CliFactory; -use crate::sys::CliSys; -use crate::util::diff::diff; -use crate::util::file_watcher; -use crate::util::fs::canonicalize_path; -use crate::util::path::get_extension; +use std::borrow::Cow; +use std::fs; +use std::io::stdin; +use std::io::stdout; +use std::io::Read; +use std::io::Write; +use std::path::Path; +use std::path::PathBuf; +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; +use std::sync::Arc; + use async_trait::async_trait; use deno_ast::ParsedSource; use deno_config::glob::FileCollector; @@ -38,19 +35,23 @@ use deno_core::url::Url; use log::debug; use log::info; use log::warn; -use std::borrow::Cow; -use std::fs; -use std::io::stdin; -use std::io::stdout; -use std::io::Read; -use std::io::Write; -use std::path::Path; -use std::path::PathBuf; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering; -use std::sync::Arc; +use crate::args::CliOptions; +use crate::args::Flags; +use crate::args::FmtFlags; +use crate::args::FmtOptions; +use crate::args::FmtOptionsConfig; +use crate::args::ProseWrap; +use crate::args::UnstableFmtOptions; +use crate::cache::Caches; use crate::cache::IncrementalCache; +use crate::colors; +use crate::factory::CliFactory; +use crate::sys::CliSys; +use crate::util::diff::diff; +use crate::util::file_watcher; +use crate::util::fs::canonicalize_path; +use crate::util::path::get_extension; /// Format JavaScript/TypeScript files. pub async fn format( diff --git a/cli/tools/init/mod.rs b/cli/tools/init/mod.rs index 36bdbac2bc6cad..ec25a051bba7bc 100644 --- a/cli/tools/init/mod.rs +++ b/cli/tools/init/mod.rs @@ -1,12 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::args::DenoSubcommand; -use crate::args::Flags; -use crate::args::InitFlags; -use crate::args::PackagesAllowedScripts; -use crate::args::PermissionFlags; -use crate::args::RunFlags; -use crate::colors; +use std::io::IsTerminal; +use std::io::Write; +use std::path::Path; + use color_print::cformat; use color_print::cstr; use deno_config::deno_json::NodeModulesDirMode; @@ -15,9 +12,14 @@ use deno_core::error::AnyError; use deno_core::serde_json::json; use deno_runtime::WorkerExecutionMode; use log::info; -use std::io::IsTerminal; -use std::io::Write; -use std::path::Path; + +use crate::args::DenoSubcommand; +use crate::args::Flags; +use crate::args::InitFlags; +use crate::args::PackagesAllowedScripts; +use crate::args::PermissionFlags; +use crate::args::RunFlags; +use crate::colors; pub async fn init_project(init_flags: InitFlags) -> Result { if let Some(package) = &init_flags.package { diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index 1bfd17f30d79d7..12d650d98e38aa 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -1,5 +1,29 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::env; +use std::fs; +use std::fs::File; +use std::io; +use std::io::Write; +#[cfg(not(windows))] +use std::os::unix::fs::PermissionsExt; +use std::path::Path; +use std::path::PathBuf; +use std::sync::Arc; + +use deno_cache_dir::file_fetcher::CacheSetting; +use deno_core::anyhow::bail; +use deno_core::anyhow::Context; +use deno_core::error::generic_error; +use deno_core::error::AnyError; +use deno_core::resolve_url_or_path; +use deno_core::url::Url; +use deno_semver::npm::NpmPackageReqReference; +use log::Level; +use once_cell::sync::Lazy; +use regex::Regex; +use regex::RegexBuilder; + use crate::args::resolve_no_prompt; use crate::args::AddFlags; use crate::args::CaData; @@ -19,30 +43,6 @@ use crate::jsr::JsrFetchResolver; use crate::npm::NpmFetchResolver; use crate::util::fs::canonicalize_path_maybe_not_exists; -use deno_cache_dir::file_fetcher::CacheSetting; -use deno_core::anyhow::bail; -use deno_core::anyhow::Context; -use deno_core::error::generic_error; -use deno_core::error::AnyError; -use deno_core::resolve_url_or_path; -use deno_core::url::Url; -use deno_semver::npm::NpmPackageReqReference; -use log::Level; -use once_cell::sync::Lazy; -use regex::Regex; -use regex::RegexBuilder; -use std::env; -use std::fs; -use std::fs::File; -use std::io; -use std::io::Write; -use std::path::Path; -use std::path::PathBuf; - -#[cfg(not(windows))] -use std::os::unix::fs::PermissionsExt; -use std::sync::Arc; - static EXEC_NAME_RE: Lazy = Lazy::new(|| { RegexBuilder::new(r"^[a-z0-9][\w-]*$") .case_insensitive(true) @@ -659,16 +659,17 @@ fn is_in_path(dir: &Path) -> bool { #[cfg(test)] mod tests { - use super::*; + use std::process::Command; + use test_util::testdata_path; + use test_util::TempDir; + + use super::*; use crate::args::ConfigFlag; use crate::args::PermissionFlags; use crate::args::UninstallFlagsGlobal; use crate::args::UnstableConfig; use crate::util::fs::canonicalize_path; - use std::process::Command; - use test_util::testdata_path; - use test_util::TempDir; #[tokio::test] async fn install_infer_name_from_url() { diff --git a/cli/tools/jupyter/install.rs b/cli/tools/jupyter/install.rs index aeff89ccf4f04a..40159a35e04170 100644 --- a/cli/tools/jupyter/install.rs +++ b/cli/tools/jupyter/install.rs @@ -1,12 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::error::AnyError; -use deno_core::serde_json; -use deno_core::serde_json::json; use std::env::current_exe; use std::io::Write; use std::path::Path; +use deno_core::error::AnyError; +use deno_core::serde_json; +use deno_core::serde_json::json; use jupyter_runtime::dirs::user_data_dir; const DENO_ICON_32: &[u8] = include_bytes!("./resources/deno-logo-32x32.png"); diff --git a/cli/tools/jupyter/mod.rs b/cli/tools/jupyter/mod.rs index 732f95c49f25f7..7f11be36d4dab4 100644 --- a/cli/tools/jupyter/mod.rs +++ b/cli/tools/jupyter/mod.rs @@ -2,17 +2,6 @@ use std::sync::Arc; -use crate::args::Flags; -use crate::args::JupyterFlags; -use crate::cdp; -use crate::lsp::ReplCompletionItem; -use crate::ops; -use crate::tools::repl; -use crate::tools::test::create_single_test_event_channel; -use crate::tools::test::reporters::PrettyTestReporter; -use crate::tools::test::TestEventWorkerSender; -use crate::tools::test::TestFailureFormatOptions; -use crate::CliFactory; use deno_core::anyhow::bail; use deno_core::anyhow::Context; use deno_core::error::generic_error; @@ -34,6 +23,18 @@ use tokio::sync::mpsc; use tokio::sync::mpsc::UnboundedSender; use tokio::sync::oneshot; +use crate::args::Flags; +use crate::args::JupyterFlags; +use crate::cdp; +use crate::lsp::ReplCompletionItem; +use crate::ops; +use crate::tools::repl; +use crate::tools::test::create_single_test_event_channel; +use crate::tools::test::reporters::PrettyTestReporter; +use crate::tools::test::TestEventWorkerSender; +use crate::tools::test::TestFailureFormatOptions; +use crate::CliFactory; + mod install; pub mod server; diff --git a/cli/tools/jupyter/server.rs b/cli/tools/jupyter/server.rs index 5680ed4c13b878..6c6d076d014513 100644 --- a/cli/tools/jupyter/server.rs +++ b/cli/tools/jupyter/server.rs @@ -11,8 +11,6 @@ use std::collections::HashMap; use std::rc::Rc; use std::sync::Arc; -use crate::cdp; -use crate::tools::repl; use deno_core::anyhow::bail; use deno_core::error::AnyError; use deno_core::futures; @@ -20,12 +18,9 @@ use deno_core::parking_lot::Mutex; use deno_core::serde_json; use deno_core::CancelFuture; use deno_core::CancelHandle; -use jupyter_runtime::ExecutionCount; -use tokio::sync::mpsc; -use tokio::sync::oneshot; - use jupyter_runtime::messaging; use jupyter_runtime::ConnectionInfo; +use jupyter_runtime::ExecutionCount; use jupyter_runtime::JupyterMessage; use jupyter_runtime::JupyterMessageContent; use jupyter_runtime::KernelControlConnection; @@ -34,9 +29,13 @@ use jupyter_runtime::KernelShellConnection; use jupyter_runtime::ReplyError; use jupyter_runtime::ReplyStatus; use jupyter_runtime::StreamContent; +use tokio::sync::mpsc; +use tokio::sync::oneshot; use uuid::Uuid; use super::JupyterReplProxy; +use crate::cdp; +use crate::tools::repl; pub struct JupyterServer { execution_count: ExecutionCount, diff --git a/cli/tools/lint/linter.rs b/cli/tools/lint/linter.rs index 6bb3c628fabd19..0537765a0ade98 100644 --- a/cli/tools/lint/linter.rs +++ b/cli/tools/lint/linter.rs @@ -17,12 +17,11 @@ use deno_lint::linter::Linter as DenoLintLinter; use deno_lint::linter::LinterOptions; use deno_path_util::fs::atomic_write_file_with_retries; -use crate::sys::CliSys; -use crate::util::fs::specifier_from_file_path; - use super::rules::FileOrPackageLintRule; use super::rules::PackageLintRule; use super::ConfiguredRules; +use crate::sys::CliSys; +use crate::util::fs::specifier_from_file_path; pub struct CliLinterOptions { pub configured_rules: ConfiguredRules, diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index 6d3997ac3b902b..cefc1d6e6688e8 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -3,6 +3,14 @@ //! This module provides file linting utilities using //! [`deno_lint`](https://github.com/denoland/deno_lint). +use std::collections::HashSet; +use std::fs; +use std::io::stdin; +use std::io::Read; +use std::path::PathBuf; +use std::rc::Rc; +use std::sync::Arc; + use deno_ast::ModuleSpecifier; use deno_ast::ParsedSource; use deno_config::deno_json::LintRulesConfig; @@ -25,13 +33,6 @@ use log::debug; use reporters::create_reporter; use reporters::LintReporter; use serde::Serialize; -use std::collections::HashSet; -use std::fs; -use std::io::stdin; -use std::io::Read; -use std::path::PathBuf; -use std::rc::Rc; -use std::sync::Arc; use crate::args::CliOptions; use crate::args::Flags; @@ -596,11 +597,12 @@ struct LintError { #[cfg(test)] mod tests { - use super::*; use pretty_assertions::assert_eq; use serde::Deserialize; use test_util as util; + use super::*; + #[derive(Serialize, Deserialize)] struct RulesSchema { #[serde(rename = "$schema")] diff --git a/cli/tools/lint/reporters.rs b/cli/tools/lint/reporters.rs index 18bc1216a69d7e..0e93f4570fe935 100644 --- a/cli/tools/lint/reporters.rs +++ b/cli/tools/lint/reporters.rs @@ -8,9 +8,8 @@ use deno_runtime::colors; use log::info; use serde::Serialize; -use crate::args::LintReporterKind; - use super::LintError; +use crate::args::LintReporterKind; const JSON_SCHEMA_VERSION: u8 = 1; diff --git a/cli/tools/lint/rules/no_sloppy_imports.rs b/cli/tools/lint/rules/no_sloppy_imports.rs index 1bf7eddf6eeb7d..fc4641df12aec8 100644 --- a/cli/tools/lint/rules/no_sloppy_imports.rs +++ b/cli/tools/lint/rules/no_sloppy_imports.rs @@ -20,11 +20,10 @@ use deno_resolver::sloppy_imports::SloppyImportsResolution; use deno_resolver::sloppy_imports::SloppyImportsResolutionKind; use text_lines::LineAndColumnIndex; +use super::ExtendedLintRule; use crate::graph_util::CliJsrUrlProvider; use crate::resolver::CliSloppyImportsResolver; -use super::ExtendedLintRule; - #[derive(Debug)] pub struct NoSloppyImportsRule { sloppy_imports_resolver: Option>, diff --git a/cli/tools/registry/api.rs b/cli/tools/registry/api.rs index 2f27cb2fea6244..623c9bee3c5d73 100644 --- a/cli/tools/registry/api.rs +++ b/cli/tools/registry/api.rs @@ -1,12 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::http_util; use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::url::Url; use deno_runtime::deno_fetch; use serde::de::DeserializeOwned; +use crate::http_util; use crate::http_util::HttpClient; #[derive(serde::Deserialize)] diff --git a/cli/tools/registry/graph.rs b/cli/tools/registry/graph.rs index 21962d009e1626..e9cf01d710681d 100644 --- a/cli/tools/registry/graph.rs +++ b/cli/tools/registry/graph.rs @@ -16,10 +16,9 @@ use deno_graph::WalkOptions; use deno_semver::jsr::JsrPackageReqReference; use deno_semver::npm::NpmPackageReqReference; -use crate::cache::ParsedSourceCache; - use super::diagnostics::PublishDiagnostic; use super::diagnostics::PublishDiagnosticsCollector; +use crate::cache::ParsedSourceCache; pub struct GraphDiagnosticsCollector { parsed_source_cache: Arc, diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index 45a040d2364e46..e3edc51d392c56 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -73,11 +73,10 @@ pub use pm::AddRmPackageReq; use publish_order::PublishOrderGraph; use unfurl::SpecifierUnfurler; -use super::check::TypeChecker; - use self::graph::GraphDiagnosticsCollector; use self::paths::CollectedPublishPath; use self::tar::PublishableTarball; +use super::check::TypeChecker; pub async fn publish( flags: Arc, @@ -1281,14 +1280,14 @@ fn ring_bell() { #[cfg(test)] mod tests { - use deno_ast::ModuleSpecifier; + use std::collections::HashMap; - use crate::tools::registry::has_license_file; + use deno_ast::ModuleSpecifier; use super::tar::PublishableTarball; use super::tar::PublishableTarballFile; use super::verify_version_manifest; - use std::collections::HashMap; + use crate::tools::registry::has_license_file; #[test] fn test_verify_version_manifest() { diff --git a/cli/tools/registry/paths.rs b/cli/tools/registry/paths.rs index 1c675982df9bd8..02b143b62046c3 100644 --- a/cli/tools/registry/paths.rs +++ b/cli/tools/registry/paths.rs @@ -6,7 +6,6 @@ use std::collections::HashSet; use std::path::Path; use std::path::PathBuf; -use crate::sys::CliSys; use deno_ast::MediaType; use deno_ast::ModuleSpecifier; use deno_config::glob::FileCollector; @@ -14,10 +13,10 @@ use deno_config::glob::FilePatterns; use deno_core::error::AnyError; use thiserror::Error; -use crate::args::CliOptions; - use super::diagnostics::PublishDiagnostic; use super::diagnostics::PublishDiagnosticsCollector; +use crate::args::CliOptions; +use crate::sys::CliSys; /// A package path, like '/foo' or '/foo/bar'. The path is prefixed with a slash /// and does not end with a slash. diff --git a/cli/tools/registry/pm/cache_deps.rs b/cli/tools/registry/pm/cache_deps.rs index 814c76cb27e63a..d41c5c6b8d3595 100644 --- a/cli/tools/registry/pm/cache_deps.rs +++ b/cli/tools/registry/pm/cache_deps.rs @@ -3,15 +3,16 @@ use std::borrow::Cow; use std::sync::Arc; -use crate::factory::CliFactory; -use crate::graph_container::ModuleGraphContainer; -use crate::graph_container::ModuleGraphUpdatePermit; -use crate::graph_util::CreateGraphOptions; use deno_core::error::AnyError; use deno_core::futures::stream::FuturesUnordered; use deno_core::futures::StreamExt; use deno_semver::jsr::JsrPackageReqReference; +use crate::factory::CliFactory; +use crate::graph_container::ModuleGraphContainer; +use crate::graph_container::ModuleGraphUpdatePermit; +use crate::graph_util::CreateGraphOptions; + pub async fn cache_top_level_deps( // todo(dsherret): don't pass the factory into this function. Instead use ctor deps factory: &CliFactory, diff --git a/cli/tools/registry/pm/deps.rs b/cli/tools/registry/pm/deps.rs index ffa53417e99b2d..6f92a9a47fb5d1 100644 --- a/cli/tools/registry/pm/deps.rs +++ b/cli/tools/registry/pm/deps.rs @@ -35,6 +35,7 @@ use import_map::ImportMapWithDiagnostics; use import_map::SpecifierMapEntry; use tokio::sync::Semaphore; +use super::ConfigUpdater; use crate::args::CliLockfile; use crate::graph_container::MainModuleGraphContainer; use crate::graph_container::ModuleGraphContainer; @@ -45,8 +46,6 @@ use crate::npm::CliNpmResolver; use crate::npm::NpmFetchResolver; use crate::util::sync::AtomicFlag; -use super::ConfigUpdater; - #[derive(Clone, Debug, PartialEq, Eq)] pub enum ImportMapKind { Inline, diff --git a/cli/tools/registry/pm/outdated.rs b/cli/tools/registry/pm/outdated.rs index bb4c60fde8dc2e..2885a58e1bc345 100644 --- a/cli/tools/registry/pm/outdated.rs +++ b/cli/tools/registry/pm/outdated.rs @@ -12,6 +12,10 @@ use deno_semver::StackString; use deno_semver::VersionReq; use deno_terminal::colors; +use super::deps::Dep; +use super::deps::DepManager; +use super::deps::DepManagerArgs; +use super::deps::PackageLatestVersion; use crate::args::CliOptions; use crate::args::Flags; use crate::args::OutdatedFlags; @@ -21,11 +25,6 @@ use crate::jsr::JsrFetchResolver; use crate::npm::NpmFetchResolver; use crate::tools::registry::pm::deps::DepKind; -use super::deps::Dep; -use super::deps::DepManager; -use super::deps::DepManagerArgs; -use super::deps::PackageLatestVersion; - #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] struct OutdatedPackage { kind: DepKind, diff --git a/cli/tools/registry/provenance.rs b/cli/tools/registry/provenance.rs index 47169f2132aef7..72e1dff80ef1ad 100644 --- a/cli/tools/registry/provenance.rs +++ b/cli/tools/registry/provenance.rs @@ -1,11 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::http_util; -use crate::http_util::HttpClient; +use std::collections::HashMap; +use std::env; -use super::api::OidcTokenResponse; -use super::auth::gha_oidc_token; -use super::auth::is_gha; use base64::engine::general_purpose::STANDARD_NO_PAD; use base64::prelude::BASE64_STANDARD; use base64::Engine as _; @@ -27,8 +24,12 @@ use sha2::Digest; use spki::der::asn1; use spki::der::pem::LineEnding; use spki::der::EncodePem; -use std::collections::HashMap; -use std::env; + +use super::api::OidcTokenResponse; +use super::auth::gha_oidc_token; +use super::auth::is_gha; +use crate::http_util; +use crate::http_util::HttpClient; const PAE_PREFIX: &str = "DSSEv1"; @@ -706,10 +707,11 @@ async fn testify( #[cfg(test)] mod tests { + use std::env; + use super::ProvenanceAttestation; use super::Subject; use super::SubjectDigest; - use std::env; #[test] fn slsa_github_actions() { diff --git a/cli/tools/registry/tar.rs b/cli/tools/registry/tar.rs index 6d1801ce6976fc..34d0ed0832b04b 100644 --- a/cli/tools/registry/tar.rs +++ b/cli/tools/registry/tar.rs @@ -1,22 +1,22 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::fmt::Write as FmtWrite; +use std::io::Write; +use std::path::Path; + use bytes::Bytes; use deno_ast::MediaType; use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::url::Url; use sha2::Digest; -use std::fmt::Write as FmtWrite; -use std::io::Write; -use std::path::Path; use tar::Header; -use crate::cache::LazyGraphSourceParser; - use super::diagnostics::PublishDiagnostic; use super::diagnostics::PublishDiagnosticsCollector; use super::paths::CollectedPublishPath; use super::unfurl::SpecifierUnfurler; +use crate::cache::LazyGraphSourceParser; #[derive(Debug, Clone, PartialEq)] pub struct PublishableTarballFile { diff --git a/cli/tools/registry/unfurl.rs b/cli/tools/registry/unfurl.rs index 989a6e1ed491aa..e02dcd62d9c6f1 100644 --- a/cli/tools/registry/unfurl.rs +++ b/cli/tools/registry/unfurl.rs @@ -655,10 +655,6 @@ fn to_range( mod tests { use std::sync::Arc; - use crate::resolver::SloppyImportsCachedFs; - - use super::*; - use crate::sys::CliSys; use deno_ast::MediaType; use deno_ast::ModuleSpecifier; use deno_config::workspace::ResolverWorkspaceJsrPackage; @@ -671,6 +667,10 @@ mod tests { use pretty_assertions::assert_eq; use test_util::testdata_path; + use super::*; + use crate::resolver::SloppyImportsCachedFs; + use crate::sys::CliSys; + fn parse_ast(specifier: &Url, source_code: &str) -> ParsedSource { let media_type = MediaType::from_specifier(specifier); deno_ast::parse_module(deno_ast::ParseParams { diff --git a/cli/tools/repl/channel.rs b/cli/tools/repl/channel.rs index 823a13d2884ce5..a32b48f61409c8 100644 --- a/cli/tools/repl/channel.rs +++ b/cli/tools/repl/channel.rs @@ -1,10 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::cell::RefCell; + use deno_core::anyhow::anyhow; use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::serde_json::Value; -use std::cell::RefCell; use tokio::sync::mpsc::channel; use tokio::sync::mpsc::unbounded_channel; use tokio::sync::mpsc::Receiver; diff --git a/cli/tools/repl/editor.rs b/cli/tools/repl/editor.rs index dbc9bce7038449..95df2c02a0bcbd 100644 --- a/cli/tools/repl/editor.rs +++ b/cli/tools/repl/editor.rs @@ -1,7 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::cdp; -use crate::colors; +use std::borrow::Cow; +use std::path::PathBuf; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::Ordering::Relaxed; +use std::sync::Arc; + use deno_ast::swc::parser::error::SyntaxError; use deno_ast::swc::parser::token::BinOpToken; use deno_ast::swc::parser::token::Token; @@ -32,14 +36,11 @@ use rustyline::Modifiers; use rustyline::RepeatCount; use rustyline_derive::Helper; use rustyline_derive::Hinter; -use std::borrow::Cow; -use std::path::PathBuf; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering::Relaxed; -use std::sync::Arc; use super::channel::RustylineSyncMessageSender; use super::session::REPL_INTERNALS_NAME; +use crate::cdp; +use crate::colors; // Provides helpers to the editor like validation for multi-line edits, completion candidates for // tab completion. diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs index 9fb4624fa44207..eacafa21608e66 100644 --- a/cli/tools/repl/mod.rs +++ b/cli/tools/repl/mod.rs @@ -2,9 +2,15 @@ use std::io; use std::io::Write; - use std::sync::Arc; +use deno_core::error::AnyError; +use deno_core::futures::StreamExt; +use deno_core::serde_json; +use deno_core::unsync::spawn_blocking; +use deno_runtime::WorkerExecutionMode; +use rustyline::error::ReadlineError; + use crate::args::CliOptions; use crate::args::Flags; use crate::args::ReplFlags; @@ -13,12 +19,6 @@ use crate::colors; use crate::factory::CliFactory; use crate::file_fetcher::CliFileFetcher; use crate::file_fetcher::TextDecodedFile; -use deno_core::error::AnyError; -use deno_core::futures::StreamExt; -use deno_core::serde_json; -use deno_core::unsync::spawn_blocking; -use deno_runtime::WorkerExecutionMode; -use rustyline::error::ReadlineError; mod channel; mod editor; diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 02594f15197f3f..b09fcafc91acf9 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -2,22 +2,6 @@ use std::sync::Arc; -use crate::args::CliOptions; -use crate::cdp; -use crate::colors; -use crate::lsp::ReplLanguageServer; -use crate::npm::CliNpmResolver; -use crate::resolver::CliResolver; -use crate::tools::test::report_tests; -use crate::tools::test::reporters::PrettyTestReporter; -use crate::tools::test::reporters::TestReporter; -use crate::tools::test::run_tests_for_worker; -use crate::tools::test::send_test_event; -use crate::tools::test::worker_has_tests; -use crate::tools::test::TestEvent; -use crate::tools::test::TestEventReceiver; -use crate::tools::test::TestFailureFormatOptions; - use deno_ast::diagnostics::Diagnostic; use deno_ast::swc::ast as swc_ast; use deno_ast::swc::common::comments::CommentKind; @@ -55,6 +39,22 @@ use regex::Match; use regex::Regex; use tokio::sync::Mutex; +use crate::args::CliOptions; +use crate::cdp; +use crate::colors; +use crate::lsp::ReplLanguageServer; +use crate::npm::CliNpmResolver; +use crate::resolver::CliResolver; +use crate::tools::test::report_tests; +use crate::tools::test::reporters::PrettyTestReporter; +use crate::tools::test::reporters::TestReporter; +use crate::tools::test::run_tests_for_worker; +use crate::tools::test::send_test_event; +use crate::tools::test::worker_has_tests; +use crate::tools::test::TestEvent; +use crate::tools::test::TestEventReceiver; +use crate::tools::test::TestFailureFormatOptions; + fn comment_source_to_position_range( comment_start: SourcePos, m: &Match, diff --git a/cli/tools/test/channel.rs b/cli/tools/test/channel.rs index 9a003f2d5da6e6..d3c1ff9564f44f 100644 --- a/cli/tools/test/channel.rs +++ b/cli/tools/test/channel.rs @@ -1,15 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::TestEvent; -use deno_core::futures::future::poll_fn; -use deno_core::parking_lot; -use deno_core::parking_lot::lock_api::RawMutex; -use deno_core::parking_lot::lock_api::RawMutexTimed; -use deno_runtime::deno_io::pipe; -use deno_runtime::deno_io::AsyncPipeRead; -use deno_runtime::deno_io::PipeRead; -use deno_runtime::deno_io::PipeWrite; -use memmem::Searcher; use std::fmt::Display; use std::future::Future; use std::io::Write; @@ -19,6 +9,16 @@ use std::sync::atomic::Ordering; use std::task::ready; use std::task::Poll; use std::time::Duration; + +use deno_core::futures::future::poll_fn; +use deno_core::parking_lot; +use deno_core::parking_lot::lock_api::RawMutex; +use deno_core::parking_lot::lock_api::RawMutexTimed; +use deno_runtime::deno_io::pipe; +use deno_runtime::deno_io::AsyncPipeRead; +use deno_runtime::deno_io::PipeRead; +use deno_runtime::deno_io::PipeWrite; +use memmem::Searcher; use tokio::io::AsyncRead; use tokio::io::AsyncReadExt; use tokio::io::ReadBuf; @@ -27,6 +27,8 @@ use tokio::sync::mpsc::UnboundedReceiver; use tokio::sync::mpsc::UnboundedSender; use tokio::sync::mpsc::WeakUnboundedSender; +use super::TestEvent; + /// 8-byte sync marker that is unlikely to appear in normal output. Equivalent /// to the string `"\u{200B}\0\u{200B}\0"`. const SYNC_MARKER: &[u8; 8] = &[226, 128, 139, 0, 226, 128, 139, 0]; @@ -437,11 +439,12 @@ impl TestEventSender { #[allow(clippy::print_stderr)] #[cfg(test)] mod tests { - use super::*; - use crate::tools::test::TestResult; use deno_core::unsync::spawn; use deno_core::unsync::spawn_blocking; + use super::*; + use crate::tools::test::TestResult; + /// Test that output is correctly interleaved with messages. #[tokio::test] async fn spawn_worker() { diff --git a/cli/tools/test/fmt.rs b/cli/tools/test/fmt.rs index 0f6a9ed2b4ea5c..a1a5174845d2da 100644 --- a/cli/tools/test/fmt.rs +++ b/cli/tools/test/fmt.rs @@ -1,16 +1,16 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::ops::AddAssign; + use deno_core::stats::RuntimeActivity; use deno_core::stats::RuntimeActivityDiff; use deno_core::stats::RuntimeActivityTrace; use deno_core::stats::RuntimeActivityType; use phf::phf_map; -use std::borrow::Cow; -use std::ops::AddAssign; - -use crate::util::path::to_percent_decoded_str; use super::*; +use crate::util::path::to_percent_decoded_str; pub fn to_relative_path_or_remote_url(cwd: &Url, path_or_url: &str) -> String { let Ok(url) = Url::parse(path_or_url) else { diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index 3745d7c7ecc649..09bdf6e3aabeab 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -1,24 +1,24 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::args::CliOptions; -use crate::args::Flags; -use crate::args::TestFlags; -use crate::args::TestReporterConfig; -use crate::colors; -use crate::display; -use crate::factory::CliFactory; -use crate::file_fetcher::CliFileFetcher; -use crate::graph_util::has_graph_root_local_dependent_changed; -use crate::ops; -use crate::sys::CliSys; -use crate::util::extract::extract_doc_tests; -use crate::util::file_watcher; -use crate::util::fs::collect_specifiers; -use crate::util::path::get_extension; -use crate::util::path::is_script_ext; -use crate::util::path::matches_pattern_or_exact_path; -use crate::worker::CliMainWorkerFactory; -use crate::worker::CoverageCollector; +use std::borrow::Cow; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::collections::BTreeSet; +use std::collections::HashMap; +use std::collections::HashSet; +use std::env; +use std::fmt::Write as _; +use std::future::poll_fn; +use std::io::Write; +use std::num::NonZeroUsize; +use std::path::Path; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; +use std::sync::Arc; +use std::task::Poll; +use std::time::Duration; +use std::time::Instant; use deno_ast::MediaType; use deno_cache_dir::file_fetcher::File; @@ -66,27 +66,28 @@ use rand::seq::SliceRandom; use rand::SeedableRng; use regex::Regex; use serde::Deserialize; -use std::borrow::Cow; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::collections::BTreeSet; -use std::collections::HashMap; -use std::collections::HashSet; -use std::env; -use std::fmt::Write as _; -use std::future::poll_fn; -use std::io::Write; -use std::num::NonZeroUsize; -use std::path::Path; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering; -use std::sync::Arc; -use std::task::Poll; -use std::time::Duration; -use std::time::Instant; use tokio::signal; +use crate::args::CliOptions; +use crate::args::Flags; +use crate::args::TestFlags; +use crate::args::TestReporterConfig; +use crate::colors; +use crate::display; +use crate::factory::CliFactory; +use crate::file_fetcher::CliFileFetcher; +use crate::graph_util::has_graph_root_local_dependent_changed; +use crate::ops; +use crate::sys::CliSys; +use crate::util::extract::extract_doc_tests; +use crate::util::file_watcher; +use crate::util::fs::collect_specifiers; +use crate::util::path::get_extension; +use crate::util::path::is_script_ext; +use crate::util::path::matches_pattern_or_exact_path; +use crate::worker::CliMainWorkerFactory; +use crate::worker::CoverageCollector; + mod channel; pub mod fmt; pub mod reporters; diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index b3d7618be96b5b..3d9e92df87def0 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -2,6 +2,27 @@ //! This module provides feature to upgrade deno executable +use std::borrow::Cow; +use std::env; +use std::fs; +use std::io::IsTerminal; +use std::ops::Sub; +use std::path::Path; +use std::path::PathBuf; +use std::process::Command; +use std::sync::Arc; +use std::time::Duration; + +use async_trait::async_trait; +use deno_core::anyhow::bail; +use deno_core::anyhow::Context; +use deno_core::error::AnyError; +use deno_core::unsync::spawn; +use deno_core::url::Url; +use deno_semver::SmallStackString; +use deno_semver::Version; +use once_cell::sync::Lazy; + use crate::args::Flags; use crate::args::UpgradeFlags; use crate::args::UPGRADE_USAGE; @@ -15,26 +36,6 @@ use crate::util::progress_bar::ProgressBar; use crate::util::progress_bar::ProgressBarStyle; use crate::version; -use async_trait::async_trait; -use deno_core::anyhow::bail; -use deno_core::anyhow::Context; -use deno_core::error::AnyError; -use deno_core::unsync::spawn; -use deno_core::url::Url; -use deno_semver::SmallStackString; -use deno_semver::Version; -use once_cell::sync::Lazy; -use std::borrow::Cow; -use std::env; -use std::fs; -use std::io::IsTerminal; -use std::ops::Sub; -use std::path::Path; -use std::path::PathBuf; -use std::process::Command; -use std::sync::Arc; -use std::time::Duration; - const RELEASE_URL: &str = "https://github.com/denoland/deno/releases"; const CANARY_URL: &str = "https://dl.deno.land/canary"; const DL_RELEASE_URL: &str = "https://dl.deno.land/release"; diff --git a/cli/tsc/diagnostics.rs b/cli/tsc/diagnostics.rs index e4cc80723f0f7c..fd0a027ae37fd8 100644 --- a/cli/tsc/diagnostics.rs +++ b/cli/tsc/diagnostics.rs @@ -1,16 +1,16 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_ast::ModuleSpecifier; -use deno_graph::ModuleGraph; -use deno_terminal::colors; +use std::error::Error; +use std::fmt; +use deno_ast::ModuleSpecifier; use deno_core::serde::Deserialize; use deno_core::serde::Deserializer; use deno_core::serde::Serialize; use deno_core::serde::Serializer; use deno_core::sourcemap::SourceMap; -use std::error::Error; -use std::fmt; +use deno_graph::ModuleGraph; +use deno_terminal::colors; const MAX_SOURCE_LINE_LENGTH: usize = 150; @@ -401,11 +401,12 @@ impl Error for Diagnostics {} #[cfg(test)] mod tests { - use super::*; use deno_core::serde_json; use deno_core::serde_json::json; use test_util::strip_ansi_codes; + use super::*; + #[test] fn test_de_diagnostics() { let value = json!([ diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index 4c84050b5e34c5..734b5c7289cac7 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -1,16 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::args::TsConfig; -use crate::args::TypeCheckMode; -use crate::cache::FastInsecureHasher; -use crate::cache::ModuleInfoCache; -use crate::node::CliNodeResolver; -use crate::npm::CliNpmResolver; -use crate::resolver::CjsTracker; -use crate::sys::CliSys; -use crate::util::checksum; -use crate::util::path::mapped_specifier_for_tsc; -use crate::worker::create_isolate_create_params; +use std::borrow::Cow; +use std::collections::HashMap; +use std::fmt; +use std::path::Path; +use std::path::PathBuf; +use std::sync::Arc; use deno_ast::MediaType; use deno_core::anyhow::anyhow; @@ -44,14 +39,20 @@ use node_resolver::resolve_specifier_into_node_modules; use node_resolver::NodeResolutionKind; use node_resolver::ResolutionMode; use once_cell::sync::Lazy; -use std::borrow::Cow; -use std::collections::HashMap; -use std::fmt; -use std::path::Path; -use std::path::PathBuf; -use std::sync::Arc; use thiserror::Error; +use crate::args::TsConfig; +use crate::args::TypeCheckMode; +use crate::cache::FastInsecureHasher; +use crate::cache::ModuleInfoCache; +use crate::node::CliNodeResolver; +use crate::npm::CliNpmResolver; +use crate::resolver::CjsTracker; +use crate::sys::CliSys; +use crate::util::checksum; +use crate::util::path::mapped_specifier_for_tsc; +use crate::worker::create_isolate_create_params; + mod diagnostics; pub use self::diagnostics::Diagnostic; @@ -1136,10 +1137,6 @@ pub fn exec(request: Request) -> Result { #[cfg(test)] mod tests { - use super::Diagnostic; - use super::DiagnosticCategory; - use super::*; - use crate::args::TsConfig; use deno_core::futures::future; use deno_core::serde_json; use deno_core::OpState; @@ -1147,6 +1144,11 @@ mod tests { use deno_graph::ModuleGraph; use test_util::PathRef; + use super::Diagnostic; + use super::DiagnosticCategory; + use super::*; + use crate::args::TsConfig; + #[derive(Debug, Default)] pub struct MockLoader { pub fixtures: PathRef, diff --git a/cli/util/diff.rs b/cli/util/diff.rs index 14ece0c44cf2ad..0852abdbafdac0 100644 --- a/cli/util/diff.rs +++ b/cli/util/diff.rs @@ -1,9 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::colors; +use std::fmt::Write as _; + use dissimilar::diff as difference; use dissimilar::Chunk; -use std::fmt::Write as _; + +use crate::colors; /// Print diff of the same file_path, before and after formatting. /// diff --git a/cli/util/display.rs b/cli/util/display.rs index 8795d3db68a6f3..244bd0740d39be 100644 --- a/cli/util/display.rs +++ b/cli/util/display.rs @@ -1,9 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::io::Write; + use deno_core::error::AnyError; use deno_core::serde_json; use deno_runtime::colors; -use std::io::Write; /// A function that converts a float to a string the represents a human /// readable version of that number. diff --git a/cli/util/draw_thread.rs b/cli/util/draw_thread.rs index 164a8fc713e71c..80aa3959c20f98 100644 --- a/cli/util/draw_thread.rs +++ b/cli/util/draw_thread.rs @@ -1,13 +1,14 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::io::IsTerminal; +use std::sync::Arc; +use std::time::Duration; + use console_static_text::ConsoleStaticText; use deno_core::parking_lot::Mutex; use deno_core::unsync::spawn_blocking; use deno_runtime::ops::tty::ConsoleSize; use once_cell::sync::Lazy; -use std::io::IsTerminal; -use std::sync::Arc; -use std::time::Duration; use crate::util::console::console_size; diff --git a/cli/util/extract.rs b/cli/util/extract.rs index c4562060d85c0f..ff778248ea6708 100644 --- a/cli/util/extract.rs +++ b/cli/util/extract.rs @@ -1,5 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::collections::BTreeSet; +use std::fmt::Write as _; +use std::sync::Arc; + use deno_ast::swc::ast; use deno_ast::swc::atoms::Atom; use deno_ast::swc::common::collections::AHashSet; @@ -17,9 +21,6 @@ use deno_cache_dir::file_fetcher::File; use deno_core::error::AnyError; use deno_core::ModuleSpecifier; use regex::Regex; -use std::collections::BTreeSet; -use std::fmt::Write as _; -use std::sync::Arc; use crate::file_fetcher::TextDecodedFile; use crate::util::path::mapped_specifier_for_tsc; @@ -808,11 +809,12 @@ fn wrap_in_deno_test(stmts: Vec, test_name: Atom) -> ast::Stmt { #[cfg(test)] mod tests { - use super::*; - use crate::file_fetcher::TextDecodedFile; use deno_ast::swc::atoms::Atom; use pretty_assertions::assert_eq; + use super::*; + use crate::file_fetcher::TextDecodedFile; + #[test] fn test_extract_doc_tests() { struct Input { diff --git a/cli/util/file_watcher.rs b/cli/util/file_watcher.rs index b9318a6e4bd612..6596afa42cdf97 100644 --- a/cli/util/file_watcher.rs +++ b/cli/util/file_watcher.rs @@ -1,8 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::args::Flags; -use crate::colors; -use crate::util::fs::canonicalize_path; +use std::cell::RefCell; +use std::collections::HashSet; +use std::io::IsTerminal; +use std::path::PathBuf; +use std::rc::Rc; +use std::sync::Arc; +use std::time::Duration; use deno_config::glob::PathOrPatternSet; use deno_core::error::AnyError; @@ -18,18 +22,15 @@ use notify::Error as NotifyError; use notify::RecommendedWatcher; use notify::RecursiveMode; use notify::Watcher; -use std::cell::RefCell; -use std::collections::HashSet; -use std::io::IsTerminal; -use std::path::PathBuf; -use std::rc::Rc; -use std::sync::Arc; -use std::time::Duration; use tokio::select; use tokio::sync::mpsc; use tokio::sync::mpsc::UnboundedReceiver; use tokio::time::sleep; +use crate::args::Flags; +use crate::colors; +use crate::util::fs::canonicalize_path; + const CLEAR_SCREEN: &str = "\x1B[H\x1B[2J\x1B[3J"; const DEBOUNCE_INTERVAL: Duration = Duration::from_millis(200); diff --git a/cli/util/fs.rs b/cli/util/fs.rs index e0b9a6f4eefef9..6c25879d6e55ac 100644 --- a/cli/util/fs.rs +++ b/cli/util/fs.rs @@ -152,10 +152,12 @@ mod clone_dir_imp { #[cfg(target_vendor = "apple")] mod apple { - use super::super::copy_dir_recursive; - use deno_core::error::AnyError; use std::os::unix::ffi::OsStrExt; use std::path::Path; + + use deno_core::error::AnyError; + + use super::super::copy_dir_recursive; fn clonefile(from: &Path, to: &Path) -> std::io::Result<()> { let from = std::ffi::CString::new(from.as_os_str().as_bytes())?; let to = std::ffi::CString::new(to.as_os_str().as_bytes())?; @@ -462,7 +464,6 @@ pub fn specifier_from_file_path( #[cfg(test)] mod tests { - use super::*; use deno_core::futures; use deno_core::parking_lot::Mutex; use deno_path_util::normalize_path; @@ -471,6 +472,8 @@ mod tests { use test_util::TempDir; use tokio::sync::Notify; + use super::*; + #[test] fn test_normalize_path() { assert_eq!(normalize_path(Path::new("a/../b")), PathBuf::from("b")); diff --git a/cli/util/logger.rs b/cli/util/logger.rs index 783f8a5f689b27..a6f025790b7036 100644 --- a/cli/util/logger.rs +++ b/cli/util/logger.rs @@ -1,9 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::draw_thread::DrawThread; +use std::io::Write; + use deno_telemetry::OtelConfig; use deno_telemetry::OtelConsoleConfig; -use std::io::Write; + +use super::draw_thread::DrawThread; struct CliLogger { otel_console_config: OtelConsoleConfig, diff --git a/cli/util/progress_bar/mod.rs b/cli/util/progress_bar/mod.rs index 85be056d847a08..eb88492657267c 100644 --- a/cli/util/progress_bar/mod.rs +++ b/cli/util/progress_bar/mod.rs @@ -8,15 +8,13 @@ use std::time::Instant; use deno_core::parking_lot::Mutex; use deno_runtime::ops::tty::ConsoleSize; -use crate::colors; - use self::renderer::ProgressBarRenderer; use self::renderer::ProgressData; use self::renderer::ProgressDataDisplayEntry; - use super::draw_thread::DrawThread; use super::draw_thread::DrawThreadGuard; use super::draw_thread::DrawThreadRenderer; +use crate::colors; mod renderer; diff --git a/cli/util/progress_bar/renderer.rs b/cli/util/progress_bar/renderer.rs index db3d37140ff950..aca745f817d4ba 100644 --- a/cli/util/progress_bar/renderer.rs +++ b/cli/util/progress_bar/renderer.rs @@ -7,9 +7,8 @@ use std::time::Duration; use deno_terminal::colors; -use crate::util::display::human_download_size; - use super::ProgressMessagePrompt; +use crate::util::display::human_download_size; #[derive(Clone)] pub struct ProgressDataDisplayEntry { @@ -224,11 +223,13 @@ fn get_elapsed_text(elapsed: Duration) -> String { #[cfg(test)] mod test { - use super::*; - use pretty_assertions::assert_eq; use std::time::Duration; + + use pretty_assertions::assert_eq; use test_util::assert_contains; + use super::*; + #[test] fn should_get_elapsed_text() { assert_eq!(get_elapsed_text(Duration::from_secs(1)), "[00:01]"); diff --git a/cli/util/sync/task_queue.rs b/cli/util/sync/task_queue.rs index 6ef747e1ae1fb1..b06fc7b4e490d9 100644 --- a/cli/util/sync/task_queue.rs +++ b/cli/util/sync/task_queue.rs @@ -146,9 +146,10 @@ impl<'a> Future for TaskQueuePermitAcquireFuture<'a> { #[cfg(test)] mod test { + use std::sync::Arc; + use deno_core::futures; use deno_core::parking_lot::Mutex; - use std::sync::Arc; use super::*; diff --git a/cli/util/windows.rs b/cli/util/windows.rs index 37e78a5d088f47..c23bec868fcea9 100644 --- a/cli/util/windows.rs +++ b/cli/util/windows.rs @@ -8,6 +8,7 @@ pub fn ensure_stdio_open() { // SAFETY: winapi calls unsafe { use std::mem::size_of; + use winapi::shared::minwindef::DWORD; use winapi::shared::minwindef::FALSE; use winapi::shared::minwindef::TRUE; diff --git a/cli/worker.rs b/cli/worker.rs index ef519c727811ec..ed166e66787d78 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -863,13 +863,14 @@ pub fn create_isolate_create_params() -> Option { #[allow(clippy::print_stderr)] #[cfg(test)] mod tests { - use super::*; use deno_core::resolve_path; use deno_core::FsModuleLoader; use deno_fs::RealFs; use deno_runtime::deno_permissions::Permissions; use deno_runtime::permissions::RuntimePermissionDescriptorParser; + use super::*; + fn create_test_worker() -> MainWorker { let main_module = resolve_path("./hello.js", &std::env::current_dir().unwrap()).unwrap(); diff --git a/ext/broadcast_channel/lib.rs b/ext/broadcast_channel/lib.rs index c1de118a364fad..e4dbe9fcb484d1 100644 --- a/ext/broadcast_channel/lib.rs +++ b/ext/broadcast_channel/lib.rs @@ -2,9 +2,6 @@ mod in_memory_broadcast_channel; -pub use in_memory_broadcast_channel::InMemoryBroadcastChannel; -pub use in_memory_broadcast_channel::InMemoryBroadcastChannelResource; - use std::cell::RefCell; use std::path::PathBuf; use std::rc::Rc; @@ -15,6 +12,8 @@ use deno_core::JsBuffer; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; +pub use in_memory_broadcast_channel::InMemoryBroadcastChannel; +pub use in_memory_broadcast_channel::InMemoryBroadcastChannelResource; use tokio::sync::broadcast::error::SendError as BroadcastSendError; use tokio::sync::mpsc::error::SendError as MpscSendError; diff --git a/ext/canvas/lib.rs b/ext/canvas/lib.rs index defb288ac9d2dd..9ce5a5d257085e 100644 --- a/ext/canvas/lib.rs +++ b/ext/canvas/lib.rs @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::path::PathBuf; + use deno_core::op2; use deno_core::ToJsBuffer; use image::imageops::FilterType; @@ -9,7 +11,6 @@ use image::Pixel; use image::RgbaImage; use serde::Deserialize; use serde::Serialize; -use std::path::PathBuf; #[derive(Debug, thiserror::Error)] pub enum CanvasError { diff --git a/ext/console/lib.rs b/ext/console/lib.rs index 87fc8327daf0ff..d44e26857e3272 100644 --- a/ext/console/lib.rs +++ b/ext/console/lib.rs @@ -1,7 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::path::PathBuf; + use deno_core::op2; use deno_core::v8; -use std::path::PathBuf; deno_core::extension!( deno_console, diff --git a/ext/cron/interface.rs b/ext/cron/interface.rs index a19525cc4e2539..50459b4afd3738 100644 --- a/ext/cron/interface.rs +++ b/ext/cron/interface.rs @@ -1,8 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::CronError; use async_trait::async_trait; +use crate::CronError; + pub trait CronHandler { type EH: CronHandle + 'static; diff --git a/ext/cron/lib.rs b/ext/cron/lib.rs index feffb5e5112114..09c4e2d3f6c0b9 100644 --- a/ext/cron/lib.rs +++ b/ext/cron/lib.rs @@ -7,13 +7,14 @@ use std::borrow::Cow; use std::cell::RefCell; use std::rc::Rc; -pub use crate::interface::*; use deno_core::error::get_custom_error_class; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; +pub use crate::interface::*; + pub const UNSTABLE_FEATURE_NAME: &str = "cron"; deno_core::extension!(deno_cron, diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs index 69dcd1413a0641..396069e776aa94 100644 --- a/ext/crypto/lib.rs +++ b/ext/crypto/lib.rs @@ -1,22 +1,22 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::num::NonZeroU32; +use std::path::PathBuf; + use aes_kw::KekAes128; use aes_kw::KekAes192; use aes_kw::KekAes256; - use base64::prelude::BASE64_URL_SAFE_NO_PAD; use base64::Engine; use deno_core::error::not_supported; use deno_core::op2; -use deno_core::ToJsBuffer; - use deno_core::unsync::spawn_blocking; use deno_core::JsBuffer; use deno_core::OpState; -use serde::Deserialize; - +use deno_core::ToJsBuffer; use p256::elliptic_curve::sec1::FromEncodedPoint; use p256::pkcs8::DecodePrivateKey; +pub use rand; use rand::rngs::OsRng; use rand::rngs::StdRng; use rand::thread_rng; @@ -41,15 +41,12 @@ use rsa::traits::SignatureScheme; use rsa::Pss; use rsa::RsaPrivateKey; use rsa::RsaPublicKey; +use serde::Deserialize; use sha1::Sha1; use sha2::Digest; use sha2::Sha256; use sha2::Sha384; -use sha2::Sha512; -use std::num::NonZeroU32; -use std::path::PathBuf; - -pub use rand; // Re-export rand +use sha2::Sha512; // Re-export rand mod decrypt; mod ed25519; diff --git a/ext/fetch/fs_fetch_handler.rs b/ext/fetch/fs_fetch_handler.rs index c236dd9c67127d..c763d4e424d56f 100644 --- a/ext/fetch/fs_fetch_handler.rs +++ b/ext/fetch/fs_fetch_handler.rs @@ -1,8 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::CancelHandle; -use crate::CancelableResponseFuture; -use crate::FetchHandler; +use std::rc::Rc; use deno_core::futures::FutureExt; use deno_core::futures::TryFutureExt; @@ -12,9 +10,12 @@ use deno_core::CancelFuture; use deno_core::OpState; use http::StatusCode; use http_body_util::BodyExt; -use std::rc::Rc; use tokio_util::io::ReaderStream; +use crate::CancelHandle; +use crate::CancelableResponseFuture; +use crate::FetchHandler; + /// An implementation which tries to read file URLs from the file system via /// tokio::fs. #[derive(Clone)] diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index 103698b3bf0ce1..5abdfc33397df2 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -19,6 +19,10 @@ use std::sync::Arc; use std::task::Context; use std::task::Poll; +use bytes::Bytes; +// Re-export data_url +pub use data_url; +use data_url::DataUrl; use deno_core::futures::stream::Peekable; use deno_core::futures::Future; use deno_core::futures::FutureExt; @@ -51,9 +55,7 @@ use deno_tls::RootCertStoreProvider; use deno_tls::TlsKey; use deno_tls::TlsKeys; use deno_tls::TlsKeysHolder; - -use bytes::Bytes; -use data_url::DataUrl; +pub use fs_fetch_handler::FsFetchHandler; use http::header::HeaderName; use http::header::HeaderValue; use http::header::ACCEPT; @@ -75,18 +77,13 @@ use hyper_util::client::legacy::connect::HttpInfo; use hyper_util::client::legacy::Builder as HyperClientBuilder; use hyper_util::rt::TokioExecutor; use hyper_util::rt::TokioTimer; +pub use proxy::basic_auth; use serde::Deserialize; use serde::Serialize; use tower::retry; use tower::ServiceExt; use tower_http::decompression::Decompression; -// Re-export data_url -pub use data_url; -pub use proxy::basic_auth; - -pub use fs_fetch_handler::FsFetchHandler; - #[derive(Clone)] pub struct Options { pub user_agent: String, diff --git a/ext/fetch/proxy.rs b/ext/fetch/proxy.rs index 88fc211ecc80e7..ec1b1b13b74712 100644 --- a/ext/fetch/proxy.rs +++ b/ext/fetch/proxy.rs @@ -13,7 +13,6 @@ use std::task::Poll; use deno_core::futures::TryFutureExt; use deno_tls::rustls::ClientConfig as TlsConfig; - use http::header::HeaderValue; use http::uri::Scheme; use http::Uri; @@ -108,9 +107,10 @@ pub(crate) fn from_env() -> Proxies { } pub fn basic_auth(user: &str, pass: Option<&str>) -> HeaderValue { + use std::io::Write; + use base64::prelude::BASE64_STANDARD; use base64::write::EncoderWriter; - use std::io::Write; let mut buf = b"Basic ".to_vec(); { diff --git a/ext/fetch/tests.rs b/ext/fetch/tests.rs index 243b80bd908a0b..8d7436157e3dba 100644 --- a/ext/fetch/tests.rs +++ b/ext/fetch/tests.rs @@ -12,10 +12,9 @@ use http_body_util::BodyExt; use tokio::io::AsyncReadExt; use tokio::io::AsyncWriteExt; -use crate::dns; - use super::create_http_client; use super::CreateHttpClientOptions; +use crate::dns; static EXAMPLE_CRT: &[u8] = include_bytes!("../tls/testdata/example1_cert.der"); static EXAMPLE_KEY: &[u8] = diff --git a/ext/ffi/call.rs b/ext/ffi/call.rs index c964071a09f538..dc1dc99ad9dc7f 100644 --- a/ext/ffi/call.rs +++ b/ext/ffi/call.rs @@ -1,12 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::callback::PtrSymbol; -use crate::dlfcn::DynamicLibraryResource; -use crate::ir::*; -use crate::symbol::NativeType; -use crate::symbol::Symbol; -use crate::FfiPermissions; -use crate::ForeignFunction; +use std::cell::RefCell; +use std::ffi::c_void; +use std::future::Future; +use std::rc::Rc; + use deno_core::op2; use deno_core::serde_json::Value; use deno_core::serde_v8::BigInt as V8BigInt; @@ -18,10 +16,14 @@ use deno_core::ResourceId; use libffi::middle::Arg; use num_bigint::BigInt; use serde::Serialize; -use std::cell::RefCell; -use std::ffi::c_void; -use std::future::Future; -use std::rc::Rc; + +use crate::callback::PtrSymbol; +use crate::dlfcn::DynamicLibraryResource; +use crate::ir::*; +use crate::symbol::NativeType; +use crate::symbol::Symbol; +use crate::FfiPermissions; +use crate::ForeignFunction; #[derive(Debug, thiserror::Error)] pub enum CallError { diff --git a/ext/ffi/callback.rs b/ext/ffi/callback.rs index eff14503d1d19b..81b8f7dda2b599 100644 --- a/ext/ffi/callback.rs +++ b/ext/ffi/callback.rs @@ -1,19 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::symbol::NativeType; -use crate::FfiPermissions; -use crate::ForeignFunction; -use deno_core::op2; -use deno_core::v8; -use deno_core::v8::TryCatch; -use deno_core::CancelFuture; -use deno_core::CancelHandle; -use deno_core::OpState; -use deno_core::Resource; -use deno_core::ResourceId; -use deno_core::V8CrossThreadTaskSpawner; -use libffi::middle::Cif; -use serde::Deserialize; use std::borrow::Cow; use std::cell::RefCell; use std::ffi::c_void; @@ -27,6 +13,22 @@ use std::sync::atomic; use std::sync::atomic::AtomicU32; use std::task::Poll; +use deno_core::op2; +use deno_core::v8; +use deno_core::v8::TryCatch; +use deno_core::CancelFuture; +use deno_core::CancelHandle; +use deno_core::OpState; +use deno_core::Resource; +use deno_core::ResourceId; +use deno_core::V8CrossThreadTaskSpawner; +use libffi::middle::Cif; +use serde::Deserialize; + +use crate::symbol::NativeType; +use crate::FfiPermissions; +use crate::ForeignFunction; + static THREAD_ID_COUNTER: AtomicU32 = AtomicU32::new(1); thread_local! { diff --git a/ext/ffi/dlfcn.rs b/ext/ffi/dlfcn.rs index e1bb121d8c39b6..8e6294e7904c6f 100644 --- a/ext/ffi/dlfcn.rs +++ b/ext/ffi/dlfcn.rs @@ -1,11 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::ir::out_buffer_as_ptr; -use crate::symbol::NativeType; -use crate::symbol::Symbol; -use crate::turbocall; -use crate::turbocall::Turbocall; -use crate::FfiPermissions; +use std::borrow::Cow; +use std::cell::RefCell; +use std::collections::HashMap; +use std::ffi::c_void; +use std::rc::Rc; + use deno_core::op2; use deno_core::v8; use deno_core::GarbageCollected; @@ -14,11 +14,13 @@ use deno_core::Resource; use dlopen2::raw::Library; use serde::Deserialize; use serde_value::ValueDeserializer; -use std::borrow::Cow; -use std::cell::RefCell; -use std::collections::HashMap; -use std::ffi::c_void; -use std::rc::Rc; + +use crate::ir::out_buffer_as_ptr; +use crate::symbol::NativeType; +use crate::symbol::Symbol; +use crate::turbocall; +use crate::turbocall::Turbocall; +use crate::FfiPermissions; #[derive(Debug, thiserror::Error)] pub enum DlfcnError { @@ -324,6 +326,7 @@ pub(crate) fn format_error( // https://github.com/denoland/deno/issues/11632 dlopen2::Error::OpeningLibraryError(e) => { use std::os::windows::ffi::OsStrExt; + use winapi::shared::minwindef::DWORD; use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; use winapi::um::errhandlingapi::GetLastError; @@ -392,10 +395,11 @@ pub(crate) fn format_error( #[cfg(test)] mod tests { + use serde_json::json; + use super::ForeignFunction; use super::ForeignSymbol; use crate::symbol::NativeType; - use serde_json::json; #[cfg(target_os = "windows")] #[test] diff --git a/ext/ffi/ir.rs b/ext/ffi/ir.rs index 2e80842166fa7e..4e6be13caf1216 100644 --- a/ext/ffi/ir.rs +++ b/ext/ffi/ir.rs @@ -1,11 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::symbol::NativeType; -use deno_core::v8; -use libffi::middle::Arg; use std::ffi::c_void; use std::ptr; +use deno_core::v8; +use libffi::middle::Arg; + +use crate::symbol::NativeType; + #[derive(Debug, thiserror::Error)] pub enum IRError { #[error("Invalid FFI u8 type, expected boolean")] diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs index 73ec7757abc4e9..9079b7ef9fa45e 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -17,23 +17,22 @@ mod turbocall; use call::op_ffi_call_nonblocking; use call::op_ffi_call_ptr; use call::op_ffi_call_ptr_nonblocking; +pub use call::CallError; use callback::op_ffi_unsafe_callback_close; use callback::op_ffi_unsafe_callback_create; use callback::op_ffi_unsafe_callback_ref; -use dlfcn::op_ffi_load; -use dlfcn::ForeignFunction; -use r#static::op_ffi_get_static; -use repr::*; -use symbol::NativeType; -use symbol::Symbol; - -pub use call::CallError; pub use callback::CallbackError; use deno_permissions::PermissionCheckError; +use dlfcn::op_ffi_load; pub use dlfcn::DlfcnError; +use dlfcn::ForeignFunction; pub use ir::IRError; +use r#static::op_ffi_get_static; pub use r#static::StaticError; pub use repr::ReprError; +use repr::*; +use symbol::NativeType; +use symbol::Symbol; #[cfg(not(target_pointer_width = "64"))] compile_error!("platform not supported"); diff --git a/ext/ffi/repr.rs b/ext/ffi/repr.rs index eea15f3e9771dd..d7952a12b460ee 100644 --- a/ext/ffi/repr.rs +++ b/ext/ffi/repr.rs @@ -1,14 +1,16 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::FfiPermissions; -use deno_core::op2; -use deno_core::v8; -use deno_core::OpState; use std::ffi::c_char; use std::ffi::c_void; use std::ffi::CStr; use std::ptr; +use deno_core::op2; +use deno_core::v8; +use deno_core::OpState; + +use crate::FfiPermissions; + #[derive(Debug, thiserror::Error)] pub enum ReprError { #[error("Invalid pointer to offset, pointer is null")] diff --git a/ext/ffi/static.rs b/ext/ffi/static.rs index 61b40593367f31..472faf77c59b72 100644 --- a/ext/ffi/static.rs +++ b/ext/ffi/static.rs @@ -1,12 +1,14 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::dlfcn::DynamicLibraryResource; -use crate::symbol::NativeType; +use std::ptr; + use deno_core::op2; use deno_core::v8; use deno_core::OpState; use deno_core::ResourceId; -use std::ptr; + +use crate::dlfcn::DynamicLibraryResource; +use crate::symbol::NativeType; #[derive(Debug, thiserror::Error)] pub enum StaticError { diff --git a/ext/fs/interface.rs b/ext/fs/interface.rs index 0e753d684ccfe2..80818887e36ec7 100644 --- a/ext/fs/interface.rs +++ b/ext/fs/interface.rs @@ -6,12 +6,11 @@ use std::path::Path; use std::path::PathBuf; use std::rc::Rc; -use serde::Deserialize; -use serde::Serialize; - use deno_io::fs::File; use deno_io::fs::FsResult; use deno_io::fs::FsStat; +use serde::Deserialize; +use serde::Serialize; use crate::sync::MaybeSend; use crate::sync::MaybeSync; diff --git a/ext/fs/lib.rs b/ext/fs/lib.rs index 360400df0d0e37..088d71c1f699bd 100644 --- a/ext/fs/lib.rs +++ b/ext/fs/lib.rs @@ -5,6 +5,13 @@ mod ops; mod std_fs; pub mod sync; +use std::borrow::Cow; +use std::path::Path; +use std::path::PathBuf; + +use deno_io::fs::FsError; +use deno_permissions::PermissionCheckError; + pub use crate::interface::AccessCheckCb; pub use crate::interface::AccessCheckFn; pub use crate::interface::FileSystem; @@ -15,18 +22,11 @@ pub use crate::interface::OpenOptions; pub use crate::ops::FsOpsError; pub use crate::ops::FsOpsErrorKind; pub use crate::ops::OperationError; +use crate::ops::*; pub use crate::std_fs::RealFs; pub use crate::sync::MaybeSend; pub use crate::sync::MaybeSync; -use crate::ops::*; - -use deno_io::fs::FsError; -use deno_permissions::PermissionCheckError; -use std::borrow::Cow; -use std::path::Path; -use std::path::PathBuf; - pub trait FsPermissions { fn check_open<'a>( &mut self, diff --git a/ext/fs/ops.rs b/ext/fs/ops.rs index ac0a8901d7f008..655c2ca6b02742 100644 --- a/ext/fs/ops.rs +++ b/ext/fs/ops.rs @@ -11,12 +11,6 @@ use std::path::PathBuf; use std::path::StripPrefixError; use std::rc::Rc; -use crate::interface::AccessCheckFn; -use crate::interface::FileSystemRc; -use crate::interface::FsDirEntry; -use crate::interface::FsFileType; -use crate::FsPermissions; -use crate::OpenOptions; use boxed_error::Boxed; use deno_core::op2; use deno_core::CancelFuture; @@ -35,6 +29,13 @@ use rand::thread_rng; use rand::Rng; use serde::Serialize; +use crate::interface::AccessCheckFn; +use crate::interface::FileSystemRc; +use crate::interface::FsDirEntry; +use crate::interface::FsFileType; +use crate::FsPermissions; +use crate::OpenOptions; + #[derive(Debug, Boxed)] pub struct FsOpsError(pub Box); diff --git a/ext/fs/std_fs.rs b/ext/fs/std_fs.rs index c28fe9f915a26c..535859fb46648d 100644 --- a/ext/fs/std_fs.rs +++ b/ext/fs/std_fs.rs @@ -503,6 +503,7 @@ fn remove(path: &Path, recursive: bool) -> FsResult<()> { #[cfg(not(unix))] { use std::os::windows::prelude::MetadataExt; + use winapi::um::winnt::FILE_ATTRIBUTE_DIRECTORY; if metadata.file_attributes() & FILE_ATTRIBUTE_DIRECTORY != 0 { fs::remove_dir(path) @@ -520,13 +521,14 @@ fn remove(path: &Path, recursive: bool) -> FsResult<()> { fn copy_file(from: &Path, to: &Path) -> FsResult<()> { #[cfg(target_os = "macos")] { - use libc::clonefile; - use libc::stat; - use libc::unlink; use std::ffi::CString; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::fs::PermissionsExt; + use libc::clonefile; + use libc::stat; + use libc::unlink; + let from_str = CString::new(from.as_os_str().as_encoded_bytes()) .map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?; let to_str = CString::new(to.as_os_str().as_encoded_bytes()) @@ -670,11 +672,12 @@ fn cp(from: &Path, to: &Path) -> FsResult<()> { #[cfg(target_os = "macos")] { // Just clonefile() - use libc::clonefile; - use libc::unlink; use std::ffi::CString; use std::os::unix::ffi::OsStrExt; + use libc::clonefile; + use libc::unlink; + let from_str = CString::new(from.as_os_str().as_bytes()) .map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?; let to_str = CString::new(to.as_os_str().as_bytes()) @@ -762,6 +765,7 @@ fn stat(path: &Path) -> FsResult { #[cfg(windows)] fn stat(path: &Path) -> FsResult { use std::os::windows::fs::OpenOptionsExt; + use winapi::um::winbase::FILE_FLAG_BACKUP_SEMANTICS; let mut opts = fs::OpenOptions::new(); @@ -924,6 +928,7 @@ fn exists(path: &Path) -> bool { #[cfg(windows)] { use std::os::windows::ffi::OsStrExt; + use winapi::um::fileapi::GetFileAttributesW; use winapi::um::fileapi::INVALID_FILE_ATTRIBUTES; diff --git a/ext/fs/sync.rs b/ext/fs/sync.rs index 06694f1dc4296b..cf87236558c345 100644 --- a/ext/fs/sync.rs +++ b/ext/fs/sync.rs @@ -6,10 +6,9 @@ pub use inner::*; mod inner { #![allow(clippy::disallowed_types)] - pub use std::sync::Arc as MaybeArc; - pub use core::marker::Send as MaybeSend; pub use core::marker::Sync as MaybeSync; + pub use std::sync::Arc as MaybeArc; } #[cfg(not(feature = "sync_fs"))] diff --git a/ext/http/compressible.rs b/ext/http/compressible.rs index 6e96582e7e75bb..ef5d830122781e 100644 --- a/ext/http/compressible.rs +++ b/ext/http/compressible.rs @@ -1,8 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use phf::phf_set; use std::str::FromStr; +use phf::phf_set; + // Data obtained from https://github.com/jshttp/mime-db/blob/fa5e4ef3cc8907ec3c5ec5b85af0c63d7059a5cd/db.json // Important! Keep this list sorted alphabetically. static CONTENT_TYPES: phf::Set<&'static [u8]> = phf_set! { diff --git a/ext/http/fly_accept_encoding.rs b/ext/http/fly_accept_encoding.rs index 4d6fd2231efb1a..a946481bd2526f 100644 --- a/ext/http/fly_accept_encoding.rs +++ b/ext/http/fly_accept_encoding.rs @@ -124,11 +124,12 @@ fn encodings_iter_inner<'s>( #[cfg(test)] mod tests { - use super::*; use http_v02::header::ACCEPT_ENCODING; use http_v02::HeaderMap; use http_v02::HeaderValue; + use super::*; + fn encodings( headers: &HeaderMap, ) -> Result, f32)>, EncodingError> { diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs index 7dbac6021ae306..003190379d69a7 100644 --- a/ext/http/http_next.rs +++ b/ext/http/http_next.rs @@ -1,24 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::compressible::is_content_compressible; -use crate::extract_network_stream; -use crate::network_buffered_stream::NetworkStreamPrefixCheck; -use crate::request_body::HttpRequestBody; -use crate::request_properties::HttpConnectionProperties; -use crate::request_properties::HttpListenProperties; -use crate::request_properties::HttpPropertyExtractor; -use crate::response_body::Compression; -use crate::response_body::ResponseBytesInner; -use crate::service::handle_request; -use crate::service::http_general_trace; -use crate::service::http_trace; -use crate::service::HttpRecord; -use crate::service::HttpRecordResponse; -use crate::service::HttpRequestBodyAutocloser; -use crate::service::HttpServerState; -use crate::service::SignallingRc; -use crate::websocket_upgrade::WebSocketUpgrade; -use crate::LocalExecutor; -use crate::Options; +use std::borrow::Cow; +use std::cell::RefCell; +use std::ffi::c_void; +use std::future::Future; +use std::io; +use std::pin::Pin; +use std::ptr::null; +use std::rc::Rc; + use cache_control::CacheControl; use deno_core::external; use deno_core::futures::future::poll_fn; @@ -44,6 +33,7 @@ use deno_core::ResourceId; use deno_net::ops_tls::TlsStream; use deno_net::raw::NetworkStream; use deno_websocket::ws_create_server_stream; +use fly_accept_encoding::Encoding; use hyper::body::Incoming; use hyper::header::HeaderMap; use hyper::header::ACCEPT_ENCODING; @@ -63,21 +53,31 @@ use hyper::StatusCode; use hyper_util::rt::TokioIo; use once_cell::sync::Lazy; use smallvec::SmallVec; -use std::borrow::Cow; -use std::cell::RefCell; -use std::ffi::c_void; -use std::future::Future; -use std::io; -use std::pin::Pin; -use std::ptr::null; -use std::rc::Rc; - -use super::fly_accept_encoding; -use fly_accept_encoding::Encoding; - use tokio::io::AsyncReadExt; use tokio::io::AsyncWriteExt; +use super::fly_accept_encoding; +use crate::compressible::is_content_compressible; +use crate::extract_network_stream; +use crate::network_buffered_stream::NetworkStreamPrefixCheck; +use crate::request_body::HttpRequestBody; +use crate::request_properties::HttpConnectionProperties; +use crate::request_properties::HttpListenProperties; +use crate::request_properties::HttpPropertyExtractor; +use crate::response_body::Compression; +use crate::response_body::ResponseBytesInner; +use crate::service::handle_request; +use crate::service::http_general_trace; +use crate::service::http_trace; +use crate::service::HttpRecord; +use crate::service::HttpRecordResponse; +use crate::service::HttpRequestBodyAutocloser; +use crate::service::HttpServerState; +use crate::service::SignallingRc; +use crate::websocket_upgrade::WebSocketUpgrade; +use crate::LocalExecutor; +use crate::Options; + type Request = hyper::Request; static USE_WRITEV: Lazy = Lazy::new(|| { diff --git a/ext/http/lib.rs b/ext/http/lib.rs index 39b0bbc2af9691..d582303167256f 100644 --- a/ext/http/lib.rs +++ b/ext/http/lib.rs @@ -1,5 +1,21 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::cell::RefCell; +use std::cmp::min; +use std::error::Error; +use std::future::Future; +use std::io; +use std::io::Write; +use std::mem::replace; +use std::mem::take; +use std::pin::pin; +use std::pin::Pin; +use std::rc::Rc; +use std::sync::Arc; +use std::task::Context; +use std::task::Poll; + use async_compression::tokio::write::BrotliEncoder; use async_compression::tokio::write::GzipEncoder; use async_compression::Level; @@ -54,21 +70,6 @@ use hyper_v014::HeaderMap; use hyper_v014::Request; use hyper_v014::Response; use serde::Serialize; -use std::borrow::Cow; -use std::cell::RefCell; -use std::cmp::min; -use std::error::Error; -use std::future::Future; -use std::io; -use std::io::Write; -use std::mem::replace; -use std::mem::take; -use std::pin::pin; -use std::pin::Pin; -use std::rc::Rc; -use std::sync::Arc; -use std::task::Context; -use std::task::Poll; use tokio::io::AsyncRead; use tokio::io::AsyncWrite; use tokio::io::AsyncWriteExt; diff --git a/ext/http/network_buffered_stream.rs b/ext/http/network_buffered_stream.rs index 73df2dbd9f0ea2..a195712d031105 100644 --- a/ext/http/network_buffered_stream.rs +++ b/ext/http/network_buffered_stream.rs @@ -1,12 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use bytes::Bytes; -use deno_core::futures::future::poll_fn; -use deno_core::futures::ready; use std::io; use std::mem::MaybeUninit; use std::pin::Pin; use std::task::Poll; + +use bytes::Bytes; +use deno_core::futures::future::poll_fn; +use deno_core::futures::ready; use tokio::io::AsyncRead; use tokio::io::AsyncWrite; use tokio::io::ReadBuf; @@ -227,9 +228,10 @@ impl AsyncWrite #[cfg(test)] mod tests { - use super::*; use tokio::io::AsyncReadExt; + use super::*; + struct YieldsOneByteAtATime(&'static [u8]); impl AsyncRead for YieldsOneByteAtATime { diff --git a/ext/http/reader_stream.rs b/ext/http/reader_stream.rs index be6d571b1a7b99..8dc6c90ae7b972 100644 --- a/ext/http/reader_stream.rs +++ b/ext/http/reader_stream.rs @@ -66,11 +66,12 @@ impl Stream for ExternallyAbortableReaderStream { #[cfg(test)] mod tests { - use super::*; use bytes::Bytes; use deno_core::futures::StreamExt; use tokio::io::AsyncWriteExt; + use super::*; + #[tokio::test] async fn success() { let (a, b) = tokio::io::duplex(64 * 1024); diff --git a/ext/http/request_body.rs b/ext/http/request_body.rs index f1c3f358ea977b..b06b591c38087b 100644 --- a/ext/http/request_body.rs +++ b/ext/http/request_body.rs @@ -1,4 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::pin::Pin; +use std::rc::Rc; +use std::task::ready; +use std::task::Poll; + use bytes::Bytes; use deno_core::futures::stream::Peekable; use deno_core::futures::Stream; @@ -12,11 +18,6 @@ use deno_core::Resource; use hyper::body::Body; use hyper::body::Incoming; use hyper::body::SizeHint; -use std::borrow::Cow; -use std::pin::Pin; -use std::rc::Rc; -use std::task::ready; -use std::task::Poll; /// Converts a hyper incoming body stream into a stream of [`Bytes`] that we can use to read in V8. struct ReadFuture(Incoming); diff --git a/ext/http/request_properties.rs b/ext/http/request_properties.rs index 39d35a79f14b82..6b89fa5a6a3fdd 100644 --- a/ext/http/request_properties.rs +++ b/ext/http/request_properties.rs @@ -1,4 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::net::Ipv4Addr; +use std::net::SocketAddr; +use std::net::SocketAddrV4; +use std::rc::Rc; + use deno_core::error::AnyError; use deno_core::OpState; use deno_core::ResourceId; @@ -11,11 +17,6 @@ use deno_net::raw::NetworkStreamType; use hyper::header::HOST; use hyper::HeaderMap; use hyper::Uri; -use std::borrow::Cow; -use std::net::Ipv4Addr; -use std::net::SocketAddr; -use std::net::SocketAddrV4; -use std::rc::Rc; // TODO(mmastrac): I don't like that we have to clone this, but it's one-time setup #[derive(Clone)] diff --git a/ext/http/response_body.rs b/ext/http/response_body.rs index bac43bf3c8be39..62430a3deae04d 100644 --- a/ext/http/response_body.rs +++ b/ext/http/response_body.rs @@ -573,12 +573,14 @@ impl PollFrame for BrotliResponseStream { #[allow(clippy::print_stderr)] #[cfg(test)] mod tests { - use super::*; - use deno_core::futures::future::poll_fn; use std::hash::Hasher; use std::io::Read; use std::io::Write; + use deno_core::futures::future::poll_fn; + + use super::*; + fn zeros() -> Vec { vec![0; 1024 * 1024] } diff --git a/ext/http/service.rs b/ext/http/service.rs index ce24dea43f372c..52bd2903902a5d 100644 --- a/ext/http/service.rs +++ b/ext/http/service.rs @@ -1,7 +1,16 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::request_properties::HttpConnectionProperties; -use crate::response_body::ResponseBytesInner; -use crate::response_body::ResponseStreamResult; +use std::cell::Cell; +use std::cell::Ref; +use std::cell::RefCell; +use std::cell::RefMut; +use std::future::Future; +use std::mem::ManuallyDrop; +use std::pin::Pin; +use std::rc::Rc; +use std::task::Context; +use std::task::Poll; +use std::task::Waker; + use deno_core::futures::ready; use deno_core::BufView; use deno_core::OpState; @@ -13,22 +22,14 @@ use hyper::body::Incoming; use hyper::body::SizeHint; use hyper::header::HeaderMap; use hyper::upgrade::OnUpgrade; - use scopeguard::guard; use scopeguard::ScopeGuard; -use std::cell::Cell; -use std::cell::Ref; -use std::cell::RefCell; -use std::cell::RefMut; -use std::future::Future; -use std::mem::ManuallyDrop; -use std::pin::Pin; -use std::rc::Rc; -use std::task::Context; -use std::task::Poll; -use std::task::Waker; use tokio::sync::oneshot; +use crate::request_properties::HttpConnectionProperties; +use crate::response_body::ResponseBytesInner; +use crate::response_body::ResponseStreamResult; + pub type Request = hyper::Request; pub type Response = hyper::Response; @@ -606,16 +607,18 @@ impl Drop for HttpRecordResponse { #[cfg(test)] mod tests { - use super::*; - use crate::response_body::Compression; - use crate::response_body::ResponseBytesInner; + use std::error::Error as StdError; + use bytes::Buf; use deno_net::raw::NetworkStreamType; use hyper::body::Body; use hyper::service::service_fn; use hyper::service::HttpService; use hyper_util::rt::TokioIo; - use std::error::Error as StdError; + + use super::*; + use crate::response_body::Compression; + use crate::response_body::ResponseBytesInner; /// Execute client request on service and concurrently map the response. async fn serve_request( diff --git a/ext/http/websocket_upgrade.rs b/ext/http/websocket_upgrade.rs index af9504717e3948..fdee19cc05c80c 100644 --- a/ext/http/websocket_upgrade.rs +++ b/ext/http/websocket_upgrade.rs @@ -169,9 +169,10 @@ impl WebSocketUpgrade { #[cfg(test)] mod tests { - use super::*; use hyper_v014::Body; + use super::*; + type ExpectedResponseAndHead = Option<(Response, &'static [u8])>; fn assert_response( diff --git a/ext/io/bi_pipe.rs b/ext/io/bi_pipe.rs index bf65d3037f6516..d8666e14a73f57 100644 --- a/ext/io/bi_pipe.rs +++ b/ext/io/bi_pipe.rs @@ -338,6 +338,11 @@ pub fn bi_pipe_pair_raw( // TODO(nathanwhit): more granular unsafe blocks // SAFETY: win32 calls unsafe { + use std::io; + use std::os::windows::ffi::OsStrExt; + use std::path::Path; + use std::ptr; + use windows_sys::Win32::Foundation::CloseHandle; use windows_sys::Win32::Foundation::ERROR_ACCESS_DENIED; use windows_sys::Win32::Foundation::ERROR_PIPE_CONNECTED; @@ -355,11 +360,6 @@ pub fn bi_pipe_pair_raw( use windows_sys::Win32::System::Pipes::PIPE_READMODE_BYTE; use windows_sys::Win32::System::Pipes::PIPE_TYPE_BYTE; - use std::io; - use std::os::windows::ffi::OsStrExt; - use std::path::Path; - use std::ptr; - let (path, hd1) = loop { let name = format!("\\\\.\\pipe\\{}", uuid::Uuid::new_v4()); let mut path = Path::new(&name) diff --git a/ext/io/lib.rs b/ext/io/lib.rs index 873fccd7b89871..536a0346f14d5f 100644 --- a/ext/io/lib.rs +++ b/ext/io/lib.rs @@ -1,5 +1,23 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::cell::RefCell; +use std::fs::File as StdFile; +use std::future::Future; +use std::io; +use std::io::ErrorKind; +use std::io::Read; +use std::io::Seek; +use std::io::Write; +#[cfg(unix)] +use std::os::unix::io::FromRawFd; +#[cfg(windows)] +use std::os::windows::io::FromRawHandle; +use std::rc::Rc; +#[cfg(windows)] +use std::sync::Arc; + +use deno_core::futures::TryFutureExt; use deno_core::op2; use deno_core::unsync::spawn_blocking; use deno_core::unsync::TaskQueue; @@ -21,40 +39,20 @@ use fs::FsResult; use fs::FsStat; use fs3::FileExt; use once_cell::sync::Lazy; -use std::borrow::Cow; -use std::cell::RefCell; -use std::fs::File as StdFile; -use std::future::Future; -use std::io; -use std::io::ErrorKind; -use std::io::Read; -use std::io::Seek; -use std::io::Write; -use std::rc::Rc; +#[cfg(windows)] +use parking_lot::Condvar; +#[cfg(windows)] +use parking_lot::Mutex; use tokio::io::AsyncRead; use tokio::io::AsyncReadExt; use tokio::io::AsyncWrite; use tokio::io::AsyncWriteExt; use tokio::process; - -#[cfg(unix)] -use std::os::unix::io::FromRawFd; - -#[cfg(windows)] -use std::os::windows::io::FromRawHandle; #[cfg(windows)] use winapi::um::processenv::GetStdHandle; #[cfg(windows)] use winapi::um::winbase; -use deno_core::futures::TryFutureExt; -#[cfg(windows)] -use parking_lot::Condvar; -#[cfg(windows)] -use parking_lot::Mutex; -#[cfg(windows)] -use std::sync::Arc; - pub mod fs; mod pipe; #[cfg(windows)] @@ -62,19 +60,18 @@ mod winpipe; mod bi_pipe; -pub use pipe::pipe; -pub use pipe::AsyncPipeRead; -pub use pipe::AsyncPipeWrite; -pub use pipe::PipeRead; -pub use pipe::PipeWrite; -pub use pipe::RawPipeHandle; - pub use bi_pipe::bi_pipe_pair_raw; pub use bi_pipe::BiPipe; pub use bi_pipe::BiPipeRead; pub use bi_pipe::BiPipeResource; pub use bi_pipe::BiPipeWrite; pub use bi_pipe::RawBiPipeHandle; +pub use pipe::pipe; +pub use pipe::AsyncPipeRead; +pub use pipe::AsyncPipeWrite; +pub use pipe::PipeRead; +pub use pipe::PipeWrite; +pub use pipe::RawPipeHandle; /// Abstraction over `AsRawFd` (unix) and `AsRawHandle` (windows) pub trait AsRawIoHandle { diff --git a/ext/io/pipe.rs b/ext/io/pipe.rs index e0e019e277dcb6..6ff449b94432c8 100644 --- a/ext/io/pipe.rs +++ b/ext/io/pipe.rs @@ -299,13 +299,14 @@ pub fn pipe_impl() -> io::Result<(PipeRead, PipeWrite)> { #[cfg(test)] mod tests { - use super::*; - use std::io::Read; use std::io::Write; + use tokio::io::AsyncReadExt; use tokio::io::AsyncWriteExt; + use super::*; + #[test] fn test_pipe() { let (mut read, mut write) = pipe().unwrap(); diff --git a/ext/io/winpipe.rs b/ext/io/winpipe.rs index 01d018008d797f..b3e659ea67d5a6 100644 --- a/ext/io/winpipe.rs +++ b/ext/io/winpipe.rs @@ -1,10 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use rand::thread_rng; -use rand::RngCore; use std::io; use std::os::windows::io::RawHandle; use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering; + +use rand::thread_rng; +use rand::RngCore; use winapi::shared::minwindef::DWORD; use winapi::um::errhandlingapi::GetLastError; use winapi::um::fileapi::CreateFileA; @@ -116,7 +117,6 @@ fn create_named_pipe_inner() -> io::Result<(RawHandle, RawHandle)> { #[cfg(test)] mod tests { - use super::*; use std::fs::File; use std::io::Read; use std::io::Write; @@ -124,6 +124,8 @@ mod tests { use std::sync::Arc; use std::sync::Barrier; + use super::*; + #[test] fn make_named_pipe() { let (server, client) = create_named_pipe().unwrap(); diff --git a/ext/kv/dynamic.rs b/ext/kv/dynamic.rs index 6d545d79f6407f..8db2b92926ea4d 100644 --- a/ext/kv/dynamic.rs +++ b/ext/kv/dynamic.rs @@ -3,6 +3,14 @@ use std::cell::RefCell; use std::rc::Rc; +use async_trait::async_trait; +use deno_core::error::type_error; +use deno_core::error::AnyError; +use deno_core::OpState; +use denokv_proto::CommitResult; +use denokv_proto::ReadRangeOutput; +use denokv_proto::WatchStream; + use crate::remote::RemoteDbHandlerPermissions; use crate::sqlite::SqliteDbHandler; use crate::sqlite::SqliteDbHandlerPermissions; @@ -12,13 +20,6 @@ use crate::DatabaseHandler; use crate::QueueMessageHandle; use crate::ReadRange; use crate::SnapshotReadOptions; -use async_trait::async_trait; -use deno_core::error::type_error; -use deno_core::error::AnyError; -use deno_core::OpState; -use denokv_proto::CommitResult; -use denokv_proto::ReadRangeOutput; -use denokv_proto::WatchStream; pub struct MultiBackendDbHandler { backends: Vec<(&'static [&'static str], Box)>, diff --git a/ext/kv/remote.rs b/ext/kv/remote.rs index 891786e319ddbc..b638ecbd4baf94 100644 --- a/ext/kv/remote.rs +++ b/ext/kv/remote.rs @@ -5,7 +5,6 @@ use std::marker::PhantomData; use std::rc::Rc; use std::sync::Arc; -use crate::DatabaseHandler; use anyhow::Context; use async_trait::async_trait; use bytes::Bytes; @@ -27,6 +26,8 @@ use denokv_remote::RemoteTransport; use http_body_util::BodyExt; use url::Url; +use crate::DatabaseHandler; + #[derive(Clone)] pub struct HttpOptions { pub user_agent: String, diff --git a/ext/kv/sqlite.rs b/ext/kv/sqlite.rs index 9de5209275c28c..c28cfdd9321a23 100644 --- a/ext/kv/sqlite.rs +++ b/ext/kv/sqlite.rs @@ -13,7 +13,6 @@ use std::sync::Arc; use std::sync::Mutex; use std::sync::OnceLock; -use crate::DatabaseHandler; use async_trait::async_trait; use deno_core::error::type_error; use deno_core::error::AnyError; @@ -27,6 +26,8 @@ use denokv_sqlite::SqliteNotifier; use rand::SeedableRng; use rusqlite::OpenFlags; +use crate::DatabaseHandler; + static SQLITE_NOTIFIERS_MAP: OnceLock>> = OnceLock::new(); diff --git a/ext/napi/js_native_api.rs b/ext/napi/js_native_api.rs index 53a12d6eba64ef..a5b0e0d32445a5 100644 --- a/ext/napi/js_native_api.rs +++ b/ext/napi/js_native_api.rs @@ -5,8 +5,10 @@ const NAPI_VERSION: u32 = 9; -use crate::*; +use std::ptr::NonNull; + use libc::INT_MAX; +use napi_sym::napi_sym; use super::util::check_new_from_utf8; use super::util::check_new_from_utf8_len; @@ -20,8 +22,7 @@ use crate::check_env; use crate::function::create_function; use crate::function::create_function_template; use crate::function::CallbackInfo; -use napi_sym::napi_sym; -use std::ptr::NonNull; +use crate::*; #[derive(Debug, Clone, Copy, PartialEq)] enum ReferenceOwnership { diff --git a/ext/napi/lib.rs b/ext/napi/lib.rs index 6db6af48a282df..dd7e5929c077a3 100644 --- a/ext/napi/lib.rs +++ b/ext/napi/lib.rs @@ -22,17 +22,18 @@ pub mod util; pub mod uv; use core::ptr::NonNull; +use std::cell::RefCell; +use std::collections::HashMap; +use std::path::PathBuf; +use std::rc::Rc; +use std::thread_local; + use deno_core::op2; use deno_core::parking_lot::RwLock; use deno_core::url::Url; use deno_core::ExternalOpsTracker; use deno_core::OpState; use deno_core::V8CrossThreadTaskSpawner; -use std::cell::RefCell; -use std::collections::HashMap; -use std::path::PathBuf; -use std::rc::Rc; -use std::thread_local; #[derive(Debug, thiserror::Error)] pub enum NApiError { @@ -46,20 +47,19 @@ pub enum NApiError { Permission(#[from] PermissionCheckError), } -#[cfg(unix)] -use libloading::os::unix::*; - -#[cfg(windows)] -use libloading::os::windows::*; +pub use std::ffi::CStr; +pub use std::os::raw::c_char; +pub use std::os::raw::c_void; +pub use std::ptr; // Expose common stuff for ease of use. // `use deno_napi::*` pub use deno_core::v8; use deno_permissions::PermissionCheckError; -pub use std::ffi::CStr; -pub use std::os::raw::c_char; -pub use std::os::raw::c_void; -pub use std::ptr; +#[cfg(unix)] +use libloading::os::unix::*; +#[cfg(windows)] +use libloading::os::windows::*; pub use value::napi_value; pub mod function; diff --git a/ext/napi/node_api.rs b/ext/napi/node_api.rs index 2ca5c8d0b4fac6..abc3d32bd0e334 100644 --- a/ext/napi/node_api.rs +++ b/ext/napi/node_api.rs @@ -2,6 +2,17 @@ #![deny(unsafe_op_in_unsafe_fn)] +use std::sync::atomic::AtomicBool; +use std::sync::atomic::AtomicU8; +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; +use std::sync::Arc; + +use deno_core::parking_lot::Condvar; +use deno_core::parking_lot::Mutex; +use deno_core::V8CrossThreadTaskSpawner; +use napi_sym::napi_sym; + use super::util::get_array_buffer_ptr; use super::util::make_external_backing_store; use super::util::napi_clear_last_error; @@ -10,15 +21,6 @@ use super::util::SendPtr; use crate::check_arg; use crate::check_env; use crate::*; -use deno_core::parking_lot::Condvar; -use deno_core::parking_lot::Mutex; -use deno_core::V8CrossThreadTaskSpawner; -use napi_sym::napi_sym; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::AtomicU8; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering; -use std::sync::Arc; #[napi_sym] fn napi_module_register(module: *const NapiModule) -> napi_status { diff --git a/ext/napi/util.rs b/ext/napi/util.rs index 21e9d433aad6c7..592536b5028f5c 100644 --- a/ext/napi/util.rs +++ b/ext/napi/util.rs @@ -1,7 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::*; use libc::INT_MAX; +use crate::*; + #[repr(transparent)] pub(crate) struct SendPtr(pub *const T); diff --git a/ext/napi/uv.rs b/ext/napi/uv.rs index ea6b5396659a59..3dda65e627f37e 100644 --- a/ext/napi/uv.rs +++ b/ext/napi/uv.rs @@ -1,10 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::*; -use deno_core::parking_lot::Mutex; use std::mem::MaybeUninit; use std::ptr::addr_of_mut; +use deno_core::parking_lot::Mutex; + +use crate::*; + fn assert_ok(res: c_int) -> c_int { if res != 0 { log::error!("bad result in uv polyfill: {res}"); @@ -15,11 +17,12 @@ fn assert_ok(res: c_int) -> c_int { res } +use std::ffi::c_int; + use js_native_api::napi_create_string_utf8; use node_api::napi_create_async_work; use node_api::napi_delete_async_work; use node_api::napi_queue_async_work; -use std::ffi::c_int; const UV_MUTEX_SIZE: usize = { #[cfg(unix)] diff --git a/ext/napi/value.rs b/ext/napi/value.rs index 71beac07e26808..5bdfef0a00a3d8 100644 --- a/ext/napi/value.rs +++ b/ext/napi/value.rs @@ -1,11 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::v8; use std::mem::transmute; use std::ops::Deref; use std::os::raw::c_void; use std::ptr::NonNull; +use deno_core::v8; + /// An FFI-opaque, nullable wrapper around v8::Local. /// rusty_v8 Local handle cannot be empty but napi_value can be. #[repr(transparent)] diff --git a/ext/net/io.rs b/ext/net/io.rs index 2907fa398b480a..84f98668a9801d 100644 --- a/ext/net/io.rs +++ b/ext/net/io.rs @@ -1,5 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::rc::Rc; + use deno_core::futures::TryFutureExt; use deno_core::AsyncMutFuture; use deno_core::AsyncRefCell; @@ -9,14 +12,11 @@ use deno_core::CancelTryFuture; use deno_core::RcRef; use deno_core::Resource; use socket2::SockRef; -use std::borrow::Cow; -use std::rc::Rc; use tokio::io::AsyncRead; use tokio::io::AsyncReadExt; use tokio::io::AsyncWrite; use tokio::io::AsyncWriteExt; use tokio::net::tcp; - #[cfg(unix)] use tokio::net::unix; diff --git a/ext/net/lib.rs b/ext/net/lib.rs index 04b3f80010cbda..18e00c5ac3e974 100644 --- a/ext/net/lib.rs +++ b/ext/net/lib.rs @@ -10,15 +10,16 @@ pub mod raw; pub mod resolve_addr; pub mod tcp; +use std::borrow::Cow; +use std::path::Path; +use std::path::PathBuf; +use std::sync::Arc; + use deno_core::error::AnyError; use deno_core::OpState; use deno_permissions::PermissionCheckError; use deno_tls::rustls::RootCertStore; use deno_tls::RootCertStoreProvider; -use std::borrow::Cow; -use std::path::Path; -use std::path::PathBuf; -use std::sync::Arc; pub const UNSTABLE_FEATURE_NAME: &str = "net"; @@ -204,9 +205,10 @@ deno_core::extension!(deno_net, /// Stub ops for non-unix platforms. #[cfg(not(unix))] mod ops_unix { - use crate::NetPermissions; use deno_core::op2; + use crate::NetPermissions; + macro_rules! stub_op { ($name:ident) => { #[op2(fast)] diff --git a/ext/net/ops.rs b/ext/net/ops.rs index 16148ac90d24dc..f8f22cb41b491e 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -1,16 +1,17 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::io::TcpStreamResource; -use crate::raw::NetworkListenerResource; -use crate::resolve_addr::resolve_addr; -use crate::resolve_addr::resolve_addr_sync; -use crate::tcp::TcpListener; -use crate::NetPermissions; -use deno_core::op2; -use deno_core::CancelFuture; +use std::borrow::Cow; +use std::cell::RefCell; +use std::net::Ipv4Addr; +use std::net::Ipv6Addr; +use std::net::SocketAddr; +use std::rc::Rc; +use std::str::FromStr; +use deno_core::op2; use deno_core::AsyncRefCell; use deno_core::ByteString; +use deno_core::CancelFuture; use deno_core::CancelHandle; use deno_core::CancelTryFuture; use deno_core::JsBuffer; @@ -35,16 +36,16 @@ use socket2::Domain; use socket2::Protocol; use socket2::Socket; use socket2::Type; -use std::borrow::Cow; -use std::cell::RefCell; -use std::net::Ipv4Addr; -use std::net::Ipv6Addr; -use std::net::SocketAddr; -use std::rc::Rc; -use std::str::FromStr; use tokio::net::TcpStream; use tokio::net::UdpSocket; +use crate::io::TcpStreamResource; +use crate::raw::NetworkListenerResource; +use crate::resolve_addr::resolve_addr; +use crate::resolve_addr::resolve_addr_sync; +use crate::tcp::TcpListener; +use crate::NetPermissions; + #[derive(Serialize, Clone, Debug)] #[serde(rename_all = "camelCase")] pub struct TlsHandshakeInfo { @@ -834,7 +835,14 @@ fn rdata_to_return_record( #[cfg(test)] mod tests { - use super::*; + use std::net::Ipv4Addr; + use std::net::Ipv6Addr; + use std::net::ToSocketAddrs; + use std::path::Path; + use std::path::PathBuf; + use std::sync::Arc; + use std::sync::Mutex; + use deno_core::futures::FutureExt; use deno_core::JsRuntime; use deno_core::RuntimeOptions; @@ -855,13 +863,8 @@ mod tests { use hickory_proto::rr::record_data::RData; use hickory_proto::rr::Name; use socket2::SockRef; - use std::net::Ipv4Addr; - use std::net::Ipv6Addr; - use std::net::ToSocketAddrs; - use std::path::Path; - use std::path::PathBuf; - use std::sync::Arc; - use std::sync::Mutex; + + use super::*; #[test] fn rdata_to_return_record_a() { diff --git a/ext/net/ops_tls.rs b/ext/net/ops_tls.rs index 4d2073fd092c92..4d715a864724a7 100644 --- a/ext/net/ops_tls.rs +++ b/ext/net/ops_tls.rs @@ -1,16 +1,17 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::io::TcpStreamResource; -use crate::ops::IpAddr; -use crate::ops::NetError; -use crate::ops::TlsHandshakeInfo; -use crate::raw::NetworkListenerResource; -use crate::resolve_addr::resolve_addr; -use crate::resolve_addr::resolve_addr_sync; -use crate::tcp::TcpListener; -use crate::DefaultTlsOptions; -use crate::NetPermissions; -use crate::UnsafelyIgnoreCertificateErrors; +use std::borrow::Cow; +use std::cell::RefCell; +use std::convert::From; +use std::fs::File; +use std::io::BufReader; +use std::io::ErrorKind; +use std::io::Read; +use std::net::SocketAddr; +use std::num::NonZeroUsize; +use std::rc::Rc; +use std::sync::Arc; + use deno_core::futures::TryFutureExt; use deno_core::op2; use deno_core::v8; @@ -35,25 +36,25 @@ use deno_tls::TlsKey; use deno_tls::TlsKeyLookup; use deno_tls::TlsKeys; use deno_tls::TlsKeysHolder; +pub use rustls_tokio_stream::TlsStream; use rustls_tokio_stream::TlsStreamRead; use rustls_tokio_stream::TlsStreamWrite; use serde::Deserialize; -use std::borrow::Cow; -use std::cell::RefCell; -use std::convert::From; -use std::fs::File; -use std::io::BufReader; -use std::io::ErrorKind; -use std::io::Read; -use std::net::SocketAddr; -use std::num::NonZeroUsize; -use std::rc::Rc; -use std::sync::Arc; use tokio::io::AsyncReadExt; use tokio::io::AsyncWriteExt; use tokio::net::TcpStream; -pub use rustls_tokio_stream::TlsStream; +use crate::io::TcpStreamResource; +use crate::ops::IpAddr; +use crate::ops::NetError; +use crate::ops::TlsHandshakeInfo; +use crate::raw::NetworkListenerResource; +use crate::resolve_addr::resolve_addr; +use crate::resolve_addr::resolve_addr_sync; +use crate::tcp::TcpListener; +use crate::DefaultTlsOptions; +use crate::NetPermissions; +use crate::UnsafelyIgnoreCertificateErrors; pub(crate) const TLS_BUFFER_SIZE: Option = NonZeroUsize::new(65536); diff --git a/ext/net/ops_unix.rs b/ext/net/ops_unix.rs index 483dc99b400c58..4d10d1b622fd59 100644 --- a/ext/net/ops_unix.rs +++ b/ext/net/ops_unix.rs @@ -1,9 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::io::UnixStreamResource; -use crate::ops::NetError; -use crate::raw::NetworkListenerResource; -use crate::NetPermissions; +use std::borrow::Cow; +use std::cell::RefCell; +use std::path::Path; +use std::rc::Rc; + use deno_core::op2; use deno_core::AsyncRefCell; use deno_core::CancelHandle; @@ -15,14 +16,15 @@ use deno_core::Resource; use deno_core::ResourceId; use serde::Deserialize; use serde::Serialize; -use std::borrow::Cow; -use std::cell::RefCell; -use std::path::Path; -use std::rc::Rc; use tokio::net::UnixDatagram; use tokio::net::UnixListener; pub use tokio::net::UnixStream; +use crate::io::UnixStreamResource; +use crate::ops::NetError; +use crate::raw::NetworkListenerResource; +use crate::NetPermissions; + /// A utility function to map OsStrings to Strings pub fn into_string(s: std::ffi::OsString) -> Result { s.into_string().map_err(NetError::InvalidUtf8) diff --git a/ext/net/quic.rs b/ext/net/quic.rs index 16f68364be32f7..be9be2a817f9da 100644 --- a/ext/net/quic.rs +++ b/ext/net/quic.rs @@ -1,9 +1,20 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::resolve_addr::resolve_addr; -use crate::DefaultTlsOptions; -use crate::NetPermissions; -use crate::UnsafelyIgnoreCertificateErrors; +use std::borrow::Cow; +use std::cell::RefCell; +use std::future::Future; +use std::net::IpAddr; +use std::net::Ipv4Addr; +use std::net::Ipv6Addr; +use std::net::SocketAddrV4; +use std::net::SocketAddrV6; +use std::pin::pin; +use std::rc::Rc; +use std::sync::Arc; +use std::task::Context; +use std::task::Poll; +use std::time::Duration; + use deno_core::error::bad_resource; use deno_core::error::generic_error; use deno_core::error::AnyError; @@ -27,20 +38,11 @@ use quinn::crypto::rustls::QuicClientConfig; use quinn::crypto::rustls::QuicServerConfig; use serde::Deserialize; use serde::Serialize; -use std::borrow::Cow; -use std::cell::RefCell; -use std::future::Future; -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::Ipv6Addr; -use std::net::SocketAddrV4; -use std::net::SocketAddrV6; -use std::pin::pin; -use std::rc::Rc; -use std::sync::Arc; -use std::task::Context; -use std::task::Poll; -use std::time::Duration; + +use crate::resolve_addr::resolve_addr; +use crate::DefaultTlsOptions; +use crate::NetPermissions; +use crate::UnsafelyIgnoreCertificateErrors; #[derive(Debug, Deserialize, Serialize)] struct Addr { diff --git a/ext/net/raw.rs b/ext/net/raw.rs index a2ebfb5acb5712..a7134017c5417e 100644 --- a/ext/net/raw.rs +++ b/ext/net/raw.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::io::TcpStreamResource; -use crate::ops_tls::TlsStreamResource; +use std::borrow::Cow; +use std::rc::Rc; + use deno_core::error::bad_resource_id; use deno_core::error::custom_error; use deno_core::error::AnyError; @@ -9,8 +10,9 @@ use deno_core::CancelHandle; use deno_core::Resource; use deno_core::ResourceId; use deno_core::ResourceTable; -use std::borrow::Cow; -use std::rc::Rc; + +use crate::io::TcpStreamResource; +use crate::ops_tls::TlsStreamResource; pub trait NetworkStreamTrait: Into { type Resource; diff --git a/ext/net/resolve_addr.rs b/ext/net/resolve_addr.rs index 3a97081eac2ea6..137af6c19fda0d 100644 --- a/ext/net/resolve_addr.rs +++ b/ext/net/resolve_addr.rs @@ -2,6 +2,7 @@ use std::net::SocketAddr; use std::net::ToSocketAddrs; + use tokio::net::lookup_host; /// Resolve network address *asynchronously*. @@ -38,12 +39,13 @@ fn make_addr_port_pair(hostname: &str, port: u16) -> (&str, u16) { #[cfg(test)] mod tests { - use super::*; use std::net::Ipv4Addr; use std::net::Ipv6Addr; use std::net::SocketAddrV4; use std::net::SocketAddrV6; + use super::*; + #[tokio::test] async fn resolve_addr1() { let expected = vec![SocketAddr::V4(SocketAddrV4::new( diff --git a/ext/node/ops/blocklist.rs b/ext/node/ops/blocklist.rs index 6c64d68ecae653..5fce0d017ea16c 100644 --- a/ext/node/ops/blocklist.rs +++ b/ext/node/ops/blocklist.rs @@ -9,7 +9,6 @@ use std::net::SocketAddr; use deno_core::op2; use deno_core::OpState; - use ipnetwork::IpNetwork; use ipnetwork::Ipv4Network; use ipnetwork::Ipv6Network; diff --git a/ext/node/ops/crypto/cipher.rs b/ext/node/ops/crypto/cipher.rs index 7f5b108a04f311..cedd092e814985 100644 --- a/ext/node/ops/crypto/cipher.rs +++ b/ext/node/ops/crypto/cipher.rs @@ -1,5 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::cell::RefCell; +use std::rc::Rc; + use aes::cipher::block_padding::Pkcs7; use aes::cipher::BlockDecryptMut; use aes::cipher::BlockEncryptMut; @@ -8,10 +12,6 @@ use deno_core::Resource; use digest::generic_array::GenericArray; use digest::KeyInit; -use std::borrow::Cow; -use std::cell::RefCell; -use std::rc::Rc; - type Tag = Option>; type Aes128Gcm = aead_gcm_stream::AesGcm; diff --git a/ext/node/ops/crypto/dh.rs b/ext/node/ops/crypto/dh.rs index ff2bd030ebecc8..3da2d15fec423e 100644 --- a/ext/node/ops/crypto/dh.rs +++ b/ext/node/ops/crypto/dh.rs @@ -1,10 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::primes::Prime; use num_bigint_dig::BigUint; use num_bigint_dig::RandBigInt; use num_traits::FromPrimitive; +use super::primes::Prime; + #[derive(Clone)] pub struct PublicKey(BigUint); diff --git a/ext/node/ops/crypto/digest.rs b/ext/node/ops/crypto/digest.rs index a7d8fb51f1b26c..dda62053bf08ed 100644 --- a/ext/node/ops/crypto/digest.rs +++ b/ext/node/ops/crypto/digest.rs @@ -1,11 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::cell::RefCell; +use std::rc::Rc; + use deno_core::GarbageCollected; use digest::Digest; use digest::DynDigest; use digest::ExtendableOutput; use digest::Update; -use std::cell::RefCell; -use std::rc::Rc; pub struct Hasher { pub hash: Rc>>, diff --git a/ext/node/ops/crypto/md5_sha1.rs b/ext/node/ops/crypto/md5_sha1.rs index 9164b0a1cbb894..e2e48449133603 100644 --- a/ext/node/ops/crypto/md5_sha1.rs +++ b/ext/node/ops/crypto/md5_sha1.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use core::fmt; + use digest::core_api::AlgorithmName; use digest::core_api::BlockSizeUser; use digest::core_api::Buffer; diff --git a/ext/node/ops/crypto/mod.rs b/ext/node/ops/crypto/mod.rs index e90e820909cdad..2f650ba164f9b5 100644 --- a/ext/node/ops/crypto/mod.rs +++ b/ext/node/ops/crypto/mod.rs @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::future::Future; +use std::rc::Rc; + use deno_core::error::generic_error; use deno_core::error::type_error; use deno_core::op2; @@ -16,16 +19,13 @@ use keys::EcPublicKey; use keys::KeyObjectHandle; use num_bigint::BigInt; use num_bigint_dig::BigUint; +use p224::NistP224; +use p256::NistP256; +use p384::NistP384; use rand::distributions::Distribution; use rand::distributions::Uniform; use rand::Rng; use ring::signature::Ed25519KeyPair; -use std::future::Future; -use std::rc::Rc; - -use p224::NistP224; -use p256::NistP256; -use p384::NistP384; use rsa::pkcs8::DecodePrivateKey; use rsa::pkcs8::DecodePublicKey; use rsa::Oaep; diff --git a/ext/node/ops/crypto/primes.rs b/ext/node/ops/crypto/primes.rs index 2e5d1ff63cd811..91297eb56c9564 100644 --- a/ext/node/ops/crypto/primes.rs +++ b/ext/node/ops/crypto/primes.rs @@ -1,12 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ops::Deref; + use num_bigint::BigInt; use num_bigint_dig::RandPrime; use num_integer::Integer; use num_traits::One; use num_traits::Zero; use rand::Rng; -use std::ops::Deref; #[derive(Clone)] pub struct Prime(pub num_bigint_dig::BigUint); @@ -283,9 +284,10 @@ static SMALL_PRIMES: [u32; 2047] = [ #[cfg(test)] mod tests { - use super::*; use num_bigint::BigInt; + use super::*; + #[test] fn test_prime() { for &p in SMALL_PRIMES.iter() { diff --git a/ext/node/ops/crypto/sign.rs b/ext/node/ops/crypto/sign.rs index 30094c07654197..ccfd1a116548e0 100644 --- a/ext/node/ops/crypto/sign.rs +++ b/ext/node/ops/crypto/sign.rs @@ -1,24 +1,24 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use core::ops::Add; + +use ecdsa::der::MaxOverhead; +use ecdsa::der::MaxSize; +use elliptic_curve::generic_array::ArrayLength; +use elliptic_curve::FieldBytesSize; use rand::rngs::OsRng; use rsa::signature::hazmat::PrehashSigner as _; use rsa::signature::hazmat::PrehashVerifier as _; use rsa::traits::SignatureScheme as _; use spki::der::Decode; -use crate::ops::crypto::digest::match_fixed_digest; -use crate::ops::crypto::digest::match_fixed_digest_with_oid; - use super::keys::AsymmetricPrivateKey; use super::keys::AsymmetricPublicKey; use super::keys::EcPrivateKey; use super::keys::EcPublicKey; use super::keys::KeyObjectHandle; use super::keys::RsaPssHashAlgorithm; -use core::ops::Add; -use ecdsa::der::MaxOverhead; -use ecdsa::der::MaxSize; -use elliptic_curve::generic_array::ArrayLength; -use elliptic_curve::FieldBytesSize; +use crate::ops::crypto::digest::match_fixed_digest; +use crate::ops::crypto::digest::match_fixed_digest_with_oid; fn dsa_signature( encoding: u32, diff --git a/ext/node/ops/crypto/x509.rs b/ext/node/ops/crypto/x509.rs index ab8e52f703dc18..ac80afb9384ca7 100644 --- a/ext/node/ops/crypto/x509.rs +++ b/ext/node/ops/crypto/x509.rs @@ -1,7 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::op2; +use std::ops::Deref; +use deno_core::op2; +use digest::Digest; use x509_parser::der_parser::asn1_rs::Any; use x509_parser::der_parser::asn1_rs::Tag; use x509_parser::der_parser::oid::Oid; @@ -9,14 +11,10 @@ pub use x509_parser::error::X509Error; use x509_parser::extensions; use x509_parser::pem; use x509_parser::prelude::*; - -use super::KeyObjectHandle; - -use std::ops::Deref; use yoke::Yoke; use yoke::Yokeable; -use digest::Digest; +use super::KeyObjectHandle; enum CertificateSources { Der(Box<[u8]>), diff --git a/ext/node/ops/fs.rs b/ext/node/ops/fs.rs index 58a688a1fec2f1..0f6b7afb118a0c 100644 --- a/ext/node/ops/fs.rs +++ b/ext/node/ops/fs.rs @@ -207,6 +207,7 @@ where { use std::ffi::OsStr; use std::os::windows::ffi::OsStrExt; + use windows_sys::Win32::Storage::FileSystem::GetDiskFreeSpaceW; let _ = bigint; diff --git a/ext/node/ops/http.rs b/ext/node/ops/http.rs index eb28e68aeef1f5..ce5fdc163eadbb 100644 --- a/ext/node/ops/http.rs +++ b/ext/node/ops/http.rs @@ -2,6 +2,7 @@ use std::borrow::Cow; use std::cell::RefCell; +use std::cmp::min; use std::fmt::Debug; use std::pin::Pin; use std::rc::Rc; @@ -48,7 +49,6 @@ use http_body_util::BodyExt; use hyper::body::Frame; use hyper::body::Incoming; use hyper_util::rt::TokioIo; -use std::cmp::min; use tokio::io::AsyncReadExt; use tokio::io::AsyncWriteExt; diff --git a/ext/node/ops/idna.rs b/ext/node/ops/idna.rs index a3d85e77c2b6b5..eb037e6079e473 100644 --- a/ext/node/ops/idna.rs +++ b/ext/node/ops/idna.rs @@ -1,9 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::op2; - use std::borrow::Cow; +use deno_core::op2; + // map_domain, to_ascii and to_unicode are based on the punycode implementation in node.js // https://github.com/nodejs/node/blob/73025c4dec042e344eeea7912ed39f7b7c4a3991/lib/punycode.js diff --git a/ext/node/ops/inspector.rs b/ext/node/ops/inspector.rs index 9986aeb1970bd7..ecd1150e0cc8ee 100644 --- a/ext/node/ops/inspector.rs +++ b/ext/node/ops/inspector.rs @@ -1,6 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::NodePermissions; +use std::cell::RefCell; +use std::rc::Rc; + use deno_core::anyhow::Error; use deno_core::error::generic_error; use deno_core::futures::channel::mpsc; @@ -11,8 +13,8 @@ use deno_core::InspectorSessionKind; use deno_core::InspectorSessionOptions; use deno_core::JsRuntimeInspector; use deno_core::OpState; -use std::cell::RefCell; -use std::rc::Rc; + +use crate::NodePermissions; #[op2(fast)] pub fn op_inspector_enabled() -> bool { diff --git a/ext/node/ops/ipc.rs b/ext/node/ops/ipc.rs index 672cf0d70709ef..8229ceadcea2bf 100644 --- a/ext/node/ops/ipc.rs +++ b/ext/node/ops/ipc.rs @@ -30,6 +30,9 @@ mod impl_ { use deno_core::RcRef; use deno_core::ResourceId; use deno_core::ToV8; + use deno_io::BiPipe; + use deno_io::BiPipeRead; + use deno_io::BiPipeWrite; use memchr::memchr; use pin_project_lite::pin_project; use serde::Serialize; @@ -37,10 +40,6 @@ mod impl_ { use tokio::io::AsyncWriteExt; use tokio::io::ReadBuf; - use deno_io::BiPipe; - use deno_io::BiPipeRead; - use deno_io::BiPipeWrite; - /// Wrapper around v8 value that implements Serialize. struct SerializeWrapper<'a, 'b>( RefCell<&'b mut v8::HandleScope<'a>>, @@ -624,13 +623,15 @@ mod impl_ { #[cfg(test)] mod tests { - use super::IpcJsonStreamResource; + use std::rc::Rc; + use deno_core::serde_json::json; use deno_core::v8; use deno_core::JsRuntime; use deno_core::RcRef; use deno_core::RuntimeOptions; - use std::rc::Rc; + + use super::IpcJsonStreamResource; #[allow(clippy::unused_async)] #[cfg(unix)] diff --git a/ext/node/ops/os/cpus.rs b/ext/node/ops/os/cpus.rs index 2b931884c36a74..c96b3838225cb6 100644 --- a/ext/node/ops/os/cpus.rs +++ b/ext/node/ops/os/cpus.rs @@ -127,13 +127,13 @@ pub fn cpu_info() -> Option> { #[cfg(target_os = "windows")] pub fn cpu_info() -> Option> { + use std::os::windows::ffi::OsStrExt; + use std::os::windows::ffi::OsStringExt; + use windows_sys::Wdk::System::SystemInformation::NtQuerySystemInformation; use windows_sys::Wdk::System::SystemInformation::SystemProcessorPerformanceInformation; use windows_sys::Win32::System::WindowsProgramming::SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION; - use std::os::windows::ffi::OsStrExt; - use std::os::windows::ffi::OsStringExt; - fn encode_wide(s: &str) -> Vec { std::ffi::OsString::from(s) .encode_wide() diff --git a/ext/node/ops/os/mod.rs b/ext/node/ops/os/mod.rs index ddb2a70c64883b..1cdf737f43d2ec 100644 --- a/ext/node/ops/os/mod.rs +++ b/ext/node/ops/os/mod.rs @@ -2,10 +2,11 @@ use std::mem::MaybeUninit; -use crate::NodePermissions; use deno_core::op2; use deno_core::OpState; +use crate::NodePermissions; + mod cpus; pub mod priority; diff --git a/ext/node/ops/perf_hooks.rs b/ext/node/ops/perf_hooks.rs index 636d0b2adbb6b0..256f879813db1e 100644 --- a/ext/node/ops/perf_hooks.rs +++ b/ext/node/ops/perf_hooks.rs @@ -1,10 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::cell::Cell; + use deno_core::op2; use deno_core::GarbageCollected; -use std::cell::Cell; - #[derive(Debug, thiserror::Error)] pub enum PerfHooksError { #[error(transparent)] diff --git a/ext/node/ops/v8.rs b/ext/node/ops/v8.rs index 8f09314d1df559..9c2dfa451a57e2 100644 --- a/ext/node/ops/v8.rs +++ b/ext/node/ops/v8.rs @@ -1,11 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ptr::NonNull; + use deno_core::op2; use deno_core::v8; use deno_core::FastString; use deno_core::GarbageCollected; use deno_core::ToJsBuffer; -use std::ptr::NonNull; use v8::ValueDeserializerHelper; use v8::ValueSerializerHelper; diff --git a/ext/node/ops/vm.rs b/ext/node/ops/vm.rs index 25881cbaed5d05..7720298e802fb1 100644 --- a/ext/node/ops/vm.rs +++ b/ext/node/ops/vm.rs @@ -1,14 +1,16 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::create_host_defined_options; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::Ordering; +use std::time::Duration; + use deno_core::op2; use deno_core::serde_v8; use deno_core::v8; use deno_core::v8::MapFnTo; use deno_core::JsBuffer; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering; -use std::time::Duration; + +use crate::create_host_defined_options; pub const PRIVATE_SYMBOL_NAME: v8::OneByteConst = v8::String::create_external_onebyte_const(b"node:contextify:context"); diff --git a/ext/node/ops/vm_internal.rs b/ext/node/ops/vm_internal.rs index 815f570eada65e..4c500786c520b5 100644 --- a/ext/node/ops/vm_internal.rs +++ b/ext/node/ops/vm_internal.rs @@ -1,11 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::create_host_defined_options; use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::v8; use deno_core::v8::MapFnTo; +use crate::create_host_defined_options; + pub const PRIVATE_SYMBOL_NAME: v8::OneByteConst = v8::String::create_external_onebyte_const(b"node:contextify:context"); diff --git a/ext/node/ops/zlib/brotli.rs b/ext/node/ops/zlib/brotli.rs index 1a681ff7f719a6..7c798aa7541aad 100644 --- a/ext/node/ops/zlib/brotli.rs +++ b/ext/node/ops/zlib/brotli.rs @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::cell::RefCell; +use std::io::Read; + use brotli::enc::backward_references::BrotliEncoderMode; use brotli::enc::encode::BrotliEncoderCompress; use brotli::enc::encode::BrotliEncoderOperation; @@ -14,8 +17,6 @@ use deno_core::JsBuffer; use deno_core::OpState; use deno_core::Resource; use deno_core::ToJsBuffer; -use std::cell::RefCell; -use std::io::Read; #[derive(Debug, thiserror::Error)] pub enum BrotliError { diff --git a/ext/node/ops/zlib/mod.rs b/ext/node/ops/zlib/mod.rs index 991c0925d2538f..777faf6f861947 100644 --- a/ext/node/ops/zlib/mod.rs +++ b/ext/node/ops/zlib/mod.rs @@ -1,9 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::op2; -use libc::c_ulong; use std::borrow::Cow; use std::cell::RefCell; + +use deno_core::op2; +use libc::c_ulong; use zlib::*; mod alloc; diff --git a/ext/node/ops/zlib/stream.rs b/ext/node/ops/zlib/stream.rs index afcdcc4d704029..949e1230d83f60 100644 --- a/ext/node/ops/zlib/stream.rs +++ b/ext/node/ops/zlib/stream.rs @@ -1,11 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::mode::Flush; -use super::mode::Mode; use std::ffi::c_int; use std::ops::Deref; use std::ops::DerefMut; +use super::mode::Flush; +use super::mode::Mode; + pub struct StreamWrapper { pub strm: zlib::z_stream, } diff --git a/ext/telemetry/lib.rs b/ext/telemetry/lib.rs index 8018843dc47d5a..ddf364a366b41c 100644 --- a/ext/telemetry/lib.rs +++ b/ext/telemetry/lib.rs @@ -1,5 +1,20 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::cell::RefCell; +use std::collections::HashMap; +use std::env; +use std::fmt::Debug; +use std::pin::Pin; +use std::rc::Rc; +use std::sync::Arc; +use std::sync::Mutex; +use std::task::Context; +use std::task::Poll; +use std::thread; +use std::time::Duration; +use std::time::SystemTime; + use deno_core::anyhow; use deno_core::anyhow::anyhow; use deno_core::futures::channel::mpsc; @@ -57,20 +72,6 @@ use opentelemetry_semantic_conventions::resource::TELEMETRY_SDK_NAME; use opentelemetry_semantic_conventions::resource::TELEMETRY_SDK_VERSION; use serde::Deserialize; use serde::Serialize; -use std::borrow::Cow; -use std::cell::RefCell; -use std::collections::HashMap; -use std::env; -use std::fmt::Debug; -use std::pin::Pin; -use std::rc::Rc; -use std::sync::Arc; -use std::sync::Mutex; -use std::task::Context; -use std::task::Poll; -use std::thread; -use std::time::Duration; -use std::time::SystemTime; use tokio::sync::oneshot; use tokio::task::JoinSet; @@ -469,6 +470,11 @@ impl DenoPeriodicReader { } mod hyper_client { + use std::fmt::Debug; + use std::pin::Pin; + use std::task::Poll; + use std::task::{self}; + use http_body_util::BodyExt; use http_body_util::Full; use hyper::body::Body as HttpBody; @@ -480,10 +486,6 @@ mod hyper_client { use opentelemetry_http::Request; use opentelemetry_http::Response; use opentelemetry_http::ResponseExt; - use std::fmt::Debug; - use std::pin::Pin; - use std::task::Poll; - use std::task::{self}; use super::OtelSharedRuntime; diff --git a/ext/tls/lib.rs b/ext/tls/lib.rs index 883d2995e4b913..a16e66ff9241ec 100644 --- a/ext/tls/lib.rs +++ b/ext/tls/lib.rs @@ -1,31 +1,31 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::io::BufRead; +use std::io::BufReader; +use std::io::Cursor; +use std::net::IpAddr; +use std::sync::Arc; + pub use deno_native_certs; pub use rustls; -use rustls::pki_types::CertificateDer; -use rustls::pki_types::PrivateKeyDer; -use rustls::pki_types::ServerName; -pub use rustls_pemfile; -pub use rustls_tokio_stream::*; -pub use webpki; -pub use webpki_roots; - use rustls::client::danger::HandshakeSignatureValid; use rustls::client::danger::ServerCertVerified; use rustls::client::danger::ServerCertVerifier; use rustls::client::WebPkiServerVerifier; +use rustls::pki_types::CertificateDer; +use rustls::pki_types::PrivateKeyDer; +use rustls::pki_types::ServerName; use rustls::ClientConfig; use rustls::DigitallySignedStruct; use rustls::RootCertStore; +pub use rustls_pemfile; use rustls_pemfile::certs; use rustls_pemfile::ec_private_keys; use rustls_pemfile::pkcs8_private_keys; use rustls_pemfile::rsa_private_keys; +pub use rustls_tokio_stream::*; use serde::Deserialize; -use std::io::BufRead; -use std::io::BufReader; -use std::io::Cursor; -use std::net::IpAddr; -use std::sync::Arc; +pub use webpki; +pub use webpki_roots; mod tls_key; pub use tls_key::*; diff --git a/ext/tls/tls_key.rs b/ext/tls/tls_key.rs index b7baa604b9add6..a11a2d81064b91 100644 --- a/ext/tls/tls_key.rs +++ b/ext/tls/tls_key.rs @@ -11,12 +11,6 @@ //! key lookup can handle closing one end of the pair, in which case they will just //! attempt to clean up the associated resources. -use deno_core::futures::future::poll_fn; -use deno_core::futures::future::Either; -use deno_core::futures::FutureExt; -use deno_core::unsync::spawn; -use rustls::ServerConfig; -use rustls_tokio_stream::ServerConfigProvider; use std::cell::RefCell; use std::collections::HashMap; use std::fmt::Debug; @@ -25,6 +19,13 @@ use std::future::Future; use std::io::ErrorKind; use std::rc::Rc; use std::sync::Arc; + +use deno_core::futures::future::poll_fn; +use deno_core::futures::future::Either; +use deno_core::futures::FutureExt; +use deno_core::unsync::spawn; +use rustls::ServerConfig; +use rustls_tokio_stream::ServerConfigProvider; use tokio::sync::broadcast; use tokio::sync::mpsc; use tokio::sync::oneshot; @@ -269,9 +270,10 @@ impl TlsKeyLookup { #[cfg(test)] pub mod tests { - use super::*; use deno_core::unsync::spawn; + use super::*; + fn tls_key_for_test(sni: &str) -> TlsKey { let manifest_dir = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); diff --git a/ext/url/benches/url_ops.rs b/ext/url/benches/url_ops.rs index 70afb96db2d96b..acde8be6bbdcd5 100644 --- a/ext/url/benches/url_ops.rs +++ b/ext/url/benches/url_ops.rs @@ -4,7 +4,6 @@ use deno_bench_util::bench_js_sync; use deno_bench_util::bench_or_profile; use deno_bench_util::bencher::benchmark_group; use deno_bench_util::bencher::Bencher; - use deno_core::Extension; fn setup() -> Vec { diff --git a/ext/url/lib.rs b/ext/url/lib.rs index f8946532ae613e..d012d359989881 100644 --- a/ext/url/lib.rs +++ b/ext/url/lib.rs @@ -2,6 +2,8 @@ mod urlpattern; +use std::path::PathBuf; + use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::op2; @@ -10,13 +12,11 @@ use deno_core::url::quirks; use deno_core::url::Url; use deno_core::JsBuffer; use deno_core::OpState; -use std::path::PathBuf; +pub use urlpattern::UrlPatternError; use crate::urlpattern::op_urlpattern_parse; use crate::urlpattern::op_urlpattern_process_match_input; -pub use urlpattern::UrlPatternError; - deno_core::extension!( deno_url, deps = [deno_webidl], diff --git a/ext/url/urlpattern.rs b/ext/url/urlpattern.rs index 7d4e8ee71b06de..2ba159b896354a 100644 --- a/ext/url/urlpattern.rs +++ b/ext/url/urlpattern.rs @@ -1,7 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use deno_core::op2; - use urlpattern::quirks; use urlpattern::quirks::MatchInput; use urlpattern::quirks::StringOrInit; diff --git a/ext/web/compression.rs b/ext/web/compression.rs index 6967009915d419..b6cc3578397c04 100644 --- a/ext/web/compression.rs +++ b/ext/web/compression.rs @@ -1,5 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::cell::RefCell; +use std::io::Write; + use deno_core::op2; use flate2::write::DeflateDecoder; use flate2::write::DeflateEncoder; @@ -8,8 +11,6 @@ use flate2::write::GzEncoder; use flate2::write::ZlibDecoder; use flate2::write::ZlibEncoder; use flate2::Compression; -use std::cell::RefCell; -use std::io::Write; #[derive(Debug, thiserror::Error)] pub enum CompressionError { diff --git a/ext/web/lib.rs b/ext/web/lib.rs index af0fc2c276563e..a031a81ecbc366 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -6,24 +6,23 @@ mod message_port; mod stream_resource; mod timers; +use std::borrow::Cow; +use std::cell::RefCell; +use std::path::PathBuf; +use std::sync::Arc; + +pub use blob::BlobError; +pub use compression::CompressionError; use deno_core::op2; use deno_core::url::Url; use deno_core::v8; use deno_core::ByteString; use deno_core::ToJsBuffer; use deno_core::U16String; - use encoding_rs::CoderResult; use encoding_rs::Decoder; use encoding_rs::DecoderResult; use encoding_rs::Encoding; -use std::borrow::Cow; -use std::cell::RefCell; -use std::path::PathBuf; -use std::sync::Arc; - -pub use blob::BlobError; -pub use compression::CompressionError; pub use message_port::MessagePortError; pub use stream_resource::StreamResourceError; @@ -38,7 +37,6 @@ pub use crate::blob::Blob; pub use crate::blob::BlobPart; pub use crate::blob::BlobStore; pub use crate::blob::InMemoryBlobPart; - pub use crate::message_port::create_entangled_message_port; pub use crate::message_port::deserialize_js_transferables; use crate::message_port::op_message_port_create_entangled; @@ -49,7 +47,6 @@ pub use crate::message_port::serialize_transferables; pub use crate::message_port::JsMessageData; pub use crate::message_port::MessagePort; pub use crate::message_port::Transferable; - use crate::timers::op_defer; use crate::timers::op_now; use crate::timers::op_time_origin; diff --git a/ext/web/message_port.rs b/ext/web/message_port.rs index 1a4a09073d176d..c55b963e092260 100644 --- a/ext/web/message_port.rs +++ b/ext/web/message_port.rs @@ -5,7 +5,6 @@ use std::cell::RefCell; use std::rc::Rc; use deno_core::op2; - use deno_core::CancelFuture; use deno_core::CancelHandle; use deno_core::DetachedBuffer; diff --git a/ext/web/stream_resource.rs b/ext/web/stream_resource.rs index c44a385ea9d59d..cb0ce440735c21 100644 --- a/ext/web/stream_resource.rs +++ b/ext/web/stream_resource.rs @@ -1,4 +1,17 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::cell::RefCell; +use std::cell::RefMut; +use std::ffi::c_void; +use std::future::Future; +use std::marker::PhantomData; +use std::mem::MaybeUninit; +use std::pin::Pin; +use std::rc::Rc; +use std::task::Context; +use std::task::Poll; +use std::task::Waker; + use bytes::BytesMut; use deno_core::external; use deno_core::op2; @@ -17,18 +30,6 @@ use deno_core::Resource; use deno_core::ResourceId; use futures::future::poll_fn; use futures::TryFutureExt; -use std::borrow::Cow; -use std::cell::RefCell; -use std::cell::RefMut; -use std::ffi::c_void; -use std::future::Future; -use std::marker::PhantomData; -use std::mem::MaybeUninit; -use std::pin::Pin; -use std::rc::Rc; -use std::task::Context; -use std::task::Poll; -use std::task::Waker; #[derive(Debug, thiserror::Error)] pub enum StreamResourceError { @@ -607,13 +608,15 @@ impl Drop for ReadableStreamResourceData { #[cfg(test)] mod tests { - use super::*; - use deno_core::v8; use std::cell::OnceCell; use std::sync::atomic::AtomicUsize; use std::sync::OnceLock; use std::time::Duration; + use deno_core::v8; + + use super::*; + static V8_GLOBAL: OnceLock<()> = OnceLock::new(); thread_local! { diff --git a/ext/web/timers.rs b/ext/web/timers.rs index 06444ed34ffba3..696f352de09b42 100644 --- a/ext/web/timers.rs +++ b/ext/web/timers.rs @@ -2,13 +2,14 @@ //! This module helps deno implement timers and performance APIs. -use deno_core::op2; -use deno_core::OpState; use std::time::Duration; use std::time::Instant; use std::time::SystemTime; use std::time::UNIX_EPOCH; +use deno_core::op2; +use deno_core::OpState; + pub trait TimersPermission { fn allow_hrtime(&mut self) -> bool; } diff --git a/ext/webgpu/binding.rs b/ext/webgpu/binding.rs index 41708acc7f1a43..6d0d11db3f362c 100644 --- a/ext/webgpu/binding.rs +++ b/ext/webgpu/binding.rs @@ -1,13 +1,14 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::rc::Rc; + use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; use serde::Deserialize; -use std::borrow::Cow; -use std::rc::Rc; use super::error::WebGpuResult; diff --git a/ext/webgpu/buffer.rs b/ext/webgpu/buffer.rs index c2b53890e0ccef..d3c15d978a8f34 100644 --- a/ext/webgpu/buffer.rs +++ b/ext/webgpu/buffer.rs @@ -1,9 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::op2; -use deno_core::OpState; -use deno_core::Resource; -use deno_core::ResourceId; use std::borrow::Cow; use std::cell::RefCell; use std::rc::Rc; @@ -11,6 +7,11 @@ use std::sync::Arc; use std::sync::Mutex; use std::time::Duration; +use deno_core::op2; +use deno_core::OpState; +use deno_core::Resource; +use deno_core::ResourceId; + use super::error::WebGpuResult; #[derive(Debug, thiserror::Error)] diff --git a/ext/webgpu/bundle.rs b/ext/webgpu/bundle.rs index d9a5b29539aa93..70bd64a77f1ddc 100644 --- a/ext/webgpu/bundle.rs +++ b/ext/webgpu/bundle.rs @@ -1,13 +1,14 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::cell::RefCell; +use std::rc::Rc; + use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; use serde::Deserialize; -use std::borrow::Cow; -use std::cell::RefCell; -use std::rc::Rc; use super::error::WebGpuResult; diff --git a/ext/webgpu/byow.rs b/ext/webgpu/byow.rs index c9e1177b1efe53..dfc1678aeff24b 100644 --- a/ext/webgpu/byow.rs +++ b/ext/webgpu/byow.rs @@ -1,8 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::op2; -use deno_core::OpState; -use deno_core::ResourceId; use std::ffi::c_void; #[cfg(any( target_os = "linux", @@ -12,6 +9,10 @@ use std::ffi::c_void; ))] use std::ptr::NonNull; +use deno_core::op2; +use deno_core::OpState; +use deno_core::ResourceId; + use crate::surface::WebGpuSurface; #[derive(Debug, thiserror::Error)] diff --git a/ext/webgpu/command_encoder.rs b/ext/webgpu/command_encoder.rs index 4bee7aac301795..de1e6102c64149 100644 --- a/ext/webgpu/command_encoder.rs +++ b/ext/webgpu/command_encoder.rs @@ -1,17 +1,18 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::WebGpuQuerySet; +use std::borrow::Cow; +use std::cell::RefCell; +use std::rc::Rc; + use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; use serde::Deserialize; -use std::borrow::Cow; -use std::cell::RefCell; -use std::rc::Rc; use super::error::WebGpuResult; +use crate::WebGpuQuerySet; pub(crate) struct WebGpuCommandEncoder( pub(crate) super::Instance, diff --git a/ext/webgpu/compute_pass.rs b/ext/webgpu/compute_pass.rs index 17043c76713973..e0e11c19a59e85 100644 --- a/ext/webgpu/compute_pass.rs +++ b/ext/webgpu/compute_pass.rs @@ -1,12 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::cell::RefCell; + use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; -use std::borrow::Cow; -use std::cell::RefCell; use super::error::WebGpuResult; diff --git a/ext/webgpu/error.rs b/ext/webgpu/error.rs index f08f765386ead3..516c3c8c35c464 100644 --- a/ext/webgpu/error.rs +++ b/ext/webgpu/error.rs @@ -1,9 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::ResourceId; -use serde::Serialize; use std::convert::From; use std::error::Error; + +use deno_core::ResourceId; +use serde::Serialize; use wgpu_core::binding_model::CreateBindGroupError; use wgpu_core::binding_model::CreateBindGroupLayoutError; use wgpu_core::binding_model::CreatePipelineLayoutError; diff --git a/ext/webgpu/lib.rs b/ext/webgpu/lib.rs index 5dc8278e410b54..a5a8ea5b95793f 100644 --- a/ext/webgpu/lib.rs +++ b/ext/webgpu/lib.rs @@ -2,21 +2,21 @@ #![cfg(not(target_arch = "wasm32"))] #![warn(unsafe_op_in_unsafe_fn)] +use std::borrow::Cow; +use std::cell::RefCell; +use std::collections::HashSet; +use std::rc::Rc; + use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; +use error::WebGpuResult; use serde::Deserialize; use serde::Serialize; -use std::borrow::Cow; -use std::cell::RefCell; -use std::collections::HashSet; -use std::rc::Rc; pub use wgpu_core; pub use wgpu_types; -use error::WebGpuResult; - pub const UNSTABLE_FEATURE_NAME: &str = "webgpu"; #[macro_use] diff --git a/ext/webgpu/pipeline.rs b/ext/webgpu/pipeline.rs index a6b0cb8cec8e11..62c1e340c8c344 100644 --- a/ext/webgpu/pipeline.rs +++ b/ext/webgpu/pipeline.rs @@ -1,5 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::collections::HashMap; +use std::rc::Rc; + use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; @@ -7,9 +11,6 @@ use deno_core::Resource; use deno_core::ResourceId; use serde::Deserialize; use serde::Serialize; -use std::borrow::Cow; -use std::collections::HashMap; -use std::rc::Rc; use super::error::WebGpuError; use super::error::WebGpuResult; diff --git a/ext/webgpu/queue.rs b/ext/webgpu/queue.rs index 8c8bbec95efb93..2d73f4fcc51646 100644 --- a/ext/webgpu/queue.rs +++ b/ext/webgpu/queue.rs @@ -1,17 +1,18 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::command_encoder::WebGpuCommandBuffer; -use crate::Instance; +use std::borrow::Cow; +use std::rc::Rc; + use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; use serde::Deserialize; -use std::borrow::Cow; -use std::rc::Rc; use super::error::WebGpuResult; +use crate::command_encoder::WebGpuCommandBuffer; +use crate::Instance; pub struct WebGpuQueue(pub Instance, pub wgpu_core::id::QueueId); impl Resource for WebGpuQueue { diff --git a/ext/webgpu/render_pass.rs b/ext/webgpu/render_pass.rs index 9b9d87d9fc05a6..e1bf2a56818c79 100644 --- a/ext/webgpu/render_pass.rs +++ b/ext/webgpu/render_pass.rs @@ -1,12 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::cell::RefCell; + use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; use serde::Deserialize; -use std::borrow::Cow; -use std::cell::RefCell; use super::error::WebGpuResult; diff --git a/ext/webgpu/sampler.rs b/ext/webgpu/sampler.rs index 9fc1269ea7b758..caeccdd5f3bb45 100644 --- a/ext/webgpu/sampler.rs +++ b/ext/webgpu/sampler.rs @@ -1,12 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::rc::Rc; + use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; use serde::Deserialize; -use std::borrow::Cow; -use std::rc::Rc; use super::error::WebGpuResult; diff --git a/ext/webgpu/shader.rs b/ext/webgpu/shader.rs index 4653bd85bf05c6..285a37f56015f9 100644 --- a/ext/webgpu/shader.rs +++ b/ext/webgpu/shader.rs @@ -1,11 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::rc::Rc; + use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; -use std::borrow::Cow; -use std::rc::Rc; use super::error::WebGpuResult; diff --git a/ext/webgpu/surface.rs b/ext/webgpu/surface.rs index 297eaeb00874ae..7471d567a1dbc6 100644 --- a/ext/webgpu/surface.rs +++ b/ext/webgpu/surface.rs @@ -1,15 +1,17 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::WebGpuResult; +use std::borrow::Cow; +use std::rc::Rc; + use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; use serde::Deserialize; -use std::borrow::Cow; -use std::rc::Rc; use wgpu_types::SurfaceStatus; +use super::WebGpuResult; + #[derive(Debug, thiserror::Error)] pub enum SurfaceError { #[error(transparent)] diff --git a/ext/webgpu/texture.rs b/ext/webgpu/texture.rs index f8a5e05a3e2b15..4c95a4cb69f0ea 100644 --- a/ext/webgpu/texture.rs +++ b/ext/webgpu/texture.rs @@ -1,12 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::rc::Rc; + use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; use serde::Deserialize; -use std::borrow::Cow; -use std::rc::Rc; use super::error::WebGpuResult; pub(crate) struct WebGpuTexture { diff --git a/ext/webidl/benches/dict.rs b/ext/webidl/benches/dict.rs index cfb658fa84bee8..1c0efc921c2097 100644 --- a/ext/webidl/benches/dict.rs +++ b/ext/webidl/benches/dict.rs @@ -4,7 +4,6 @@ use deno_bench_util::bench_js_sync; use deno_bench_util::bench_or_profile; use deno_bench_util::bencher::benchmark_group; use deno_bench_util::bencher::Bencher; - use deno_core::Extension; fn setup() -> Vec { diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index 5aef1a7a550646..4dcead2a77c3d2 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -1,5 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::stream::WebSocketStream; +use std::borrow::Cow; +use std::cell::Cell; +use std::cell::RefCell; +use std::future::Future; +use std::num::NonZeroUsize; +use std::path::PathBuf; +use std::rc::Rc; +use std::sync::Arc; + use bytes::Bytes; use deno_core::futures::TryFutureExt; use deno_core::op2; @@ -17,12 +25,20 @@ use deno_core::Resource; use deno_core::ResourceId; use deno_core::ToJsBuffer; use deno_net::raw::NetworkStream; +use deno_permissions::PermissionCheckError; use deno_tls::create_client_config; use deno_tls::rustls::ClientConfig; use deno_tls::rustls::ClientConnection; use deno_tls::RootCertStoreProvider; use deno_tls::SocketUse; use deno_tls::TlsKeys; +use fastwebsockets::CloseCode; +use fastwebsockets::FragmentCollectorRead; +use fastwebsockets::Frame; +use fastwebsockets::OpCode; +use fastwebsockets::Role; +use fastwebsockets::WebSocket; +use fastwebsockets::WebSocketWrite; use http::header::CONNECTION; use http::header::UPGRADE; use http::HeaderName; @@ -36,28 +52,13 @@ use rustls_tokio_stream::rustls::pki_types::ServerName; use rustls_tokio_stream::rustls::RootCertStore; use rustls_tokio_stream::TlsStream; use serde::Serialize; -use std::borrow::Cow; -use std::cell::Cell; -use std::cell::RefCell; -use std::future::Future; -use std::num::NonZeroUsize; -use std::path::PathBuf; -use std::rc::Rc; -use std::sync::Arc; use tokio::io::AsyncRead; use tokio::io::AsyncWrite; use tokio::io::ReadHalf; use tokio::io::WriteHalf; use tokio::net::TcpStream; -use deno_permissions::PermissionCheckError; -use fastwebsockets::CloseCode; -use fastwebsockets::FragmentCollectorRead; -use fastwebsockets::Frame; -use fastwebsockets::OpCode; -use fastwebsockets::Role; -use fastwebsockets::WebSocket; -use fastwebsockets::WebSocketWrite; +use crate::stream::WebSocketStream; mod stream; diff --git a/ext/websocket/stream.rs b/ext/websocket/stream.rs index 2cd2622175bb29..6900922bb79c9d 100644 --- a/ext/websocket/stream.rs +++ b/ext/websocket/stream.rs @@ -1,4 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::io::ErrorKind; +use std::pin::Pin; +use std::task::ready; +use std::task::Poll; + use bytes::Buf; use bytes::Bytes; use deno_net::raw::NetworkStream; @@ -6,10 +11,6 @@ use h2::RecvStream; use h2::SendStream; use hyper::upgrade::Upgraded; use hyper_util::rt::TokioIo; -use std::io::ErrorKind; -use std::pin::Pin; -use std::task::ready; -use std::task::Poll; use tokio::io::AsyncRead; use tokio::io::AsyncWrite; use tokio::io::ReadBuf; diff --git a/ext/webstorage/lib.rs b/ext/webstorage/lib.rs index c3e4c465969ed3..6b14cbb08c99a0 100644 --- a/ext/webstorage/lib.rs +++ b/ext/webstorage/lib.rs @@ -7,12 +7,11 @@ use std::path::PathBuf; use deno_core::op2; use deno_core::GarbageCollected; use deno_core::OpState; +pub use rusqlite; use rusqlite::params; use rusqlite::Connection; use rusqlite::OptionalExtension; -pub use rusqlite; - #[derive(Debug, thiserror::Error)] pub enum WebStorageError { #[error("LocalStorage is not supported in this context.")] diff --git a/resolvers/deno/npm/mod.rs b/resolvers/deno/npm/mod.rs index 082940eb343733..7b4b09a842378e 100644 --- a/resolvers/deno/npm/mod.rs +++ b/resolvers/deno/npm/mod.rs @@ -4,8 +4,14 @@ use std::fmt::Debug; use std::path::PathBuf; use boxed_error::Boxed; +pub use byonm::ByonmInNpmPackageChecker; +pub use byonm::ByonmNpmResolver; +pub use byonm::ByonmNpmResolverCreateOptions; +pub use byonm::ByonmNpmResolverRc; +pub use byonm::ByonmResolvePkgFolderFromDenoReqError; use deno_semver::npm::NpmPackageReqReference; use deno_semver::package::PackageReq; +pub use local::normalize_pkg_name_for_node_modules_deno_folder; use node_resolver::errors::NodeResolveError; use node_resolver::errors::NodeResolveErrorKind; use node_resolver::errors::PackageFolderResolveErrorKind; @@ -26,13 +32,6 @@ use sys_traits::FsReadDir; use thiserror::Error; use url::Url; -pub use byonm::ByonmInNpmPackageChecker; -pub use byonm::ByonmNpmResolver; -pub use byonm::ByonmNpmResolverCreateOptions; -pub use byonm::ByonmNpmResolverRc; -pub use byonm::ByonmResolvePkgFolderFromDenoReqError; -pub use local::normalize_pkg_name_for_node_modules_deno_folder; - mod byonm; mod local; diff --git a/resolvers/node/analyze.rs b/resolvers/node/analyze.rs index 2024e6a1e89c24..7f21473c109e67 100644 --- a/resolvers/node/analyze.rs +++ b/resolvers/node/analyze.rs @@ -6,6 +6,8 @@ use std::collections::HashSet; use std::path::Path; use std::path::PathBuf; +use anyhow::Context; +use anyhow::Error as AnyError; use deno_path_util::url_from_file_path; use deno_path_util::url_to_file_path; use futures::future::LocalBoxFuture; @@ -13,9 +15,6 @@ use futures::stream::FuturesUnordered; use futures::FutureExt; use futures::StreamExt; use once_cell::sync::Lazy; - -use anyhow::Context; -use anyhow::Error as AnyError; use sys_traits::FsCanonicalize; use sys_traits::FsMetadata; use sys_traits::FsRead; diff --git a/resolvers/node/resolution.rs b/resolvers/node/resolution.rs index 95631daf39565d..e2ee2799e6d791 100644 --- a/resolvers/node/resolution.rs +++ b/resolvers/node/resolution.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; use anyhow::bail; use anyhow::Error as AnyError; +use deno_package_json::PackageJson; use deno_path_util::url_from_file_path; use serde_json::Map; use serde_json::Value; @@ -48,7 +49,6 @@ use crate::npm::InNpmPackageCheckerRc; use crate::NpmPackageFolderResolverRc; use crate::PackageJsonResolverRc; use crate::PathClean; -use deno_package_json::PackageJson; pub static DEFAULT_CONDITIONS: &[&str] = &["deno", "node", "import"]; pub static REQUIRE_CONDITIONS: &[&str] = &["require", "node"]; diff --git a/resolvers/node/sync.rs b/resolvers/node/sync.rs index 3c4729aa2c9c08..e8add4e0fcc364 100644 --- a/resolvers/node/sync.rs +++ b/resolvers/node/sync.rs @@ -6,10 +6,9 @@ pub use inner::*; mod inner { #![allow(clippy::disallowed_types)] - pub use std::sync::Arc as MaybeArc; - pub use core::marker::Send as MaybeSend; pub use core::marker::Sync as MaybeSync; + pub use std::sync::Arc as MaybeArc; } #[cfg(not(feature = "sync"))] diff --git a/resolvers/npm_cache/fs_util.rs b/resolvers/npm_cache/fs_util.rs index ed123f085c1141..d5a634e36fc0f8 100644 --- a/resolvers/npm_cache/fs_util.rs +++ b/resolvers/npm_cache/fs_util.rs @@ -1,10 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use anyhow::Context; -use anyhow::Error as AnyError; use std::io::ErrorKind; use std::path::Path; use std::time::Duration; + +use anyhow::Context; +use anyhow::Error as AnyError; use sys_traits::FsCreateDirAll; use sys_traits::FsDirEntry; use sys_traits::FsHardLink; diff --git a/resolvers/npm_cache/lib.rs b/resolvers/npm_cache/lib.rs index e681fa71ac0071..50614a239a4382 100644 --- a/resolvers/npm_cache/lib.rs +++ b/resolvers/npm_cache/lib.rs @@ -40,13 +40,12 @@ mod tarball; mod tarball_extract; pub use fs_util::hard_link_dir_recursive; -pub use registry_info::RegistryInfoProvider; -pub use tarball::TarballCache; - // todo(#27198): make both of these private and get the rest of the code // using RegistryInfoProvider. pub use registry_info::get_package_url; +pub use registry_info::RegistryInfoProvider; pub use remote::maybe_auth_header_for_npm_registry; +pub use tarball::TarballCache; #[derive(Debug)] pub struct DownloadError { diff --git a/runtime/errors.rs b/runtime/errors.rs index 01588c593bcb13..e0f807d3ae2ea0 100644 --- a/runtime/errors.rs +++ b/runtime/errors.rs @@ -9,16 +9,11 @@ //! Diagnostics are compile-time type errors, whereas JsErrors are runtime //! exceptions. -use crate::ops::fs_events::FsEventsError; -use crate::ops::http::HttpStartError; -use crate::ops::os::OsError; -use crate::ops::permissions::PermissionError; -use crate::ops::process::CheckRunPermissionError; -use crate::ops::process::ProcessError; -use crate::ops::signal::SignalError; -use crate::ops::tty::TtyError; -use crate::ops::web_worker::SyncFetchError; -use crate::ops::worker_host::CreateWorkerError; +use std::env; +use std::error::Error; +use std::io; +use std::sync::Arc; + use deno_broadcast_channel::BroadcastChannelError; use deno_cache::CacheError; use deno_canvas::CanvasError; @@ -68,10 +63,17 @@ use deno_websocket::HandshakeError; use deno_websocket::WebsocketError; use deno_webstorage::WebStorageError; use rustyline::error::ReadlineError; -use std::env; -use std::error::Error; -use std::io; -use std::sync::Arc; + +use crate::ops::fs_events::FsEventsError; +use crate::ops::http::HttpStartError; +use crate::ops::os::OsError; +use crate::ops::permissions::PermissionError; +use crate::ops::process::CheckRunPermissionError; +use crate::ops::process::ProcessError; +use crate::ops::signal::SignalError; +use crate::ops::tty::TtyError; +use crate::ops::web_worker::SyncFetchError; +use crate::ops::worker_host::CreateWorkerError; fn get_run_descriptor_parse_error(e: &RunDescriptorParseError) -> &'static str { match e { @@ -1047,11 +1049,6 @@ fn get_fs_error(e: &FsError) -> &'static str { } mod node { - use super::get_error_class_name; - use super::get_io_error_class; - use super::get_permission_check_error_class; - use super::get_serde_json_error_class; - use super::get_url_parse_error_class; pub use deno_node::ops::blocklist::BlocklistError; pub use deno_node::ops::crypto::cipher::CipherContextError; pub use deno_node::ops::crypto::cipher::CipherError; @@ -1096,6 +1093,12 @@ mod node { pub use deno_node::ops::zlib::mode::ModeError; pub use deno_node::ops::zlib::ZlibError; + use super::get_error_class_name; + use super::get_io_error_class; + use super::get_permission_check_error_class; + use super::get_serde_json_error_class; + use super::get_url_parse_error_class; + pub fn get_blocklist_error(error: &BlocklistError) -> &'static str { match error { BlocklistError::AddrParse(_) => "Error", diff --git a/runtime/fmt_errors.rs b/runtime/fmt_errors.rs index 3c60c3a3d7e796..5af84c67bc7014 100644 --- a/runtime/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -1,11 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. //! This mod provides DenoError to unify errors across Deno. +use std::fmt::Write as _; + use color_print::cformat; use color_print::cstr; use deno_core::error::format_frame; use deno_core::error::JsError; use deno_terminal::colors; -use std::fmt::Write as _; #[derive(Debug, Clone)] struct ErrorReference<'a> { @@ -490,9 +491,10 @@ pub fn format_js_error(js_error: &JsError) -> String { #[cfg(test)] mod tests { - use super::*; use test_util::strip_ansi_codes; + use super::*; + #[test] fn test_format_none_source_line() { let actual = format_maybe_source_line(None, None, false, 0); diff --git a/runtime/fs_util.rs b/runtime/fs_util.rs index a858e9770d5ec4..2fc34dd31174ba 100644 --- a/runtime/fs_util.rs +++ b/runtime/fs_util.rs @@ -1,10 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::path::Path; +use std::path::PathBuf; + use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_path_util::normalize_path; -use std::path::Path; -use std::path::PathBuf; #[inline] pub fn resolve_from_cwd(path: &Path) -> Result { diff --git a/runtime/inspector_server.rs b/runtime/inspector_server.rs index a789dd3dcab10d..cbe97738c7c711 100644 --- a/runtime/inspector_server.rs +++ b/runtime/inspector_server.rs @@ -2,6 +2,14 @@ // Alias for the future `!` type. use core::convert::Infallible as Never; +use std::cell::RefCell; +use std::collections::HashMap; +use std::net::SocketAddr; +use std::pin::pin; +use std::process; +use std::rc::Rc; +use std::thread; + use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::futures::channel::mpsc; @@ -28,13 +36,6 @@ use fastwebsockets::OpCode; use fastwebsockets::WebSocket; use hyper::body::Bytes; use hyper_util::rt::TokioIo; -use std::cell::RefCell; -use std::collections::HashMap; -use std::net::SocketAddr; -use std::pin::pin; -use std::process; -use std::rc::Rc; -use std::thread; use tokio::net::TcpListener; use tokio::sync::broadcast; use uuid::Uuid; diff --git a/runtime/ops/fs_events.rs b/runtime/ops/fs_events.rs index f6e5ceff5c8488..1b89199e372053 100644 --- a/runtime/ops/fs_events.rs +++ b/runtime/ops/fs_events.rs @@ -1,5 +1,14 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::cell::RefCell; +use std::convert::From; +use std::path::Path; +use std::path::PathBuf; +use std::rc::Rc; +use std::sync::Arc; + +use deno_core::op2; use deno_core::parking_lot::Mutex; use deno_core::AsyncRefCell; use deno_core::CancelFuture; @@ -8,9 +17,6 @@ use deno_core::OpState; use deno_core::RcRef; use deno_core::Resource; use deno_core::ResourceId; - -use deno_core::op2; - use deno_permissions::PermissionsContainer; use notify::event::Event as NotifyEvent; use notify::event::ModifyKind; @@ -20,13 +26,6 @@ use notify::RecommendedWatcher; use notify::RecursiveMode; use notify::Watcher; use serde::Serialize; -use std::borrow::Cow; -use std::cell::RefCell; -use std::convert::From; -use std::path::Path; -use std::path::PathBuf; -use std::rc::Rc; -use std::sync::Arc; use tokio::sync::mpsc; deno_core::extension!( diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index 71169217a7ed47..3b767fd94fd7f7 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -1,7 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::sys_info; -use crate::worker::ExitCode; +use std::collections::HashMap; +use std::env; + use deno_core::op2; use deno_core::v8; use deno_core::OpState; @@ -9,8 +10,9 @@ use deno_node::NODE_ENV_VAR_ALLOWLIST; use deno_path_util::normalize_path; use deno_permissions::PermissionsContainer; use serde::Serialize; -use std::collections::HashMap; -use std::env; + +use crate::sys_info; +use crate::worker::ExitCode; deno_core::extension!( deno_os, diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index 422f229632be2f..f4064367b90111 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -1,5 +1,21 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::cell::RefCell; +use std::collections::HashMap; +use std::ffi::OsString; +use std::io::Write; +#[cfg(unix)] +use std::os::unix::prelude::ExitStatusExt; +#[cfg(unix)] +use std::os::unix::process::CommandExt; +#[cfg(windows)] +use std::os::windows::process::CommandExt; +use std::path::Path; +use std::path::PathBuf; +use std::process::ExitStatus; +use std::rc::Rc; + use deno_core::op2; use deno_core::serde_json; use deno_core::AsyncMutFuture; @@ -18,25 +34,9 @@ use deno_permissions::PermissionsContainer; use deno_permissions::RunQueryDescriptor; use serde::Deserialize; use serde::Serialize; -use std::borrow::Cow; -use std::cell::RefCell; -use std::collections::HashMap; -use std::ffi::OsString; -use std::io::Write; -use std::path::Path; -use std::path::PathBuf; -use std::process::ExitStatus; -use std::rc::Rc; use tokio::process::Command; -#[cfg(windows)] -use std::os::windows::process::CommandExt; - use crate::ops::signal::SignalError; -#[cfg(unix)] -use std::os::unix::prelude::ExitStatusExt; -#[cfg(unix)] -use std::os::unix::process::CommandExt; pub const UNSTABLE_FEATURE_NAME: &str = "process"; @@ -1087,6 +1087,7 @@ mod deprecated { pub fn kill(pid: i32, signal: &str) -> Result<(), ProcessError> { use std::io::Error; use std::io::ErrorKind::NotFound; + use winapi::shared::minwindef::DWORD; use winapi::shared::minwindef::FALSE; use winapi::shared::minwindef::TRUE; diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index 8d54783fc96ec2..4b30ab8d8df2b7 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -34,6 +34,7 @@ pub fn op_ppid() -> i64 { // - Apache License, Version 2.0 // - MIT license use std::mem; + use winapi::shared::minwindef::DWORD; use winapi::um::handleapi::CloseHandle; use winapi::um::handleapi::INVALID_HANDLE_VALUE; diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index ef87c372975183..85c883021c50d0 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -1,13 +1,4 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::op2; -use deno_core::AsyncRefCell; -use deno_core::CancelFuture; -use deno_core::CancelHandle; -use deno_core::OpState; -use deno_core::RcRef; -use deno_core::Resource; -use deno_core::ResourceId; - use std::borrow::Cow; use std::cell::RefCell; #[cfg(unix)] @@ -18,6 +9,14 @@ use std::sync::atomic::AtomicBool; #[cfg(unix)] use std::sync::Arc; +use deno_core::op2; +use deno_core::AsyncRefCell; +use deno_core::CancelFuture; +use deno_core::CancelHandle; +use deno_core::OpState; +use deno_core::RcRef; +use deno_core::Resource; +use deno_core::ResourceId; #[cfg(unix)] use tokio::signal::unix::signal; #[cfg(unix)] diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs index 7849185faaeaf8..0b3c2e0064edd6 100644 --- a/runtime/ops/tty.rs +++ b/runtime/ops/tty.rs @@ -1,9 +1,23 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +#[cfg(unix)] +use std::cell::RefCell; +#[cfg(unix)] +use std::collections::HashMap; use std::io::Error; +#[cfg(windows)] +use std::sync::Arc; use deno_core::op2; +#[cfg(windows)] +use deno_core::parking_lot::Mutex; use deno_core::OpState; +#[cfg(unix)] +use deno_core::ResourceId; +#[cfg(windows)] +use deno_io::WinTtyState; +#[cfg(unix)] +use nix::sys::termios; use rustyline::config::Configurer; use rustyline::error::ReadlineError; use rustyline::Cmd; @@ -12,22 +26,6 @@ use rustyline::KeyCode; use rustyline::KeyEvent; use rustyline::Modifiers; -#[cfg(windows)] -use deno_core::parking_lot::Mutex; -#[cfg(windows)] -use deno_io::WinTtyState; -#[cfg(windows)] -use std::sync::Arc; - -#[cfg(unix)] -use deno_core::ResourceId; -#[cfg(unix)] -use nix::sys::termios; -#[cfg(unix)] -use std::cell::RefCell; -#[cfg(unix)] -use std::collections::HashMap; - #[cfg(unix)] #[derive(Default, Clone)] struct TtyModeStore( @@ -116,7 +114,6 @@ fn op_set_raw( #[cfg(windows)] { use winapi::shared::minwindef::FALSE; - use winapi::um::consoleapi; let handle = handle_or_fd; diff --git a/runtime/ops/web_worker.rs b/runtime/ops/web_worker.rs index d0c3eea668b791..34466f8db9e9f4 100644 --- a/runtime/ops/web_worker.rs +++ b/runtime/ops/web_worker.rs @@ -2,18 +2,19 @@ mod sync_fetch; -use crate::web_worker::WebWorkerInternalHandle; -use crate::web_worker::WebWorkerType; +use std::cell::RefCell; +use std::rc::Rc; + use deno_core::op2; use deno_core::CancelFuture; use deno_core::OpState; use deno_web::JsMessageData; use deno_web::MessagePortError; -use std::cell::RefCell; -use std::rc::Rc; +pub use sync_fetch::SyncFetchError; use self::sync_fetch::op_worker_sync_fetch; -pub use sync_fetch::SyncFetchError; +use crate::web_worker::WebWorkerInternalHandle; +use crate::web_worker::WebWorkerType; deno_core::extension!( deno_web_worker, diff --git a/runtime/ops/web_worker/sync_fetch.rs b/runtime/ops/web_worker/sync_fetch.rs index 508bcb7bb02bfe..a774e6db346a85 100644 --- a/runtime/ops/web_worker/sync_fetch.rs +++ b/runtime/ops/web_worker/sync_fetch.rs @@ -2,8 +2,6 @@ use std::sync::Arc; -use crate::web_worker::WebWorkerInternalHandle; -use crate::web_worker::WebWorkerType; use deno_core::futures::StreamExt; use deno_core::op2; use deno_core::url::Url; @@ -16,6 +14,9 @@ use hyper::body::Bytes; use serde::Deserialize; use serde::Serialize; +use crate::web_worker::WebWorkerInternalHandle; +use crate::web_worker::WebWorkerType; + // TODO(andreubotella) Properly parse the MIME type fn mime_type_essence(mime_type: &str) -> String { let essence = match mime_type.split_once(';') { diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index 131bad19623fde..fafce5dccdb354 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -1,15 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::ops::TestingFeaturesEnabled; -use crate::web_worker::run_web_worker; -use crate::web_worker::SendableWebWorkerHandle; -use crate::web_worker::WebWorker; -use crate::web_worker::WebWorkerHandle; -use crate::web_worker::WebWorkerType; -use crate::web_worker::WorkerControlEvent; -use crate::web_worker::WorkerId; -use crate::web_worker::WorkerMetadata; -use crate::worker::FormatJsErrorFn; +use std::cell::RefCell; +use std::collections::HashMap; +use std::rc::Rc; +use std::sync::Arc; + use deno_core::op2; use deno_core::serde::Deserialize; use deno_core::CancelFuture; @@ -22,10 +17,17 @@ use deno_web::deserialize_js_transferables; use deno_web::JsMessageData; use deno_web::MessagePortError; use log::debug; -use std::cell::RefCell; -use std::collections::HashMap; -use std::rc::Rc; -use std::sync::Arc; + +use crate::ops::TestingFeaturesEnabled; +use crate::web_worker::run_web_worker; +use crate::web_worker::SendableWebWorkerHandle; +use crate::web_worker::WebWorker; +use crate::web_worker::WebWorkerHandle; +use crate::web_worker::WebWorkerType; +use crate::web_worker::WorkerControlEvent; +use crate::web_worker::WorkerId; +use crate::web_worker::WorkerMetadata; +use crate::worker::FormatJsErrorFn; pub const UNSTABLE_FEATURE_NAME: &str = "worker-options"; diff --git a/runtime/permissions/lib.rs b/runtime/permissions/lib.rs index 1c5fb36f930fa8..8730ba20d183f5 100644 --- a/runtime/permissions/lib.rs +++ b/runtime/permissions/lib.rs @@ -1,5 +1,18 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; +use std::collections::HashSet; +use std::ffi::OsStr; +use std::fmt; +use std::fmt::Debug; +use std::hash::Hash; +use std::net::IpAddr; +use std::net::Ipv6Addr; +use std::path::Path; +use std::path::PathBuf; +use std::string::ToString; +use std::sync::Arc; + use capacity_builder::StringBuilder; use deno_core::parking_lot::Mutex; use deno_core::serde::de; @@ -15,28 +28,15 @@ use deno_path_util::url_to_file_path; use deno_terminal::colors; use fqdn::FQDN; use once_cell::sync::Lazy; -use std::borrow::Cow; -use std::collections::HashSet; -use std::ffi::OsStr; -use std::fmt; -use std::fmt::Debug; -use std::hash::Hash; -use std::net::IpAddr; -use std::net::Ipv6Addr; -use std::path::Path; -use std::path::PathBuf; -use std::string::ToString; -use std::sync::Arc; pub mod prompter; use prompter::permission_prompt; -use prompter::PERMISSION_EMOJI; - pub use prompter::set_prompt_callbacks; pub use prompter::set_prompter; pub use prompter::PermissionPrompter; pub use prompter::PromptCallback; pub use prompter::PromptResponse; +use prompter::PERMISSION_EMOJI; #[derive(Debug, thiserror::Error)] pub enum PermissionDeniedError { @@ -3691,11 +3691,13 @@ pub fn is_standalone() -> bool { #[cfg(test)] mod tests { - use super::*; + use std::net::Ipv4Addr; + use deno_core::serde_json::json; use fqdn::fqdn; use prompter::tests::*; - use std::net::Ipv4Addr; + + use super::*; // Creates vector of strings, Vec macro_rules! svec { diff --git a/runtime/permissions/prompter.rs b/runtime/permissions/prompter.rs index 0272744cc2f555..19f94434caf3df 100644 --- a/runtime/permissions/prompter.rs +++ b/runtime/permissions/prompter.rs @@ -1,10 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::is_standalone; -use deno_core::error::JsStackFrame; -use deno_core::parking_lot::Mutex; -use deno_terminal::colors; -use once_cell::sync::Lazy; use std::fmt::Write; use std::io::BufRead; use std::io::IsTerminal; @@ -12,6 +7,13 @@ use std::io::StderrLock; use std::io::StdinLock; use std::io::Write as IoWrite; +use deno_core::error::JsStackFrame; +use deno_core::parking_lot::Mutex; +use deno_terminal::colors; +use once_cell::sync::Lazy; + +use crate::is_standalone; + /// Helper function to make control characters visible so users can see the underlying filename. fn escape_control_characters(s: &str) -> std::borrow::Cow { if !s.contains(|c: char| c.is_ascii_control() || c.is_control()) { @@ -489,10 +491,11 @@ impl PermissionPrompter for TtyPrompter { #[cfg(test)] pub mod tests { - use super::*; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; + use super::*; + pub struct TestPrompter; impl PermissionPrompter for TestPrompter { diff --git a/runtime/shared.rs b/runtime/shared.rs index f7d76f67a760da..ce4350237fff0b 100644 --- a/runtime/shared.rs +++ b/runtime/shared.rs @@ -1,6 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Utilities shared between `build.rs` and the rest of the crate. +use std::path::Path; + use deno_ast::MediaType; use deno_ast::ParseParams; use deno_ast::SourceMapOption; @@ -10,7 +12,6 @@ use deno_core::Extension; use deno_core::ModuleCodeString; use deno_core::ModuleName; use deno_core::SourceMapData; -use std::path::Path; extension!(runtime, deps = [ diff --git a/runtime/snapshot.rs b/runtime/snapshot.rs index ad73f485ad8923..751cc43f2de8db 100644 --- a/runtime/snapshot.rs +++ b/runtime/snapshot.rs @@ -1,9 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::ops; -use crate::ops::bootstrap::SnapshotOptions; -use crate::shared::maybe_transpile_source; -use crate::shared::runtime; +use std::borrow::Cow; +use std::io::Write; +use std::path::Path; +use std::path::PathBuf; +use std::rc::Rc; +use std::sync::Arc; + use deno_cache::SqliteBackedCache; use deno_core::snapshot::*; use deno_core::v8; @@ -11,12 +14,11 @@ use deno_core::Extension; use deno_http::DefaultHttpPropertyExtractor; use deno_io::fs::FsError; use deno_permissions::PermissionCheckError; -use std::borrow::Cow; -use std::io::Write; -use std::path::Path; -use std::path::PathBuf; -use std::rc::Rc; -use std::sync::Arc; + +use crate::ops; +use crate::ops::bootstrap::SnapshotOptions; +use crate::shared::maybe_transpile_source; +use crate::shared::runtime; #[derive(Clone)] struct Permissions; diff --git a/runtime/sys_info.rs b/runtime/sys_info.rs index 99bfcfe103a5f8..d711e80ff04bef 100644 --- a/runtime/sys_info.rs +++ b/runtime/sys_info.rs @@ -159,6 +159,7 @@ pub fn hostname() -> String { use std::ffi::OsString; use std::mem; use std::os::windows::ffi::OsStringExt; + use winapi::shared::minwindef::MAKEWORD; use winapi::um::winsock2::GetHostNameW; use winapi::um::winsock2::WSAStartup; @@ -307,6 +308,7 @@ pub fn mem_info() -> Option { // - `dwLength` is set to the size of the struct. unsafe { use std::mem; + use winapi::shared::minwindef; use winapi::um::psapi::GetPerformanceInfo; use winapi::um::psapi::PERFORMANCE_INFORMATION; diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 2b46d9a2ff9d89..8902e0fe7e3226 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -1,5 +1,15 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::cell::RefCell; +use std::fmt; +use std::rc::Rc; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::AtomicU32; +use std::sync::atomic::Ordering; +use std::sync::Arc; +use std::task::Context; +use std::task::Poll; + use deno_broadcast_channel::InMemoryBroadcastChannel; use deno_cache::CreateCache; use deno_cache::SqliteBackedCache; @@ -46,15 +56,6 @@ use deno_web::JsMessageData; use deno_web::MessagePort; use deno_web::Transferable; use log::debug; -use std::cell::RefCell; -use std::fmt; -use std::rc::Rc; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::AtomicU32; -use std::sync::atomic::Ordering; -use std::sync::Arc; -use std::task::Context; -use std::task::Poll; use crate::inspector_server::InspectorServer; use crate::ops; diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs index 8364fe0d2b9670..f1e7dc05d09c3e 100644 --- a/runtime/worker_bootstrap.rs +++ b/runtime/worker_bootstrap.rs @@ -1,13 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::v8; -use deno_core::ModuleSpecifier; -use deno_telemetry::OtelConfig; -use serde::Serialize; use std::cell::RefCell; use std::thread; +use deno_core::v8; +use deno_core::ModuleSpecifier; +use deno_telemetry::OtelConfig; use deno_terminal::colors; +use serde::Serialize; /// The execution mode for this worker. Some modes may have implicit behaviour. #[derive(Copy, Clone)] diff --git a/tests/ffi/tests/integration_tests.rs b/tests/ffi/tests/integration_tests.rs index dbc0036bc2fefb..34fcc16355b616 100644 --- a/tests/ffi/tests/integration_tests.rs +++ b/tests/ffi/tests/integration_tests.rs @@ -3,8 +3,9 @@ #![allow(clippy::print_stdout)] #![allow(clippy::print_stderr)] -use pretty_assertions::assert_eq; use std::process::Command; + +use pretty_assertions::assert_eq; use test_util::deno_cmd; use test_util::deno_config_path; use test_util::ffi_tests_path; diff --git a/tests/integration/inspector_tests.rs b/tests/integration/inspector_tests.rs index fa1b3a9d83671c..c3586beb964d8d 100644 --- a/tests/integration/inspector_tests.rs +++ b/tests/integration/inspector_tests.rs @@ -1,12 +1,15 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::io::BufRead; +use std::process::ChildStderr; +use std::time::Duration; + use bytes::Bytes; use deno_core::anyhow::anyhow; use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::url; - use fastwebsockets::FragmentCollector; use fastwebsockets::Frame; use fastwebsockets::WebSocket; @@ -15,9 +18,6 @@ use hyper::upgrade::Upgraded; use hyper::Request; use hyper::Response; use hyper_util::rt::TokioIo; -use std::io::BufRead; -use std::process::ChildStderr; -use std::time::Duration; use test_util as util; use tokio::net::TcpStream; use tokio::time::timeout; diff --git a/tests/integration/js_unit_tests.rs b/tests/integration/js_unit_tests.rs index afb97a34584e38..685c85e2fed8ae 100644 --- a/tests/integration/js_unit_tests.rs +++ b/tests/integration/js_unit_tests.rs @@ -4,6 +4,7 @@ use std::io::BufRead; use std::io::BufReader; use std::time::Duration; use std::time::Instant; + use test_util as util; util::unit_test_factory!( diff --git a/tests/integration/jupyter_tests.rs b/tests/integration/jupyter_tests.rs index e99780a27647a8..dc8c1a5aec7369 100644 --- a/tests/integration/jupyter_tests.rs +++ b/tests/integration/jupyter_tests.rs @@ -5,11 +5,6 @@ use std::sync::Arc; use std::time::Duration; use bytes::Bytes; -use test_util::assertions::assert_json_subset; -use test_util::DenoChild; -use test_util::TestContext; -use test_util::TestContextBuilder; - use chrono::DateTime; use chrono::Utc; use deno_core::anyhow::Result; @@ -18,6 +13,10 @@ use deno_core::serde_json::json; use deno_core::serde_json::Value; use serde::Deserialize; use serde::Serialize; +use test_util::assertions::assert_json_subset; +use test_util::DenoChild; +use test_util::TestContext; +use test_util::TestContextBuilder; use tokio::sync::Mutex; use tokio::time::timeout; use uuid::Uuid; diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index ee31b617512f1a..3641dd923070f7 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -1,5 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::fs; +use std::str::FromStr; + use deno_ast::ModuleSpecifier; use deno_core::serde::Deserialize; use deno_core::serde_json; @@ -7,8 +10,6 @@ use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::url::Url; use pretty_assertions::assert_eq; -use std::fs; -use std::str::FromStr; use test_util::assert_starts_with; use test_util::assertions::assert_json_subset; use test_util::deno_cmd_with_deno_dir; diff --git a/tests/integration/node_unit_tests.rs b/tests/integration/node_unit_tests.rs index 9cb1af94965082..c49699be6a5e0e 100644 --- a/tests/integration/node_unit_tests.rs +++ b/tests/integration/node_unit_tests.rs @@ -4,6 +4,7 @@ use std::io::BufRead; use std::io::BufReader; use std::time::Duration; use std::time::Instant; + use test_util as util; use test_util::itest; use util::deno_config_path; diff --git a/tests/integration/npm_tests.rs b/tests/integration/npm_tests.rs index ffd3b817d45358..16e956d947ec73 100644 --- a/tests/integration/npm_tests.rs +++ b/tests/integration/npm_tests.rs @@ -3,7 +3,6 @@ use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::serde_json::Value; - use pretty_assertions::assert_eq; use test_util as util; use test_util::itest; diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index 77c0a46c5f1276..9edb29adae7f3d 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -11,7 +11,6 @@ use std::sync::Arc; use bytes::Bytes; use deno_core::serde_json::json; use deno_core::url; - use deno_tls::rustls; use deno_tls::rustls::ClientConnection; use deno_tls::rustls_pemfile; @@ -2215,15 +2214,16 @@ fn basic_auth_tokens() { #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_resolve_dns() { + use std::net::SocketAddr; + use std::str::FromStr; + use std::sync::Arc; + use std::time::Duration; + use hickory_server::authority::Catalog; use hickory_server::authority::ZoneType; use hickory_server::proto::rr::Name; use hickory_server::store::in_memory::InMemoryAuthority; use hickory_server::ServerFuture; - use std::net::SocketAddr; - use std::str::FromStr; - use std::sync::Arc; - use std::time::Duration; use tokio::net::TcpListener; use tokio::net::UdpSocket; use tokio::sync::oneshot; diff --git a/tests/integration/upgrade_tests.rs b/tests/integration/upgrade_tests.rs index 5132b4ca5b38c9..59dea8bf74a11d 100644 --- a/tests/integration/upgrade_tests.rs +++ b/tests/integration/upgrade_tests.rs @@ -3,6 +3,7 @@ use std::process::Command; use std::process::Stdio; use std::time::Instant; + use test_util as util; use test_util::assert_starts_with; use test_util::TestContext; diff --git a/tests/integration/watcher_tests.rs b/tests/integration/watcher_tests.rs index 055e46af9cf555..cd27062885548b 100644 --- a/tests/integration/watcher_tests.rs +++ b/tests/integration/watcher_tests.rs @@ -6,9 +6,8 @@ use test_util::assert_contains; use test_util::env_vars_for_npm_tests; use test_util::TempDir; use tokio::io::AsyncBufReadExt; -use util::DenoChild; - use util::assert_not_contains; +use util::DenoChild; /// Logs to stderr every time next_line() is called struct LoggingLines diff --git a/tests/napi/src/array.rs b/tests/napi/src/array.rs index 6df420eb57f983..3769264ad0a3a2 100644 --- a/tests/napi/src/array.rs +++ b/tests/napi/src/array.rs @@ -1,12 +1,14 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::assert_napi_ok; -use crate::napi_get_callback_info; -use crate::napi_new_property; +use std::ptr; + use napi_sys::ValueType::napi_number; use napi_sys::ValueType::napi_object; use napi_sys::*; -use std::ptr; + +use crate::assert_napi_ok; +use crate::napi_get_callback_info; +use crate::napi_new_property; extern "C" fn test_array_new( env: napi_env, diff --git a/tests/napi/src/arraybuffer.rs b/tests/napi/src/arraybuffer.rs index 8402f5d861b0a1..cf165f2f91ae2a 100644 --- a/tests/napi/src/arraybuffer.rs +++ b/tests/napi/src/arraybuffer.rs @@ -1,9 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::*; extern "C" fn test_detached( env: napi_env, diff --git a/tests/napi/src/async.rs b/tests/napi/src/async.rs index 367d2e9ef02c8e..dd79da7f183da3 100644 --- a/tests/napi/src/async.rs +++ b/tests/napi/src/async.rs @@ -1,15 +1,17 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::assert_napi_ok; -use crate::napi_get_callback_info; -use crate::napi_new_property; -use napi_sys::Status::napi_ok; -use napi_sys::ValueType::napi_function; -use napi_sys::*; use std::os::raw::c_char; use std::os::raw::c_void; use std::ptr; +use napi_sys::Status::napi_ok; +use napi_sys::ValueType::napi_function; +use napi_sys::*; + +use crate::assert_napi_ok; +use crate::napi_get_callback_info; +use crate::napi_new_property; + pub struct Baton { called: bool, func: napi_ref, diff --git a/tests/napi/src/bigint.rs b/tests/napi/src/bigint.rs index d8678233134e90..bea72c43c24ab6 100644 --- a/tests/napi/src/bigint.rs +++ b/tests/napi/src/bigint.rs @@ -1,13 +1,15 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ptr; + +use napi_sys::Status::napi_pending_exception; +use napi_sys::ValueType::napi_bigint; +use napi_sys::*; + use crate::assert_napi_ok; use crate::cstr; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::Status::napi_pending_exception; -use napi_sys::ValueType::napi_bigint; -use napi_sys::*; -use std::ptr; extern "C" fn is_lossless( env: napi_env, diff --git a/tests/napi/src/callback.rs b/tests/napi/src/callback.rs index 2512f6a38f0527..9f127304780c12 100644 --- a/tests/napi/src/callback.rs +++ b/tests/napi/src/callback.rs @@ -1,15 +1,17 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::assert_napi_ok; -use crate::napi_get_callback_info; -use crate::napi_new_property; +use std::ptr; + use napi_sys::ValueType::napi_function; use napi_sys::ValueType::napi_object; use napi_sys::ValueType::napi_undefined; use napi_sys::*; -use std::ptr; use Status::napi_pending_exception; +use crate::assert_napi_ok; +use crate::napi_get_callback_info; +use crate::napi_new_property; + /// `test_callback_run((a, b) => a + b, [1, 2])` => 3 extern "C" fn test_callback_run( env: napi_env, diff --git a/tests/napi/src/coerce.rs b/tests/napi/src/coerce.rs index a4057838438f5b..a022481d2ad201 100644 --- a/tests/napi/src/coerce.rs +++ b/tests/napi/src/coerce.rs @@ -1,10 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ptr; + +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::*; -use std::ptr; extern "C" fn test_coerce_bool( env: napi_env, diff --git a/tests/napi/src/date.rs b/tests/napi/src/date.rs index 4d3c155c32e9dc..3a5a62b6f4c143 100644 --- a/tests/napi/src/date.rs +++ b/tests/napi/src/date.rs @@ -1,11 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ptr; + +use napi_sys::ValueType::napi_number; +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::ValueType::napi_number; -use napi_sys::*; -use std::ptr; extern "C" fn create_date( env: napi_env, diff --git a/tests/napi/src/env.rs b/tests/napi/src/env.rs index ebc6532a3c651c..57f7469d69bb7a 100644 --- a/tests/napi/src/env.rs +++ b/tests/napi/src/env.rs @@ -1,9 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::*; extern "C" fn get_node_global( env: napi_env, diff --git a/tests/napi/src/error.rs b/tests/napi/src/error.rs index e0d79c836abf36..9c421984c01668 100644 --- a/tests/napi/src/error.rs +++ b/tests/napi/src/error.rs @@ -1,11 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ptr; + +use napi_sys::*; + use crate::assert_napi_ok; use crate::cstr; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::*; -use std::ptr; extern "C" fn check_error( env: napi_env, diff --git a/tests/napi/src/finalizer.rs b/tests/napi/src/finalizer.rs index 9769e775e247c4..6b72dcfca7a59e 100644 --- a/tests/napi/src/finalizer.rs +++ b/tests/napi/src/finalizer.rs @@ -1,11 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ptr; + +use napi_sys::ValueType::napi_object; +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::ValueType::napi_object; -use napi_sys::*; -use std::ptr; unsafe extern "C" fn finalize_cb( _env: napi_env, diff --git a/tests/napi/src/make_callback.rs b/tests/napi/src/make_callback.rs index 945df3452324bb..19948dce3df9b8 100644 --- a/tests/napi/src/make_callback.rs +++ b/tests/napi/src/make_callback.rs @@ -1,10 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::assert_napi_ok; -use crate::cstr; +use std::ptr; + use napi_sys::ValueType::napi_function; use napi_sys::*; -use std::ptr; + +use crate::assert_napi_ok; +use crate::cstr; extern "C" fn make_callback( env: napi_env, diff --git a/tests/napi/src/mem.rs b/tests/napi/src/mem.rs index ebb6a5c7acbe2d..fd488da97488f1 100644 --- a/tests/napi/src/mem.rs +++ b/tests/napi/src/mem.rs @@ -1,9 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ptr; + +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_new_property; -use napi_sys::*; -use std::ptr; extern "C" fn adjust_external_memory( env: napi_env, diff --git a/tests/napi/src/numbers.rs b/tests/napi/src/numbers.rs index 777ccbfac7e708..00d68c9bf3bcfa 100644 --- a/tests/napi/src/numbers.rs +++ b/tests/napi/src/numbers.rs @@ -1,11 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ptr; + +use napi_sys::ValueType::napi_number; +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::ValueType::napi_number; -use napi_sys::*; -use std::ptr; extern "C" fn test_int32( env: napi_env, diff --git a/tests/napi/src/object.rs b/tests/napi/src/object.rs index 9876f4dae0d8fa..93424b4b264e6f 100644 --- a/tests/napi/src/object.rs +++ b/tests/napi/src/object.rs @@ -1,10 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ptr; + +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::*; -use std::ptr; extern "C" fn test_object_new( env: napi_env, diff --git a/tests/napi/src/object_wrap.rs b/tests/napi/src/object_wrap.rs index 63e9e2e23202cc..66b1a9f926b0d5 100644 --- a/tests/napi/src/object_wrap.rs +++ b/tests/napi/src/object_wrap.rs @@ -1,16 +1,18 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::assert_napi_ok; -use crate::napi_get_callback_info; -use crate::napi_new_property; -use napi_sys::ValueType::napi_number; -use napi_sys::*; use std::cell::RefCell; use std::collections::HashMap; use std::os::raw::c_char; use std::os::raw::c_void; use std::ptr; +use napi_sys::ValueType::napi_number; +use napi_sys::*; + +use crate::assert_napi_ok; +use crate::napi_get_callback_info; +use crate::napi_new_property; + pub struct NapiObject { counter: i32, } diff --git a/tests/napi/src/primitives.rs b/tests/napi/src/primitives.rs index 28fb8ec3db6310..7afa05157b11f1 100644 --- a/tests/napi/src/primitives.rs +++ b/tests/napi/src/primitives.rs @@ -1,9 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ptr; + +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_new_property; -use napi_sys::*; -use std::ptr; extern "C" fn test_get_undefined( env: napi_env, diff --git a/tests/napi/src/promise.rs b/tests/napi/src/promise.rs index 1f1c31f1eb5960..26bfbbd1fa46e9 100644 --- a/tests/napi/src/promise.rs +++ b/tests/napi/src/promise.rs @@ -1,11 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::ptr; +use std::ptr::addr_of_mut; + +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::*; -use std::ptr; -use std::ptr::addr_of_mut; static mut CURRENT_DEFERRED: napi_deferred = ptr::null_mut(); diff --git a/tests/napi/src/properties.rs b/tests/napi/src/properties.rs index 43bef1949a48e9..3ef2290e67c5b2 100644 --- a/tests/napi/src/properties.rs +++ b/tests/napi/src/properties.rs @@ -1,10 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::assert_napi_ok; -use crate::cstr; +use std::ptr; + use napi_sys::PropertyAttributes::*; use napi_sys::*; -use std::ptr; + +use crate::assert_napi_ok; +use crate::cstr; static NICE: i64 = 69; diff --git a/tests/napi/src/strings.rs b/tests/napi/src/strings.rs index 301ab23df2b432..dd7ae35b38fb22 100644 --- a/tests/napi/src/strings.rs +++ b/tests/napi/src/strings.rs @@ -1,10 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use napi_sys::ValueType::napi_string; +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::ValueType::napi_string; -use napi_sys::*; extern "C" fn test_utf8(env: napi_env, info: napi_callback_info) -> napi_value { let (args, argc, _) = napi_get_callback_info!(env, info, 1); diff --git a/tests/napi/src/symbol.rs b/tests/napi/src/symbol.rs index 6387d449f13c39..780a6dad0f9298 100644 --- a/tests/napi/src/symbol.rs +++ b/tests/napi/src/symbol.rs @@ -1,10 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use napi_sys::ValueType::napi_string; +use napi_sys::*; + use crate::assert_napi_ok; use crate::napi_get_callback_info; use crate::napi_new_property; -use napi_sys::ValueType::napi_string; -use napi_sys::*; extern "C" fn symbol_new( env: napi_env, diff --git a/tests/napi/src/tsfn.rs b/tests/napi/src/tsfn.rs index a3a231cec19c12..c8e885c6c3a357 100644 --- a/tests/napi/src/tsfn.rs +++ b/tests/napi/src/tsfn.rs @@ -3,11 +3,12 @@ // This test performs initialization similar to napi-rs. // https://github.com/napi-rs/napi-rs/commit/a5a04a4e545f268769cc78e2bd6c45af4336aac3 -use napi_sys as sys; use std::ffi::c_char; use std::ffi::c_void; use std::ptr; +use napi_sys as sys; + macro_rules! check_status_or_panic { ($code:expr, $msg:expr) => {{ let c = $code; diff --git a/tests/napi/src/typedarray.rs b/tests/napi/src/typedarray.rs index b512bd32fe71a2..2482c1dac64ea0 100644 --- a/tests/napi/src/typedarray.rs +++ b/tests/napi/src/typedarray.rs @@ -1,16 +1,18 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::assert_napi_ok; -use crate::napi_get_callback_info; -use crate::napi_new_property; use core::ffi::c_void; +use std::os::raw::c_char; +use std::ptr; + use napi_sys::Status::napi_ok; use napi_sys::TypedarrayType; use napi_sys::ValueType::napi_number; use napi_sys::ValueType::napi_object; use napi_sys::*; -use std::os::raw::c_char; -use std::ptr; + +use crate::assert_napi_ok; +use crate::napi_get_callback_info; +use crate::napi_new_property; extern "C" fn test_multiply( env: napi_env, diff --git a/tests/napi/src/uv.rs b/tests/napi/src/uv.rs index 555470c008c461..685b4040bd4ef7 100644 --- a/tests/napi/src/uv.rs +++ b/tests/napi/src/uv.rs @@ -1,8 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::assert_napi_ok; -use crate::napi_get_callback_info; -use crate::napi_new_property; +use std::mem::MaybeUninit; +use std::ptr; +use std::ptr::addr_of_mut; +use std::ptr::null_mut; +use std::time::Duration; + use libuv_sys_lite::uv_async_init; use libuv_sys_lite::uv_async_t; use libuv_sys_lite::uv_close; @@ -12,11 +15,10 @@ use libuv_sys_lite::uv_mutex_lock; use libuv_sys_lite::uv_mutex_t; use libuv_sys_lite::uv_mutex_unlock; use napi_sys::*; -use std::mem::MaybeUninit; -use std::ptr; -use std::ptr::addr_of_mut; -use std::ptr::null_mut; -use std::time::Duration; + +use crate::assert_napi_ok; +use crate::napi_get_callback_info; +use crate::napi_new_property; struct KeepAlive { tsfn: napi_threadsafe_function, diff --git a/tests/napi/tests/napi_tests.rs b/tests/napi/tests/napi_tests.rs index 53d4258f932f19..ff09565ff3e5fc 100644 --- a/tests/napi/tests/napi_tests.rs +++ b/tests/napi/tests/napi_tests.rs @@ -4,6 +4,7 @@ #![allow(clippy::print_stderr)] use std::process::Command; + use test_util::deno_cmd; use test_util::deno_config_path; use test_util::env_vars_for_npm_tests; diff --git a/tests/util/server/src/factory.rs b/tests/util/server/src/factory.rs index 5b796fbc1d63ca..4b972d9b0e36c0 100644 --- a/tests/util/server/src/factory.rs +++ b/tests/util/server/src/factory.rs @@ -1,8 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use glob::glob; use std::collections::HashSet; use std::path::PathBuf; +use glob::glob; + /// Generate a unit test factory verified and backed by a glob. #[macro_export] macro_rules! unit_test_factory { diff --git a/tests/util/server/src/fs.rs b/tests/util/server/src/fs.rs index 7feb0799ae45b9..4bb3a7dd8c3e9d 100644 --- a/tests/util/server/src/fs.rs +++ b/tests/util/server/src/fs.rs @@ -1,7 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use lsp_types::Uri; -use pretty_assertions::assert_eq; use std::borrow::Cow; use std::collections::HashSet; use std::ffi::OsStr; @@ -15,6 +13,8 @@ use std::str::FromStr; use std::sync::Arc; use anyhow::Context; +use lsp_types::Uri; +use pretty_assertions::assert_eq; use serde::de::DeserializeOwned; use serde::Serialize; use url::Url; diff --git a/tests/util/server/src/https.rs b/tests/util/server/src/https.rs index 617fd5cae29d44..ab90800a4557df 100644 --- a/tests/util/server/src/https.rs +++ b/tests/util/server/src/https.rs @@ -1,4 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::io; +use std::num::NonZeroUsize; +use std::result::Result; +use std::sync::Arc; + use anyhow::anyhow; use futures::Stream; use futures::StreamExt; @@ -6,10 +11,6 @@ use rustls_tokio_stream::rustls; use rustls_tokio_stream::rustls::pki_types::CertificateDer; use rustls_tokio_stream::rustls::pki_types::PrivateKeyDer; use rustls_tokio_stream::TlsStream; -use std::io; -use std::num::NonZeroUsize; -use std::result::Result; -use std::sync::Arc; use tokio::net::TcpStream; use crate::get_tcp_listener_stream; diff --git a/tests/util/server/src/lib.rs b/tests/util/server/src/lib.rs index 531944bf6aefce..6361dac16dd986 100644 --- a/tests/util/server/src/lib.rs +++ b/tests/util/server/src/lib.rs @@ -1296,9 +1296,10 @@ pub(crate) mod colors { #[cfg(test)] mod tests { - use super::*; use pretty_assertions::assert_eq; + use super::*; + #[test] fn parse_wrk_output_1() { const TEXT: &str = include_str!("./testdata/wrk1.txt"); diff --git a/tests/util/server/src/lsp.rs b/tests/util/server/src/lsp.rs index 92169ee6449ba3..9da7042e2092dc 100644 --- a/tests/util/server/src/lsp.rs +++ b/tests/util/server/src/lsp.rs @@ -1,11 +1,24 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::deno_exe_path; -use crate::jsr_registry_url; -use crate::npm_registry_url; -use crate::PathRef; - -use super::TempDir; +use std::collections::HashMap; +use std::collections::HashSet; +use std::ffi::OsStr; +use std::ffi::OsString; +use std::io; +use std::io::BufRead; +use std::io::BufReader; +use std::io::Write; +use std::path::Path; +use std::process::Child; +use std::process::ChildStdin; +use std::process::ChildStdout; +use std::process::Command; +use std::process::Stdio; +use std::str::FromStr; +use std::sync::mpsc; +use std::sync::Arc; +use std::time::Duration; +use std::time::Instant; use anyhow::Result; use lsp_types as lsp; @@ -32,27 +45,14 @@ use serde::Serialize; use serde_json::json; use serde_json::to_value; use serde_json::Value; -use std::collections::HashMap; -use std::collections::HashSet; -use std::ffi::OsStr; -use std::ffi::OsString; -use std::io; -use std::io::BufRead; -use std::io::BufReader; -use std::io::Write; -use std::path::Path; -use std::process::Child; -use std::process::ChildStdin; -use std::process::ChildStdout; -use std::process::Command; -use std::process::Stdio; -use std::str::FromStr; -use std::sync::mpsc; -use std::sync::Arc; -use std::time::Duration; -use std::time::Instant; use url::Url; +use super::TempDir; +use crate::deno_exe_path; +use crate::jsr_registry_url; +use crate::npm_registry_url; +use crate::PathRef; + static CONTENT_TYPE_REG: Lazy = lazy_regex::lazy_regex!(r"(?i)^content-length:\s+(\d+)"); diff --git a/tests/util/server/src/pty.rs b/tests/util/server/src/pty.rs index 07659262cf4e4c..fa22c4ecc817c7 100644 --- a/tests/util/server/src/pty.rs +++ b/tests/util/server/src/pty.rs @@ -323,9 +323,10 @@ fn create_pty( cwd: &Path, env_vars: Option>, ) -> Box { - use crate::pty::unix::UnixPty; use std::os::unix::process::CommandExt; + use crate::pty::unix::UnixPty; + // Manually open pty main/secondary sides in the test process. Since we're not actually // changing uid/gid here, this is the easiest way to do it. diff --git a/tests/util/server/src/servers/hyper_utils.rs b/tests/util/server/src/servers/hyper_utils.rs index 8e01151ed494bb..dfb9464abe918d 100644 --- a/tests/util/server/src/servers/hyper_utils.rs +++ b/tests/util/server/src/servers/hyper_utils.rs @@ -1,5 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::convert::Infallible; +use std::io; +use std::net::SocketAddr; +use std::pin::Pin; +use std::result::Result; + use bytes::Bytes; use futures::Future; use futures::FutureExt; @@ -10,11 +16,6 @@ use http::Request; use http::Response; use http_body_util::combinators::UnsyncBoxBody; use hyper_util::rt::TokioIo; -use std::convert::Infallible; -use std::io; -use std::net::SocketAddr; -use std::pin::Pin; -use std::result::Result; use tokio::net::TcpListener; #[derive(Debug, Clone, Copy)] diff --git a/tests/util/server/src/servers/jsr_registry.rs b/tests/util/server/src/servers/jsr_registry.rs index 8970750a2811be..418a0ebe2973e5 100644 --- a/tests/util/server/src/servers/jsr_registry.rs +++ b/tests/util/server/src/servers/jsr_registry.rs @@ -1,10 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::tests_path; +use std::collections::BTreeMap; +use std::collections::HashMap; +use std::convert::Infallible; +use std::net::SocketAddr; +use std::path::Path; +use std::sync::Mutex; -use super::run_server; -use super::ServerKind; -use super::ServerOptions; use base64::engine::general_purpose::STANDARD_NO_PAD; use base64::Engine as _; use bytes::Bytes; @@ -17,12 +19,11 @@ use hyper::Response; use hyper::StatusCode; use once_cell::sync::Lazy; use serde_json::json; -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::convert::Infallible; -use std::net::SocketAddr; -use std::path::Path; -use std::sync::Mutex; + +use super::run_server; +use super::ServerKind; +use super::ServerOptions; +use crate::tests_path; pub async fn registry_server(port: u16) { let registry_server_addr = SocketAddr::from(([127, 0, 0, 1], port)); diff --git a/tests/util/server/src/servers/mod.rs b/tests/util/server/src/servers/mod.rs index 4345c27cde0ed1..4c8901b7cc37f4 100644 --- a/tests/util/server/src/servers/mod.rs +++ b/tests/util/server/src/servers/mod.rs @@ -2,6 +2,13 @@ // Usage: provide a port as argument to run hyper_hello benchmark server // otherwise this starts multiple servers on many ports for test endpoints. +use std::collections::HashMap; +use std::convert::Infallible; +use std::env; +use std::net::SocketAddr; +use std::result::Result; +use std::time::Duration; + use base64::prelude::BASE64_STANDARD; use base64::Engine; use bytes::Bytes; @@ -27,12 +34,6 @@ use http_body_util::Empty; use http_body_util::Full; use pretty_assertions::assert_eq; use prost::Message; -use std::collections::HashMap; -use std::convert::Infallible; -use std::env; -use std::net::SocketAddr; -use std::result::Result; -use std::time::Duration; use tokio::io::AsyncWriteExt; use tokio::net::TcpStream; @@ -48,12 +49,11 @@ use hyper_utils::run_server_with_acceptor; use hyper_utils::ServerKind; use hyper_utils::ServerOptions; -use crate::TEST_SERVERS_COUNT; - use super::https::get_tls_listener_stream; use super::https::SupportedHttpVersions; use super::std_path; use super::testdata_path; +use crate::TEST_SERVERS_COUNT; pub(crate) const PORT: u16 = 4545; const TEST_AUTH_TOKEN: &str = "abcdef123456789"; diff --git a/tests/util/server/src/servers/npm_registry.rs b/tests/util/server/src/servers/npm_registry.rs index 4ada468fac4577..fa8fa6a2f5b479 100644 --- a/tests/util/server/src/servers/npm_registry.rs +++ b/tests/util/server/src/servers/npm_registry.rs @@ -1,14 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use crate::npm; +use std::convert::Infallible; +use std::net::Ipv6Addr; +use std::net::SocketAddr; +use std::net::SocketAddrV6; +use std::path::PathBuf; -use super::custom_headers; -use super::empty_body; -use super::hyper_utils::HandlerOutput; -use super::run_server; -use super::string_body; -use super::ServerKind; -use super::ServerOptions; use bytes::Bytes; use futures::future::LocalBoxFuture; use futures::Future; @@ -18,11 +15,15 @@ use hyper::body::Incoming; use hyper::Request; use hyper::Response; use hyper::StatusCode; -use std::convert::Infallible; -use std::net::Ipv6Addr; -use std::net::SocketAddr; -use std::net::SocketAddrV6; -use std::path::PathBuf; + +use super::custom_headers; +use super::empty_body; +use super::hyper_utils::HandlerOutput; +use super::run_server; +use super::string_body; +use super::ServerKind; +use super::ServerOptions; +use crate::npm; pub fn public_npm_registry(port: u16) -> Vec> { run_npm_server(port, "npm registry server error", { diff --git a/tests/util/server/src/servers/ws.rs b/tests/util/server/src/servers/ws.rs index dd4efbf659809e..f2637402fad844 100644 --- a/tests/util/server/src/servers/ws.rs +++ b/tests/util/server/src/servers/ws.rs @@ -1,5 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::pin::Pin; +use std::result::Result; + use anyhow::anyhow; use bytes::Bytes; use fastwebsockets::FragmentCollector; @@ -22,8 +25,6 @@ use hyper::Response; use hyper::StatusCode; use hyper_util::rt::TokioIo; use pretty_assertions::assert_eq; -use std::pin::Pin; -use std::result::Result; use tokio::io::AsyncReadExt; use tokio::io::AsyncWriteExt; diff --git a/tests/util/server/src/spawn.rs b/tests/util/server/src/spawn.rs index bfd83e9b26a878..c76168db536cf1 100644 --- a/tests/util/server/src/spawn.rs +++ b/tests/util/server/src/spawn.rs @@ -1,7 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use anyhow::Error; use std::convert::Infallible; +use anyhow::Error; + /// For unix targets, we just replace our current process with the desired cargo process. #[cfg(unix)] pub fn exec_replace_inner( @@ -30,6 +31,7 @@ pub fn exec_replace_inner( ) -> Result { use std::os::windows::io::AsRawHandle; use std::process::Command; + use win32job::ExtendedLimitInfo; use win32job::Job;