summaryrefslogtreecommitdiff
path: root/cli/npm/managed/mod.rs
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-06-28 17:18:21 -0700
committerGitHub <noreply@github.com>2024-06-28 17:18:21 -0700
commitbc8a0e6e68547cf07a246b8b6c886de155dc8282 (patch)
treea3540b01218c4674c399eb770c0f08e5ba594793 /cli/npm/managed/mod.rs
parent2ddae872f956ddd84656a302aa5f6b752f6a6ab5 (diff)
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
Diffstat (limited to 'cli/npm/managed/mod.rs')
-rw-r--r--cli/npm/managed/mod.rs22
1 files changed, 9 insertions, 13 deletions
diff --git a/cli/npm/managed/mod.rs b/cli/npm/managed/mod.rs
index c086235c3..f0fc0f7f7 100644
--- a/cli/npm/managed/mod.rs
+++ b/cli/npm/managed/mod.rs
@@ -9,7 +9,6 @@ use cache::TarballCache;
use deno_ast::ModuleSpecifier;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
-use deno_core::parking_lot::Mutex;
use deno_core::serde_json;
use deno_npm::npm_rc::ResolvedNpmRc;
use deno_npm::registry::NpmPackageInfo;
@@ -27,7 +26,7 @@ use deno_semver::package::PackageNv;
use deno_semver::package::PackageReq;
use resolution::AddPkgReqsResult;
-use crate::args::Lockfile;
+use crate::args::CliLockfile;
use crate::args::NpmProcessState;
use crate::args::NpmProcessStateKind;
use crate::args::PackageJsonDepsProvider;
@@ -53,13 +52,13 @@ mod resolution;
mod resolvers;
pub enum CliNpmResolverManagedSnapshotOption {
- ResolveFromLockfile(Arc<Mutex<Lockfile>>),
+ ResolveFromLockfile(Arc<CliLockfile>),
Specified(Option<ValidSerializedNpmResolutionSnapshot>),
}
pub struct CliNpmResolverManagedCreateOptions {
pub snapshot: CliNpmResolverManagedSnapshotOption,
- pub maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
+ pub maybe_lockfile: Option<Arc<CliLockfile>>,
pub fs: Arc<dyn deno_runtime::deno_fs::FileSystem>,
pub http_client_provider: Arc<crate::http_util::HttpClientProvider>,
pub npm_global_cache_dir: PathBuf,
@@ -128,7 +127,7 @@ pub async fn create_managed_npm_resolver(
fn create_inner(
fs: Arc<dyn deno_runtime::deno_fs::FileSystem>,
http_client_provider: Arc<HttpClientProvider>,
- maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
+ maybe_lockfile: Option<Arc<CliLockfile>>,
npm_api: Arc<CliNpmRegistryApi>,
npm_cache: Arc<NpmCache>,
npm_rc: Arc<ResolvedNpmRc>,
@@ -205,14 +204,11 @@ async fn resolve_snapshot(
) -> Result<Option<ValidSerializedNpmResolutionSnapshot>, AnyError> {
match snapshot {
CliNpmResolverManagedSnapshotOption::ResolveFromLockfile(lockfile) => {
- if !lockfile.lock().overwrite {
+ if !lockfile.overwrite() {
let snapshot = snapshot_from_lockfile(lockfile.clone(), api)
.await
.with_context(|| {
- format!(
- "failed reading lockfile '{}'",
- lockfile.lock().filename.display()
- )
+ format!("failed reading lockfile '{}'", lockfile.filename.display())
})?;
Ok(Some(snapshot))
} else {
@@ -224,7 +220,7 @@ async fn resolve_snapshot(
}
async fn snapshot_from_lockfile(
- lockfile: Arc<Mutex<Lockfile>>,
+ lockfile: Arc<CliLockfile>,
api: &dyn NpmRegistryApi,
) -> Result<ValidSerializedNpmResolutionSnapshot, AnyError> {
let (incomplete_snapshot, skip_integrity_check) = {
@@ -250,7 +246,7 @@ async fn snapshot_from_lockfile(
pub struct ManagedCliNpmResolver {
fs: Arc<dyn FileSystem>,
fs_resolver: Arc<dyn NpmPackageFsResolver>,
- maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
+ maybe_lockfile: Option<Arc<CliLockfile>>,
npm_api: Arc<CliNpmRegistryApi>,
npm_cache: Arc<NpmCache>,
package_json_deps_provider: Arc<PackageJsonDepsProvider>,
@@ -274,7 +270,7 @@ impl ManagedCliNpmResolver {
pub fn new(
fs: Arc<dyn FileSystem>,
fs_resolver: Arc<dyn NpmPackageFsResolver>,
- maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
+ maybe_lockfile: Option<Arc<CliLockfile>>,
npm_api: Arc<CliNpmRegistryApi>,
npm_cache: Arc<NpmCache>,
package_json_deps_provider: Arc<PackageJsonDepsProvider>,