1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00
This commit is contained in:
Benjamin Swerdlow 2025-01-10 14:13:28 -08:00
parent f51353879b
commit 12f061a860
4 changed files with 22 additions and 16 deletions

View file

@ -670,7 +670,7 @@ impl CliFactory {
.into_npm_pkg_folder_resolver(),
self.pkg_json_resolver().clone(),
self.sys(),
node_resolver::ConditionsFromResolutionMode::default_conditions(),
node_resolver::ConditionsFromResolutionMode::default(),
)))
}
.boxed_local(),

View file

@ -783,7 +783,7 @@ impl<'a> ResolverFactory<'a> {
npm_resolver.clone().into_npm_pkg_folder_resolver(),
self.pkg_json_resolver.clone(),
self.sys.clone(),
node_resolver::ConditionsFromResolutionMode::default_conditions(),
node_resolver::ConditionsFromResolutionMode::default(),
)))
})
.as_ref()

View file

@ -833,7 +833,7 @@ pub async fn run(
npm_resolver.clone().into_npm_pkg_folder_resolver(),
pkg_json_resolver.clone(),
sys.clone(),
node_resolver::ConditionsFromResolutionMode::default_conditions(),
node_resolver::ConditionsFromResolutionMode::default(),
));
let cjs_tracker = Arc::new(CjsTracker::new(
in_npm_pkg_checker.clone(),

View file

@ -55,21 +55,20 @@ pub static DEFAULT_CONDITIONS: &[&str] = &["deno", "node", "import"];
pub static REQUIRE_CONDITIONS: &[&str] = &["require", "node"];
static TYPES_ONLY_CONDITIONS: &[&str] = &["types"];
pub fn deno_conditions_from_resolution_mode(
resolution_mode: ResolutionMode,
) -> &'static [&'static str] {
match resolution_mode {
ResolutionMode::Import => DEFAULT_CONDITIONS,
ResolutionMode::Require => REQUIRE_CONDITIONS,
}
}
pub struct ConditionsFromResolutionMode {
func: Box<
dyn Fn(ResolutionMode) -> &'static [&'static str] + Send + Sync + 'static,
>,
}
impl Default for ConditionsFromResolutionMode {
fn default() -> Self {
Self {
func: Box::new(ResolutionMode::default_conditions),
}
}
}
impl Debug for ConditionsFromResolutionMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ConditionsFromResolutionMode").finish()
@ -77,10 +76,6 @@ impl Debug for ConditionsFromResolutionMode {
}
impl ConditionsFromResolutionMode {
pub fn default_conditions() -> Self {
Self::new(Box::new(deno_conditions_from_resolution_mode))
}
pub fn new(
func: Box<
dyn Fn(ResolutionMode) -> &'static [&'static str] + Send + Sync + 'static,
@ -96,6 +91,17 @@ pub enum ResolutionMode {
Require,
}
impl ResolutionMode {
fn default_conditions(
resolution_mode: ResolutionMode,
) -> &'static [&'static str] {
match resolution_mode {
ResolutionMode::Import => DEFAULT_CONDITIONS,
ResolutionMode::Require => REQUIRE_CONDITIONS,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NodeResolutionKind {
Execution,