diff options
Diffstat (limited to 'cli/npm/resolvers/mod.rs')
-rw-r--r-- | cli/npm/resolvers/mod.rs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/cli/npm/resolvers/mod.rs b/cli/npm/resolvers/mod.rs index 039864c5f..583a1c955 100644 --- a/cli/npm/resolvers/mod.rs +++ b/cli/npm/resolvers/mod.rs @@ -19,7 +19,7 @@ use deno_runtime::deno_node::RequireNpmResolver; use global::GlobalNpmPackageResolver; use serde::Deserialize; use serde::Serialize; -use std::collections::HashSet; +use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; use std::sync::Arc; @@ -214,9 +214,9 @@ impl NpmPackageResolver { /// Gets if the provided specifier is in an npm package. pub fn in_npm_package(&self, specifier: &ModuleSpecifier) -> bool { - self - .resolve_package_folder_from_specifier(specifier) - .is_ok() + let root_dir_url = self.fs_resolver.root_dir_url(); + debug_assert!(root_dir_url.as_str().ends_with('/')); + specifier.as_ref().starts_with(root_dir_url.as_str()) } /// If the resolver has resolved any npm packages. @@ -224,6 +224,19 @@ impl NpmPackageResolver { self.resolution.has_packages() } + /// Adds the package reqs from a package.json if they exist. + pub async fn add_package_json_deps( + &self, + maybe_package_json_deps: Option<&HashMap<String, NpmPackageReq>>, + ) -> Result<(), AnyError> { + if let Some(deps) = maybe_package_json_deps { + let mut package_reqs = deps.values().cloned().collect::<Vec<_>>(); + package_reqs.sort(); // deterministic resolution + self.add_package_reqs(package_reqs).await?; + } + Ok(()) + } + /// Adds package requirements to the resolver and ensures everything is setup. pub async fn add_package_reqs( &self, @@ -250,7 +263,7 @@ impl NpmPackageResolver { /// This will retrieve and resolve package information, but not cache any package files. pub async fn set_package_reqs( &self, - packages: HashSet<NpmPackageReq>, + packages: Vec<NpmPackageReq>, ) -> Result<(), AnyError> { self.resolution.set_package_reqs(packages).await } |