From bc8a0e6e68547cf07a246b8b6c886de155dc8282 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Fri, 28 Jun 2024 17:18:21 -0700 Subject: refactor(cli): Create wrapper around `deno_lockfile::Lockfile` (#24366) As suggested in https://github.com/denoland/deno/pull/24355#discussion_r1657875422. I wasn't able to hide the mutex stuff as much as I'd like (ended up just adding an escape hatch `inner()` method that locks the inner mutex), because you can't return references to the inner fields through a mutex. This is mostly motivated by the frozen lockfile changes --- cli/worker.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'cli/worker.rs') diff --git a/cli/worker.rs b/cli/worker.rs index 420d92c02..00a20ab4d 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -10,7 +10,6 @@ use deno_config::package_json::PackageJsonDeps; use deno_core::anyhow::bail; use deno_core::error::AnyError; use deno_core::futures::FutureExt; -use deno_core::parking_lot::Mutex; use deno_core::url::Url; use deno_core::v8; use deno_core::CompiledWasmModuleStore; @@ -21,7 +20,6 @@ use deno_core::ModuleLoader; use deno_core::PollEventLoopOptions; use deno_core::SharedArrayBufferStore; use deno_core::SourceMapGetter; -use deno_lockfile::Lockfile; use deno_runtime::code_cache; use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel; use deno_runtime::deno_fs; @@ -47,7 +45,7 @@ use deno_semver::package::PackageReqReference; use deno_terminal::colors; use tokio::select; -use crate::args::write_lockfile_if_has_changes; +use crate::args::CliLockfile; use crate::args::DenoSubcommand; use crate::args::StorageKeyResolver; use crate::errors; @@ -139,7 +137,7 @@ struct SharedWorkerState { fs: Arc, maybe_file_watcher_communicator: Option>, maybe_inspector_server: Option>, - maybe_lockfile: Option>>, + maybe_lockfile: Option>, feature_checker: Arc, node_ipc: Option, enable_future_features: bool, @@ -412,7 +410,7 @@ impl CliMainWorkerFactory { fs: Arc, maybe_file_watcher_communicator: Option>, maybe_inspector_server: Option>, - maybe_lockfile: Option>>, + maybe_lockfile: Option>, feature_checker: Arc, options: CliMainWorkerOptions, node_ipc: Option, @@ -529,7 +527,7 @@ impl CliMainWorkerFactory { // For npm binary commands, ensure that the lockfile gets updated // so that we can re-use the npm resolution the next time it runs // for better performance - write_lockfile_if_has_changes(&mut lockfile.lock())?; + lockfile.write_if_changed()?; } (node_resolution.into_url(), is_main_cjs) -- cgit v1.2.3