Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cli): Create wrapper around deno_lockfile::Lockfile #24366

Merged
merged 5 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 0 additions & 91 deletions cli/args/lockfile.rs

This file was deleted.

16 changes: 6 additions & 10 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,6 @@ pub mod deno_json;
mod flags;
mod flags_net;
mod import_map;
mod lockfile;
pub mod package_json;

pub use self::import_map::resolve_import_map;
Expand Down Expand Up @@ -34,16 33,12 @@ pub use deno_config::TsConfigType;
pub use deno_config::TsTypeLib;
pub use deno_config::WorkspaceConfig;
pub use flags::*;
pub use lockfile::read_lockfile_at_path;
pub use lockfile::write_lockfile_if_has_changes;
pub use lockfile::Lockfile;
pub use package_json::PackageJsonDepsProvider;

use deno_ast::ModuleSpecifier;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::parking_lot::Mutex;
use deno_core::serde_json;
use deno_core::url::Url;
use deno_runtime::deno_node::PackageJson;
Expand Down Expand Up @@ -74,6 69,7 @@ use thiserror::Error;
use crate::args::import_map::enhance_import_map_value_with_workspace_members;
use crate::cache;
use crate::file_fetcher::FileFetcher;
use crate::lockfile::CliLockfile;
use crate::util::fs::canonicalize_path_maybe_not_exists;
use crate::version;

Expand Down Expand Up @@ -812,7 808,7 @@ pub struct CliOptions {
maybe_config_file: Option<ConfigFile>,
maybe_package_json: Option<Arc<PackageJson>>,
npmrc: Arc<ResolvedNpmRc>,
maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
maybe_lockfile: Option<Arc<CliLockfile>>,
overrides: CliOptionOverrides,
maybe_workspace_config: Option<WorkspaceConfig>,
pub disable_deprecated_api_warning: bool,
Expand All @@ -824,7 820,7 @@ impl CliOptions {
flags: Flags,
initial_cwd: PathBuf,
maybe_config_file: Option<ConfigFile>,
maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
maybe_lockfile: Option<Arc<CliLockfile>>,
maybe_package_json: Option<Arc<PackageJson>>,
npmrc: Arc<ResolvedNpmRc>,
force_global_cache: bool,
Expand Down Expand Up @@ -958,7 954,7 @@ impl CliOptions {
}),
)?;

let maybe_lock_file = lockfile::discover(
let maybe_lock_file = CliLockfile::discover(
&flags,
maybe_config_file.as_ref(),
maybe_package_json.as_deref(),
Expand All @@ -967,7 963,7 @@ impl CliOptions {
flags,
initial_cwd,
maybe_config_file,
maybe_lock_file.map(|l| Arc::new(Mutex::new(l))),
maybe_lock_file.map(Arc::new),
maybe_package_json,
npmrc,
false,
Expand Down Expand Up @@ -1353,7 1349,7 @@ impl CliOptions {
Ok(Some(InspectorServer::new(host, version::get_user_agent())?))
}

pub fn maybe_lockfile(&self) -> Option<Arc<Mutex<Lockfile>>> {
pub fn maybe_lockfile(&self) -> Option<Arc<CliLockfile>> {
self.maybe_lockfile.clone()
}

Expand Down
12 changes: 5 additions & 7 deletions cli/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,6 @@ use crate::args::deno_json::deno_json_deps;
use crate::args::CliOptions;
use crate::args::DenoSubcommand;
use crate::args::Flags;
use crate::args::Lockfile;
use crate::args::PackageJsonDepsProvider;
use crate::args::StorageKeyResolver;
use crate::args::TsConfigType;
Expand All @@ -26,6 25,7 @@ use crate::graph_util::FileWatcherReporter;
use crate::graph_util::ModuleGraphBuilder;
use crate::graph_util::ModuleGraphCreator;
use crate::http_util::HttpClientProvider;
use crate::lockfile::CliLockfile;
use crate::module_loader::CliModuleLoaderFactory;
use crate::module_loader::ModuleLoadPreparer;
use crate::node::CliCjsCodeAnalyzer;
Expand Down Expand Up @@ -56,7 56,6 @@ use std::path::PathBuf;

use deno_core::error::AnyError;
use deno_core::futures::FutureExt;
use deno_core::parking_lot::Mutex;
use deno_core::FeatureChecker;

use deno_lockfile::WorkspaceMemberConfig;
Expand Down Expand Up @@ -156,7 155,7 @@ struct CliFactoryServices {
emitter: Deferred<Arc<Emitter>>,
fs: Deferred<Arc<dyn deno_fs::FileSystem>>,
main_graph_container: Deferred<Arc<MainModuleGraphContainer>>,
lockfile: Deferred<Option<Arc<Mutex<Lockfile>>>>,
lockfile: Deferred<Option<Arc<CliLockfile>>>,
maybe_import_map: Deferred<Option<Arc<ImportMap>>>,
maybe_inspector_server: Deferred<Option<Arc<InspectorServer>>>,
root_cert_store_provider: Deferred<Arc<dyn RootCertStoreProvider>>,
Expand Down Expand Up @@ -304,8 303,8 @@ impl CliFactory {
self.services.fs.get_or_init(|| Arc::new(deno_fs::RealFs))
}

pub fn maybe_lockfile(&self) -> &Option<Arc<Mutex<Lockfile>>> {
fn check_no_npm(lockfile: &Mutex<Lockfile>, options: &CliOptions) -> bool {
pub fn maybe_lockfile(&self) -> &Option<Arc<CliLockfile>> {
fn check_no_npm(lockfile: &CliLockfile, options: &CliOptions) -> bool {
if options.no_npm() {
return true;
}
Expand All @@ -315,7 314,7 @@ impl CliFactory {
options
.maybe_package_json()
.map(|package_json| {
package_json.path.parent() != lockfile.lock().filename.parent()
package_json.path.parent() != lockfile.inner().filename.parent()
})
.unwrap_or(false)
}
Expand All @@ -337,7 336,6 @@ impl CliFactory {
.unwrap_or_default()
})
.unwrap_or_default();
let mut lockfile = lockfile.lock();
let config = match self.options.maybe_workspace_config() {
Some(workspace_config) => deno_lockfile::WorkspaceConfig {
root: WorkspaceMemberConfig {
Expand Down
22 changes: 11 additions & 11 deletions cli/graph_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,6 @@

use crate::args::jsr_url;
use crate::args::CliOptions;
use crate::args::Lockfile;
use crate::args::DENO_DISABLE_PEDANTIC_NODE_WARNINGS;
use crate::cache;
use crate::cache::GlobalHttpCache;
Expand All @@ -11,6 10,7 @@ use crate::cache::ParsedSourceCache;
use crate::colors;
use crate::errors::get_error_class_name;
use crate::file_fetcher::FileFetcher;
use crate::lockfile::CliLockfile;
use crate::npm::CliNpmResolver;
use crate::resolver::CliGraphResolver;
use crate::resolver::SloppyImportsResolver;
Expand Down Expand Up @@ -354,7 354,7 @@ pub struct ModuleGraphBuilder {
npm_resolver: Arc<dyn CliNpmResolver>,
module_info_cache: Arc<ModuleInfoCache>,
parsed_source_cache: Arc<ParsedSourceCache>,
lockfile: Option<Arc<Mutex<Lockfile>>>,
lockfile: Option<Arc<CliLockfile>>,
maybe_file_watcher_reporter: Option<FileWatcherReporter>,
emit_cache: cache::EmitCache,
file_fetcher: Arc<FileFetcher>,
Expand All @@ -371,7 371,7 @@ impl ModuleGraphBuilder {
npm_resolver: Arc<dyn CliNpmResolver>,
module_info_cache: Arc<ModuleInfoCache>,
parsed_source_cache: Arc<ParsedSourceCache>,
lockfile: Option<Arc<Mutex<Lockfile>>>,
lockfile: Option<Arc<CliLockfile>>,
maybe_file_watcher_reporter: Option<FileWatcherReporter>,
emit_cache: cache::EmitCache,
file_fetcher: Arc<FileFetcher>,
Expand Down Expand Up @@ -412,7 412,7 @@ impl ModuleGraphBuilder {
}
}

struct LockfileLocker<'a>(&'a Mutex<Lockfile>);
struct LockfileLocker<'a>(&'a CliLockfile);

impl<'a> deno_graph::source::Locker for LockfileLocker<'a> {
fn get_remote_checksum(
Expand All @@ -421,7 421,7 @@ impl ModuleGraphBuilder {
) -> Option<LoaderChecksum> {
self
.0
.lock()
.inner()
.remote()
.get(specifier.as_str())
.map(|s| LoaderChecksum::new(s.clone()))
Expand All @@ -431,7 431,7 @@ impl ModuleGraphBuilder {
&self,
specifier: &deno_ast::ModuleSpecifier,
) -> bool {
self.0.lock().remote().contains_key(specifier.as_str())
self.0.inner().remote().contains_key(specifier.as_str())
}

fn set_remote_checksum(
Expand All @@ -441,7 441,7 @@ impl ModuleGraphBuilder {
) {
self
.0
.lock()
.inner()
.insert_remote(specifier.to_string(), checksum.into_string())
}

Expand All @@ -451,7 451,7 @@ impl ModuleGraphBuilder {
) -> Option<LoaderChecksum> {
self
.0
.lock()
.inner()
.content
.packages
.jsr
Expand All @@ -468,7 468,7 @@ impl ModuleGraphBuilder {
// to insert the same package manifest checksum
self
.0
.lock()
.inner()
.insert_package(package_nv.to_string(), checksum.into_string());
}
}
Expand Down Expand Up @@ -537,7 537,7 @@ impl ModuleGraphBuilder {
if is_first_execution {
// populate the information from the lockfile
if let Some(lockfile) = &self.lockfile {
let lockfile = lockfile.lock();
let lockfile = lockfile.inner();
for (from, to) in &lockfile.content.redirects {
if let Ok(from) = ModuleSpecifier::parse(from) {
if let Ok(to) = ModuleSpecifier::parse(to) {
Expand Down Expand Up @@ -580,7 580,7 @@ impl ModuleGraphBuilder {
|| has_jsr_package_mappings_changed
{
if let Some(lockfile) = &self.lockfile {
let mut lockfile = lockfile.lock();
let mut lockfile = lockfile.inner();
// https redirects
if has_redirects_changed {
let graph_redirects = graph.redirects.iter().filter(|(from, _)| {
Expand Down
Loading