Skip to content

Commit

Permalink
Support module_resolution: "nodenext"
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Jul 15, 2024
1 parent a482caa commit 1a8f574
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/turbopack-core/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,18 @@ async fn resolve_relative_request(

let fragment_val = fragment.await?;

if !options_value.fully_specified && options_value.enable_js_ts_rewriting {
// TODO path_pattern might not be a constant?
// TODO extension might be empty, or dots in filepath
if let Pattern::Constant(s) = path_pattern {
if let Some((base, _ext)) = s.rsplit_once(".") {
new_path = Pattern::Alternatives(vec![Pattern::Constant(base.into()), new_path])
}
} else {
todo!("enable_js_ts_rewriting");
}
}

if !fragment_val.is_empty() {
new_path.push(Pattern::Alternatives(
once(Pattern::Constant("".into()))
Expand Down
1 change: 1 addition & 0 deletions crates/turbopack-core/src/resolve/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ pub struct ResolveOptions {
pub before_resolve_plugins: Vec<Vc<Box<dyn BeforeResolvePlugin>>>,
pub plugins: Vec<Vc<Box<dyn AfterResolvePlugin>>>,
pub placeholder_for_future_extensions: (),
pub enable_js_ts_rewriting: bool,
}

#[turbo_tasks::value_impl]
Expand Down
18 changes: 18 additions & 0 deletions crates/turbopack-resolve/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ pub async fn read_from_tsconfigs<T>(
pub struct TsConfigResolveOptions {
base_url: Option<Vc<FileSystemPath>>,
import_map: Option<Vc<ImportMap>>,
// TODO Vc<bool> ?
is_module_resolution_nodenext: Option<bool>,
}

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -318,9 +320,17 @@ pub async fn tsconfig_resolve_options(
None
};

let is_module_resolution_nodenext = read_from_tsconfigs(&configs, |json, _| {
json["compilerOptions"]["moduleResolution"]
.as_str()
.map(|module_resolution| module_resolution.eq_ignore_ascii_case("nodenext"))
})
.await?;

Ok(TsConfigResolveOptions {
base_url,
import_map,
is_module_resolution_nodenext,
}
.cell())
}
Expand Down Expand Up @@ -352,6 +362,14 @@ pub async fn apply_tsconfig_resolve_options(
.unwrap_or(tsconfig_import_map),
);
}
// TODO precedence, OR or AND with existing resolve_options value?
if let Some(is_module_resolution_nodenext) =
tsconfig_resolve_options.is_module_resolution_nodenext
{
if is_module_resolution_nodenext {
resolve_options.enable_js_ts_rewriting = is_module_resolution_nodenext
}
}
Ok(resolve_options.cell())
}

Expand Down

0 comments on commit 1a8f574

Please sign in to comment.