Skip to content

Commit bcf1978

Browse files
committed
fix: resolve dir index with dot specifier correctly
1 parent 52f8e2b commit bcf1978

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed
File renamed without changes.

fixtures/dot/foo/index.js

Whitespace-only changes.

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,10 @@ impl<C: Cache<Cp = FsCachedPath>> ResolverGeneric<C> {
435435
let cached_path = cached_path.normalize_with(specifier, self.cache.as_ref());
436436
// a. LOAD_AS_FILE(Y + X)
437437
// b. LOAD_AS_DIRECTORY(Y + X)
438-
if specifier == "." || specifier == "./" {
439-
let cached_path =
440-
cached_path.clone().normalize_with("../index.js", self.cache.as_ref());
438+
if !self.options.fully_specified && (specifier == "." || specifier == "./") {
439+
let sub_path =
440+
if self.cache.is_dir(&cached_path, ctx) { "./index.js" } else { "../index.js" };
441+
let cached_path = cached_path.clone().normalize_with(sub_path, self.cache.as_ref());
441442
if self.cache.is_file(&cached_path, ctx) {
442443
return Ok(cached_path);
443444
}

src/tests/resolve.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,15 @@ fn prefer_file_over_dir() {
135135
#[test]
136136
fn resolve_dot() {
137137
let f = super::fixture_root().join("dot");
138-
let dot = f.join("dot.js");
138+
let foo_dir: std::path::PathBuf = f.join("foo");
139+
let foo_dir_foo = foo_dir.join("foo.js");
139140
let resolver = Resolver::default();
141+
let foo_index = foo_dir.join("index.js");
140142
let data = [
141-
("dot", dot.clone(), ".", f.join("index.js")),
142-
("dot slash", dot, "./", f.join("index.js")),
143+
("dot file", foo_dir_foo.clone(), ".", foo_index.clone()),
144+
("dot file slash", foo_dir_foo, "./", foo_index.clone()),
145+
("dot dir", foo_dir.clone(), ".", foo_index.clone()),
146+
("dot dir slash", foo_dir, "./", foo_index),
143147
];
144148
for (comment, path, request, expected) in data {
145149
let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path());

0 commit comments

Comments
 (0)