From e098afa4675bd3caac613502dec937d186382496 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:38:13 +0200 Subject: [PATCH 1/9] Add nodenext resolution test --- .../turbopack/resolving/tsconfig-nodenext/input/index.js | 5 +++++ .../turbopack/resolving/tsconfig-nodenext/input/src/foo.ts | 1 + .../resolving/tsconfig-nodenext/input/tsconfig.json | 5 +++++ 3 files changed, 11 insertions(+) create mode 100644 crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/index.js create mode 100644 crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo.ts create mode 100644 crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/tsconfig.json diff --git a/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/index.js b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/index.js new file mode 100644 index 0000000000000..1a5020c38792f --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/index.js @@ -0,0 +1,5 @@ +import foo from "./src/foo.js"; + +it("should correctly resolve explicit extensions with nodenext", () => { + expect(foo).toBe("foo"); +}); diff --git a/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo.ts b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo.ts new file mode 100644 index 0000000000000..60c6c8d8b04f9 --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo.ts @@ -0,0 +1 @@ +export default "foo"; diff --git a/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/tsconfig.json b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/tsconfig.json new file mode 100644 index 0000000000000..0d505be7b71a9 --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "moduleResolution": "NodeNext" + } +} From 0962bb71c5b4920389ccee1972f8de946b329f0d Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:38:59 +0200 Subject: [PATCH 2/9] Support `module_resolution: "nodenext"` --- crates/turbopack-core/src/resolve/mod.rs | 12 ++++++++++++ crates/turbopack-core/src/resolve/options.rs | 1 + crates/turbopack-resolve/src/typescript.rs | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/crates/turbopack-core/src/resolve/mod.rs b/crates/turbopack-core/src/resolve/mod.rs index aa92072afed30..27906ac82f4ca 100644 --- a/crates/turbopack-core/src/resolve/mod.rs +++ b/crates/turbopack-core/src/resolve/mod.rs @@ -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())) diff --git a/crates/turbopack-core/src/resolve/options.rs b/crates/turbopack-core/src/resolve/options.rs index 7472b946f9635..df40bcf33c2e5 100644 --- a/crates/turbopack-core/src/resolve/options.rs +++ b/crates/turbopack-core/src/resolve/options.rs @@ -443,6 +443,7 @@ pub struct ResolveOptions { pub before_resolve_plugins: Vec>>, pub plugins: Vec>>, pub placeholder_for_future_extensions: (), + pub enable_js_ts_rewriting: bool, } #[turbo_tasks::value_impl] diff --git a/crates/turbopack-resolve/src/typescript.rs b/crates/turbopack-resolve/src/typescript.rs index 0a3282f7dffe4..8453e59dd5b74 100644 --- a/crates/turbopack-resolve/src/typescript.rs +++ b/crates/turbopack-resolve/src/typescript.rs @@ -215,6 +215,8 @@ pub async fn read_from_tsconfigs( pub struct TsConfigResolveOptions { base_url: Option>, import_map: Option>, + // TODO Vc ? + is_module_resolution_nodenext: Option, } #[turbo_tasks::value_impl] @@ -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()) } @@ -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()) } From 61bb5af596ee5f8d359b290edbde90f9fb5617a0 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Mon, 15 Jul 2024 11:00:01 +0200 Subject: [PATCH 3/9] Only allow for `.../*.js` specifiers --- crates/turbopack-core/src/resolve/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/turbopack-core/src/resolve/mod.rs b/crates/turbopack-core/src/resolve/mod.rs index 27906ac82f4ca..5ad119726fda4 100644 --- a/crates/turbopack-core/src/resolve/mod.rs +++ b/crates/turbopack-core/src/resolve/mod.rs @@ -1925,8 +1925,10 @@ async fn resolve_relative_request( // 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]) + if let Some((base, ext)) = s.rsplit_once(".") { + if ext == "js" { + new_path = Pattern::Alternatives(vec![Pattern::Constant(base.into()), new_path]) + } } } else { todo!("enable_js_ts_rewriting"); From 847081e04e286571b3d2d91d899c78b2446c980c Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Wed, 17 Jul 2024 11:56:37 +0200 Subject: [PATCH 4/9] Cleanup config loading --- crates/turbopack-core/src/resolve/options.rs | 4 +++- crates/turbopack-resolve/src/typescript.rs | 16 +++++----------- .../tsconfig-nodenext/input/tsconfig.json | 1 + 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/crates/turbopack-core/src/resolve/options.rs b/crates/turbopack-core/src/resolve/options.rs index df40bcf33c2e5..853db395cd84c 100644 --- a/crates/turbopack-core/src/resolve/options.rs +++ b/crates/turbopack-core/src/resolve/options.rs @@ -442,8 +442,10 @@ pub struct ResolveOptions { pub resolved_map: Option>, pub before_resolve_plugins: Vec>>, pub plugins: Vec>>, - pub placeholder_for_future_extensions: (), + /// Support resolving *.js requests to *.ts files pub enable_js_ts_rewriting: bool, + + pub placeholder_for_future_extensions: (), } #[turbo_tasks::value_impl] diff --git a/crates/turbopack-resolve/src/typescript.rs b/crates/turbopack-resolve/src/typescript.rs index 8453e59dd5b74..613e37794efd1 100644 --- a/crates/turbopack-resolve/src/typescript.rs +++ b/crates/turbopack-resolve/src/typescript.rs @@ -215,8 +215,7 @@ pub async fn read_from_tsconfigs( pub struct TsConfigResolveOptions { base_url: Option>, import_map: Option>, - // TODO Vc ? - is_module_resolution_nodenext: Option, + is_module_resolution_nodenext: bool, } #[turbo_tasks::value_impl] @@ -325,7 +324,8 @@ pub async fn tsconfig_resolve_options( .as_str() .map(|module_resolution| module_resolution.eq_ignore_ascii_case("nodenext")) }) - .await?; + .await? + .unwrap_or_default(); Ok(TsConfigResolveOptions { base_url, @@ -362,14 +362,8 @@ 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 - } - } + resolve_options.enable_js_ts_rewriting = tsconfig_resolve_options.is_module_resolution_nodenext; + Ok(resolve_options.cell()) } diff --git a/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/tsconfig.json b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/tsconfig.json index 0d505be7b71a9..cb7f695badd8e 100644 --- a/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/tsconfig.json +++ b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "module": "NodeNext", "moduleResolution": "NodeNext" } } From 8c02b98b5ae11ab4b3d074bc8e39ab2b32edbcf5 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Wed, 17 Jul 2024 13:35:48 +0200 Subject: [PATCH 5/9] Properly rewrite the pattern --- crates/turbopack-core/src/resolve/mod.rs | 45 ++++++---- crates/turbopack-core/src/resolve/pattern.rs | 92 ++++++++++++++++++++ 2 files changed, 122 insertions(+), 15 deletions(-) diff --git a/crates/turbopack-core/src/resolve/mod.rs b/crates/turbopack-core/src/resolve/mod.rs index 5ad119726fda4..5f8a139fc66cf 100644 --- a/crates/turbopack-core/src/resolve/mod.rs +++ b/crates/turbopack-core/src/resolve/mod.rs @@ -1920,21 +1920,6 @@ async fn resolve_relative_request( let mut new_path = path_pattern.clone(); 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(".") { - if ext == "js" { - 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())) @@ -1957,6 +1942,36 @@ async fn resolve_relative_request( .collect(), )); + if options_value.enable_js_ts_rewriting { + let mut rewritten_path = path_pattern.clone(); + let rewritten_path_modified = + rewritten_path.replace_final_constants(&|c: &RcStr| -> Option { + let result = match c.rsplit_once(".") { + Some((base, "js")) => Some(( + base, + vec![ + Pattern::Constant(".ts".into()), + Pattern::Constant(".tsx".into()), + ], + )), + Some((base, "mjs")) => Some((base, vec![Pattern::Constant(".mts".into())])), + Some((base, "cjs")) => Some((base, vec![Pattern::Constant(".cts".into())])), + _ => None, + }; + result.map(|(base, replacement)| { + Pattern::Concatenation(vec![ + Pattern::Constant(base.into()), + Pattern::Alternatives(replacement), + ]) + }) + }); + + if rewritten_path_modified { + // Prepend the rewritten pattern to give it higher priority + new_path = Pattern::Alternatives(vec![rewritten_path, new_path]) + } + } + new_path.normalize(); }; diff --git a/crates/turbopack-core/src/resolve/pattern.rs b/crates/turbopack-core/src/resolve/pattern.rs index 825a3c766ff2d..337f0e02bb8b0 100644 --- a/crates/turbopack-core/src/resolve/pattern.rs +++ b/crates/turbopack-core/src/resolve/pattern.rs @@ -627,6 +627,33 @@ impl Pattern { new.normalize(); Pattern::alternatives([self.clone(), new]) } + + /// Calls `cb` on all constants that are at the end of the pattern and + /// replaces the given final constant with the returned pattern. Returns + /// true if replacements were performed. + pub fn replace_final_constants(&mut self, cb: &impl Fn(&RcStr) -> Option) -> bool { + let mut replaced = false; + match self { + Pattern::Constant(c) => { + if let Some(replacement) = cb(c) { + *self = replacement; + replaced = true; + } + } + Pattern::Dynamic => {} + Pattern::Alternatives(list) => { + for i in list { + replaced = i.replace_final_constants(cb) || replaced; + } + } + Pattern::Concatenation(list) => { + if let Some(c @ Pattern::Constant(_)) = list.last_mut() { + replaced = c.replace_final_constants(cb) || replaced; + } + } + } + replaced + } } impl Pattern { @@ -1097,6 +1124,7 @@ pub async fn read_matches( #[cfg(test)] mod tests { use rstest::*; + use turbo_tasks::RcStr; use super::Pattern; @@ -1344,4 +1372,68 @@ mod tests { ) { assert_eq!(pat.next_constants(value), expected); } + + #[test] + fn replace_final_constants() { + fn f(mut p: Pattern, cb: &impl Fn(&RcStr) -> Option) -> Pattern { + p.replace_final_constants(cb); + p + } + + let js_to_ts_tsx = |c: &RcStr| -> Option { + c.strip_suffix(".js").map(|rest| { + let new_ending = Pattern::Alternatives(vec![ + Pattern::Constant(".ts".into()), + Pattern::Constant(".tsx".into()), + ]); + if !rest.is_empty() { + Pattern::Concatenation(vec![Pattern::Constant(rest.into()), new_ending]) + } else { + new_ending + } + }) + }; + + assert_eq!( + f( + Pattern::Concatenation(vec![ + Pattern::Constant(".".into()), + Pattern::Constant("/".into()), + Pattern::Dynamic, + Pattern::Constant(".js".into()), + ]), + &js_to_ts_tsx + ), + Pattern::Concatenation(vec![ + Pattern::Constant(".".into()), + Pattern::Constant("/".into()), + Pattern::Dynamic, + Pattern::Alternatives(vec![ + Pattern::Constant(".ts".into()), + Pattern::Constant(".tsx".into()), + ]), + ]) + ); + assert_eq!( + f( + Pattern::Concatenation(vec![ + Pattern::Constant(".".into()), + Pattern::Constant("/".into()), + Pattern::Constant("abc.js".into()), + ]), + &js_to_ts_tsx + ), + Pattern::Concatenation(vec![ + Pattern::Constant(".".into()), + Pattern::Constant("/".into()), + Pattern::Concatenation(vec![ + Pattern::Constant("abc".into()), + Pattern::Alternatives(vec![ + Pattern::Constant(".ts".into()), + Pattern::Constant(".tsx".into()), + ]) + ]), + ]) + ); + } } From e37969a61ebfe9668a6bf8b445b8a8a0dddf2c7b Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:24:11 +0200 Subject: [PATCH 6/9] Rename to enable_typescript_with_output_extension --- crates/turbopack-core/src/resolve/mod.rs | 2 +- crates/turbopack-core/src/resolve/options.rs | 2 +- crates/turbopack-resolve/src/typescript.rs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/turbopack-core/src/resolve/mod.rs b/crates/turbopack-core/src/resolve/mod.rs index 5f8a139fc66cf..0ee2b583949ce 100644 --- a/crates/turbopack-core/src/resolve/mod.rs +++ b/crates/turbopack-core/src/resolve/mod.rs @@ -1942,7 +1942,7 @@ async fn resolve_relative_request( .collect(), )); - if options_value.enable_js_ts_rewriting { + if options_value.enable_typescript_with_output_extension { let mut rewritten_path = path_pattern.clone(); let rewritten_path_modified = rewritten_path.replace_final_constants(&|c: &RcStr| -> Option { diff --git a/crates/turbopack-core/src/resolve/options.rs b/crates/turbopack-core/src/resolve/options.rs index 853db395cd84c..c4c69142a9b26 100644 --- a/crates/turbopack-core/src/resolve/options.rs +++ b/crates/turbopack-core/src/resolve/options.rs @@ -443,7 +443,7 @@ pub struct ResolveOptions { pub before_resolve_plugins: Vec>>, pub plugins: Vec>>, /// Support resolving *.js requests to *.ts files - pub enable_js_ts_rewriting: bool, + pub enable_typescript_with_output_extension: bool, pub placeholder_for_future_extensions: (), } diff --git a/crates/turbopack-resolve/src/typescript.rs b/crates/turbopack-resolve/src/typescript.rs index 613e37794efd1..5d04cb9c027f3 100644 --- a/crates/turbopack-resolve/src/typescript.rs +++ b/crates/turbopack-resolve/src/typescript.rs @@ -362,7 +362,8 @@ pub async fn apply_tsconfig_resolve_options( .unwrap_or(tsconfig_import_map), ); } - resolve_options.enable_js_ts_rewriting = tsconfig_resolve_options.is_module_resolution_nodenext; + resolve_options.enable_typescript_with_output_extension = + tsconfig_resolve_options.is_module_resolution_nodenext; Ok(resolve_options.cell()) } From f07e80cbe58d00c8eef62d5039be7660554f0732 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:25:18 +0200 Subject: [PATCH 7/9] Fixup Pattern::replace_final_constants --- crates/turbopack-core/src/resolve/pattern.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/turbopack-core/src/resolve/pattern.rs b/crates/turbopack-core/src/resolve/pattern.rs index 337f0e02bb8b0..d20cb6c815737 100644 --- a/crates/turbopack-core/src/resolve/pattern.rs +++ b/crates/turbopack-core/src/resolve/pattern.rs @@ -647,8 +647,8 @@ impl Pattern { } } Pattern::Concatenation(list) => { - if let Some(c @ Pattern::Constant(_)) = list.last_mut() { - replaced = c.replace_final_constants(cb) || replaced; + if let Some(i) = list.last_mut() { + replaced = i.replace_final_constants(cb) || replaced; } } } From 51237d297d1a14c64ea199ca940d1d6b0ef01096 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:46:09 +0200 Subject: [PATCH 8/9] Replace inside new_path directly --- crates/turbopack-core/src/resolve/mod.rs | 72 +++++++++++--------- crates/turbopack-core/src/resolve/pattern.rs | 19 ++++-- 2 files changed, 55 insertions(+), 36 deletions(-) diff --git a/crates/turbopack-core/src/resolve/mod.rs b/crates/turbopack-core/src/resolve/mod.rs index 2a0c34535436b..d5f6ef629f176 100644 --- a/crates/turbopack-core/src/resolve/mod.rs +++ b/crates/turbopack-core/src/resolve/mod.rs @@ -1943,40 +1943,50 @@ async fn resolve_relative_request( ) .collect(), )); - - if options_value.enable_typescript_with_output_extension { - let mut rewritten_path = path_pattern.clone(); - let rewritten_path_modified = - rewritten_path.replace_final_constants(&|c: &RcStr| -> Option { - let result = match c.rsplit_once(".") { - Some((base, "js")) => Some(( - base, - vec![ - Pattern::Constant(".ts".into()), - Pattern::Constant(".tsx".into()), - ], - )), - Some((base, "mjs")) => Some((base, vec![Pattern::Constant(".mts".into())])), - Some((base, "cjs")) => Some((base, vec![Pattern::Constant(".cts".into())])), - _ => None, - }; - result.map(|(base, replacement)| { - Pattern::Concatenation(vec![ - Pattern::Constant(base.into()), - Pattern::Alternatives(replacement), - ]) - }) - }); - - if rewritten_path_modified { - // Prepend the rewritten pattern to give it higher priority - new_path = Pattern::Alternatives(vec![rewritten_path, new_path]) - } - } - new_path.normalize(); }; + if options_value.enable_typescript_with_output_extension { + new_path.replace_final_constants(&|c: &RcStr| -> Option { + let result = match c.rsplit_once(".") { + Some((base, "js")) => Some(( + base, + vec![ + Pattern::Constant(".ts".into()), + Pattern::Constant(".tsx".into()), + Pattern::Constant(".js".into()), + ], + )), + Some((base, "mjs")) => Some(( + base, + vec![ + Pattern::Constant(".mts".into()), + Pattern::Constant(".js".into()), + ], + )), + Some((base, "cjs")) => Some(( + base, + vec![ + Pattern::Constant(".cts".into()), + Pattern::Constant(".js".into()), + ], + )), + _ => None, + }; + result.map(|(base, replacement)| { + if base.is_empty() { + Pattern::Alternatives(replacement) + } else { + Pattern::Concatenation(vec![ + Pattern::Constant(base.into()), + Pattern::Alternatives(replacement), + ]) + } + }) + }); + new_path.normalize(); + } + let mut results = Vec::new(); let matches = read_matches( lookup_path, diff --git a/crates/turbopack-core/src/resolve/pattern.rs b/crates/turbopack-core/src/resolve/pattern.rs index 45f79240b0518..26702a53640b3 100644 --- a/crates/turbopack-core/src/resolve/pattern.rs +++ b/crates/turbopack-core/src/resolve/pattern.rs @@ -1399,6 +1399,7 @@ mod tests { let new_ending = Pattern::Alternatives(vec![ Pattern::Constant(".ts".into()), Pattern::Constant(".tsx".into()), + Pattern::Constant(".js".into()), ]); if !rest.is_empty() { Pattern::Concatenation(vec![Pattern::Constant(rest.into()), new_ending]) @@ -1414,7 +1415,10 @@ mod tests { Pattern::Constant(".".into()), Pattern::Constant("/".into()), Pattern::Dynamic, - Pattern::Constant(".js".into()), + Pattern::Alternatives(vec![ + Pattern::Constant(".js".into()), + Pattern::Constant(".node".into()), + ]) ]), &js_to_ts_tsx ), @@ -1423,10 +1427,14 @@ mod tests { Pattern::Constant("/".into()), Pattern::Dynamic, Pattern::Alternatives(vec![ - Pattern::Constant(".ts".into()), - Pattern::Constant(".tsx".into()), - ]), - ]) + Pattern::Alternatives(vec![ + Pattern::Constant(".ts".into()), + Pattern::Constant(".tsx".into()), + Pattern::Constant(".js".into()), + ]), + Pattern::Constant(".node".into()), + ]) + ]), ); assert_eq!( f( @@ -1445,6 +1453,7 @@ mod tests { Pattern::Alternatives(vec![ Pattern::Constant(".ts".into()), Pattern::Constant(".tsx".into()), + Pattern::Constant(".js".into()), ]) ]), ]) From bdce7e0b37a5b287567fa82b83ef27779e27123f Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Mon, 22 Jul 2024 12:58:17 +0200 Subject: [PATCH 9/9] Add more test cases --- .../turbopack/resolving/tsconfig-nodenext/input/index.js | 6 ++++++ .../turbopack/resolving/tsconfig-nodenext/input/src/bar.tsx | 1 + .../resolving/tsconfig-nodenext/input/src/foo-cjs.cts | 1 + .../resolving/tsconfig-nodenext/input/src/foo-esm.mts | 1 + .../turbopack/resolving/tsconfig-nodenext/input/src/foo.js | 1 + 5 files changed, 10 insertions(+) create mode 100644 crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/bar.tsx create mode 100644 crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo-cjs.cts create mode 100644 crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo-esm.mts create mode 100644 crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo.js diff --git a/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/index.js b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/index.js index 1a5020c38792f..3a0b2a12345ec 100644 --- a/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/index.js +++ b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/index.js @@ -1,5 +1,11 @@ import foo from "./src/foo.js"; +import bar from "./src/bar.js"; +import fooEsm from "./src/foo-esm.mjs"; +import fooCjs from "./src/foo-cjs.cjs"; it("should correctly resolve explicit extensions with nodenext", () => { expect(foo).toBe("foo"); + expect(bar).toBe("bar"); + expect(fooEsm).toBe("fooEsm"); + expect(fooCjs).toBe("fooCjs"); }); diff --git a/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/bar.tsx b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/bar.tsx new file mode 100644 index 0000000000000..801821e109c18 --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/bar.tsx @@ -0,0 +1 @@ +export default "bar"; diff --git a/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo-cjs.cts b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo-cjs.cts new file mode 100644 index 0000000000000..122dbfc3ec216 --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo-cjs.cts @@ -0,0 +1 @@ +module.exports = "fooCjs"; diff --git a/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo-esm.mts b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo-esm.mts new file mode 100644 index 0000000000000..4c5f085924c15 --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo-esm.mts @@ -0,0 +1 @@ +export default "fooEsm"; diff --git a/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo.js b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo.js new file mode 100644 index 0000000000000..fd7935a602d71 --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo.js @@ -0,0 +1 @@ +throw new Error("Should have a lower precedence than foo.ts");