summaryrefslogtreecommitdiff
path: root/cli/npm/resolvers/common.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-02-22 14:15:25 -0500
committerGitHub <noreply@github.com>2023-02-22 14:15:25 -0500
commita6ca4d0d61c95b9f7fa79ecce81a31a6d1f6cc5d (patch)
tree278a915d7722a8a3d1fffbfa1f3a12752f44d13f /cli/npm/resolvers/common.rs
parent0f9daaeacb402a7199e58b14ad01ec0091ac2c8d (diff)
refactor: use deno_graph for npm specifiers (#17858)
This changes npm specifiers to be handled by deno_graph and resolved to an npm package name and version when the specifier is encountered. It also slightly changes how npm specifier resolution occurs—previously it would collect all the npm specifiers and resolve them all at once, but now it resolves them on the fly as they are encountered in the module graph. https://github.com/denoland/deno_graph/pull/232 --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/npm/resolvers/common.rs')
-rw-r--r--cli/npm/resolvers/common.rs36
1 files changed, 7 insertions, 29 deletions
diff --git a/cli/npm/resolvers/common.rs b/cli/npm/resolvers/common.rs
index 2b02e7721..8c1ecd892 100644
--- a/cli/npm/resolvers/common.rs
+++ b/cli/npm/resolvers/common.rs
@@ -1,30 +1,28 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-use std::collections::HashSet;
use std::io::ErrorKind;
use std::path::Path;
use std::path::PathBuf;
+use async_trait::async_trait;
use deno_ast::ModuleSpecifier;
use deno_core::error::AnyError;
use deno_core::futures;
-use deno_core::futures::future::BoxFuture;
use deno_core::url::Url;
-use deno_graph::npm::NpmPackageReq;
use deno_runtime::deno_node::NodePermissions;
use deno_runtime::deno_node::NodeResolutionMode;
-use crate::args::Lockfile;
use crate::npm::cache::should_sync_download;
-use crate::npm::resolution::NpmResolutionSnapshot;
use crate::npm::NpmCache;
use crate::npm::NpmPackageId;
use crate::npm::NpmResolutionPackage;
-pub trait InnerNpmPackageResolver: Send + Sync {
+/// Part of the resolution that interacts with the file system.
+#[async_trait]
+pub trait NpmPackageFsResolver: Send + Sync {
fn resolve_package_folder_from_deno_module(
&self,
- pkg_req: &NpmPackageReq,
+ id: &NpmPackageId,
) -> Result<PathBuf, AnyError>;
fn resolve_package_folder_from_package(
@@ -41,29 +39,13 @@ pub trait InnerNpmPackageResolver: Send + Sync {
fn package_size(&self, package_id: &NpmPackageId) -> Result<u64, AnyError>;
- fn has_packages(&self) -> bool;
-
- fn add_package_reqs(
- &self,
- packages: Vec<NpmPackageReq>,
- ) -> BoxFuture<'static, Result<(), AnyError>>;
-
- fn set_package_reqs(
- &self,
- packages: HashSet<NpmPackageReq>,
- ) -> BoxFuture<'static, Result<(), AnyError>>;
-
- fn cache_packages(&self) -> BoxFuture<'static, Result<(), AnyError>>;
+ async fn cache_packages(&self) -> Result<(), AnyError>;
fn ensure_read_permission(
&self,
permissions: &mut dyn NodePermissions,
path: &Path,
) -> Result<(), AnyError>;
-
- fn snapshot(&self) -> NpmResolutionSnapshot;
-
- fn lock(&self, lockfile: &mut Lockfile) -> Result<(), AnyError>;
}
/// Caches all the packages in parallel.
@@ -86,11 +68,7 @@ pub async fn cache_packages(
let registry_url = registry_url.clone();
let handle = tokio::task::spawn(async move {
cache
- .ensure_package(
- (package.pkg_id.nv.name.as_str(), &package.pkg_id.nv.version),
- &package.dist,
- &registry_url,
- )
+ .ensure_package(&package.pkg_id.nv, &package.dist, &registry_url)
.await
});
if sync_download {