Skip to content

Commit 7ea7e65

Browse files
committed
fix: skip loading tsconfig.json from virtual module paths (#809)
refs #758 fixes, vitejs/rolldown-vite#477 The tests passes without the change, but covers the new `if`. To make a test that fails, we need to configure the cwd to a different path, but that makes the test more complex, so I didn't do that.
1 parent c957d95 commit 7ea7e65

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,17 +1505,12 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
15051505
if cached_path.inside_node_modules() {
15061506
return Ok(None);
15071507
}
1508-
1509-
let mut cache_value = cached_path.clone();
1510-
// Go up directories when the querying path is not a directory
1511-
while !self.cache.is_dir(&cache_value, ctx) {
1512-
if let Some(cv) = cache_value.parent() {
1513-
cache_value = cv;
1514-
} else {
1515-
break;
1516-
}
1508+
// Skip non-absolute paths (e.g. virtual modules)
1509+
if !cached_path.path.is_absolute() {
1510+
return Ok(None);
15171511
}
1518-
let mut cache_value = Some(cache_value);
1512+
1513+
let mut cache_value = Some(cached_path.clone());
15191514
while let Some(cv) = cache_value {
15201515
if let Some(tsconfig) = cv.tsconfig.get_or_try_init(|| {
15211516
let tsconfig_path = cv.path.join("tsconfig.json");

src/tests/tsconfig_discovery.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,24 @@
22
//!
33
//! Tests that tsconfig.json can be auto-discovered when no explicit tsconfig option is provided.
44
5+
use crate::{ResolveError, ResolveOptions, Resolver, TsconfigDiscovery};
6+
57
#[test]
68
fn tsconfig_discovery() {
79
super::tsconfig_paths::tsconfig_resolve_impl(/* tsconfig_discovery */ true);
810
}
11+
12+
#[test]
13+
fn tsconfig_discovery_virtual_file_importer() {
14+
let f = super::fixture_root().join("tsconfig");
15+
16+
let resolver = Resolver::new(ResolveOptions {
17+
tsconfig: Some(TsconfigDiscovery::Auto),
18+
cwd: Some(f.join("cases/index")),
19+
..ResolveOptions::default()
20+
});
21+
22+
let resolved_path =
23+
resolver.resolve("\0virtual-module", "random-import").map(|f| f.full_path());
24+
assert_eq!(resolved_path, Err(ResolveError::NotFound("random-import".into())));
25+
}

0 commit comments

Comments
 (0)