summaryrefslogtreecommitdiff
path: root/resolvers
diff options
context:
space:
mode:
Diffstat (limited to 'resolvers')
-rw-r--r--resolvers/node/package_json.rs4
-rw-r--r--resolvers/node/resolution.rs23
2 files changed, 16 insertions, 11 deletions
diff --git a/resolvers/node/package_json.rs b/resolvers/node/package_json.rs
index 6967779e5..ae016ebe3 100644
--- a/resolvers/node/package_json.rs
+++ b/resolvers/node/package_json.rs
@@ -15,8 +15,8 @@ use crate::errors::CanonicalizingPkgJsonDirError;
use crate::errors::ClosestPkgJsonError;
use crate::errors::PackageJsonLoadError;
-// todo(dsherret): this isn't exactly correct and we should change it to instead
-// be created per worker and passed down as a ctor arg to the pkg json resolver
+// it would be nice if this was passed down as a ctor arg to the package.json resolver,
+// but it's a little bit complicated to do that, so we just maintain a thread local cache
thread_local! {
static CACHE: RefCell<HashMap<PathBuf, PackageJsonRc>> = RefCell::new(HashMap::new());
}
diff --git a/resolvers/node/resolution.rs b/resolvers/node/resolution.rs
index d44539e97..fcff29242 100644
--- a/resolvers/node/resolution.rs
+++ b/resolvers/node/resolution.rs
@@ -50,6 +50,15 @@ pub static DEFAULT_CONDITIONS: &[&str] = &["deno", "node", "import"];
pub static REQUIRE_CONDITIONS: &[&str] = &["require", "node"];
static TYPES_ONLY_CONDITIONS: &[&str] = &["types"];
+fn conditions_from_module_kind(
+ kind: NodeModuleKind,
+) -> &'static [&'static str] {
+ match kind {
+ NodeModuleKind::Esm => DEFAULT_CONDITIONS,
+ NodeModuleKind::Cjs => REQUIRE_CONDITIONS,
+ }
+}
+
pub type NodeModuleKind = deno_package_json::NodeModuleKind;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -166,8 +175,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
specifier,
referrer,
referrer_kind,
- // even though the referrer may be CJS, if we're here that means we're doing ESM resolution
- DEFAULT_CONDITIONS,
+ conditions_from_module_kind(referrer_kind),
mode,
)?;
@@ -299,9 +307,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
package_dir: &Path,
package_subpath: Option<&str>,
maybe_referrer: Option<&Url>,
+ referrer_kind: NodeModuleKind,
mode: NodeResolutionMode,
) -> Result<Url, PackageSubpathResolveError> {
- let node_module_kind = NodeModuleKind::Esm;
let package_subpath = package_subpath
.map(|s| format!("./{s}"))
.unwrap_or_else(|| ".".to_string());
@@ -309,8 +317,8 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
package_dir,
&package_subpath,
maybe_referrer,
- node_module_kind,
- DEFAULT_CONDITIONS,
+ referrer_kind,
+ conditions_from_module_kind(referrer_kind),
mode,
)?;
// TODO(bartlomieju): skipped checking errors for commonJS resolution and
@@ -441,10 +449,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
/* sub path */ ".",
maybe_referrer,
referrer_kind,
- match referrer_kind {
- NodeModuleKind::Esm => DEFAULT_CONDITIONS,
- NodeModuleKind::Cjs => REQUIRE_CONDITIONS,
- },
+ conditions_from_module_kind(referrer_kind),
NodeResolutionMode::Types,
);
if let Ok(resolution) = resolution_result {