From 0cc90d9246ff2c392457632d5030eaca2ca1ca6f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 25 Nov 2022 17:00:28 -0500 Subject: [PATCH] refactor: move lockfile.rs to args module (#16818) This should be in the `args` folder as it's similar to `config_file`. --- cli/{ => args}/lockfile.rs | 18 +++++++++--------- cli/args/mod.rs | 11 +++++++---- cli/emit.rs | 2 +- cli/main.rs | 6 +++--- cli/npm/resolution/mod.rs | 2 +- cli/npm/resolution/snapshot.rs | 2 +- cli/npm/resolvers/common.rs | 2 +- cli/npm/resolvers/global.rs | 2 +- cli/npm/resolvers/local.rs | 2 +- cli/npm/resolvers/mod.rs | 2 +- cli/proc_state.rs | 7 +++---- cli/resolver.rs | 2 +- 12 files changed, 30 insertions(+), 28 deletions(-) rename cli/{ => args}/lockfile.rs (98%) diff --git a/cli/lockfile.rs b/cli/args/lockfile.rs similarity index 98% rename from cli/lockfile.rs rename to cli/args/lockfile.rs index b1f0c777fe..f99d2f5701 100644 --- a/cli/lockfile.rs +++ b/cli/args/lockfile.rs @@ -95,6 +95,15 @@ pub struct Lockfile { } impl Lockfile { + pub fn as_maybe_locker( + lockfile: Option>>, + ) -> Option>> { + lockfile.as_ref().map(|lf| { + Rc::new(RefCell::new(Locker(Some(lf.clone())))) + as Rc> + }) + } + pub fn discover( flags: &Flags, maybe_config_file: Option<&ConfigFile>, @@ -359,15 +368,6 @@ impl deno_graph::source::Locker for Locker { } } -pub fn as_maybe_locker( - lockfile: Option>>, -) -> Option>> { - lockfile.as_ref().map(|lf| { - Rc::new(RefCell::new(Locker(Some(lf.clone())))) - as Rc> - }) -} - #[cfg(test)] mod tests { use super::*; diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 64755a4948..ff9a6f73ca 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1,7 +1,8 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -pub mod config_file; -pub mod flags; +mod config_file; +mod flags; +mod lockfile; mod flags_allow_net; @@ -10,6 +11,8 @@ pub use config_file::ConfigFile; pub use config_file::EmitConfigOptions; pub use config_file::FmtConfig; pub use config_file::FmtOptionsConfig; +pub use config_file::IgnoredCompilerOptions; +pub use config_file::JsxImportSourceConfig; pub use config_file::LintConfig; pub use config_file::LintRulesConfig; pub use config_file::MaybeImportsResult; @@ -17,6 +20,8 @@ pub use config_file::ProseWrap; pub use config_file::TestConfig; pub use config_file::TsConfig; pub use flags::*; +pub use lockfile::Lockfile; +pub use lockfile::LockfileError; use deno_ast::ModuleSpecifier; use deno_core::anyhow::anyhow; @@ -36,7 +41,6 @@ use std::net::SocketAddr; use std::path::PathBuf; use std::sync::Arc; -use crate::args::config_file::JsxImportSourceConfig; use crate::deno_dir::DenoDir; use crate::emit::get_ts_config_for_emit; use crate::emit::TsConfigType; @@ -45,7 +49,6 @@ use crate::emit::TsTypeLib; use crate::file_fetcher::get_root_cert_store; use crate::file_fetcher::CacheSetting; use crate::fs_util; -use crate::lockfile::Lockfile; use crate::version; /// Overrides for the options below that when set will diff --git a/cli/emit.rs b/cli/emit.rs index f2d890adc5..7665241875 100644 --- a/cli/emit.rs +++ b/cli/emit.rs @@ -4,9 +4,9 @@ //! populate a cache, emit files, and transform a graph into the structures for //! loading into an isolate. -use crate::args::config_file::IgnoredCompilerOptions; use crate::args::ConfigFile; use crate::args::EmitConfigOptions; +use crate::args::IgnoredCompilerOptions; use crate::args::TsConfig; use crate::cache::EmitCache; use crate::cache::FastInsecureHasher; diff --git a/cli/main.rs b/cli/main.rs index f18c3c9769..93f2c501d6 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -19,7 +19,6 @@ mod graph_util; mod http_cache; mod http_util; mod js; -mod lockfile; mod logger; mod lsp; mod module_loader; @@ -74,6 +73,7 @@ use crate::resolver::CliResolver; use crate::tools::check; use args::CliOptions; +use args::Lockfile; use deno_ast::MediaType; use deno_core::anyhow::bail; use deno_core::error::generic_error; @@ -327,7 +327,7 @@ async fn create_graph_and_maybe_check( Permissions::allow_all(), Permissions::allow_all(), ); - let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone()); + let maybe_locker = Lockfile::as_maybe_locker(ps.lockfile.clone()); let maybe_imports = ps.options.to_maybe_imports()?; let maybe_cli_resolver = CliResolver::maybe_new( ps.options.to_maybe_jsx_import_source_config(), @@ -937,7 +937,7 @@ fn unwrap_or_exit(result: Result) -> T { if let Some(e) = error.downcast_ref::() { error_string = format_js_error(e); - } else if let Some(e) = error.downcast_ref::() { + } else if let Some(e) = error.downcast_ref::() { error_string = e.to_string(); error_code = 10; } diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index 4a8c2e8e17..15de4ceffa 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -10,7 +10,7 @@ use deno_core::parking_lot::RwLock; use serde::Deserialize; use serde::Serialize; -use crate::lockfile::Lockfile; +use crate::args::Lockfile; use self::graph::GraphDependencyResolver; use self::snapshot::NpmPackagesPartitioned; diff --git a/cli/npm/resolution/snapshot.rs b/cli/npm/resolution/snapshot.rs index d76ba8b1a6..738b68d21f 100644 --- a/cli/npm/resolution/snapshot.rs +++ b/cli/npm/resolution/snapshot.rs @@ -13,7 +13,7 @@ use deno_core::parking_lot::Mutex; use serde::Deserialize; use serde::Serialize; -use crate::lockfile::Lockfile; +use crate::args::Lockfile; use crate::npm::cache::should_sync_download; use crate::npm::cache::NpmPackageCacheFolderId; use crate::npm::registry::NpmPackageVersionDistInfo; diff --git a/cli/npm/resolvers/common.rs b/cli/npm/resolvers/common.rs index b160697d10..e3acef3f52 100644 --- a/cli/npm/resolvers/common.rs +++ b/cli/npm/resolvers/common.rs @@ -11,7 +11,7 @@ use deno_core::futures; use deno_core::futures::future::BoxFuture; use deno_core::url::Url; -use crate::lockfile::Lockfile; +use crate::args::Lockfile; use crate::npm::cache::should_sync_download; use crate::npm::resolution::NpmResolutionSnapshot; use crate::npm::NpmCache; diff --git a/cli/npm/resolvers/global.rs b/cli/npm/resolvers/global.rs index 3fad9f2d93..044c889d8f 100644 --- a/cli/npm/resolvers/global.rs +++ b/cli/npm/resolvers/global.rs @@ -15,8 +15,8 @@ use deno_core::url::Url; use deno_runtime::deno_node::PackageJson; use deno_runtime::deno_node::TYPES_CONDITIONS; +use crate::args::Lockfile; use crate::fs_util; -use crate::lockfile::Lockfile; use crate::npm::resolution::NpmResolution; use crate::npm::resolution::NpmResolutionSnapshot; use crate::npm::resolvers::common::cache_packages; diff --git a/cli/npm/resolvers/local.rs b/cli/npm/resolvers/local.rs index 0a47a7ff1e..a6df641d19 100644 --- a/cli/npm/resolvers/local.rs +++ b/cli/npm/resolvers/local.rs @@ -22,8 +22,8 @@ use deno_runtime::deno_node::PackageJson; use deno_runtime::deno_node::TYPES_CONDITIONS; use tokio::task::JoinHandle; +use crate::args::Lockfile; use crate::fs_util; -use crate::lockfile::Lockfile; use crate::npm::cache::mixed_case_package_name_encode; use crate::npm::cache::should_sync_download; use crate::npm::cache::NpmPackageCacheFolderId; diff --git a/cli/npm/resolvers/mod.rs b/cli/npm/resolvers/mod.rs index 23cbde5d9c..869874c8b6 100644 --- a/cli/npm/resolvers/mod.rs +++ b/cli/npm/resolvers/mod.rs @@ -22,8 +22,8 @@ use std::path::Path; use std::path::PathBuf; use std::sync::Arc; +use crate::args::Lockfile; use crate::fs_util; -use crate::lockfile::Lockfile; use self::common::InnerNpmPackageResolver; use self::local::LocalNpmPackageResolver; diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 2064d38511..32a2d9d429 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -3,6 +3,7 @@ use crate::args::CliOptions; use crate::args::DenoSubcommand; use crate::args::Flags; +use crate::args::Lockfile; use crate::args::TypeCheckMode; use crate::cache; use crate::cache::EmitCache; @@ -20,8 +21,6 @@ use crate::graph_util::GraphData; use crate::graph_util::ModuleEntry; use crate::http_cache; use crate::http_util::HttpClient; -use crate::lockfile::as_maybe_locker; -use crate::lockfile::Lockfile; use crate::node; use crate::node::NodeResolution; use crate::npm::resolve_npm_package_reqs; @@ -330,7 +329,7 @@ impl ProcState { root_permissions.clone(), dynamic_permissions.clone(), ); - let maybe_locker = as_maybe_locker(self.lockfile.clone()); + let maybe_locker = Lockfile::as_maybe_locker(self.lockfile.clone()); let maybe_imports = self.options.to_maybe_imports()?; let maybe_resolver = self.maybe_resolver.as_ref().map(|r| r.as_graph_resolver()); @@ -640,7 +639,7 @@ impl ProcState { roots: Vec<(ModuleSpecifier, ModuleKind)>, loader: &mut dyn Loader, ) -> Result { - let maybe_locker = as_maybe_locker(self.lockfile.clone()); + let maybe_locker = Lockfile::as_maybe_locker(self.lockfile.clone()); let maybe_imports = self.options.to_maybe_imports()?; let maybe_cli_resolver = CliResolver::maybe_new( diff --git a/cli/resolver.rs b/cli/resolver.rs index c28d9df75c..a4c4439abd 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -8,7 +8,7 @@ use deno_graph::source::DEFAULT_JSX_IMPORT_SOURCE_MODULE; use import_map::ImportMap; use std::sync::Arc; -use crate::args::config_file::JsxImportSourceConfig; +use crate::args::JsxImportSourceConfig; /// A resolver that takes care of resolution, taking into account loaded /// import map, JSX settings.