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

fix(node): better detection for when to surface node resolution errors #24653

Merged
merged 10 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 8 additions & 9 deletions cli/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,14 @@ impl<TGraphContainer: ModuleGraphContainer>
specifier: &str,
referrer: &ModuleSpecifier,
) -> Result<ModuleSpecifier, AnyError> {
if let Some(result) = self.shared.node_resolver.resolve_if_in_npm_package(
specifier,
referrer,
NodeResolutionMode::Execution,
) {
return match result? {
Some(res) => Ok(res.into_url()),
None => Err(generic_error("not found")),
};
if self.shared.node_resolver.in_npm_package(referrer) {
return Ok(
self
.shared
.node_resolver
.resolve(specifier, referrer, NodeResolutionMode::Execution)?
.into_url(),
);
}

let graph = self.graph_container.graph();
Expand Down
7 changes: 4 additions & 3 deletions cli/npm/byonm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use deno_core::serde_json;
use deno_package_json::PackageJsonDepValue;
use deno_runtime::deno_fs::FileSystem;
use deno_runtime::deno_node::errors::PackageFolderResolveError;
use deno_runtime::deno_node::errors::PackageFolderResolveErrorKind;
use deno_runtime::deno_node::errors::PackageFolderResolveIoError;
use deno_runtime::deno_node::errors::PackageNotFoundError;
use deno_runtime::deno_node::load_pkg_json;
use deno_runtime::deno_node::NodePermissions;
use deno_runtime::deno_node::NpmResolver;
Expand Down Expand Up @@ -198,7 +199,7 @@ impl NpmResolver for ByonmCliNpmResolver {
}

Err(
PackageFolderResolveErrorKind::NotFoundPackage {
PackageNotFoundError {
package_name: name.to_string(),
referrer: referrer.clone(),
referrer_extra: None,
Expand All @@ -209,7 +210,7 @@ impl NpmResolver for ByonmCliNpmResolver {

let path = inner(&*self.fs, name, referrer)?;
self.fs.realpath_sync(&path).map_err(|err| {
PackageFolderResolveErrorKind::Io {
PackageFolderResolveIoError {
package_name: name.to_string(),
referrer: referrer.clone(),
source: err.into_io_error(),
Expand Down
4 changes: 2 additions & 2 deletions cli/npm/managed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use deno_npm::NpmResolutionPackage;
use deno_npm::NpmSystemInfo;
use deno_runtime::deno_fs::FileSystem;
use deno_runtime::deno_node::errors::PackageFolderResolveError;
use deno_runtime::deno_node::errors::PackageFolderResolveErrorKind;
use deno_runtime::deno_node::errors::PackageFolderResolveIoError;
use deno_runtime::deno_node::NodePermissions;
use deno_runtime::deno_node::NpmResolver;
use deno_semver::package::PackageNv;
Expand Down Expand Up @@ -549,7 +549,7 @@ impl NpmResolver for ManagedCliNpmResolver {
.resolve_package_folder_from_package(name, referrer)?;
let path =
canonicalize_path_maybe_not_exists_with_fs(&path, self.fs.as_ref())
.map_err(|err| PackageFolderResolveErrorKind::Io {
.map_err(|err| PackageFolderResolveIoError {
package_name: name.to_string(),
referrer: referrer.clone(),
source: err,
Expand Down
11 changes: 6 additions & 5 deletions cli/npm/managed/resolvers/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use deno_npm::NpmPackageId;
use deno_npm::NpmSystemInfo;
use deno_runtime::deno_fs::FileSystem;
use deno_runtime::deno_node::errors::PackageFolderResolveError;
use deno_runtime::deno_node::errors::PackageFolderResolveErrorKind;
use deno_runtime::deno_node::errors::PackageNotFoundError;
use deno_runtime::deno_node::errors::ReferrerNotFoundError;
use deno_runtime::deno_node::NodePermissions;

use super::super::cache::NpmCache;
Expand Down Expand Up @@ -84,7 +85,7 @@ impl NpmPackageFsResolver for GlobalNpmPackageResolver {
.resolve_package_folder_id_from_specifier(referrer)
else {
return Err(
PackageFolderResolveErrorKind::NotFoundReferrer {
ReferrerNotFoundError {
referrer: referrer.clone(),
referrer_extra: None,
}
Expand All @@ -98,7 +99,7 @@ impl NpmPackageFsResolver for GlobalNpmPackageResolver {
Ok(pkg) => match self.maybe_package_folder(&pkg.id) {
Some(folder) => Ok(folder),
None => Err(
PackageFolderResolveErrorKind::NotFoundPackage {
PackageNotFoundError {
package_name: name.to_string(),
referrer: referrer.clone(),
referrer_extra: Some(format!(
Expand All @@ -112,7 +113,7 @@ impl NpmPackageFsResolver for GlobalNpmPackageResolver {
},
Err(err) => match *err {
PackageNotFoundFromReferrerError::Referrer(cache_folder_id) => Err(
PackageFolderResolveErrorKind::NotFoundReferrer {
ReferrerNotFoundError {
referrer: referrer.clone(),
referrer_extra: Some(cache_folder_id.to_string()),
}
Expand All @@ -122,7 +123,7 @@ impl NpmPackageFsResolver for GlobalNpmPackageResolver {
name,
referrer: cache_folder_id_referrer,
} => Err(
PackageFolderResolveErrorKind::NotFoundPackage {
PackageNotFoundError {
package_name: name,
referrer: referrer.clone(),
referrer_extra: Some(cache_folder_id_referrer.to_string()),
Expand Down
10 changes: 6 additions & 4 deletions cli/npm/managed/resolvers/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ use deno_npm::NpmResolutionPackage;
use deno_npm::NpmSystemInfo;
use deno_runtime::deno_fs;
use deno_runtime::deno_node::errors::PackageFolderResolveError;
use deno_runtime::deno_node::errors::PackageFolderResolveErrorKind;
use deno_runtime::deno_node::errors::PackageFolderResolveIoError;
use deno_runtime::deno_node::errors::PackageNotFoundError;
use deno_runtime::deno_node::errors::ReferrerNotFoundError;
use deno_runtime::deno_node::NodePermissions;
use deno_semver::package::PackageNv;
use serde::Deserialize;
Expand Down Expand Up @@ -185,14 +187,14 @@ impl NpmPackageFsResolver for LocalNpmPackageResolver {
) -> Result<PathBuf, PackageFolderResolveError> {
let maybe_local_path = self
.resolve_folder_for_specifier(referrer)
.map_err(|err| PackageFolderResolveErrorKind::Io {
.map_err(|err| PackageFolderResolveIoError {
package_name: name.to_string(),
referrer: referrer.clone(),
source: err,
})?;
let Some(local_path) = maybe_local_path else {
return Err(
PackageFolderResolveErrorKind::NotFoundReferrer {
ReferrerNotFoundError {
referrer: referrer.clone(),
referrer_extra: None,
}
Expand Down Expand Up @@ -220,7 +222,7 @@ impl NpmPackageFsResolver for LocalNpmPackageResolver {
}

Err(
PackageFolderResolveErrorKind::NotFoundPackage {
PackageNotFoundError {
package_name: name.to_string(),
referrer: referrer.clone(),
referrer_extra: None,
Expand Down
Loading